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.
---
doc/APIchanges | 3 +++
libavutil/frame.c | 9 +++++++++
libavutil/frame.h | 11 +++++++++++
3 files changed, 23 insertions(+)
diff --git a/doc/APIchanges b/doc/APIchanges
index c161618d92..033995fb7d 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,9 @@ libavutil: 2015-08-28
API changes, most recent first:
+2016-02-xx - xxxxxxx - lavu 55.xx.0 - frame.h
+ Add AVFrame.opaque_ref.
+
2017-02-01 - xxxxxxx - lavc - avcodec.h
Deprecate AVCodecContext.refcounted_frames. This was useful for deprecated
API only (avcodec_decode_video2/avcodec_decode_audio4). The new decode APIs
diff --git a/libavutil/frame.c b/libavutil/frame.c
index aafaa57d8b..b7fd9f3815 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -313,6 +313,8 @@ void av_frame_unref(AVFrame *frame)
av_buffer_unref(&frame->hw_frames_ctx);
+ av_buffer_unref(&frame->opaque_ref);
+
get_frame_defaults(frame);
}
@@ -436,6 +438,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;
}
diff --git a/libavutil/frame.h b/libavutil/frame.h
index c718f7bd62..d7be3f2f20 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -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;
/**
--
2.11.0
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel