diff mbox series

[FFmpeg-devel,v2,6/7] lavf/codec2: Silence warnings when either muxer/demuxer is disabled

Message ID e07c3eb81e161c6d6d1215597710ab44416c6b13.camel@haerdin.se
State New
Headers show
Series [FFmpeg-devel,v2,1/7] lavc/codec2utils: Use actual libcodec2 version | expand

Checks

Context Check Description
yinshiyou/configure_loongarch64 warning Failed to apply patch
andriy/configure_x86 warning Failed to apply patch

Commit Message

Tomas Härdin Dec. 30, 2023, 9:26 p.m. UTC

diff mbox series

Patch

From f64b4a90ea22421db494d87f5904ae8c7294c871 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 6/7] 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 7447109752..8ff14bc72a 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_HEADER_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