[FFmpeg-devel] [PATCH 2/2] lavc: G.721 codec

Paul B Mahol onemda at gmail.com
Sat Jan 12 12:38:49 CET 2013


It is just subset of G.726; add new codec id
thus allowing remuxing without fear that we
will mux 6.726 instead of 6.721.

Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
 configure               |  2 ++
 libavcodec/allcodecs.c  |  1 +
 libavcodec/avcodec.h    |  1 +
 libavcodec/codec_desc.c |  7 +++++++
 libavcodec/g726.c       | 34 ++++++++++++++++++++++++++++++++++
 libavcodec/utils.c      |  1 +
 libavformat/au.c        |  1 +
 libavformat/riff.c      |  1 +
 8 files changed, 48 insertions(+)

diff --git a/configure b/configure
index 889b186..6682c2a 100755
--- a/configure
+++ b/configure
@@ -1671,6 +1671,8 @@ flashsv2_decoder_select="zlib"
 flv_decoder_select="h263_decoder"
 flv_encoder_select="h263_encoder"
 fraps_decoder_select="huffman"
+g721_decoder_select="g726_decoder"
+g721_encoder_select="g726_encoder"
 h261_decoder_select="error_resilience mpegvideo"
 h261_encoder_select="aandcttables mpegvideoenc"
 h263_decoder_select="error_resilience h263_parser mpegvideo"
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 619c8e6..5107a9b 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -417,6 +417,7 @@ void avcodec_register_all(void)
     REGISTER_DECODER(ADPCM_EA_R2,       adpcm_ea_r2);
     REGISTER_DECODER(ADPCM_EA_R3,       adpcm_ea_r3);
     REGISTER_DECODER(ADPCM_EA_XAS,      adpcm_ea_xas);
+    REGISTER_ENCDEC (ADPCM_G721,        adpcm_g721);
     REGISTER_ENCDEC (ADPCM_G722,        adpcm_g722);
     REGISTER_ENCDEC (ADPCM_G726,        adpcm_g726);
     REGISTER_DECODER(ADPCM_IMA_AMV,     adpcm_ima_amv);
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 1522c95..f984e3c 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -358,6 +358,7 @@ enum AVCodecID {
     AV_CODEC_ID_VIMA       = MKBETAG('V','I','M','A'),
     AV_CODEC_ID_ADPCM_AFC  = MKBETAG('A','F','C',' '),
     AV_CODEC_ID_ADPCM_IMA_OKI = MKBETAG('O','K','I',' '),
+    AV_CODEC_ID_ADPCM_G721 = MKBETAG('G','7','2','1'),
 
     /* AMR */
     AV_CODEC_ID_AMR_NB = 0x12000,
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 7802094..353a7da 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -1654,6 +1654,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
         .props     = AV_CODEC_PROP_LOSSY,
     },
     {
+        .id        = AV_CODEC_ID_ADPCM_G721,
+        .type      = AVMEDIA_TYPE_AUDIO,
+        .name      = "adpcm_g721",
+        .long_name = NULL_IF_CONFIG_SMALL("G.721 ADPCM"),
+        .props     = AV_CODEC_PROP_LOSSY,
+    },
+    {
         .id        = AV_CODEC_ID_ADPCM_G726,
         .type      = AVMEDIA_TYPE_AUDIO,
         .name      = "adpcm_g726",
diff --git a/libavcodec/g726.c b/libavcodec/g726.c
index ff69fb6..0c6c67a 100644
--- a/libavcodec/g726.c
+++ b/libavcodec/g726.c
@@ -325,10 +325,14 @@ static av_cold int g726_encode_init(AVCodecContext *avctx)
         return AVERROR(EINVAL);
     }
 
+    if (avctx->codec_id == AV_CODEC_ID_ADPCM_G726) {
     if (avctx->bit_rate)
         c->code_size = (avctx->bit_rate + avctx->sample_rate/2) / avctx->sample_rate;
 
     c->code_size = av_clip(c->code_size, 2, 5);
+    } else {
+        c->code_size = 4;
+    }
     avctx->bit_rate = c->code_size * avctx->sample_rate;
     avctx->bits_per_coded_sample = c->code_size;
 
@@ -415,6 +419,22 @@ AVCodec ff_adpcm_g726_encoder = {
     .priv_class     = &class,
     .defaults       = defaults,
 };
+
+AVCodec ff_adpcm_g721_encoder = {
+    .name           = "g721",
+    .type           = AVMEDIA_TYPE_AUDIO,
+    .id             = AV_CODEC_ID_ADPCM_G721,
+    .priv_data_size = sizeof(G726Context),
+    .init           = g726_encode_init,
+    .encode2        = g726_encode_frame,
+#if FF_API_OLD_ENCODE_AUDIO
+    .close          = g726_encode_close,
+#endif
+    .capabilities   = CODEC_CAP_SMALL_LAST_FRAME,
+    .sample_fmts    = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16,
+                                                     AV_SAMPLE_FMT_NONE },
+    .long_name      = NULL_IF_CONFIG_SMALL("G.721 ADPCM"),
+};
 #endif
 
 #if CONFIG_ADPCM_G726_DECODER
@@ -425,6 +445,8 @@ static av_cold int g726_decode_init(AVCodecContext *avctx)
     avctx->channels       = 1;
     avctx->channel_layout = AV_CH_LAYOUT_MONO;
 
+    if (avctx->codec_id == AV_CODEC_ID_ADPCM_G721)
+        avctx->bits_per_coded_sample = 4;
     c->code_size = avctx->bits_per_coded_sample;
     if (c->code_size < 2 || c->code_size > 5) {
         av_log(avctx, AV_LOG_ERROR, "Invalid number of bits %d\n", c->code_size);
@@ -491,4 +513,16 @@ AVCodec ff_adpcm_g726_decoder = {
     .capabilities   = CODEC_CAP_DR1,
     .long_name      = NULL_IF_CONFIG_SMALL("G.726 ADPCM"),
 };
+
+AVCodec ff_adpcm_g721_decoder = {
+    .name           = "g721",
+    .type           = AVMEDIA_TYPE_AUDIO,
+    .id             = AV_CODEC_ID_ADPCM_G721,
+    .priv_data_size = sizeof(G726Context),
+    .init           = g726_decode_init,
+    .decode         = g726_decode_frame,
+    .flush          = g726_decode_flush,
+    .capabilities   = CODEC_CAP_DR1,
+    .long_name      = NULL_IF_CONFIG_SMALL("G.721 ADPCM"),
+};
 #endif
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index f5ceae4..5628330 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -2235,6 +2235,7 @@ int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
     case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
     case AV_CODEC_ID_ADPCM_IMA_OKI:
     case AV_CODEC_ID_ADPCM_IMA_WS:
+    case AV_CODEC_ID_ADPCM_G721:
     case AV_CODEC_ID_ADPCM_G722:
     case AV_CODEC_ID_ADPCM_YAMAHA:
         return 4;
diff --git a/libavformat/au.c b/libavformat/au.c
index b3a793d..c528862 100644
--- a/libavformat/au.c
+++ b/libavformat/au.c
@@ -45,6 +45,7 @@ static const AVCodecTag codec_au_tags[] = {
     { AV_CODEC_ID_PCM_S32BE,  5 },
     { AV_CODEC_ID_PCM_F32BE,  6 },
     { AV_CODEC_ID_PCM_F64BE,  7 },
+    { AV_CODEC_ID_ADPCM_G721,23 },
     { AV_CODEC_ID_ADPCM_G722,24 },
     { AV_CODEC_ID_PCM_ALAW,  27 },
     { AV_CODEC_ID_NONE,       0 },
diff --git a/libavformat/riff.c b/libavformat/riff.c
index 573e417..cb6687e 100644
--- a/libavformat/riff.c
+++ b/libavformat/riff.c
@@ -349,6 +349,7 @@ const AVCodecTag ff_codec_wav_tags[] = {
     { AV_CODEC_ID_TRUESPEECH,      0x0022 },
     { AV_CODEC_ID_GSM_MS,          0x0031 },
     { AV_CODEC_ID_AMR_NB,          0x0038 },  /* rogue format number */
+    { AV_CODEC_ID_ADPCM_G721,      0x0040 },
     { AV_CODEC_ID_G723_1,          0x0042 },
     { AV_CODEC_ID_ADPCM_G726,      0x0045 },
     { AV_CODEC_ID_MP2,             0x0050 },
-- 
1.7.11.4



More information about the ffmpeg-devel mailing list