]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/eac3dec.c
Loop up to MAX_THREADS instead of h->s.avctx->thread_count to free the thread
[ffmpeg] / libavcodec / eac3dec.c
index 836cb8ef0524b748121d4562826bf2eef242ecd1..8af729dc22e6797b5fa76d9bce2940edc922fecc 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+/*
+ * There are several features of E-AC-3 that this decoder does not yet support.
+ *
+ * Spectral Extension
+ *     There is a patch to get this working for the two samples we have that
+ *     use it, but it needs some minor changes in order to be accepted.
+ *
+ * Enhanced Coupling
+ *     No known samples exist.  If any ever surface, this feature should not be
+ *     too difficult to implement.
+ *
+ * Reduced Sample Rates
+ *     No known samples exist.  The spec also does not give clear information
+ *     on how this is to be implemented.
+ *
+ * Dependent Streams
+ *     Only the independent stream is currently decoded. Any dependent
+ *     streams are skipped.  We have only come across two examples of this, and
+ *     they are both just test streams, one for HD-DVD and the other for
+ *     Blu-ray.
+ *
+ * Transient Pre-noise Processing
+ *     This is side information which a decoder should use to reduce artifacts
+ *     caused by transients.  There are samples which are known to have this
+ *     information, but this decoder currently ignores it.
+ */
+
+
 #include "avcodec.h"
+#include "internal.h"
+#include "aac_ac3_parser.h"
 #include "ac3.h"
 #include "ac3_parser.h"
 #include "ac3dec.h"
@@ -131,7 +161,7 @@ void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch)
             /* Vector Quantization */
             int v = get_bits(gbc, bits);
             for (blk = 0; blk < 6; blk++) {
-                s->pre_mantissa[ch][bin][blk] = ff_eac3_vq_hebap[hebap][v][blk] << 8;
+                s->pre_mantissa[ch][bin][blk] = ff_eac3_mantissa_vq[hebap][v][blk] << 8;
             }
         } else {
             /* Gain Adaptive Quantization */
@@ -182,11 +212,11 @@ int ff_eac3_parse_header(AC3DecodeContext *s)
        application can select from. each independent stream can also contain
        dependent streams which are used to add or replace channels. */
     if (s->frame_type == EAC3_FRAME_TYPE_DEPENDENT) {
-        av_log_missing_feature(s->avctx, "Dependent substream decoding", 1);
-        return AC3_PARSE_ERROR_FRAME_TYPE;
+        ff_log_missing_feature(s->avctx, "Dependent substream decoding", 1);
+        return AAC_AC3_PARSE_ERROR_FRAME_TYPE;
     } else if (s->frame_type == EAC3_FRAME_TYPE_RESERVED) {
         av_log(s->avctx, AV_LOG_ERROR, "Reserved frame type\n");
-        return AC3_PARSE_ERROR_FRAME_TYPE;
+        return AAC_AC3_PARSE_ERROR_FRAME_TYPE;
     }
 
     /* The substream id indicates which substream this frame belongs to. each
@@ -194,8 +224,8 @@ int ff_eac3_parse_header(AC3DecodeContext *s)
        associated to an independent stream have matching substream id's. */
     if (s->substreamid) {
         /* only decode substream with id=0. skip any additional substreams. */
-        av_log_missing_feature(s->avctx, "Additional substreams", 1);
-        return AC3_PARSE_ERROR_FRAME_TYPE;
+        ff_log_missing_feature(s->avctx, "Additional substreams", 1);
+        return AAC_AC3_PARSE_ERROR_FRAME_TYPE;
     }
 
     if (s->bit_alloc_params.sr_code == EAC3_SR_CODE_REDUCED) {
@@ -203,7 +233,7 @@ int ff_eac3_parse_header(AC3DecodeContext *s)
            rates in bit allocation.  The best assumption would be that it is
            handled like AC-3 DolbyNet, but we cannot be sure until we have a
            sample which utilizes this feature. */
-        av_log_missing_feature(s->avctx, "Reduced sampling rates", 1);
+        ff_log_missing_feature(s->avctx, "Reduced sampling rates", 1);
         return -1;
     }
     skip_bits(gbc, 5); // skip bitstream id
@@ -420,21 +450,21 @@ int ff_eac3_parse_header(AC3DecodeContext *s)
 
     /* determine which channels use AHT */
     if (parse_aht_info) {
-        /* AHT is only available when there are 6 blocks in the frame.
-           The coupling channel can only use AHT when coupling is in use for
-           all blocks.
-           reference: Section E3.3.2 Bit Stream Helper Variables */
+        /* For AHT to be used, all non-zero blocks must reuse exponents from
+           the first block.  Furthermore, for AHT to be used in the coupling
+           channel, all blocks must use coupling and use the same coupling
+           strategy. */
         s->channel_uses_aht[CPL_CH]=0;
         for (ch = (num_cpl_blocks != 6); ch <= s->channels; ch++) {
-            int nchregs = 0;
-            for (blk = 0; blk < 6; blk++) {
-                if (ch)
-                    nchregs += (s->exp_strategy[blk][ch] != EXP_REUSE);
-                else
-                    nchregs += s->cpl_strategy_exists[blk] ||
-                               (s->exp_strategy[blk][CPL_CH] != EXP_REUSE);
+            int use_aht = 1;
+            for (blk = 1; blk < 6; blk++) {
+                if ((s->exp_strategy[blk][ch] != EXP_REUSE) ||
+                        (!ch && s->cpl_strategy_exists[blk])) {
+                    use_aht = 0;
+                    break;
+                }
             }
-            s->channel_uses_aht[ch] = (nchregs == 1) && get_bits1(gbc);
+            s->channel_uses_aht[ch] = use_aht && get_bits1(gbc);
         }
     } else {
         memset(s->channel_uses_aht, 0, sizeof(s->channel_uses_aht));
@@ -460,7 +490,7 @@ int ff_eac3_parse_header(AC3DecodeContext *s)
 
     /* spectral extension attenuation data */
     if (parse_spx_atten_data) {
-        av_log_missing_feature(s->avctx, "Spectral extension attenuation", 1);
+        ff_log_missing_feature(s->avctx, "Spectral extension attenuation", 1);
         for (ch = 1; ch <= s->fbw_channels; ch++) {
             if (get_bits1(gbc)) { // channel has spx attenuation
                 skip_bits(gbc, 5); // skip spx attenuation code
@@ -475,7 +505,8 @@ int ff_eac3_parse_header(AC3DecodeContext *s)
            The spec does not say what this data is or what it's used for.
            It is likely the offset of each block within the frame. */
         int block_start_bits = (s->num_blocks-1) * (4 + av_log2(s->frame_size-2));
-        skip_bits(gbc, block_start_bits);
+        skip_bits_long(gbc, block_start_bits);
+        ff_log_missing_feature(s->avctx, "Block start info", 1);
     }
 
     /* syntax state initialization */