]> git.sesse.net Git - ffmpeg/commitdiff
lavu/frame: add QP side data
authorwm4 <nfxjfg@googlemail.com>
Thu, 1 Mar 2018 14:57:01 +0000 (15:57 +0100)
committerwm4 <nfxjfg@googlemail.com>
Sun, 18 Mar 2018 11:36:24 +0000 (12:36 +0100)
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).

doc/APIchanges
libavutil/frame.c
libavutil/frame.h
libavutil/version.h
tests/ref/fate/exif-image-embedded
tests/ref/fate/exif-image-jpg

index f757f5063ed4ebca2faadee79b58d9b46ed2198c..4c0ee7147a15ae54e1141b59ae6a419885f6426f 100644 (file)
@@ -15,6 +15,9 @@ libavutil:     2017-10-21
 
 API changes, most recent first:
 
+2018-03-18 - xxxxxxx - lavu 56.11.100 - frame.h
+  Add AV_FRAME_DATA_QP_TABLE_PROPERTIES and AV_FRAME_DATA_QP_TABLE_DATA.
+
 2018-03-15 - e0e72539cf - lavu 56.10.100 - opt.h
   Add AV_OPT_FLAG_BSF_PARAM
 
index 0db2a2d57b69d7fcf56601c55d5d035f1a36f821..ea13cd3ed61a98c443119fb092ce4e5cfb1cfc93 100644 (file)
@@ -46,8 +46,17 @@ MAKE_ACCESSORS(AVFrame, frame, enum AVColorRange, color_range)
                av_get_channel_layout_nb_channels((frame)->channel_layout))
 
 #if FF_API_FRAME_QP
+struct qp_properties {
+    int stride;
+    int type;
+};
+
 int av_frame_set_qp_table(AVFrame *f, AVBufferRef *buf, int stride, int qp_type)
 {
+    struct qp_properties *p;
+    AVFrameSideData *sd;
+    AVBufferRef *ref;
+
 FF_DISABLE_DEPRECATION_WARNINGS
     av_buffer_unref(&f->qp_table_buf);
 
@@ -57,20 +66,56 @@ FF_DISABLE_DEPRECATION_WARNINGS
     f->qscale_type  = qp_type;
 FF_ENABLE_DEPRECATION_WARNINGS
 
+    av_frame_remove_side_data(f, AV_FRAME_DATA_QP_TABLE_PROPERTIES);
+    av_frame_remove_side_data(f, AV_FRAME_DATA_QP_TABLE_DATA);
+
+    ref = av_buffer_ref(buf);
+    if (!av_frame_new_side_data_from_buf(f, AV_FRAME_DATA_QP_TABLE_DATA, ref)) {
+        av_buffer_unref(&ref);
+        return AVERROR(ENOMEM);
+    }
+
+    sd = av_frame_new_side_data(f, AV_FRAME_DATA_QP_TABLE_PROPERTIES,
+                                sizeof(struct qp_properties));
+    if (!sd)
+        return AVERROR(ENOMEM);
+
+    p = (struct qp_properties *)sd->data;
+    p->stride = stride;
+    p->type = qp_type;
+
     return 0;
 }
 
 int8_t *av_frame_get_qp_table(AVFrame *f, int *stride, int *type)
 {
-FF_DISABLE_DEPRECATION_WARNINGS
-    *stride = f->qstride;
-    *type   = f->qscale_type;
+    AVBufferRef *buf = NULL;
 
-    if (!f->qp_table_buf)
-        return NULL;
+    *stride = 0;
+    *type   = 0;
 
-    return f->qp_table_buf->data;
+FF_DISABLE_DEPRECATION_WARNINGS
+    if (f->qp_table_buf) {
+        *stride = f->qstride;
+        *type   = f->qscale_type;
+        buf     = f->qp_table_buf;
 FF_ENABLE_DEPRECATION_WARNINGS
+    } else {
+        AVFrameSideData *sd;
+        struct qp_properties *p;
+        sd = av_frame_get_side_data(f, AV_FRAME_DATA_QP_TABLE_PROPERTIES);
+        if (!sd)
+            return NULL;
+        p = (struct qp_properties *)sd->data;
+        sd = av_frame_get_side_data(f, AV_FRAME_DATA_QP_TABLE_DATA);
+        if (!sd)
+            return NULL;
+        *stride = p->stride;
+        *type   = p->type;
+        buf     = sd->buf;
+    }
+
+    return buf ? buf->data : NULL;
 }
 #endif
 
@@ -787,6 +832,8 @@ const char *av_frame_side_data_name(enum AVFrameSideDataType type)
     case AV_FRAME_DATA_CONTENT_LIGHT_LEVEL:         return "Content light level metadata";
     case AV_FRAME_DATA_GOP_TIMECODE:                return "GOP timecode";
     case AV_FRAME_DATA_ICC_PROFILE:                 return "ICC profile";
+    case AV_FRAME_DATA_QP_TABLE_PROPERTIES:         return "QP table properties";
+    case AV_FRAME_DATA_QP_TABLE_DATA:               return "QP table data";
     }
     return NULL;
 }
index ddbac3156dcf7363f7e7e15d6fb72e0cf6903913..9d57d6ce66ff92420145caf55643b2ec34b63147 100644 (file)
@@ -141,6 +141,23 @@ enum AVFrameSideDataType {
      * metadata key entry "name".
      */
     AV_FRAME_DATA_ICC_PROFILE,
+
+#if FF_API_FRAME_QP
+    /**
+     * Implementation-specific description of the format of AV_FRAME_QP_TABLE_DATA.
+     * The contents of this side data are undocumented and internal; use
+     * av_frame_set_qp_table() and av_frame_get_qp_table() to access this in a
+     * meaningful way instead.
+     */
+    AV_FRAME_DATA_QP_TABLE_PROPERTIES,
+
+    /**
+     * Raw QP table data. Its format is described by
+     * AV_FRAME_DATA_QP_TABLE_PROPERTIES. Use av_frame_set_qp_table() and
+     * av_frame_get_qp_table() to access this instead.
+     */
+    AV_FRAME_DATA_QP_TABLE_DATA,
+#endif
 };
 
 enum AVActiveFormatDescription {
index 9ca556ddc9d1ceaa55e3a5773ee1a33d660b88d5..d166bb30e7c53e113dfb27d6a4af4cea911abc3d 100644 (file)
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  56
-#define LIBAVUTIL_VERSION_MINOR  10
+#define LIBAVUTIL_VERSION_MINOR  11
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
index 306ae0854b1a8fa9a45ba0763637e41113c94287..0b640767a88e367f3929f9017dad6bbdd6e51172 100644 (file)
@@ -29,6 +29,12 @@ color_transfer=unknown
 chroma_location=center
 TAG:UserComment=AppleMark
 
+[SIDE_DATA]
+side_data_type=QP table data
+[/SIDE_DATA]
+[SIDE_DATA]
+side_data_type=QP table properties
+[/SIDE_DATA]
 [/FRAME]
 [FRAME]
 media_type=audio
index b266501191bedf02bb3af425a01efe4d462fd11c..eb18dede2192542401db9332fea5e8e0b3688e57 100644 (file)
@@ -229,4 +229,10 @@ TAG:ExposureMode=    0
 TAG:WhiteBalance=    0
 TAG:DigitalZoomRatio=   4000:4000
 TAG:SceneCaptureType=    0
+[SIDE_DATA]
+side_data_type=QP table data
+[/SIDE_DATA]
+[SIDE_DATA]
+side_data_type=QP table properties
+[/SIDE_DATA]
 [/FRAME]