From: Mark Thompson <sw@jkqxz.net> To: ffmpeg-devel@ffmpeg.org Subject: Re: [FFmpeg-devel] [PATCH v3 3/7] lavf: APV demuxer Date: Thu, 24 Apr 2025 21:15:10 +0100 Message-ID: <38e098bd-4c3e-4c9f-b1dd-80914f9c01a7@jkqxz.net> (raw) In-Reply-To: <f3361db0-72f5-4655-92d2-8214cc0abcf3@gmail.com> On 24/04/2025 01:10, James Almer wrote: > On 4/23/2025 5:45 PM, Mark Thompson wrote: >> +static int apv_read_header(AVFormatContext *s) >> +{ >> + AVStream *st; >> + GetByteContext gbc; >> + APVHeaderInfo header; >> + uint8_t buffer[28]; >> + uint32_t au_size, signature, pbu_size; >> + int err, size; >> + >> + err = ffio_ensure_seekback(s->pb, sizeof(buffer)); > > Isn't 28 bytes small enough that a backwards avio_seek() should always succeed? I don't see any documentation to that effect and I'm not familiar with the details of the implementation. There are various calls in other places in lavf which give single-digit numbers to ffio_ensure_seekback, so I'll keep it unless there is a guarantee somewhere that I've missed. >> + if (err < 0) >> + return err; >> + size = avio_read(s->pb, buffer, sizeof(buffer)); >> + if (size < 0) >> + return size; >> + >> + bytestream2_init(&gbc, buffer, sizeof(buffer)); >> + >> + au_size = bytestream2_get_be32(&gbc); >> + if (au_size < 24) { >> + // Too small. >> + return AVERROR_INVALIDDATA; >> + } >> + signature = bytestream2_get_be32(&gbc); >> + if (signature != APV_SIGNATURE) { >> + // Signature is mandatory. >> + return AVERROR_INVALIDDATA; >> + } >> + pbu_size = bytestream2_get_be32(&gbc); >> + if (pbu_size < 16) { >> + // Too small. >> + return AVERROR_INVALIDDATA; >> + } >> + >> + err = apv_extract_header_info(&header, &gbc); >> + if (err < 0) >> + return err; >> + >> + st = avformat_new_stream(s, NULL); >> + if (!st) >> + return AVERROR(ENOMEM); >> + >> + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; >> + st->codecpar->codec_id = AV_CODEC_ID_APV; >> + st->codecpar->format = header.pixel_format; >> + st->codecpar->profile = header.profile_idc; >> + st->codecpar->level = header.level_idc; >> + st->codecpar->width = header.frame_width; >> + st->codecpar->height = header.frame_height; >> + >> + st->avg_frame_rate = (AVRational){ 30, 1 }; >> + avpriv_set_pts_info(st, 64, 1, 30); >> + >> + avio_seek(s->pb, -size, SEEK_CUR); >> + >> + return 0; >> +} >> + >> +static int apv_read_packet(AVFormatContext *s, AVPacket *pkt) >> +{ >> + uint32_t au_size; >> + int ret; >> + >> + au_size = avio_rb32(s->pb); >> + if (au_size == 0 && avio_feof(s->pb)) >> + return AVERROR_EOF; >> + if (au_size < 16 || au_size > 1 << 24) { > > Might be a good idea to also check for the signature. Fair, added. Also made the upper limit a bit bigger because it feels a little too close if 16K video is ever a thing. >> + av_log(s, AV_LOG_ERROR, "APV AU is bad\n"); >> + return AVERROR_INVALIDDATA; >> + } >> + >> + ret = av_get_packet(s->pb, pkt, au_size); >> + pkt->flags = AV_PKT_FLAG_KEY; >> + >> + return ret; >> +} Thanks, - Mark _______________________________________________ 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:[~2025-04-24 20:15 UTC|newest] Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-04-23 20:45 [FFmpeg-devel] [PATCH v3 0/7] APV support Mark Thompson 2025-04-23 20:45 ` [FFmpeg-devel] [PATCH v3 1/7] lavc: APV codec ID and descriptor Mark Thompson 2025-04-23 20:45 ` [FFmpeg-devel] [PATCH v3 2/7] lavc/cbs: APV support Mark Thompson 2025-04-24 0:02 ` James Almer 2025-04-24 20:16 ` Mark Thompson 2025-04-23 20:45 ` [FFmpeg-devel] [PATCH v3 3/7] lavf: APV demuxer Mark Thompson 2025-04-24 0:10 ` James Almer 2025-04-24 20:15 ` Mark Thompson [this message] 2025-04-23 20:45 ` [FFmpeg-devel] [PATCH v3 4/7] lavc: APV decoder Mark Thompson 2025-04-24 3:04 ` James Almer 2025-04-25 17:25 ` Michael Niedermayer 2025-04-23 20:45 ` [FFmpeg-devel] [PATCH v3 5/7] lavc/apv: AVX2 transquant for x86-64 Mark Thompson 2025-04-24 2:55 ` James Almer 2025-04-24 20:37 ` Mark Thompson 2025-04-24 21:41 ` James Almer 2025-04-23 20:45 ` [FFmpeg-devel] [PATCH v3 6/7] lavc: APV metadata bitstream filter Mark Thompson 2025-04-23 20:45 ` [FFmpeg-devel] [PATCH v3 7/7] lavf: APV muxer Mark Thompson
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=38e098bd-4c3e-4c9f-b1dd-80914f9c01a7@jkqxz.net \ --to=sw@jkqxz.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