From: Anton Khirnov <anton@khirnov.net> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 1/3] fftools/ffmpeg: merge DemuxPktData into FrameData Date: Tue, 12 Dec 2023 13:09:56 +0100 Message-ID: <20231212120958.21313-1-anton@khirnov.net> (raw) This way we can propagate arbitrary data from the demuxer all the way into the muxer, using a single struct. --- fftools/ffmpeg.c | 28 ++++++++++++++++++++-------- fftools/ffmpeg.h | 13 +++++++------ fftools/ffmpeg_demux.c | 9 ++++----- fftools/ffmpeg_mux.c | 4 ++-- 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 30b594fd97..e7ff9a6d6f 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -404,36 +404,48 @@ InputStream *ist_iter(InputStream *prev) return NULL; } -static int frame_data_ensure(AVFrame *frame, int writable) +static int frame_data_ensure(AVBufferRef **dst, int writable) { - if (!frame->opaque_ref) { + if (!*dst) { FrameData *fd; - frame->opaque_ref = av_buffer_allocz(sizeof(*fd)); - if (!frame->opaque_ref) + *dst = av_buffer_allocz(sizeof(*fd)); + if (!*dst) return AVERROR(ENOMEM); - fd = (FrameData*)frame->opaque_ref->data; + fd = (FrameData*)((*dst)->data); fd->dec.frame_num = UINT64_MAX; fd->dec.pts = AV_NOPTS_VALUE; } else if (writable) - return av_buffer_make_writable(&frame->opaque_ref); + return av_buffer_make_writable(dst); return 0; } FrameData *frame_data(AVFrame *frame) { - int ret = frame_data_ensure(frame, 1); + int ret = frame_data_ensure(&frame->opaque_ref, 1); return ret < 0 ? NULL : (FrameData*)frame->opaque_ref->data; } const FrameData *frame_data_c(AVFrame *frame) { - int ret = frame_data_ensure(frame, 0); + int ret = frame_data_ensure(&frame->opaque_ref, 0); return ret < 0 ? NULL : (const FrameData*)frame->opaque_ref->data; } +FrameData *packet_data(AVPacket *pkt) +{ + int ret = frame_data_ensure(&pkt->opaque_ref, 1); + return ret < 0 ? NULL : (FrameData*)pkt->opaque_ref->data; +} + +const FrameData *packet_data_c(AVPacket *pkt) +{ + int ret = frame_data_ensure(&pkt->opaque_ref, 0); + return ret < 0 ? NULL : (const FrameData*)pkt->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 ba82b7490d..aafb35538e 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -115,12 +115,6 @@ typedef struct { } AudioChannelMap; #endif -typedef struct DemuxPktData { - // estimated dts in AV_TIME_BASE_Q, - // to be used when real dts is missing - int64_t dts_est; -} DemuxPktData; - typedef struct OptionsContext { OptionGroup *g; @@ -622,6 +616,10 @@ typedef struct OutputFile { // optionally attached as opaque_ref to decoded AVFrames typedef struct FrameData { + // demuxer-estimated dts in AV_TIME_BASE_Q, + // to be used when real dts is missing + int64_t dts_est; + // properties that come from the decoder struct { uint64_t frame_num; @@ -723,6 +721,9 @@ FrameData *frame_data(AVFrame *frame); const FrameData *frame_data_c(AVFrame *frame); +FrameData *packet_data (AVPacket *pkt); +const FrameData *packet_data_c(AVPacket *pkt); + /** * Set up fallback filtering parameters from a decoder context. They will only * be used if no frames are ever sent on this input, otherwise the actual diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 91cd7a1125..392b447338 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -328,14 +328,13 @@ static int ist_dts_update(DemuxStream *ds, AVPacket *pkt) av_assert0(!pkt->opaque_ref); if (ds->streamcopy_needed) { - DemuxPktData *pd; + FrameData *fd; - pkt->opaque_ref = av_buffer_allocz(sizeof(*pd)); - if (!pkt->opaque_ref) + fd = packet_data(pkt); + if (!fd) return AVERROR(ENOMEM); - pd = (DemuxPktData*)pkt->opaque_ref->data; - pd->dts_est = ds->dts; + fd->dts_est = ds->dts; } return 0; diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 067dc65d4e..62925be8d0 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -381,8 +381,8 @@ static int of_streamcopy(OutputStream *ost, AVPacket *pkt) { OutputFile *of = output_files[ost->file_index]; MuxStream *ms = ms_from_ost(ost); - DemuxPktData *pd = pkt->opaque_ref ? (DemuxPktData*)pkt->opaque_ref->data : NULL; - int64_t dts = pd ? pd->dts_est : AV_NOPTS_VALUE; + FrameData *fd = pkt->opaque_ref ? (FrameData*)pkt->opaque_ref->data : NULL; + int64_t dts = fd ? fd->dts_est : AV_NOPTS_VALUE; int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time; int64_t ts_offset; -- 2.42.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next reply other threads:[~2023-12-12 12:10 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-12-12 12:09 Anton Khirnov [this message] 2023-12-12 12:09 ` [FFmpeg-devel] [PATCH 2/3] fftools/ffmpeg: attach wallclock timing information to packets and frames Anton Khirnov 2023-12-12 12:09 ` [FFmpeg-devel] [PATCH 3/3] fftools/ffmpeg_mux: print latency information in -debug_ts muxing output Anton Khirnov
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20231212120958.21313-1-anton@khirnov.net \ --to=anton@khirnov.net \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git