From 963034107356cc83a75115644e1516e92c6fa3db Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 27 May 2023 12:25:51 +0200 Subject: [PATCH] fftools/ffmpeg: factor out attaching FrameData to a frame Will be useful in following commits. --- fftools/ffmpeg.c | 11 +++++++++++ fftools/ffmpeg.h | 6 ++++++ fftools/ffmpeg_dec.c | 5 ++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index bcda7570e9..9997881572 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -431,6 +431,17 @@ InputStream *ist_iter(InputStream *prev) return NULL; } +FrameData *frame_data(AVFrame *frame) +{ + if (!frame->opaque_ref) { + frame->opaque_ref = av_buffer_allocz(sizeof(FrameData)); + if (!frame->opaque_ref) + return NULL; + } + + return (FrameData*)frame->opaque_ref->data; +} + void remove_avoptions(AVDictionary **a, AVDictionary *b) { const AVDictionaryEntry *t = NULL; diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 0e9ad5f9f7..6f71e85658 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -737,6 +737,12 @@ int init_complex_filtergraph(FilterGraph *fg); int copy_av_subtitle(AVSubtitle *dst, const AVSubtitle *src); +/** + * Get our axiliary frame data attached to the frame, allocating it + * if needed. + */ +FrameData *frame_data(AVFrame *frame); + int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int keep_reference); int ifilter_send_eof(InputFilter *ifilter, int64_t pts, AVRational tb); int ifilter_sub2video(InputFilter *ifilter, const AVSubtitle *sub); diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index 30959c64b7..799be63215 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -499,12 +499,11 @@ int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof) FrameData *fd; av_assert0(!frame->opaque_ref); - frame->opaque_ref = av_buffer_allocz(sizeof(*fd)); - if (!frame->opaque_ref) { + fd = frame_data(frame); + if (!fd) { av_frame_unref(frame); report_and_exit(AVERROR(ENOMEM)); } - fd = (FrameData*)frame->opaque_ref->data; fd->pts = frame->pts; fd->tb = dec->pkt_timebase; fd->idx = dec->frame_num - 1;