@ -21,6 +21,7 @@
# include "config_components.h"
# include "libavutil/buffer.h"
# include "libavutil/eval.h"
# include "libavutil/internal.h"
# include "libavutil/opt.h"
@ -51,6 +52,9 @@
typedef struct X264Opaque {
int64_t reordered_opaque ;
int64_t wallclock ;
void * frame_opaque ;
AVBufferRef * frame_opaque_ref ;
} X264Opaque ;
typedef struct X264Context {
@ -133,6 +137,11 @@ static void X264_log(void *p, int level, const char *fmt, va_list args)
av_vlog ( p , level_map [ level ] , fmt , args ) ;
}
static void opaque_uninit ( X264Opaque * o )
{
av_buffer_unref ( & o - > frame_opaque_ref ) ;
memset ( o , 0 , sizeof ( * o ) ) ;
}
static int encode_nals ( AVCodecContext * ctx , AVPacket * pkt ,
const x264_nal_t * nals , int nnal )
@ -440,6 +449,15 @@ static int setup_frame(AVCodecContext *ctx, const AVFrame *frame,
pic - > i_pts = frame - > pts ;
opaque_uninit ( opaque ) ;
if ( ctx - > flags & AV_CODEC_FLAG_COPY_OPAQUE ) {
opaque - > frame_opaque = frame - > opaque ;
ret = av_buffer_replace ( & opaque - > frame_opaque_ref , frame - > opaque_ref ) ;
if ( ret < 0 )
goto fail ;
}
opaque - > reordered_opaque = frame - > reordered_opaque ;
opaque - > wallclock = wallclock ;
if ( ctx - > export_side_data & AV_CODEC_EXPORT_DATA_PRFT )
@ -594,6 +612,14 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
out_opaque < & x4 - > reordered_opaque [ x4 - > nb_reordered_opaque ] ) {
ctx - > reordered_opaque = out_opaque - > reordered_opaque ;
wallclock = out_opaque - > wallclock ;
if ( ctx - > flags & AV_CODEC_FLAG_COPY_OPAQUE ) {
pkt - > opaque = out_opaque - > frame_opaque ;
pkt - > opaque_ref = out_opaque - > frame_opaque_ref ;
out_opaque - > frame_opaque_ref = NULL ;
}
opaque_uninit ( out_opaque ) ;
} else {
// Unexpected opaque pointer on picture output
av_log ( ctx , AV_LOG_ERROR , " Unexpected opaque pointer; "
@ -634,6 +660,9 @@ static av_cold int X264_close(AVCodecContext *avctx)
X264Context * x4 = avctx - > priv_data ;
av_freep ( & x4 - > sei ) ;
for ( int i = 0 ; i < x4 - > nb_reordered_opaque ; i + + )
opaque_uninit ( & x4 - > reordered_opaque [ i ] ) ;
av_freep ( & x4 - > reordered_opaque ) ;
# if X264_BUILD >= 161