]> git.sesse.net Git - ffmpeg/commitdiff
AVFrame: add an opaque_ref field
authorwm4 <nfxjfg@googlemail.com>
Thu, 2 Feb 2017 10:27:54 +0000 (11:27 +0100)
committerAnton Khirnov <anton@khirnov.net>
Sat, 11 Feb 2017 10:37:45 +0000 (11:37 +0100)
This is an extended version of the AVFrame.opaque field, which can be
used to attach arbitrary user information to an AVFrame.

The usefulness of the opaque field is rather limited, because it can
store only up to 32 bits of information (or 64 bit on 64 bit systems).
It's not possible to set this field to a memory allocation, because
there is no way to deallocate it correctly.

The opaque_ref field circumvents this by letting the user set an
AVBuffer, which makes the user data refcounted.

Signed-off-by: Anton Khirnov <anton@khirnov.net>
doc/APIchanges
libavutil/frame.c
libavutil/frame.h
libavutil/version.h

index 9b9f46ef4934886c8decc3a33730cf860c17e5b6..e7a0b14038bd2e6927b24a96b202c727a7de4577 100644 (file)
@@ -13,6 +13,9 @@ libavutil:     2015-08-28
 
 API changes, most recent first:
 
+2017-02-11 - xxxxxxx - lavu 55.32.0 - frame.h
+  Add AVFrame.opaque_ref.
+
 2017-02-xx - xxxxxxx - lavu 55.31.1 - frame.h
   Allow passing the value of 0 (meaning "automatic") as the required alignment
   to av_frame_get_buffer().
index aa5820c0e95ce7d0471f0258825d77307c219ce9..9cd5f9ab37cb524fde37b2ac4acc47a4f2869bbc 100644 (file)
@@ -317,6 +317,8 @@ void av_frame_unref(AVFrame *frame)
 
     av_buffer_unref(&frame->hw_frames_ctx);
 
+    av_buffer_unref(&frame->opaque_ref);
+
     get_frame_defaults(frame);
 }
 
@@ -440,6 +442,13 @@ FF_ENABLE_DEPRECATION_WARNINGS
         av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0);
     }
 
+    av_buffer_unref(&dst->opaque_ref);
+    if (src->opaque_ref) {
+        dst->opaque_ref = av_buffer_ref(src->opaque_ref);
+        if (!dst->opaque_ref)
+            return AVERROR(ENOMEM);
+    }
+
     return 0;
 }
 
index 4f63fb024911bd7bfe77395c46c62aeed5fdcedb..f9ffb5bbbf852de4728442a3940c6f2ddb752ecd 100644 (file)
@@ -395,6 +395,17 @@ typedef struct AVFrame {
     /**
      * @}
      */
+
+    /**
+     * AVBufferRef for free use by the API user. Libav will never check the
+     * contents of the buffer ref. Libav calls av_buffer_unref() on it when
+     * the frame is unreferenced. av_frame_copy_props() calls create a new
+     * reference with av_buffer_ref() for the target frame's opaque_ref field.
+     *
+     * This is unrelated to the opaque field, although it serves a similar
+     * purpose.
+     */
+    AVBufferRef *opaque_ref;
 } AVFrame;
 
 /**
index 0768f9fe9996cc8cbc58334f4f716f7e1fb549b2..5dbc57cc1b475f260a464d5ce96460e8271b56de 100644 (file)
@@ -54,8 +54,8 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR 55
-#define LIBAVUTIL_VERSION_MINOR 31
-#define LIBAVUTIL_VERSION_MICRO  1
+#define LIBAVUTIL_VERSION_MINOR 32
+#define LIBAVUTIL_VERSION_MICRO  0
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
                                                LIBAVUTIL_VERSION_MINOR, \