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
15 15
16API changes, most recent first:16API changes, most recent first:
17 17
182018-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
182018-03-15 - e0e72539cf - lavu 56.10.100 - opt.h212018-03-15 - e0e72539cf - lavu 56.10.100 - opt.h
19 Add AV_OPT_FLAG_BSF_PARAM22 Add AV_OPT_FLAG_BSF_PARAM
20 23
libavutil/frame.c+53−6
@@ -46,8 +46,17 @@ MAKE_ACCESSORS(AVFrame, frame, enum AVColorRange, color_range) · 45 unmodified lines
46 av_get_channel_layout_nb_channels((frame)->channel_layout))46 av_get_channel_layout_nb_channels((frame)->channel_layout))
47 47
48#if FF_API_FRAME_QP48#if FF_API_FRAME_QP
49struct qp_properties {
50 int stride;
51 int type;
52};
53
49int av_frame_set_qp_table(AVFrame *f, AVBufferRef *buf, int stride, int qp_type)54int av_frame_set_qp_table(AVFrame *f, AVBufferRef *buf, int stride, int qp_type)
50{55{
56 struct qp_properties *p;
57 AVFrameSideData *sd;
58 AVBufferRef *ref;
59
51FF_DISABLE_DEPRECATION_WARNINGS60FF_DISABLE_DEPRECATION_WARNINGS
52 av_buffer_unref(&f->qp_table_buf);61 av_buffer_unref(&f->qp_table_buf);
53 62
@@ -57,20 +66,56 @@ FF_DISABLE_DEPRECATION_WARNINGS · 3 unmodified lines
57 f->qscale_type = qp_type;66 f->qscale_type = qp_type;
58FF_ENABLE_DEPRECATION_WARNINGS67FF_ENABLE_DEPRECATION_WARNINGS
59 68
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
60 return 0;87 return 0;
61}88}
62 89
63int8_t *av_frame_get_qp_table(AVFrame *f, int *stride, int *type)90int8_t *av_frame_get_qp_table(AVFrame *f, int *stride, int *type)
64{91{
65FF_DISABLE_DEPRECATION_WARNINGS92 AVBufferRef *buf = NULL;
66 *stride = f->qstride;
67 *type = f->qscale_type;
68 93
69 if (!f->qp_table_buf)94 *stride = 0;
70 return NULL;95 *type = 0;
71 96
72 return f->qp_table_buf->data;97FF_DISABLE_DEPRECATION_WARNINGS
98 if (f->qp_table_buf) {
99 *stride = f->qstride;
100 *type = f->qscale_type;
101 buf = f->qp_table_buf;
73FF_ENABLE_DEPRECATION_WARNINGS102FF_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;
74}119}
75#endif120#endif
76 121
@@ -787,6 +832,8 @@ const char *av_frame_side_data_name(enum AVFrameSideDataType type) · 710 unmodified lines
787 case AV_FRAME_DATA_CONTENT_LIGHT_LEVEL: return "Content light level metadata";832 case AV_FRAME_DATA_CONTENT_LIGHT_LEVEL: return "Content light level metadata";
788 case AV_FRAME_DATA_GOP_TIMECODE: return "GOP timecode";833 case AV_FRAME_DATA_GOP_TIMECODE: return "GOP timecode";
789 case AV_FRAME_DATA_ICC_PROFILE: return "ICC profile";834 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";
790 }837 }
791 return NULL;838 return NULL;
792}839}
libavutil/frame.h+17−0
@@ -141,6 +141,23 @@ enum AVFrameSideDataType { · 140 unmodified lines
141 * metadata key entry "name".141 * metadata key entry "name".
142 */142 */
143 AV_FRAME_DATA_ICC_PROFILE,143 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
144};161};
145 162
146enum AVActiveFormatDescription {163enum AVActiveFormatDescription {
libavutil/version.h+1−1
@@ -79,7 +79,7 @@ · 78 unmodified lines
79 */79 */
80 80
81#define LIBAVUTIL_VERSION_MAJOR 5681#define LIBAVUTIL_VERSION_MAJOR 56
82#define LIBAVUTIL_VERSION_MINOR 1082#define LIBAVUTIL_VERSION_MINOR 11
83#define LIBAVUTIL_VERSION_MICRO 10083#define LIBAVUTIL_VERSION_MICRO 100
84 84
85#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \85#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
29chroma_location=center29chroma_location=center
30TAG:UserComment=AppleMark30TAG:UserComment=AppleMark
31 31
32[SIDE_DATA]
33side_data_type=QP table data
34[/SIDE_DATA]
35[SIDE_DATA]
36side_data_type=QP table properties
37[/SIDE_DATA]
32[/FRAME]38[/FRAME]
33[FRAME]39[FRAME]
34media_type=audio40media_type=audio
tests/ref/fate/exif-image-jpg+6−0
@@ -229,4 +229,10 @@ TAG:ExposureMode= 0 · 228 unmodified lines
229TAG:WhiteBalance= 0229TAG:WhiteBalance= 0
230TAG:DigitalZoomRatio= 4000:4000230TAG:DigitalZoomRatio= 4000:4000
231TAG:SceneCaptureType= 0231TAG:SceneCaptureType= 0
232[SIDE_DATA]
233side_data_type=QP table data
234[/SIDE_DATA]
235[SIDE_DATA]
236side_data_type=QP table properties
237[/SIDE_DATA]
232[/FRAME]238[/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