]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/ac3enc.c
lavc: introduce a new decoding/encoding API with decoupled input/output
[ffmpeg] / libavcodec / ac3enc.c
index df86f0bd94228e5a5820e8a97616762b6901781e..da141e1acb3ffb81700e93dc57ad462f73d583e2 100644 (file)
  * The simplest AC-3 encoder.
  */
 
-//#define ASSERT_LEVEL 2
-
 #include <stdint.h>
 
+#include "libavutil/attributes.h"
 #include "libavutil/avassert.h"
 #include "libavutil/avstring.h"
 #include "libavutil/channel_layout.h"
 #include "libavutil/internal.h"
 #include "libavutil/opt.h"
 #include "avcodec.h"
+#include "me_cmp.h"
 #include "put_bits.h"
+#include "audiodsp.h"
 #include "ac3dsp.h"
 #include "ac3.h"
 #include "fft.h"
+#include "internal.h"
 #include "ac3enc.h"
 #include "eac3enc.h"
 
@@ -379,7 +381,7 @@ static void compute_exp_strategy(AC3EncodeContext *s)
                 exp_strategy[blk] = EXP_NEW;
                 continue;
             }
-            exp_diff = s->dsp.sad[0](NULL, exp, exp - AC3_MAX_COEFS, 16, 16);
+            exp_diff = s->mecc.sad[0](NULL, exp, exp - AC3_MAX_COEFS, 16, 16);
             exp_strategy[blk] = EXP_REUSE;
             if (ch == CPL_CH && exp_diff > (EXP_DIFF_THRESHOLD * (s->blocks[blk].end_freq[ch] - s->start_freq[ch]) / AC3_MAX_COEFS))
                 exp_strategy[blk] = EXP_NEW;
@@ -754,7 +756,7 @@ static void count_frame_bits_fixed(AC3EncodeContext *s)
  * Initialize bit allocation.
  * Set default parameter codes and calculate parameter values.
  */
-static void bit_alloc_init(AC3EncodeContext *s)
+static av_cold void bit_alloc_init(AC3EncodeContext *s)
 {
     int ch;
 
@@ -1689,43 +1691,43 @@ static void dprint_options(AC3EncodeContext *s)
     case 16:  av_strlcpy(strbuf, "E-AC-3 (enhanced)",       32); break;
     default: snprintf(strbuf, 32, "ERROR");
     }
-    av_dlog(avctx, "bitstream_id: %s (%d)\n", strbuf, s->bitstream_id);
-    av_dlog(avctx, "sample_fmt: %s\n", av_get_sample_fmt_name(avctx->sample_fmt));
+    ff_dlog(avctx, "bitstream_id: %s (%d)\n", strbuf, s->bitstream_id);
+    ff_dlog(avctx, "sample_fmt: %s\n", av_get_sample_fmt_name(avctx->sample_fmt));
     av_get_channel_layout_string(strbuf, 32, s->channels, avctx->channel_layout);
-    av_dlog(avctx, "channel_layout: %s\n", strbuf);
-    av_dlog(avctx, "sample_rate: %d\n", s->sample_rate);
-    av_dlog(avctx, "bit_rate: %d\n", s->bit_rate);
-    av_dlog(avctx, "blocks/frame: %d (code=%d)\n", s->num_blocks, s->num_blks_code);
+    ff_dlog(avctx, "channel_layout: %s\n", strbuf);
+    ff_dlog(avctx, "sample_rate: %d\n", s->sample_rate);
+    ff_dlog(avctx, "bit_rate: %d\n", s->bit_rate);
+    ff_dlog(avctx, "blocks/frame: %d (code=%d)\n", s->num_blocks, s->num_blks_code);
     if (s->cutoff)
-        av_dlog(avctx, "cutoff: %d\n", s->cutoff);
+        ff_dlog(avctx, "cutoff: %d\n", s->cutoff);
 
-    av_dlog(avctx, "per_frame_metadata: %s\n",
+    ff_dlog(avctx, "per_frame_metadata: %s\n",
             opt->allow_per_frame_metadata?"on":"off");
     if (s->has_center)
-        av_dlog(avctx, "center_mixlev: %0.3f (%d)\n", opt->center_mix_level,
+        ff_dlog(avctx, "center_mixlev: %0.3f (%d)\n", opt->center_mix_level,
                 s->center_mix_level);
     else
-        av_dlog(avctx, "center_mixlev: {not written}\n");
+        ff_dlog(avctx, "center_mixlev: {not written}\n");
     if (s->has_surround)
-        av_dlog(avctx, "surround_mixlev: %0.3f (%d)\n", opt->surround_mix_level,
+        ff_dlog(avctx, "surround_mixlev: %0.3f (%d)\n", opt->surround_mix_level,
                 s->surround_mix_level);
     else
-        av_dlog(avctx, "surround_mixlev: {not written}\n");
+        ff_dlog(avctx, "surround_mixlev: {not written}\n");
     if (opt->audio_production_info) {
-        av_dlog(avctx, "mixing_level: %ddB\n", opt->mixing_level);
+        ff_dlog(avctx, "mixing_level: %ddB\n", opt->mixing_level);
         switch (opt->room_type) {
         case AC3ENC_OPT_NOT_INDICATED: av_strlcpy(strbuf, "notindicated", 32); break;
         case AC3ENC_OPT_LARGE_ROOM:    av_strlcpy(strbuf, "large", 32);        break;
         case AC3ENC_OPT_SMALL_ROOM:    av_strlcpy(strbuf, "small", 32);        break;
         default: snprintf(strbuf, 32, "ERROR (%d)", opt->room_type);
         }
-        av_dlog(avctx, "room_type: %s\n", strbuf);
+        ff_dlog(avctx, "room_type: %s\n", strbuf);
     } else {
-        av_dlog(avctx, "mixing_level: {not written}\n");
-        av_dlog(avctx, "room_type: {not written}\n");
+        ff_dlog(avctx, "mixing_level: {not written}\n");
+        ff_dlog(avctx, "room_type: {not written}\n");
     }
-    av_dlog(avctx, "copyright: %s\n", opt->copyright?"on":"off");
-    av_dlog(avctx, "dialnorm: %ddB\n", opt->dialogue_level);
+    ff_dlog(avctx, "copyright: %s\n", opt->copyright?"on":"off");
+    ff_dlog(avctx, "dialnorm: %ddB\n", opt->dialogue_level);
     if (s->channel_mode == AC3_CHMODE_STEREO) {
         switch (opt->dolby_surround_mode) {
         case AC3ENC_OPT_NOT_INDICATED: av_strlcpy(strbuf, "notindicated", 32); break;
@@ -1733,11 +1735,11 @@ static void dprint_options(AC3EncodeContext *s)
         case AC3ENC_OPT_MODE_OFF:      av_strlcpy(strbuf, "off", 32);          break;
         default: snprintf(strbuf, 32, "ERROR (%d)", opt->dolby_surround_mode);
         }
-        av_dlog(avctx, "dsur_mode: %s\n", strbuf);
+        ff_dlog(avctx, "dsur_mode: %s\n", strbuf);
     } else {
-        av_dlog(avctx, "dsur_mode: {not written}\n");
+        ff_dlog(avctx, "dsur_mode: {not written}\n");
     }
-    av_dlog(avctx, "original: %s\n", opt->original?"on":"off");
+    ff_dlog(avctx, "original: %s\n", opt->original?"on":"off");
 
     if (s->bitstream_id == 6) {
         if (opt->extended_bsi_1) {
@@ -1747,17 +1749,17 @@ static void dprint_options(AC3EncodeContext *s)
             case AC3ENC_OPT_DOWNMIX_LORO:  av_strlcpy(strbuf, "loro", 32);         break;
             default: snprintf(strbuf, 32, "ERROR (%d)", opt->preferred_stereo_downmix);
             }
-            av_dlog(avctx, "dmix_mode: %s\n", strbuf);
-            av_dlog(avctx, "ltrt_cmixlev: %0.3f (%d)\n",
+            ff_dlog(avctx, "dmix_mode: %s\n", strbuf);
+            ff_dlog(avctx, "ltrt_cmixlev: %0.3f (%d)\n",
                     opt->ltrt_center_mix_level, s->ltrt_center_mix_level);
-            av_dlog(avctx, "ltrt_surmixlev: %0.3f (%d)\n",
+            ff_dlog(avctx, "ltrt_surmixlev: %0.3f (%d)\n",
                     opt->ltrt_surround_mix_level, s->ltrt_surround_mix_level);
-            av_dlog(avctx, "loro_cmixlev: %0.3f (%d)\n",
+            ff_dlog(avctx, "loro_cmixlev: %0.3f (%d)\n",
                     opt->loro_center_mix_level, s->loro_center_mix_level);
-            av_dlog(avctx, "loro_surmixlev: %0.3f (%d)\n",
+            ff_dlog(avctx, "loro_surmixlev: %0.3f (%d)\n",
                     opt->loro_surround_mix_level, s->loro_surround_mix_level);
         } else {
-            av_dlog(avctx, "extended bitstream info 1: {not written}\n");
+            ff_dlog(avctx, "extended bitstream info 1: {not written}\n");
         }
         if (opt->extended_bsi_2) {
             switch (opt->dolby_surround_ex_mode) {
@@ -1766,23 +1768,23 @@ static void dprint_options(AC3EncodeContext *s)
             case AC3ENC_OPT_MODE_OFF:      av_strlcpy(strbuf, "off", 32);          break;
             default: snprintf(strbuf, 32, "ERROR (%d)", opt->dolby_surround_ex_mode);
             }
-            av_dlog(avctx, "dsurex_mode: %s\n", strbuf);
+            ff_dlog(avctx, "dsurex_mode: %s\n", strbuf);
             switch (opt->dolby_headphone_mode) {
             case AC3ENC_OPT_NOT_INDICATED: av_strlcpy(strbuf, "notindicated", 32); break;
             case AC3ENC_OPT_MODE_ON:       av_strlcpy(strbuf, "on", 32);           break;
             case AC3ENC_OPT_MODE_OFF:      av_strlcpy(strbuf, "off", 32);          break;
             default: snprintf(strbuf, 32, "ERROR (%d)", opt->dolby_headphone_mode);
             }
-            av_dlog(avctx, "dheadphone_mode: %s\n", strbuf);
+            ff_dlog(avctx, "dheadphone_mode: %s\n", strbuf);
 
             switch (opt->ad_converter_type) {
             case AC3ENC_OPT_ADCONV_STANDARD: av_strlcpy(strbuf, "standard", 32); break;
             case AC3ENC_OPT_ADCONV_HDCD:     av_strlcpy(strbuf, "hdcd", 32);     break;
             default: snprintf(strbuf, 32, "ERROR (%d)", opt->ad_converter_type);
             }
-            av_dlog(avctx, "ad_conv_type: %s\n", strbuf);
+            ff_dlog(avctx, "ad_conv_type: %s\n", strbuf);
         } else {
-            av_dlog(avctx, "extended bitstream info 2: {not written}\n");
+            ff_dlog(avctx, "extended bitstream info 2: {not written}\n");
         }
     }
 #endif
@@ -2435,7 +2437,7 @@ av_cold int ff_ac3_encode_init(AVCodecContext *avctx)
         return ret;
 
     avctx->frame_size = AC3_BLOCK_SIZE * s->num_blocks;
-    avctx->delay      = AC3_BLOCK_SIZE;
+    avctx->initial_padding = AC3_BLOCK_SIZE;
 
     s->bitstream_mode = avctx->audio_service_type;
     if (s->bitstream_mode == AV_AUDIO_SERVICE_TYPE_KARAOKE)
@@ -2481,9 +2483,9 @@ av_cold int ff_ac3_encode_init(AVCodecContext *avctx)
     if (ret)
         goto init_fail;
 
-    ff_dsputil_init(&s->dsp, avctx);
-    avpriv_float_dsp_init(&s->fdsp, avctx->flags & CODEC_FLAG_BITEXACT);
-    ff_ac3dsp_init(&s->ac3dsp, avctx->flags & CODEC_FLAG_BITEXACT);
+    ff_audiodsp_init(&s->adsp);
+    ff_me_cmp_init(&s->mecc, avctx);
+    ff_ac3dsp_init(&s->ac3dsp, avctx->flags & AV_CODEC_FLAG_BITEXACT);
 
     dprint_options(s);