[FFmpeg-cvslog] avcodec/codec2utils: move the remaining avpriv functions to lavf

James Almer git at videolan.org
Wed Oct 28 18:33:28 EET 2020


ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Mon Oct 26 11:18:03 2020 -0300| [37d742b607d47122d23d548ffd7ad9b09cbc5298] | committer: James Almer

avcodec/codec2utils: move the remaining avpriv functions to lavf

They are only used by the codec2 demuxers.

The symbols are kept around until the next major bump.

Signed-off-by: James Almer <jamrial at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=37d742b607d47122d23d548ffd7ad9b09cbc5298
---

 libavcodec/codec2utils.c |  2 ++
 libavcodec/codec2utils.h |  4 +++
 libavformat/codec2.c     | 66 +++++++++++++++++++++++++++++++++++++++++++++---
 3 files changed, 69 insertions(+), 3 deletions(-)

diff --git a/libavcodec/codec2utils.c b/libavcodec/codec2utils.c
index f1b6e56526..a942662403 100644
--- a/libavcodec/codec2utils.c
+++ b/libavcodec/codec2utils.c
@@ -23,6 +23,7 @@
 #include "internal.h"
 #include "libavcodec/codec2utils.h"
 
+#if LIBAVCODEC_VERSION_MAJOR < 59
 int avpriv_codec2_mode_bit_rate(void *logctx, int mode)
 {
     int frame_size  = avpriv_codec2_mode_frame_size(logctx, mode);
@@ -78,3 +79,4 @@ int avpriv_codec2_mode_block_align(void *logctx, int mode)
         return block_align_table[mode];
     }
 }
+#endif
diff --git a/libavcodec/codec2utils.h b/libavcodec/codec2utils.h
index 2ee7a592a1..37f0693dc7 100644
--- a/libavcodec/codec2utils.h
+++ b/libavcodec/codec2utils.h
@@ -24,6 +24,8 @@
 
 #include <stdint.h>
 
+#include "version.h"
+
 //Highest mode we're willing to use.
 //Don't want to let users accidentally produce files that can't be decoded in the future.
 //CODEC2_MODE_WB (9) is experimental/unstable as of 2017-11-23.
@@ -45,6 +47,7 @@
     { "700B", "700B", 0, AV_OPT_TYPE_CONST, {.i64 = 7}, .flags=option_flags, .unit="codec2_mode"},\
     { "700C", "700C", 0, AV_OPT_TYPE_CONST, {.i64 = 8}, .flags=option_flags, .unit="codec2_mode"}
 
+#if LIBAVCODEC_VERSION_MAJOR < 59
 //The three following functions are here to avoid needing libavformat/codec2.c to depend on libcodec2
 
 //Computes bitrate from mode, with frames rounded up to the nearest octet.
@@ -58,6 +61,7 @@ int avpriv_codec2_mode_frame_size(void *logctx, int mode);
 
 //Mimics (codec2_bits_per_frame()+7)/8
 int avpriv_codec2_mode_block_align(void *logctx, int mode);
+#endif
 
 #define CODEC2_EXTRADATA_SIZE 4
 
diff --git a/libavformat/codec2.c b/libavformat/codec2.c
index bf2fb4aa43..0c2ad3aa01 100644
--- a/libavformat/codec2.c
+++ b/libavformat/codec2.c
@@ -61,6 +61,66 @@ static int codec2_probe(const AVProbeData *p)
     return AVPROBE_SCORE_EXTENSION + 1;
 }
 
+//Mimics codec2_samples_per_frame()
+static int codec2_mode_frame_size(AVFormatContext *s, int mode)
+{
+    int frame_size_table[CODEC2_MODE_MAX+1] = {
+        160,    // 3200
+        160,    // 2400
+        320,    // 1600
+        320,    // 1400
+        320,    // 1300
+        320,    // 1200
+        320,    // 700
+        320,    // 700B
+        320,    // 700C
+    };
+
+    if (mode < 0 || mode > CODEC2_MODE_MAX) {
+        av_log(s, AV_LOG_ERROR, "unknown codec2 mode %i, can't find frame_size\n", mode);
+        return 0;
+    } else {
+        return frame_size_table[mode];
+    }
+}
+
+//Mimics (codec2_bits_per_frame()+7)/8
+static int codec2_mode_block_align(AVFormatContext *s, int mode)
+{
+    int block_align_table[CODEC2_MODE_MAX+1] = {
+        8,      // 3200
+        6,      // 2400
+        8,      // 1600
+        7,      // 1400
+        7,      // 1300
+        6,      // 1200
+        4,      // 700
+        4,      // 700B
+        4,      // 700C
+    };
+
+    if (mode < 0 || mode > CODEC2_MODE_MAX) {
+        av_log(s, AV_LOG_ERROR, "unknown codec2 mode %i, can't find block_align\n", mode);
+        return 0;
+    } else {
+        return block_align_table[mode];
+    }
+}
+
+//Computes bitrate from mode, with frames rounded up to the nearest octet.
+//So 700 bit/s (28 bits/frame) becomes 800 bits/s (32 bits/frame).
+static int codec2_mode_bit_rate(AVFormatContext *s, int mode)
+{
+    int frame_size  = codec2_mode_frame_size(s, mode);
+    int block_align = codec2_mode_block_align(s, mode);
+
+    if (frame_size <= 0 || block_align <= 0) {
+        return 0;
+    }
+
+    return 8 * 8000 * block_align / frame_size;
+}
+
 static int codec2_read_header_common(AVFormatContext *s, AVStream *st)
 {
     int mode = codec2_mode_from_extradata(st->codecpar->extradata);
@@ -71,9 +131,9 @@ static int codec2_read_header_common(AVFormatContext *s, AVStream *st)
     st->codecpar->channels          = 1;
     st->codecpar->format            = AV_SAMPLE_FMT_S16;
     st->codecpar->channel_layout    = AV_CH_LAYOUT_MONO;
-    st->codecpar->bit_rate          = avpriv_codec2_mode_bit_rate(s, mode);
-    st->codecpar->frame_size        = avpriv_codec2_mode_frame_size(s, mode);
-    st->codecpar->block_align       = avpriv_codec2_mode_block_align(s, mode);
+    st->codecpar->bit_rate          = codec2_mode_bit_rate(s, mode);
+    st->codecpar->frame_size        = codec2_mode_frame_size(s, mode);
+    st->codecpar->block_align       = codec2_mode_block_align(s, mode);
 
     if (st->codecpar->bit_rate <= 0 ||
         st->codecpar->frame_size <= 0 ||



More information about the ffmpeg-cvslog mailing list