From: Anton Khirnov <anton@khirnov.net> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 6/8] fftools/ffmpeg_demux: add demuxing thread private data Date: Fri, 5 Jan 2024 17:42:49 +0100 Message-ID: <20240105164251.28935-6-anton@khirnov.net> (raw) In-Reply-To: <20240105164251.28935-1-anton@khirnov.net> To be used for data that never needs to be visible outside of the demuxer thread, similarly as was previously done for other components. --- fftools/ffmpeg_demux.c | 67 ++++++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 22 deletions(-) diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index c51140b1c5..eae1f0bde5 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -115,6 +115,11 @@ typedef struct Demuxer { int nb_streams_finished; } Demuxer; +typedef struct DemuxThreadContext { + // packet used for reading from the demuxer + AVPacket *pkt_demux; +} DemuxThreadContext; + static DemuxStream *ds_from_ist(InputStream *ist) { return (DemuxStream*)ist; @@ -565,18 +570,36 @@ static void thread_set_name(InputFile *f) ff_thread_setname(name); } +static void demux_thread_uninit(DemuxThreadContext *dt) +{ + av_packet_free(&dt->pkt_demux); + + memset(dt, 0, sizeof(*dt)); +} + +static int demux_thread_init(DemuxThreadContext *dt) +{ + memset(dt, 0, sizeof(*dt)); + + dt->pkt_demux = av_packet_alloc(); + if (!dt->pkt_demux) + return AVERROR(ENOMEM); + + return 0; +} + static void *input_thread(void *arg) { Demuxer *d = arg; InputFile *f = &d->f; - AVPacket *pkt; + + DemuxThreadContext dt; + int ret = 0; - pkt = av_packet_alloc(); - if (!pkt) { - ret = AVERROR(ENOMEM); + ret = demux_thread_init(&dt); + if (ret < 0) goto finish; - } thread_set_name(f); @@ -589,7 +612,7 @@ static void *input_thread(void *arg) DemuxStream *ds; unsigned send_flags = 0; - ret = av_read_frame(f->ctx, pkt); + ret = av_read_frame(f->ctx, dt.pkt_demux); if (ret == AVERROR(EAGAIN)) { av_usleep(10000); @@ -598,12 +621,12 @@ static void *input_thread(void *arg) if (ret < 0) { if (d->loop) { /* signal looping to our consumers */ - pkt->stream_index = -1; + dt.pkt_demux->stream_index = -1; - ret = sch_demux_send(d->sch, f->index, pkt, 0); + ret = sch_demux_send(d->sch, f->index, dt.pkt_demux, 0); if (ret >= 0) - ret = seek_to_start(d, (Timestamp){ .ts = pkt->pts, - .tb = pkt->time_base }); + ret = seek_to_start(d, (Timestamp){ .ts = dt.pkt_demux->pts, + .tb = dt.pkt_demux->time_base }); if (ret >= 0) continue; @@ -622,39 +645,39 @@ static void *input_thread(void *arg) } if (do_pkt_dump) { - av_pkt_dump_log2(NULL, AV_LOG_INFO, pkt, do_hex_dump, - f->ctx->streams[pkt->stream_index]); + av_pkt_dump_log2(NULL, AV_LOG_INFO, dt.pkt_demux, do_hex_dump, + f->ctx->streams[dt.pkt_demux->stream_index]); } /* the following test is needed in case new streams appear dynamically in stream : we ignore them */ - ds = pkt->stream_index < f->nb_streams ? - ds_from_ist(f->streams[pkt->stream_index]) : NULL; + ds = dt.pkt_demux->stream_index < f->nb_streams ? + ds_from_ist(f->streams[dt.pkt_demux->stream_index]) : NULL; if (!ds || ds->discard || ds->finished) { - report_new_stream(d, pkt); - av_packet_unref(pkt); + report_new_stream(d, dt.pkt_demux); + av_packet_unref(dt.pkt_demux); continue; } - if (pkt->flags & AV_PKT_FLAG_CORRUPT) { + if (dt.pkt_demux->flags & AV_PKT_FLAG_CORRUPT) { av_log(d, exit_on_error ? AV_LOG_FATAL : AV_LOG_WARNING, "corrupt input packet in stream %d\n", - pkt->stream_index); + dt.pkt_demux->stream_index); if (exit_on_error) { - av_packet_unref(pkt); + av_packet_unref(dt.pkt_demux); ret = AVERROR_INVALIDDATA; break; } } - ret = input_packet_process(d, pkt, &send_flags); + ret = input_packet_process(d, dt.pkt_demux, &send_flags); if (ret < 0) break; if (d->readrate) readrate_sleep(d); - ret = demux_send(d, ds, pkt, send_flags); + ret = demux_send(d, ds, dt.pkt_demux, send_flags); if (ret < 0) break; } @@ -664,7 +687,7 @@ static void *input_thread(void *arg) ret = 0; finish: - av_packet_free(&pkt); + demux_thread_uninit(&dt); return (void*)(intptr_t)ret; } -- 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 prev parent reply other threads:[~2024-01-05 16:44 UTC|newest] Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-01-05 16:42 [FFmpeg-devel] [PATCH 1/8] fftools/ffmpeg_demux: replace abort() by av_assert0(0) Anton Khirnov 2024-01-05 16:42 ` [FFmpeg-devel] [PATCH 2/8] doc/ffmpeg: drop documentation for non-existent -sbsf Anton Khirnov 2024-01-06 11:22 ` Stefano Sabatini 2024-01-05 16:42 ` [FFmpeg-devel] [PATCH 3/8] fftools/ffmpeg_demux: do not set bitexact directly on the decoder Anton Khirnov 2024-01-06 11:24 ` Stefano Sabatini 2024-01-05 16:42 ` [FFmpeg-devel] [PATCH 4/8] fftools/ffmpeg_demux: set options on codec parameters rather than decoder Anton Khirnov 2024-01-06 11:31 ` Stefano Sabatini 2024-01-06 14:22 ` James Almer 2024-01-16 19:49 ` Anton Khirnov 2024-01-16 22:37 ` James Almer 2024-01-05 16:42 ` [FFmpeg-devel] [PATCH 5/8] fftools/ffmpeg_demux: only allocate the decoder when actually decoding Anton Khirnov 2024-01-06 11:34 ` Stefano Sabatini 2024-01-16 19:50 ` Anton Khirnov 2024-01-05 16:42 ` Anton Khirnov [this message] 2024-01-06 11:44 ` [FFmpeg-devel] [PATCH 6/8] fftools/ffmpeg_demux: add demuxing thread private data Stefano Sabatini 2024-01-16 19:52 ` Anton Khirnov 2024-01-05 16:42 ` [FFmpeg-devel] [PATCH 7/8] fftools/ffmpeg_demux: implement -bsf for input Anton Khirnov 2024-01-06 12:12 ` Stefano Sabatini 2024-01-17 9:02 ` Anton Khirnov 2024-01-20 11:32 ` Stefano Sabatini 2024-01-21 17:43 ` Anton Khirnov 2024-01-21 18:22 ` Stefano Sabatini 2024-01-21 18:35 ` Anton Khirnov 2024-01-21 19:15 ` Stefano Sabatini 2024-01-22 8:57 ` Anton Khirnov 2024-01-05 16:42 ` [FFmpeg-devel] [PATCH 8/8] fftools/ffmpeg_opt: mark -stream_group as expert option Anton Khirnov 2024-01-06 12:12 ` Stefano Sabatini 2024-01-06 11:18 ` [FFmpeg-devel] [PATCH 1/8] fftools/ffmpeg_demux: replace abort() by av_assert0(0) Stefano Sabatini
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=20240105164251.28935-6-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