Skip to content

Commit

Permalink
AVFrame: add an opaque_ref field
Browse files Browse the repository at this point in the history
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>

Merges Libav commit 04f3bd3.
  • Loading branch information
wm4 committed Feb 13, 2017
1 parent 2b9f92f commit e3af49b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions doc/APIchanges
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ libavutil: 2015-08-28

API changes, most recent first:

2017-02-11 - xxxxxxx - lavu 55.47.100 - frame.h
Add AVFrame.opaque_ref.

2017-01-31 - xxxxxxx - lavu 55.46.100 / 55.20.0 - cpu.h
Add AV_CPU_FLAG_SSSE3SLOW.

Expand Down
9 changes: 9 additions & 0 deletions libavutil/frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,13 @@ FF_DISABLE_DEPRECATION_WARNINGS
FF_ENABLE_DEPRECATION_WARNINGS
#endif

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;
}

Expand Down Expand Up @@ -513,6 +520,8 @@ void av_frame_unref(AVFrame *frame)

av_buffer_unref(&frame->hw_frames_ctx);

av_buffer_unref(&frame->opaque_ref);

get_frame_defaults(frame);
}

Expand Down
11 changes: 11 additions & 0 deletions libavutil/frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,17 @@ typedef struct AVFrame {
* AVHWFramesContext describing the frame.
*/
AVBufferRef *hw_frames_ctx;

/**
* AVBufferRef for free use by the API user. FFmpeg will never check the
* contents of the buffer ref. FFmpeg 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;

/**
Expand Down
2 changes: 1 addition & 1 deletion libavutil/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
*/

#define LIBAVUTIL_VERSION_MAJOR 55
#define LIBAVUTIL_VERSION_MINOR 46
#define LIBAVUTIL_VERSION_MINOR 47
#define LIBAVUTIL_VERSION_MICRO 100

#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
Expand Down

0 comments on commit e3af49b

Please sign in to comment.