From: "Tomas Härdin" <git@haerdin.se> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Subject: [FFmpeg-devel] [PATCH 5/6] lavf/codec2: Silence warnings when either muxer/demuxer is disabled Date: Thu, 28 Dec 2023 19:45:05 +0100 Message-ID: <2598dd89da395130bfd2b63460dceffc723bc4fc.camel@haerdin.se> (raw) In-Reply-To: <d62160779ddc0f16521167819e70994a1270e662.camel@haerdin.se> [-- Attachment #1: Type: text/plain, Size: 1 bytes --] [-- Attachment #2: 0005-lavf-codec2-Silence-warnings-when-either-muxer-demux.patch --] [-- Type: text/x-patch, Size: 4363 bytes --] From 6fd458b7b9867a92a0876ddd3455ac37b160f08a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= <git@haerdin.se> Date: Wed, 27 Dec 2023 22:52:25 +0100 Subject: [PATCH 5/6] lavf/codec2: Silence warnings when either muxer/demuxer is disabled --- libavformat/codec2.c | 76 +++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 33 deletions(-) diff --git a/libavformat/codec2.c b/libavformat/codec2.c index b0c76714bc..0cba9bbd6c 100644 --- a/libavformat/codec2.c +++ b/libavformat/codec2.c @@ -49,6 +49,7 @@ typedef struct { int frames_per_packet; } Codec2Context; +#if CONFIG_CODEC2_DEMUXER static int check_version(uint8_t major, uint8_t minor) { //no .c2 files prior to 0.8 or later than 1.X if (major == MIN_MAJOR_VERSION && minor < MIN_MINOR_VERSION) @@ -69,7 +70,9 @@ static int codec2_probe(const AVProbeData *p) //32 bits of identification -> low score return AVPROBE_SCORE_EXTENSION + 1; } +#endif +#if CONFIG_CODEC2_DEMUXER || CONFIG_CODEC2RAW_DEMUXER //Mimics codec2_samples_per_frame() static int codec2_mode_frame_size(AVFormatContext *s, int mode) { @@ -161,6 +164,41 @@ static int codec2_read_header_common(AVFormatContext *s, AVStream *st, int heade return 0; } +static int codec2_read_packet(AVFormatContext *s, AVPacket *pkt) +{ + Codec2Context *c2 = s->priv_data; + AVStream *st = s->streams[0]; + int ret, size, n, block_align, frame_size; + + block_align = st->codecpar->block_align; + frame_size = st->codecpar->frame_size; + + if (block_align <= 0 || frame_size <= 0 || c2->frames_per_packet <= 0) { + return AVERROR(EINVAL); + } + + //try to read desired number of frames, compute n from to actual number of bytes read + size = c2->frames_per_packet * block_align; + ret = av_get_packet(s->pb, pkt, size); + if (ret < 0) { + return ret; + } + + //only set duration - compute_pkt_fields() and ff_pcm_read_seek() takes care of everything else + //tested by spamming the seek functionality in ffplay + n = ret / block_align; + pkt->duration = n * frame_size; + + //un-mark packet as corrupt if size is a multiple of block_align + //this can happen when frames_per_packet > 1 + if (ret % block_align == 0) + pkt->flags &= ~AV_PKT_FLAG_CORRUPT; + + return ret; +} +#endif + +#if CONFIG_CODEC2_DEMUXER static int codec2_read_header(AVFormatContext *s) { AVStream *st = avformat_new_stream(s, NULL); @@ -197,40 +235,9 @@ static int codec2_read_header(AVFormatContext *s) return codec2_read_header_common(s, st, CODEC2_EXTRADATA_SIZE); } +#endif -static int codec2_read_packet(AVFormatContext *s, AVPacket *pkt) -{ - Codec2Context *c2 = s->priv_data; - AVStream *st = s->streams[0]; - int ret, size, n, block_align, frame_size; - - block_align = st->codecpar->block_align; - frame_size = st->codecpar->frame_size; - - if (block_align <= 0 || frame_size <= 0 || c2->frames_per_packet <= 0) { - return AVERROR(EINVAL); - } - - //try to read desired number of frames, compute n from to actual number of bytes read - size = c2->frames_per_packet * block_align; - ret = av_get_packet(s->pb, pkt, size); - if (ret < 0) { - return ret; - } - - //only set duration - compute_pkt_fields() and ff_pcm_read_seek() takes care of everything else - //tested by spamming the seek functionality in ffplay - n = ret / block_align; - pkt->duration = n * frame_size; - - //un-mark packet as corrupt if size is a multiple of block_align - //this can happen when frames_per_packet > 1 - if (ret % block_align == 0) - pkt->flags &= ~AV_PKT_FLAG_CORRUPT; - - return ret; -} - +#if CONFIG_CODEC2_MUXER static int codec2_write_header(AVFormatContext *s) { AVStream *st; @@ -253,7 +260,9 @@ static int codec2_write_header(AVFormatContext *s) return 0; } +#endif +#if CONFIG_CODEC2RAW_DEMUXER static int codec2raw_read_header(AVFormatContext *s) { Codec2Context *c2 = s->priv_data; @@ -280,6 +289,7 @@ static int codec2raw_read_header(AVFormatContext *s) return codec2_read_header_common(s, st, 0); } +#endif //transcoding report2074.c2 to wav went from 7.391s to 5.322s with -frames_per_packet 1000 compared to default, same sha1sum #define FRAMES_PER_PACKET \ -- 2.39.2 [-- Attachment #3: Type: text/plain, Size: 251 bytes --] _______________________________________________ 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:[~2023-12-28 18:45 UTC|newest] Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-12-28 18:43 [FFmpeg-devel] [PATCH 1/6] lavc/codec2utils: Use actual libcodec2 version Tomas Härdin 2023-12-28 18:43 ` [FFmpeg-devel] [PATCH 2/6] lavf/codec2: Compute duration from filesize Tomas Härdin 2023-12-28 18:44 ` [FFmpeg-devel] [PATCH 3/6] lavf/codec2: Allow versions between 0.8 and 1.X Tomas Härdin 2023-12-28 18:44 ` [FFmpeg-devel] [PATCH 4/6] lavf/codec2: Multiple of block_align -> not corrupt Tomas Härdin 2023-12-28 18:45 ` Tomas Härdin [this message] 2023-12-28 18:48 ` [FFmpeg-devel] [PATCH 6/6] Add FATE tests for codec2, codec2raw and libcodec2 wrapper Tomas Härdin 2023-12-29 10:40 ` Andreas Rheinhardt 2023-12-29 12:40 ` Tomas Härdin 2023-12-30 16:02 ` Tomas Härdin 2023-12-30 16:55 ` Tomas Härdin 2023-12-28 20:29 ` [FFmpeg-devel] [PATCH 1/6] lavc/codec2utils: Use actual libcodec2 version Michael Niedermayer 2023-12-28 21:21 ` Tomas Härdin 2023-12-28 23:30 ` Michael Niedermayer 2023-12-29 12:43 ` Tomas Härdin 2023-12-30 16:00 ` Tomas Härdin
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=2598dd89da395130bfd2b63460dceffc723bc4fc.camel@haerdin.se \ --to=git@haerdin.se \ --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