History

lavu/frame: add QP side data

This adds a way for an API user to transfer QP data and metadata without having to keep the reference to AVFrame, and without having to explicitly care about QP APIs. It might also provide a way to finally remove the deprecated QP related fields. In the end, the QP table should be handled in a very similar way to e.g. AV_FRAME_DATA_MOTION_VECTORS. There are two side data types, because I didn't care about having to repack the QP data so the table and the metadata are in a single AVBufferRef. Otherwise it would have either required a copy on decoding (extra slowdown for something as obscure as the QP data), or would have required making intrusive changes to the codecs which support export of this data. The new side data types are added under deprecation guards, because I don't intend to change the status of the QP export as being deprecated (as it was before this patch too).

wm4 committed 8 years ago

Commit 4b86ac21 parent 36855ab6 files · +86 −7Browse files

Unified · Split

6 files
  1. doc/APIchanges +3 −0
  2. libavutil/frame.c +53 −6
  3. libavutil/frame.h +17 −0
  4. libavutil/version.h +1 −1
  5. tests/ref/fate/exif-image-embedded +6 −0
  6. tests/ref/fate/exif-image-jpg +6 −0
doc/APIchanges+3−0
@@ -15,6 +15,9 @@ libavutil: 2017-10-21 · 14 unmodified lines
1515
1616 API changes, most recent first:
1717
18+2018-03-18 - xxxxxxx - lavu 56.11.100 - frame.h
19+ Add AV_FRAME_DATA_QP_TABLE_PROPERTIES and AV_FRAME_DATA_QP_TABLE_DATA.
20+
1821 2018-03-15 - e0e72539cf - lavu 56.10.100 - opt.h
1922 Add AV_OPT_FLAG_BSF_PARAM
2023
libavutil/frame.c+53−6
@@ -46,8 +46,17 @@ MAKE_ACCESSORS(AVFrame, frame, enum AVColorRange, color_range) · 45 unmodified lines
4646 av_get_channel_layout_nb_channels((frame)->channel_layout))
4747
4848 #if FF_API_FRAME_QP
49+struct qp_properties {
50+ int stride;
51+ int type;
52+};
53+
4954 int av_frame_set_qp_table(AVFrame *f, AVBufferRef *buf, int stride, int qp_type)
5055 {
56+ struct qp_properties *p;
57+ AVFrameSideData *sd;
58+ AVBufferRef *ref;
59+
5160 FF_DISABLE_DEPRECATION_WARNINGS
5261 av_buffer_unref(&f->qp_table_buf);
5362
@@ -57,20 +66,56 @@ FF_DISABLE_DEPRECATION_WARNINGS · 3 unmodified lines
5766 f->qscale_type = qp_type;
5867 FF_ENABLE_DEPRECATION_WARNINGS
5968
69+ av_frame_remove_side_data(f, AV_FRAME_DATA_QP_TABLE_PROPERTIES);
70+ av_frame_remove_side_data(f, AV_FRAME_DATA_QP_TABLE_DATA);
71+
72+ ref = av_buffer_ref(buf);
73+ if (!av_frame_new_side_data_from_buf(f, AV_FRAME_DATA_QP_TABLE_DATA, ref)) {
74+ av_buffer_unref(&ref);
75+ return AVERROR(ENOMEM);
76+ }
77+
78+ sd = av_frame_new_side_data(f, AV_FRAME_DATA_QP_TABLE_PROPERTIES,
79+ sizeof(struct qp_properties));
80+ if (!sd)
81+ return AVERROR(ENOMEM);
82+
83+ p = (struct qp_properties *)sd->data;
84+ p->stride = stride;
85+ p->type = qp_type;
86+
6087 return 0;
6188 }
6289
6390 int8_t *av_frame_get_qp_table(AVFrame *f, int *stride, int *type)
6491 {
65−FF_DISABLE_DEPRECATION_WARNINGS
66− *stride = f->qstride;
67− *type = f->qscale_type;
92+ AVBufferRef *buf = NULL;
6893
69− if (!f->qp_table_buf)
70− return NULL;
94+ *stride = 0;
95+ *type = 0;
7196
72− return f->qp_table_buf->data;
97+FF_DISABLE_DEPRECATION_WARNINGS
98+ if (f->qp_table_buf) {
99+ *stride = f->qstride;
100+ *type = f->qscale_type;
101+ buf = f->qp_table_buf;
73102 FF_ENABLE_DEPRECATION_WARNINGS
103+ } else {
104+ AVFrameSideData *sd;
105+ struct qp_properties *p;
106+ sd = av_frame_get_side_data(f, AV_FRAME_DATA_QP_TABLE_PROPERTIES);
107+ if (!sd)
108+ return NULL;
109+ p = (struct qp_properties *)sd->data;
110+ sd = av_frame_get_side_data(f, AV_FRAME_DATA_QP_TABLE_DATA);
111+ if (!sd)
112+ return NULL;
113+ *stride = p->stride;
114+ *type = p->type;
115+ buf = sd->buf;
116+ }
117+
118+ return buf ? buf->data : NULL;
74119 }
75120 #endif
76121
@@ -787,6 +832,8 @@ const char *av_frame_side_data_name(enum AVFrameSideDataType type) · 710 unmodified lines
787832 case AV_FRAME_DATA_CONTENT_LIGHT_LEVEL: return "Content light level metadata";
788833 case AV_FRAME_DATA_GOP_TIMECODE: return "GOP timecode";
789834 case AV_FRAME_DATA_ICC_PROFILE: return "ICC profile";
835+ case AV_FRAME_DATA_QP_TABLE_PROPERTIES: return "QP table properties";
836+ case AV_FRAME_DATA_QP_TABLE_DATA: return "QP table data";
790837 }
791838 return NULL;
792839 }
libavutil/frame.h+17−0
@@ -141,6 +141,23 @@ enum AVFrameSideDataType { · 140 unmodified lines
141141 * metadata key entry "name".
142142 */
143143 AV_FRAME_DATA_ICC_PROFILE,
144+
145+#if FF_API_FRAME_QP
146+ /**
147+ * Implementation-specific description of the format of AV_FRAME_QP_TABLE_DATA.
148+ * The contents of this side data are undocumented and internal; use
149+ * av_frame_set_qp_table() and av_frame_get_qp_table() to access this in a
150+ * meaningful way instead.
151+ */
152+ AV_FRAME_DATA_QP_TABLE_PROPERTIES,
153+
154+ /**
155+ * Raw QP table data. Its format is described by
156+ * AV_FRAME_DATA_QP_TABLE_PROPERTIES. Use av_frame_set_qp_table() and
157+ * av_frame_get_qp_table() to access this instead.
158+ */
159+ AV_FRAME_DATA_QP_TABLE_DATA,
160+#endif
144161 };
145162
146163 enum AVActiveFormatDescription {
libavutil/version.h+1−1
@@ -79,7 +79,7 @@ · 78 unmodified lines
7979 */
8080
8181 #define LIBAVUTIL_VERSION_MAJOR 56
82−#define LIBAVUTIL_VERSION_MINOR 10
82+#define LIBAVUTIL_VERSION_MINOR 11
8383 #define LIBAVUTIL_VERSION_MICRO 100
8484
8585 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
tests/ref/fate/exif-image-embedded+6−0
@@ -29,6 +29,12 @@ color_transfer=unknown · 28 unmodified lines
2929 chroma_location=center
3030 TAG:UserComment=AppleMark
3131
32+[SIDE_DATA]
33+side_data_type=QP table data
34+[/SIDE_DATA]
35+[SIDE_DATA]
36+side_data_type=QP table properties
37+[/SIDE_DATA]
3238 [/FRAME]
3339 [FRAME]
3440 media_type=audio
tests/ref/fate/exif-image-jpg+6−0
@@ -229,4 +229,10 @@ TAG:ExposureMode= 0 · 228 unmodified lines
229229 TAG:WhiteBalance= 0
230230 TAG:DigitalZoomRatio= 4000:4000
231231 TAG:SceneCaptureType= 0
232+[SIDE_DATA]
233+side_data_type=QP table data
234+[/SIDE_DATA]
235+[SIDE_DATA]
236+side_data_type=QP table properties
237+[/SIDE_DATA]
232238 [/FRAME]

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t