From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH 1/2] avformat/demux: Restore pkt->stream_index assert check
Date: Sat, 23 Mar 2024 00:41:24 +0100
Message-ID: <GV1P250MB073707EDAE7167CC908AA27E8F312@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <DU0P250MB07476CC694B668741E513E8E8F322@DU0P250MB0747.EURP250.PROD.OUTLOOK.COM>
Andreas Rheinhardt:
> It has been moved after "st = s->streams[pkt->stream_index]"
> in b140b8332c617b0eef4f872f3ef90c469e99920f.
> Deduplicate ff_read_packet() and ff_buffer_packet()
> while fixing this.
> This also fixes shadowing in ff_read_packet().
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
> libavformat/demux.c | 75 +++++++++++++++++++--------------------------
> 1 file changed, 31 insertions(+), 44 deletions(-)
>
> diff --git a/libavformat/demux.c b/libavformat/demux.c
> index 4c50eb5568..4345ed4c8c 100644
> --- a/libavformat/demux.c
> +++ b/libavformat/demux.c
> @@ -532,9 +532,6 @@ static void update_timestamps(AVFormatContext *s, AVStream *st, AVPacket *pkt)
> {
> FFStream *const sti = ffstream(st);
>
> - av_assert0(pkt->stream_index < (unsigned)s->nb_streams &&
> - "Invalid stream index.\n");
> -
> if (update_wrap_reference(s, st, pkt->stream_index, pkt) && sti->pts_wrap_behavior == AV_PTS_WRAP_SUB_OFFSET) {
> // correct first time stamps to negative values
> if (!is_relative(sti->first_dts))
> @@ -555,13 +552,24 @@ static void update_timestamps(AVFormatContext *s, AVStream *st, AVPacket *pkt)
> pkt->dts = pkt->pts = av_rescale_q(av_gettime(), AV_TIME_BASE_Q, st->time_base);
> }
>
> -int ff_buffer_packet(AVFormatContext *s, AVPacket *pkt)
> +/**
> + * Handle a new packet and either return it directly if possible and
> + * allow_passthrough is true or queue the packet (or drop the packet
> + * if corrupt).
> + *
> + * @return < 0 on error, 0 if the packet was passed through,
> + * 1 if it was queued or dropped
> + */
> +static int handle_new_packet(AVFormatContext *s, AVPacket *pkt, int allow_passthrough)
> {
> FFFormatContext *const si = ffformatcontext(s);
> - AVStream *st = s->streams[pkt->stream_index];
> - FFStream *sti = ffstream(st);
> + AVStream *st;
> + FFStream *sti;
> int err;
>
> + av_assert0(pkt->stream_index < (unsigned)s->nb_streams &&
> + "Invalid stream index.\n");
> +
> if (pkt->flags & AV_PKT_FLAG_CORRUPT) {
> av_log(s, AV_LOG_WARNING,
> "Packet corrupt (stream = %d, dts = %s)",
> @@ -569,13 +577,19 @@ int ff_buffer_packet(AVFormatContext *s, AVPacket *pkt)
> if (s->flags & AVFMT_FLAG_DISCARD_CORRUPT) {
> av_log(s, AV_LOG_WARNING, ", dropping it.\n");
> av_packet_unref(pkt);
> - return 0;
> + return 1;
> }
> av_log(s, AV_LOG_WARNING, ".\n");
> }
>
> + st = s->streams[pkt->stream_index];
> + sti = ffstream(st);
> +
> update_timestamps(s, st, pkt);
>
> + if (sti->request_probe <= 0 && allow_passthrough && !si->raw_packet_buffer.head)
> + return 0;
> +
> err = avpriv_packet_list_put(&si->raw_packet_buffer, pkt, NULL, 0);
> if (err < 0) {
> av_packet_unref(pkt);
> @@ -585,14 +599,18 @@ int ff_buffer_packet(AVFormatContext *s, AVPacket *pkt)
> pkt = &si->raw_packet_buffer.tail->pkt;
> si->raw_packet_buffer_size += pkt->size;
>
> - if (sti->request_probe <= 0)
> - return 0;
> -
> err = probe_codec(s, st, pkt);
> if (err < 0)
> return err;
>
> - return 0;
> + return 1;
> +}
> +
> +int ff_buffer_packet(AVFormatContext *s, AVPacket *pkt)
> +{
> + int err = handle_new_packet(s, pkt, 0);
> +
> + return err < 0 ? err : 0;
> }
>
> int ff_read_packet(AVFormatContext *s, AVPacket *pkt)
> @@ -612,9 +630,6 @@ FF_ENABLE_DEPRECATION_WARNINGS
>
> for (;;) {
> PacketListEntry *pktl = si->raw_packet_buffer.head;
> - AVStream *st;
> - FFStream *sti;
> - const AVPacket *pkt1;
>
> if (pktl) {
> AVStream *const st = s->streams[pktl->pkt.stream_index];
> @@ -656,36 +671,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
> return err;
> }
>
> - if (pkt->flags & AV_PKT_FLAG_CORRUPT) {
> - av_log(s, AV_LOG_WARNING,
> - "Packet corrupt (stream = %d, dts = %s)",
> - pkt->stream_index, av_ts2str(pkt->dts));
> - if (s->flags & AVFMT_FLAG_DISCARD_CORRUPT) {
> - av_log(s, AV_LOG_WARNING, ", dropping it.\n");
> - av_packet_unref(pkt);
> - continue;
> - }
> - av_log(s, AV_LOG_WARNING, ".\n");
> - }
> -
> - st = s->streams[pkt->stream_index];
> - sti = ffstream(st);
> -
> - update_timestamps(s, st, pkt);
> -
> - if (!pktl && sti->request_probe <= 0)
> - return 0;
> -
> - err = avpriv_packet_list_put(&si->raw_packet_buffer,
> - pkt, NULL, 0);
> - if (err < 0) {
> - av_packet_unref(pkt);
> - return err;
> - }
> - pkt1 = &si->raw_packet_buffer.tail->pkt;
> - si->raw_packet_buffer_size += pkt1->size;
> -
> - if ((err = probe_codec(s, st, pkt1)) < 0)
> + err = handle_new_packet(s, pkt, 1);
> + if (err <= 0) /* Error or passthrough */
> return err;
> }
> }
Will apply this patchset tomorrow unless there are objections.
- Andreas
_______________________________________________
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".
prev parent reply other threads:[~2024-03-22 23:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-21 12:34 Andreas Rheinhardt
2024-03-21 12:34 ` [FFmpeg-devel] [PATCH 2/2] avformat/demux: Combine "Packet corrupt" logmessages Andreas Rheinhardt
2024-03-22 23:41 ` Andreas Rheinhardt [this message]
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=GV1P250MB073707EDAE7167CC908AA27E8F312@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM \
--to=andreas.rheinhardt@outlook.com \
--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