Browse Source

Merge remote-tracking branch 'qatar/master'

* qatar/master: (28 commits)
  Remove some non-compiling debug messages.
  ffplay: Fix non-compiling debug printf and replace it by av_dlog.
  H264: x86 predict init cosmetics.
  ac3enc: Fix linking of AC-3 encoder without the E-AC-3 encoder.
  Move E-AC-3 encoder functions to a separate eac3enc.c file.
  ac3enc: remove convenience macro, #define DEBUG
  ac3enc: remove unused #define
  vc1: re-initialize tables after width/height change.
  APIchanges: fill-in git commit hash for av_get_bytes_per_sample() addition
  samplefmt: add av_get_bytes_per_sample()
  iirfilter: fix biquad filter coefficients.
  swscale: remove duplicate conversion routine in swScale().
  swscale: add yuv2planar/packed function typedefs.
  swscale: integrate yuv2nv12X_C into yuv2yuvX() function pointers.
  swscale: reindent x86 init code.
  swscale: extract SWS_FULL_CHR_H_INT conditional into init code.
  swscale: cosmetics.
  swscale: remove alp/chr/lumSrcOffset.
  swscale: un-special-case yuv2yuvX16_c().
  shorten: Remove stray DEBUG #define and corresponding av_dlog statement.
  ...

Conflicts:
	doc/APIchanges
	libavcodec/ac3enc.c
	libavutil/avutil.h
	libavutil/samplefmt.c
	libswscale/swscale.c
	libswscale/swscale_internal.h
	libswscale/x86/swscale_template.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
Michael Niedermayer 13 years ago
parent
commit
d552f616a2
10 changed files with 241 additions and 285 deletions
  1. 1 1
      configure
  2. 4 0
      doc/APIchanges
  3. 4 8
      ffplay.c
  4. 2 1
      libavcodec/Makefile
  5. 1 1
      libavcodec/aac_tablegen.h
  6. 0 1
      libavcodec/ac3.h
  7. 6 251
      libavcodec/ac3enc.c
  8. 214 0
      libavcodec/ac3enc.h
  9. 6 20
      libavcodec/bitstream.c
  10. 3 2
      libavcodec/dnxhdenc.h

+ 1 - 1
configure

@@ -107,7 +107,7 @@ Configuration options:
   --disable-mdct           disable MDCT code
   --disable-rdft           disable RDFT code
   --enable-vaapi           enable VAAPI code
-  --disable-vdpau          disable VDPAU code
+  --enable-vdpau           enable VDPAU code
   --disable-dxva2          disable DXVA2 code
   --enable-runtime-cpudetect detect cpu capabilities at runtime (bigger binary)
   --enable-hardcoded-tables use hardcoded tables instead of runtime generation

+ 4 - 0
doc/APIchanges

@@ -50,6 +50,10 @@ API changes, most recent first:
 2011-05-XX - XXXXXX - lavfi 2.6.0 - avcodec.h
   Add avfilter_get_video_buffer_ref_from_frame() to libavfilter/avcodec.h.
 
+2011-06-07 - a6703fa - lavu 51.4.0 - av_get_bytes_per_sample()
+  Add av_get_bytes_per_sample() in libavutil/samplefmt.h.
+  Deprecate av_get_bits_per_sample_fmt().
+
 2011-06-xx - xxxxxxx - lavu 51.3.0 - opt.h
   Add av_opt_free convenience function.
 

+ 4 - 8
ffplay.c

@@ -54,9 +54,6 @@
 const char program_name[] = "ffplay";
 const int program_birth_year = 2003;
 
-//#define DEBUG
-//#define DEBUG_SYNC
-
 #define MAX_QUEUE_SIZE (15 * 1024 * 1024)
 #define MIN_AUDIOQ_SIZE (20 * 16 * 1024)
 #define MIN_FRAMES 5
@@ -1052,10 +1049,9 @@ static double compute_target_time(double frame_current_pts, VideoState *is)
         }
     }
     is->frame_timer += delay;
-#if defined(DEBUG_SYNC)
-    printf("video: delay=%0.3f actual_delay=%0.3f pts=%0.3f A-V=%f\n",
-            delay, actual_delay, frame_current_pts, -diff);
-#endif
+
+    av_dlog(NULL, "video: delay=%0.3f pts=%0.3f A-V=%f\n",
+            delay, frame_current_pts, -diff);
 
     return is->frame_timer;
 }
@@ -2033,7 +2029,7 @@ static int audio_decode_frame(VideoState *is, double *pts_ptr)
             n = 2 * dec->channels;
             is->audio_clock += (double)data_size /
                 (double)(n * dec->sample_rate);
-#if defined(DEBUG_SYNC)
+#ifdef DEBUG
             {
                 static double last_clock;
                 printf("audio: delay=%0.3f clock=%0.3f pts=%0.3f\n",

+ 2 - 1
libavcodec/Makefile

@@ -127,7 +127,8 @@ OBJS-$(CONFIG_DVVIDEO_DECODER)         += dv.o dvdata.o
 OBJS-$(CONFIG_DVVIDEO_ENCODER)         += dv.o dvdata.o
 OBJS-$(CONFIG_DXA_DECODER)             += dxa.o
 OBJS-$(CONFIG_EAC3_DECODER)            += eac3dec.o eac3dec_data.o
-OBJS-$(CONFIG_EAC3_ENCODER)            += ac3enc_float.o ac3tab.o ac3.o kbdwin.o
+OBJS-$(CONFIG_EAC3_ENCODER)            += eac3enc.o ac3enc_float.o ac3tab.o \
+                                          ac3.o kbdwin.o
 OBJS-$(CONFIG_EACMV_DECODER)           += eacmv.o
 OBJS-$(CONFIG_EAMAD_DECODER)           += eamad.o eaidct.o mpeg12.o \
                                           mpeg12data.o mpegvideo.o  \

+ 1 - 1
libavcodec/aac_tablegen.h

@@ -29,7 +29,7 @@
 #include "libavcodec/aac_tables.h"
 #else
 #include "libavutil/mathematics.h"
-#include "libavcodec/aac.h"
+#include "aac.h"
 float ff_aac_pow2sf_tab[428];
 
 void ff_aac_tableinit(void)

+ 0 - 1
libavcodec/ac3.h

@@ -164,7 +164,6 @@ typedef struct AC3EncOptions {
     int cpl_start;    
 } AC3EncOptions;
 
-
 void ff_ac3_common_init(void);
 
 extern const int64_t ff_ac3_channel_layouts[];

+ 6 - 251
libavcodec/ac3enc.c

@@ -26,7 +26,6 @@
  * The simplest AC-3 encoder.
  */
 
-//#define DEBUG
 //#define ASSERT_LEVEL 2
 
 #include <stdint.h>
@@ -44,153 +43,8 @@
 #include "audioconvert.h"
 #include "fft.h"
 
-
-#ifndef CONFIG_AC3ENC_FLOAT
-#define CONFIG_AC3ENC_FLOAT 0
-#endif
-
-
-/** Maximum number of exponent groups. +1 for separate DC exponent. */
-#define AC3_MAX_EXP_GROUPS 85
-
-#if CONFIG_AC3ENC_FLOAT
-#define MAC_COEF(d,a,b) ((d)+=(a)*(b))
-typedef float SampleType;
-typedef float CoefType;
-typedef float CoefSumType;
-#else
-#define MAC_COEF(d,a,b) MAC64(d,a,b)
-typedef int16_t SampleType;
-typedef int32_t CoefType;
-typedef int64_t CoefSumType;
-#endif
-
-typedef struct AC3MDCTContext {
-    const SampleType *window;           ///< MDCT window function
-    FFTContext fft;                     ///< FFT context for MDCT calculation
-} AC3MDCTContext;
-
-
-/**
- * Data for a single audio block.
- */
-typedef struct AC3Block {
-    CoefType **mdct_coef;                       ///< MDCT coefficients
-    int32_t  **fixed_coef;                      ///< fixed-point MDCT coefficients
-    uint8_t  **exp;                             ///< original exponents
-    uint8_t  **grouped_exp;                     ///< grouped exponents
-    int16_t  **psd;                             ///< psd per frequency bin
-    int16_t  **band_psd;                        ///< psd per critical band
-    int16_t  **mask;                            ///< masking curve
-    uint16_t **qmant;                           ///< quantized mantissas
-    uint8_t  **cpl_coord_exp;                   ///< coupling coord exponents           (cplcoexp)
-    uint8_t  **cpl_coord_mant;                  ///< coupling coord mantissas           (cplcomant)
-    uint8_t  coeff_shift[AC3_MAX_CHANNELS];     ///< fixed-point coefficient shift values
-    uint8_t  new_rematrixing_strategy;          ///< send new rematrixing flags in this block
-    int      num_rematrixing_bands;             ///< number of rematrixing bands
-    uint8_t  rematrixing_flags[4];              ///< rematrixing flags
-    int      new_cpl_strategy;                  ///< send new coupling strategy
-    int      cpl_in_use;                        ///< coupling in use for this block     (cplinu)
-    uint8_t  channel_in_cpl[AC3_MAX_CHANNELS];  ///< channel in coupling                (chincpl)
-    int      num_cpl_channels;                  ///< number of channels in coupling
-    uint8_t  new_cpl_coords;                    ///< send new coupling coordinates      (cplcoe)
-    uint8_t  cpl_master_exp[AC3_MAX_CHANNELS];  ///< coupling coord master exponents    (mstrcplco)
-    int      new_snr_offsets;                   ///< send new SNR offsets
-    int      new_cpl_leak;                      ///< send new coupling leak info
-    int      end_freq[AC3_MAX_CHANNELS];        ///< end frequency bin                  (endmant)
-} AC3Block;
-
-/**
- * AC-3 encoder private context.
- */
-typedef struct AC3EncodeContext {
-    AVClass *av_class;                      ///< AVClass used for AVOption
-    AC3EncOptions options;                  ///< encoding options
-    PutBitContext pb;                       ///< bitstream writer context
-    DSPContext dsp;
-    AC3DSPContext ac3dsp;                   ///< AC-3 optimized functions
-    AC3MDCTContext mdct;                    ///< MDCT context
-
-    AC3Block blocks[AC3_MAX_BLOCKS];        ///< per-block info
-
-    int eac3;                               ///< indicates if this is E-AC-3 vs. AC-3
-    int bitstream_id;                       ///< bitstream id                           (bsid)
-    int bitstream_mode;                     ///< bitstream mode                         (bsmod)
-
-    int bit_rate;                           ///< target bit rate, in bits-per-second
-    int sample_rate;                        ///< sampling frequency, in Hz
-
-    int frame_size_min;                     ///< minimum frame size in case rounding is necessary
-    int frame_size;                         ///< current frame size in bytes
-    int frame_size_code;                    ///< frame size code                        (frmsizecod)
-    uint16_t crc_inv[2];
-    int64_t bits_written;                   ///< bit count    (used to avg. bitrate)
-    int64_t samples_written;                ///< sample count (used to avg. bitrate)
-
-    int fbw_channels;                       ///< number of full-bandwidth channels      (nfchans)
-    int channels;                           ///< total number of channels               (nchans)
-    int lfe_on;                             ///< indicates if there is an LFE channel   (lfeon)
-    int lfe_channel;                        ///< channel index of the LFE channel
-    int has_center;                         ///< indicates if there is a center channel
-    int has_surround;                       ///< indicates if there are one or more surround channels
-    int channel_mode;                       ///< channel mode                           (acmod)
-    const uint8_t *channel_map;             ///< channel map used to reorder channels
-
-    int center_mix_level;                   ///< center mix level code
-    int surround_mix_level;                 ///< surround mix level code
-    int ltrt_center_mix_level;              ///< Lt/Rt center mix level code
-    int ltrt_surround_mix_level;            ///< Lt/Rt surround mix level code
-    int loro_center_mix_level;              ///< Lo/Ro center mix level code
-    int loro_surround_mix_level;            ///< Lo/Ro surround mix level code
-
-    int cutoff;                             ///< user-specified cutoff frequency, in Hz
-    int bandwidth_code;                     ///< bandwidth code (0 to 60)               (chbwcod)
-    int start_freq[AC3_MAX_CHANNELS];       ///< start frequency bin                    (strtmant)
-    int cpl_end_freq;                       ///< coupling channel end frequency bin
-
-    int cpl_on;                             ///< coupling turned on for this frame
-    int cpl_enabled;                        ///< coupling enabled for all frames
-    int num_cpl_subbands;                   ///< number of coupling subbands            (ncplsubnd)
-    int num_cpl_bands;                      ///< number of coupling bands               (ncplbnd)
-    uint8_t cpl_band_sizes[AC3_MAX_CPL_BANDS];  ///< number of coeffs in each coupling band
-
-    int rematrixing_enabled;                ///< stereo rematrixing enabled
-
-    /* bitrate allocation control */
-    int slow_gain_code;                     ///< slow gain code                         (sgaincod)
-    int slow_decay_code;                    ///< slow decay code                        (sdcycod)
-    int fast_decay_code;                    ///< fast decay code                        (fdcycod)
-    int db_per_bit_code;                    ///< dB/bit code                            (dbpbcod)
-    int floor_code;                         ///< floor code                             (floorcod)
-    AC3BitAllocParameters bit_alloc;        ///< bit allocation parameters
-    int coarse_snr_offset;                  ///< coarse SNR offsets                     (csnroffst)
-    int fast_gain_code[AC3_MAX_CHANNELS];   ///< fast gain codes (signal-to-mask ratio) (fgaincod)
-    int fine_snr_offset[AC3_MAX_CHANNELS];  ///< fine SNR offsets                       (fsnroffst)
-    int frame_bits_fixed;                   ///< number of non-coefficient bits for fixed parameters
-    int frame_bits;                         ///< all frame bits except exponents and mantissas
-    int exponent_bits;                      ///< number of bits used for exponents
-
-    SampleType **planar_samples;
-    uint8_t *bap_buffer;
-    uint8_t *bap1_buffer;
-    CoefType *mdct_coef_buffer;
-    int32_t *fixed_coef_buffer;
-    uint8_t *exp_buffer;
-    uint8_t *grouped_exp_buffer;
-    int16_t *psd_buffer;
-    int16_t *band_psd_buffer;
-    int16_t *mask_buffer;
-    uint16_t *qmant_buffer;
-    uint8_t *cpl_coord_exp_buffer;
-    uint8_t *cpl_coord_mant_buffer;
-
-    uint8_t exp_strategy[AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; ///< exponent strategies
-    uint8_t exp_ref_block[AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; ///< reference blocks for EXP_REUSE
-    uint8_t *ref_bap     [AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; ///< bit allocation pointers (bap)
-    int ref_bap_set;                                         ///< indicates if ref_bap pointers have been set
-
-    DECLARE_ALIGNED(32, SampleType, windowed_samples)[AC3_WINDOW_SIZE];
-} AC3EncodeContext;
+#include "ac3enc.h"
+#include "eac3enc.h"
 
 typedef struct AC3Mant {
     uint16_t *qmant1_ptr, *qmant2_ptr, *qmant4_ptr; ///< mantissa pointers for bap=1,2,4
@@ -715,34 +569,8 @@ static void apply_channel_coupling(AC3EncodeContext *s)
         }
     }
 
-    if (s->eac3) {
-        /* set first cpl coords */
-        int first_cpl_coords[AC3_MAX_CHANNELS];
-        for (ch = 1; ch <= s->fbw_channels; ch++)
-            first_cpl_coords[ch] = 1;
-        for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
-            AC3Block *block = &s->blocks[blk];
-            for (ch = 1; ch <= s->fbw_channels; ch++) {
-                if (block->channel_in_cpl[ch]) {
-                    if (first_cpl_coords[ch]) {
-                        block->new_cpl_coords = 2;
-                        first_cpl_coords[ch]  = 0;
-                    }
-                } else {
-                    first_cpl_coords[ch] = 1;
-                }
-            }
-        }
-
-        /* set first cpl leak */
-        for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
-            AC3Block *block = &s->blocks[blk];
-            if (block->cpl_in_use) {
-                block->new_cpl_leak = 2;
-                break;
-            }
-        }
-    }
+    if (CONFIG_EAC3_ENCODER && s->eac3)
+        ff_eac3_set_cpl_states(s);
 #endif /* CONFIG_AC3ENC_FLOAT */
 }
 
@@ -1879,79 +1707,6 @@ static void ac3_output_frame_header(AC3EncodeContext *s)
 }
 
 
-/**
- * Write the E-AC-3 frame header to the output bitstream.
- */
-static void eac3_output_frame_header(AC3EncodeContext *s)
-{
-    int blk, ch;
-    AC3EncOptions *opt = &s->options;
-
-    put_bits(&s->pb, 16, 0x0b77);                   /* sync word */
-
-    /* BSI header */
-    put_bits(&s->pb,  2, 0);                        /* stream type = independent */
-    put_bits(&s->pb,  3, 0);                        /* substream id = 0 */
-    put_bits(&s->pb, 11, (s->frame_size / 2) - 1);  /* frame size */
-    if (s->bit_alloc.sr_shift) {
-        put_bits(&s->pb, 2, 0x3);                   /* fscod2 */
-        put_bits(&s->pb, 2, s->bit_alloc.sr_code);  /* sample rate code */
-    } else {
-        put_bits(&s->pb, 2, s->bit_alloc.sr_code);  /* sample rate code */
-        put_bits(&s->pb, 2, 0x3);                   /* number of blocks = 6 */
-    }
-    put_bits(&s->pb, 3, s->channel_mode);           /* audio coding mode */
-    put_bits(&s->pb, 1, s->lfe_on);                 /* LFE channel indicator */
-    put_bits(&s->pb, 5, s->bitstream_id);           /* bitstream id (EAC3=16) */
-    put_bits(&s->pb, 5, -opt->dialogue_level);      /* dialogue normalization level */
-    put_bits(&s->pb, 1, 0);                         /* no compression gain */
-    put_bits(&s->pb, 1, 0);                         /* no mixing metadata */
-    /* TODO: mixing metadata */
-    put_bits(&s->pb, 1, 0);                         /* no info metadata */
-    /* TODO: info metadata */
-    put_bits(&s->pb, 1, 0);                         /* no additional bit stream info */
-
-    /* frame header */
-    put_bits(&s->pb, 1, 1);                         /* exponent strategy syntax = each block */
-    put_bits(&s->pb, 1, 0);                         /* aht enabled = no */
-    put_bits(&s->pb, 2, 0);                         /* snr offset strategy = 1 */
-    put_bits(&s->pb, 1, 0);                         /* transient pre-noise processing enabled = no */
-    put_bits(&s->pb, 1, 0);                         /* block switch syntax enabled = no */
-    put_bits(&s->pb, 1, 0);                         /* dither flag syntax enabled = no */
-    put_bits(&s->pb, 1, 0);                         /* bit allocation model syntax enabled = no */
-    put_bits(&s->pb, 1, 0);                         /* fast gain codes enabled = no */
-    put_bits(&s->pb, 1, 0);                         /* dba syntax enabled = no */
-    put_bits(&s->pb, 1, 0);                         /* skip field syntax enabled = no */
-    put_bits(&s->pb, 1, 0);                         /* spx enabled = no */
-    /* coupling strategy use flags */
-    if (s->channel_mode > AC3_CHMODE_MONO) {
-        put_bits(&s->pb, 1, s->blocks[0].cpl_in_use);
-        for (blk = 1; blk < AC3_MAX_BLOCKS; blk++) {
-            AC3Block *block = &s->blocks[blk];
-            put_bits(&s->pb, 1, block->new_cpl_strategy);
-            if (block->new_cpl_strategy)
-                put_bits(&s->pb, 1, block->cpl_in_use);
-        }
-    }
-    /* exponent strategy */
-    for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)
-        for (ch = !s->blocks[blk].cpl_in_use; ch <= s->fbw_channels; ch++)
-            put_bits(&s->pb, 2, s->exp_strategy[ch][blk]);
-    if (s->lfe_on) {
-        for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)
-            put_bits(&s->pb, 1, s->exp_strategy[s->lfe_channel][blk]);
-    }
-    /* E-AC-3 to AC-3 converter exponent strategy (unfortunately not optional...) */
-    for (ch = 1; ch <= s->fbw_channels; ch++)
-        put_bits(&s->pb, 5, 0);
-    /* snr offsets */
-    put_bits(&s->pb, 6, s->coarse_snr_offset);
-    put_bits(&s->pb, 4, s->fine_snr_offset[1]);
-    /* block start info */
-    put_bits(&s->pb, 1, 0);
-}
-
-
 /**
  * Write one audio block to the output bitstream.
  */
@@ -2235,8 +1990,8 @@ static void output_frame(AC3EncodeContext *s, unsigned char *frame)
 
     init_put_bits(&s->pb, frame, AC3_MAX_CODED_FRAME_SIZE);
 
-    if (s->eac3)
-        eac3_output_frame_header(s);
+    if (CONFIG_EAC3_ENCODER && s->eac3)
+        ff_eac3_output_frame_header(s);
     else
         ac3_output_frame_header(s);
 

+ 214 - 0
libavcodec/ac3enc.h

@@ -0,0 +1,214 @@
+/*
+ * AC-3 encoder & E-AC-3 encoder common header
+ * Copyright (c) 2000 Fabrice Bellard
+ * Copyright (c) 2006-2010 Justin Ruggles <justin.ruggles@gmail.com>
+ *
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * Libav is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * AC-3 encoder & E-AC-3 encoder common header
+ */
+
+#ifndef AVCODEC_AC3ENC_H
+#define AVCODEC_AC3ENC_H
+
+#include <stdint.h>
+#include "ac3.h"
+#include "ac3dsp.h"
+#include "avcodec.h"
+#include "dsputil.h"
+#include "put_bits.h"
+#include "fft.h"
+
+#ifndef CONFIG_AC3ENC_FLOAT
+#define CONFIG_AC3ENC_FLOAT 0
+#endif
+
+#if CONFIG_AC3ENC_FLOAT
+#define MAC_COEF(d,a,b) ((d)+=(a)*(b))
+typedef float SampleType;
+typedef float CoefType;
+typedef float CoefSumType;
+#else
+#define MAC_COEF(d,a,b) MAC64(d,a,b)
+typedef int16_t SampleType;
+typedef int32_t CoefType;
+typedef int64_t CoefSumType;
+#endif
+
+typedef struct AC3MDCTContext {
+    const SampleType *window;           ///< MDCT window function
+    FFTContext fft;                     ///< FFT context for MDCT calculation
+} AC3MDCTContext;
+#if 0
+/**
+ * Encoding Options used by AVOption.
+ */
+typedef struct AC3EncOptions {
+    /* AC-3 metadata options*/
+    int dialogue_level;
+    int bitstream_mode;
+    float center_mix_level;
+    float surround_mix_level;
+    int dolby_surround_mode;
+    int audio_production_info;
+    int mixing_level;
+    int room_type;
+    int copyright;
+    int original;
+    int extended_bsi_1;
+    int preferred_stereo_downmix;
+    float ltrt_center_mix_level;
+    float ltrt_surround_mix_level;
+    float loro_center_mix_level;
+    float loro_surround_mix_level;
+    int extended_bsi_2;
+    int dolby_surround_ex_mode;
+    int dolby_headphone_mode;
+    int ad_converter_type;
+
+    /* other encoding options */
+    int allow_per_frame_metadata;
+    int stereo_rematrixing;
+    int channel_coupling;
+    int cpl_start;
+} AC3EncOptions;
+#endif
+/**
+ * Data for a single audio block.
+ */
+typedef struct AC3Block {
+    CoefType **mdct_coef;                       ///< MDCT coefficients
+    int32_t  **fixed_coef;                      ///< fixed-point MDCT coefficients
+    uint8_t  **exp;                             ///< original exponents
+    uint8_t  **grouped_exp;                     ///< grouped exponents
+    int16_t  **psd;                             ///< psd per frequency bin
+    int16_t  **band_psd;                        ///< psd per critical band
+    int16_t  **mask;                            ///< masking curve
+    uint16_t **qmant;                           ///< quantized mantissas
+    uint8_t  **cpl_coord_exp;                   ///< coupling coord exponents           (cplcoexp)
+    uint8_t  **cpl_coord_mant;                  ///< coupling coord mantissas           (cplcomant)
+    uint8_t  coeff_shift[AC3_MAX_CHANNELS];     ///< fixed-point coefficient shift values
+    uint8_t  new_rematrixing_strategy;          ///< send new rematrixing flags in this block
+    int      num_rematrixing_bands;             ///< number of rematrixing bands
+    uint8_t  rematrixing_flags[4];              ///< rematrixing flags
+    int      new_cpl_strategy;                  ///< send new coupling strategy
+    int      cpl_in_use;                        ///< coupling in use for this block     (cplinu)
+    uint8_t  channel_in_cpl[AC3_MAX_CHANNELS];  ///< channel in coupling                (chincpl)
+    int      num_cpl_channels;                  ///< number of channels in coupling
+    uint8_t  new_cpl_coords;                    ///< send new coupling coordinates      (cplcoe)
+    uint8_t  cpl_master_exp[AC3_MAX_CHANNELS];  ///< coupling coord master exponents    (mstrcplco)
+    int      new_snr_offsets;                   ///< send new SNR offsets
+    int      new_cpl_leak;                      ///< send new coupling leak info
+    int      end_freq[AC3_MAX_CHANNELS];        ///< end frequency bin                  (endmant)
+} AC3Block;
+
+/**
+ * AC-3 encoder private context.
+ */
+typedef struct AC3EncodeContext {
+    AVClass *av_class;                      ///< AVClass used for AVOption
+    AC3EncOptions options;                  ///< encoding options
+    PutBitContext pb;                       ///< bitstream writer context
+    DSPContext dsp;
+    AC3DSPContext ac3dsp;                   ///< AC-3 optimized functions
+    AC3MDCTContext mdct;                    ///< MDCT context
+
+    AC3Block blocks[AC3_MAX_BLOCKS];        ///< per-block info
+
+    int eac3;                               ///< indicates if this is E-AC-3 vs. AC-3
+    int bitstream_id;                       ///< bitstream id                           (bsid)
+    int bitstream_mode;                     ///< bitstream mode                         (bsmod)
+
+    int bit_rate;                           ///< target bit rate, in bits-per-second
+    int sample_rate;                        ///< sampling frequency, in Hz
+
+    int frame_size_min;                     ///< minimum frame size in case rounding is necessary
+    int frame_size;                         ///< current frame size in bytes
+    int frame_size_code;                    ///< frame size code                        (frmsizecod)
+    uint16_t crc_inv[2];
+    int64_t bits_written;                   ///< bit count    (used to avg. bitrate)
+    int64_t samples_written;                ///< sample count (used to avg. bitrate)
+
+    int fbw_channels;                       ///< number of full-bandwidth channels      (nfchans)
+    int channels;                           ///< total number of channels               (nchans)
+    int lfe_on;                             ///< indicates if there is an LFE channel   (lfeon)
+    int lfe_channel;                        ///< channel index of the LFE channel
+    int has_center;                         ///< indicates if there is a center channel
+    int has_surround;                       ///< indicates if there are one or more surround channels
+    int channel_mode;                       ///< channel mode                           (acmod)
+    const uint8_t *channel_map;             ///< channel map used to reorder channels
+
+    int center_mix_level;                   ///< center mix level code
+    int surround_mix_level;                 ///< surround mix level code
+    int ltrt_center_mix_level;              ///< Lt/Rt center mix level code
+    int ltrt_surround_mix_level;            ///< Lt/Rt surround mix level code
+    int loro_center_mix_level;              ///< Lo/Ro center mix level code
+    int loro_surround_mix_level;            ///< Lo/Ro surround mix level code
+
+    int cutoff;                             ///< user-specified cutoff frequency, in Hz
+    int bandwidth_code;                     ///< bandwidth code (0 to 60)               (chbwcod)
+    int start_freq[AC3_MAX_CHANNELS];       ///< start frequency bin                    (strtmant)
+    int cpl_end_freq;                       ///< coupling channel end frequency bin
+
+    int cpl_on;                             ///< coupling turned on for this frame
+    int cpl_enabled;                        ///< coupling enabled for all frames
+    int num_cpl_subbands;                   ///< number of coupling subbands            (ncplsubnd)
+    int num_cpl_bands;                      ///< number of coupling bands               (ncplbnd)
+    uint8_t cpl_band_sizes[AC3_MAX_CPL_BANDS];  ///< number of coeffs in each coupling band
+
+    int rematrixing_enabled;                ///< stereo rematrixing enabled
+
+    /* bitrate allocation control */
+    int slow_gain_code;                     ///< slow gain code                         (sgaincod)
+    int slow_decay_code;                    ///< slow decay code                        (sdcycod)
+    int fast_decay_code;                    ///< fast decay code                        (fdcycod)
+    int db_per_bit_code;                    ///< dB/bit code                            (dbpbcod)
+    int floor_code;                         ///< floor code                             (floorcod)
+    AC3BitAllocParameters bit_alloc;        ///< bit allocation parameters
+    int coarse_snr_offset;                  ///< coarse SNR offsets                     (csnroffst)
+    int fast_gain_code[AC3_MAX_CHANNELS];   ///< fast gain codes (signal-to-mask ratio) (fgaincod)
+    int fine_snr_offset[AC3_MAX_CHANNELS];  ///< fine SNR offsets                       (fsnroffst)
+    int frame_bits_fixed;                   ///< number of non-coefficient bits for fixed parameters
+    int frame_bits;                         ///< all frame bits except exponents and mantissas
+    int exponent_bits;                      ///< number of bits used for exponents
+
+    SampleType **planar_samples;
+    uint8_t *bap_buffer;
+    uint8_t *bap1_buffer;
+    CoefType *mdct_coef_buffer;
+    int32_t *fixed_coef_buffer;
+    uint8_t *exp_buffer;
+    uint8_t *grouped_exp_buffer;
+    int16_t *psd_buffer;
+    int16_t *band_psd_buffer;
+    int16_t *mask_buffer;
+    uint16_t *qmant_buffer;
+    uint8_t *cpl_coord_exp_buffer;
+    uint8_t *cpl_coord_mant_buffer;
+
+    uint8_t exp_strategy[AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; ///< exponent strategies
+    uint8_t exp_ref_block[AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; ///< reference blocks for EXP_REUSE
+    uint8_t *ref_bap     [AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; ///< bit allocation pointers (bap)
+    int ref_bap_set;                                         ///< indicates if ref_bap pointers have been set
+
+    DECLARE_ALIGNED(32, SampleType, windowed_samples)[AC3_WINDOW_SIZE];
+} AC3EncodeContext;
+
+#endif /* AVCODEC_AC3ENC_H */

+ 6 - 20
libavcodec/bitstream.c

@@ -83,8 +83,6 @@ void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
 
 /* VLC decoding */
 
-//#define DEBUG_VLC
-
 #define GET_DATA(v, table, i, wrap, size) \
 {\
     const uint8_t *ptr = (const uint8_t *)table + i * wrap;\
@@ -164,10 +162,7 @@ static int build_table(VLC *vlc, int table_nb_bits, int nb_codes,
 
     table_size = 1 << table_nb_bits;
     table_index = alloc_table(vlc, table_size, flags & INIT_VLC_USE_NEW_STATIC);
-#ifdef DEBUG_VLC
-    av_log(NULL,AV_LOG_DEBUG,"new table index=%d size=%d\n",
-           table_index, table_size);
-#endif
+    av_dlog(NULL, "new table index=%d size=%d\n", table_index, table_size);
     if (table_index < 0)
         return -1;
     table = &vlc->table[table_index];
@@ -182,9 +177,7 @@ static int build_table(VLC *vlc, int table_nb_bits, int nb_codes,
         n = codes[i].bits;
         code = codes[i].code;
         symbol = codes[i].symbol;
-#if defined(DEBUG_VLC) && 0
-        av_log(NULL,AV_LOG_DEBUG,"i=%d n=%d code=0x%x\n", i, n, code);
-#endif
+        av_dlog(NULL, "i=%d n=%d code=0x%x\n", i, n, code);
         if (n <= table_nb_bits) {
             /* no need to add another table */
             j = code >> (32 - table_nb_bits);
@@ -195,10 +188,7 @@ static int build_table(VLC *vlc, int table_nb_bits, int nb_codes,
                 inc = 1 << n;
             }
             for (k = 0; k < nb; k++) {
-#ifdef DEBUG_VLC
-                av_log(NULL, AV_LOG_DEBUG, "%4x: code=%d n=%d\n",
-                       j, i, n);
-#endif
+                av_dlog(NULL, "%4x: code=%d n=%d\n", j, i, n);
                 if (table[j][1] /*bits*/ != 0) {
                     av_log(NULL, AV_LOG_ERROR, "incorrect codes\n");
                     return -1;
@@ -228,10 +218,8 @@ static int build_table(VLC *vlc, int table_nb_bits, int nb_codes,
             subtable_bits = FFMIN(subtable_bits, table_nb_bits);
             j = (flags & INIT_VLC_LE) ? bitswap_32(code_prefix) >> (32 - table_nb_bits) : code_prefix;
             table[j][1] = -subtable_bits;
-#ifdef DEBUG_VLC
-            av_log(NULL,AV_LOG_DEBUG,"%4x: n=%d (subtable)\n",
-                   j, codes[i].bits + table_nb_bits);
-#endif
+            av_dlog(NULL, "%4x: n=%d (subtable)\n",
+                    j, codes[i].bits + table_nb_bits);
             index = build_table(vlc, subtable_bits, k-i, codes+i, flags);
             if (index < 0)
                 return -1;
@@ -293,9 +281,7 @@ int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
         vlc->table_size = 0;
     }
 
-#ifdef DEBUG_VLC
-    av_log(NULL,AV_LOG_DEBUG,"build table nb_codes=%d\n", nb_codes);
-#endif
+    av_dlog(NULL, "build table nb_codes=%d\n", nb_codes);
 
     buf = av_malloc((nb_codes+1)*sizeof(VLCcode));
 

+ 3 - 2
libavcodec/dnxhdenc.h

@@ -25,8 +25,9 @@
 #define AVCODEC_DNXHDENC_H
 
 #include <stdint.h>
-#include "libavcodec/mpegvideo.h"
-#include "libavcodec/dnxhddata.h"
+
+#include "mpegvideo.h"
+#include "dnxhddata.h"
 
 typedef struct {
     uint16_t mb;

Some files were not shown because too many files changed in this diff