From 6fd458b7b9867a92a0876ddd3455ac37b160f08a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= <g...@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
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".