]> granicus.if.org Git - handbrake/commitdiff
Make HB_AMIXDOWN_* defines a simple enumeration. The existing system wasn't necessary...
authorRodeo <tdskywalker@gmail.com>
Wed, 6 Jun 2012 16:07:58 +0000 (16:07 +0000)
committerRodeo <tdskywalker@gmail.com>
Wed, 6 Jun 2012 16:07:58 +0000 (16:07 +0000)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4714 b64f7644-9d1e-0410-96f1-a4d463321fa5

13 files changed:
libhb/common.c
libhb/common.h
libhb/deca52.c
libhb/decavcodec.c
libhb/decdca.c
libhb/encavcodecaudio.c
libhb/encfaac.c
libhb/enclame.c
libhb/encvorbis.c
libhb/muxmkv.c
libhb/muxmp4.c
libhb/platform/macosx/encca_aac.c
libhb/sync.c

index 0bc48a84231f24a29eb64569f290f75fb3644691..0c3616890c9b4a197186fd7c97c662eeca0efe32 100644 (file)
@@ -96,6 +96,21 @@ int hb_get_video_encoders_count() { return hb_video_encoders_count; }
 hb_encoder_t* hb_get_audio_encoders() { return hb_audio_encoders; }
 int hb_get_audio_encoders_count() { return hb_audio_encoders_count; }
 
+int hb_mixdown_get_discrete_channel_count( int amixdown )
+{
+    switch( amixdown )
+    {
+        case HB_AMIXDOWN_6CH:
+            return 6;
+
+        case HB_AMIXDOWN_MONO:
+            return 1;
+
+        default:
+            return 2;
+    }
+}
+
 int hb_mixdown_get_mixdown_from_short_name( const char * short_name )
 {
     int i;
@@ -330,14 +345,13 @@ void hb_get_audio_bitrate_limits(uint32_t codec, int samplerate, int mixdown, in
 {
     int channels;
 
-    channels = HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT(mixdown);
+    channels = hb_mixdown_get_discrete_channel_count( mixdown );
     if( codec & HB_ACODEC_PASS_FLAG )
     {
-        // Bitrates don't apply to "lossless" audio (Passthru, FLAC)
-        // ... but may be applied if we fallback to an encoder
-        // when the source can not be passed.
-        *high = 768;
-        *low = 32;
+        // Bitrates don't apply to "lossless" audio (Passthru, FLAC), but may apply
+        // if we fallback to an encoder when the source can't be passed through.
+        *low = hb_audio_bitrates[0].rate;
+        *high = hb_audio_bitrates[hb_audio_bitrates_count-1].rate;
         return;
     }
     switch( codec )
@@ -518,7 +532,7 @@ int hb_get_default_audio_bitrate( uint32_t codec, int samplerate, int mixdown )
     if( codec & HB_ACODEC_PASS_FLAG )
         return -1;
 
-    channels = HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT(mixdown);
+    channels = hb_mixdown_get_discrete_channel_count( mixdown );
 
     // Min bitrate is established such that we get good quality
     // audio as a minimum.
index ac486b4a5d30acc61481ad3c4e30767dc715e76d..deb60da86d6eb2969498b1894a35a8aac25afbdb 100644 (file)
@@ -193,8 +193,10 @@ int           hb_get_video_encoders_count();
 hb_encoder_t* hb_get_audio_encoders();
 int           hb_get_audio_encoders_count();
 
+int hb_mixdown_get_discrete_channel_count( int amixdown );
 int hb_mixdown_get_mixdown_from_short_name( const char * short_name );
 const char * hb_mixdown_get_short_name_from_mixdown( int amixdown );
+
 void hb_autopassthru_apply_settings( hb_job_t * job, hb_title_t * title );
 void hb_autopassthru_print_settings( hb_job_t * job );
 int hb_autopassthru_get_encoder( int in_codec, int copy_mask, int fallback, int muxer );
@@ -418,40 +420,8 @@ struct hb_job_s
 #define HB_SUBSTREAM_BD_DTSHD   0x72
 #define HB_SUBSTREAM_BD_DTS     0x71
 
-/* Audio Mixdown */
-/* define some masks, used to extract the various information from the HB_AMIXDOWN_XXXX values */
-#define HB_AMIXDOWN_DCA_FORMAT_MASK             0x00FFF000
-#define HB_AMIXDOWN_A52_FORMAT_MASK             0x00000FF0
-#define HB_AMIXDOWN_DISCRETE_CHANNEL_COUNT_MASK 0x0000000F
-/* define the HB_AMIXDOWN_XXXX values */
-#define HB_AMIXDOWN_NONE                        0x00000000
-#define HB_AMIXDOWN_MONO                        0x01000011
-// DCA_FORMAT of DCA_MONO                  = 0    = 0x000
-// A52_FORMAT of A52_MONO                  = 1    = 0x01
-// discrete channel count of 1
-#define HB_AMIXDOWN_STEREO                      0x02002022
-// DCA_FORMAT of DCA_STEREO                = 2    = 0x002
-// A52_FORMAT of A52_STEREO                = 2    = 0x02
-// discrete channel count of 2
-#define HB_AMIXDOWN_DOLBY                       0x040000A2
-// DCA_FORMAT handled directly in decdca.c
-// A52_FORMAT of A52_DOLBY                 = 10   = 0x0A
-// discrete channel count of 2
-#define HB_AMIXDOWN_DOLBYPLII                   0x080004A2
-// DCA_FORMAT handled directly in decdca.c
-// A52_FORMAT of A52_DOLBY | A52_USE_DPLII = 74   = 0x4A
-// discrete channel count of 2
-#define HB_AMIXDOWN_6CH                         0x10089176
-// DCA_FORMAT of DCA_3F2R | DCA_LFE        = 137  = 0x089
-// A52_FORMAT of A52_3F2R | A52_LFE        = 23   = 0x17
-// discrete channel count of 6
-/* define some macros to extract the various information from the HB_AMIXDOWN_XXXX values */
-#define HB_AMIXDOWN_GET_DCA_FORMAT( a ) ( ( a & HB_AMIXDOWN_DCA_FORMAT_MASK ) >> 12 )
-#define HB_AMIXDOWN_GET_A52_FORMAT( a ) ( ( a & HB_AMIXDOWN_A52_FORMAT_MASK ) >> 4 )
-#define HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT( a ) ( ( a & HB_AMIXDOWN_DISCRETE_CHANNEL_COUNT_MASK ) )
-
 /* Input Channel Layout */
-/* define some masks, used to extract the various information from the HB_AMIXDOWN_XXXX values */
+/* define some masks, used to extract the various information from the HB_INPUT_CH_LAYOUT_* values */
 #define HB_INPUT_CH_LAYOUT_DISCRETE_FRONT_MASK  0x00F0000
 #define HB_INPUT_CH_LAYOUT_DISCRETE_REAR_MASK   0x000F000
 #define HB_INPUT_CH_LAYOUT_DISCRETE_LFE_MASK    0x0000F00
@@ -470,7 +440,7 @@ struct hb_job_s
 #define HB_INPUT_CH_LAYOUT_4F2R    0x0942042
 #define HB_INPUT_CH_LAYOUT_3F4R    0x0a34034
 #define HB_INPUT_CH_LAYOUT_HAS_LFE 0x0000100
-/* define some macros to extract the various information from the HB_AMIXDOWN_XXXX values */
+/* define some macros to extract the various information from the HB_INPUT_CH_LAYOUT_* values */
 #define HB_INPUT_CH_LAYOUT_GET_DISCRETE_FRONT_COUNT( a ) ( ( a & HB_INPUT_CH_LAYOUT_DISCRETE_FRONT_MASK ) >> 16 )
 #define HB_INPUT_CH_LAYOUT_GET_DISCRETE_REAR_COUNT( a )  ( ( a & HB_INPUT_CH_LAYOUT_DISCRETE_REAR_MASK ) >> 12 )
 #define HB_INPUT_CH_LAYOUT_GET_DISCRETE_LFE_COUNT( a )   ( ( a & HB_INPUT_CH_LAYOUT_DISCRETE_LFE_MASK ) >> 8 )
@@ -486,17 +456,25 @@ struct hb_audio_config_s
     /* Output */
     struct
     {
-            int track; /* Output track number */
-            uint32_t codec; /* Output audio codec */
-            int samplerate; /* Output sample rate (Hz) */
-            int samples_per_frame; /* Number of samples per frame */
-            int bitrate; /* Output bitrate (Kbps) */
-            float quality; /* Output quality (encoder-specific) */
-            float compression_level;  /* Output compression level (encoder-specific) */
-            int mixdown; /* The mixdown used for this audio track (see HB_AMIXDOWN_*) */
-            double dynamic_range_compression; /* Amount of DRC applied to this track */
-            double gain; /* Gain (in dB), negative is quieter */
-            char * name; /* Output track name */
+        enum
+        {
+            HB_AMIXDOWN_NONE = 0,
+            HB_AMIXDOWN_MONO,
+            HB_AMIXDOWN_STEREO,
+            HB_AMIXDOWN_DOLBY,
+            HB_AMIXDOWN_DOLBYPLII,
+            HB_AMIXDOWN_6CH,
+        } mixdown; /* Audio mixdown */
+        int      track; /* Output track number */
+        uint32_t codec; /* Output audio codec */
+        int      samplerate; /* Output sample rate (Hz) */
+        int      samples_per_frame; /* Number of samples per frame */
+        int      bitrate; /* Output bitrate (Kbps) */
+        float    quality; /* Output quality (encoder-specific) */
+        float    compression_level;  /* Output compression level (encoder-specific) */
+        double   dynamic_range_compression; /* Amount of DRC applied to this track */
+        double   gain; /* Gain (in dB), negative is quieter */
+        char *   name; /* Output track name */
     } out;
 
     /* Input */
index f0befdd014285fd1ac05641e8522ed03a9b8614e..049281fb5b17c94b0ce76fc3111d15316f267fea 100644 (file)
@@ -97,18 +97,36 @@ static int deca52Init( hb_work_object_t * w, hb_job_t * job )
     pv->crc_table = av_crc_get_table( AV_CRC_16_ANSI );
     pv->list      = hb_list_init();
     pv->state     = a52_init( 0 );
+    pv->level     = 1.0;
+    pv->dynamic_range_compression = audio->config.out.dynamic_range_compression;
 
-    /* Decide what format we want out of a52dec
-    work.c has already done some of this deduction for us in do_job() */
+    /* Decide what format we want out of a52dec;
+     * work.c has already done some of this deduction for us in do_job(). */
+    switch( audio->config.out.mixdown )
+    {
+        case HB_AMIXDOWN_6CH:
+            pv->flags_out = ( A52_3F2R | A52_LFE );
+            break;
 
-    pv->flags_out = HB_AMIXDOWN_GET_A52_FORMAT(audio->config.out.mixdown);
+        case HB_AMIXDOWN_DOLBYPLII:
+            pv->flags_out = ( A52_DOLBY | A52_USE_DPLII );
+            break;
 
-    /* pass the number of channels used into the private work data */
-    /* will only be actually used if we're not doing AC3 passthru */
-    pv->out_discrete_channels = HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT(audio->config.out.mixdown);
+        case HB_AMIXDOWN_DOLBY:
+            pv->flags_out = A52_DOLBY;
+            break;
 
-    pv->level     = 1.0;
-    pv->dynamic_range_compression = audio->config.out.dynamic_range_compression;
+        case HB_AMIXDOWN_MONO:
+            pv->flags_out = A52_MONO;
+            break;
+
+        default:
+            pv->flags_out = A52_STEREO;
+            break;
+    }
+
+    /* pass the number of channels used into the private work data */
+    pv->out_discrete_channels = hb_mixdown_get_discrete_channel_count( audio->config.out.mixdown );
 
     return 0;
 }
index fca6c2f453a39e76e460adac7a8f12e2cb93d973..3efdd276d5c4498eaad2f790b0493be9b827ea1b 100644 (file)
@@ -1459,7 +1459,7 @@ static hb_buffer_t * downmixAudio(
     if ( pv->downmix )
     {
         int n_ch_samples = nsamples / channels;
-        int out_channels = HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT(audio->config.out.mixdown);
+        int out_channels = hb_mixdown_get_discrete_channel_count( audio->config.out.mixdown );
 
         buf = hb_buffer_init( n_ch_samples * out_channels * sizeof(float) );
         hb_sample_t *samples = (hb_sample_t *)buf->data;
index a459dcd23b2242e41c6bc7e331abcb9328288878..70ac1aa35797b1ed44fa6569eac2d48598e81638 100644 (file)
@@ -84,6 +84,10 @@ static int decdcaInit( hb_work_object_t * w, hb_job_t * job )
     int layout = ( audio->config.in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK );
     switch( audio->config.out.mixdown )
     {
+        case HB_AMIXDOWN_6CH:
+            pv->flags_out = ( DCA_3F2R | DCA_LFE );
+            break;
+
         case HB_AMIXDOWN_DOLBYPLII:
         {
             if( layout == HB_INPUT_CH_LAYOUT_3F2R )
@@ -129,13 +133,17 @@ static int decdcaInit( hb_work_object_t * w, hb_job_t * job )
             }
         } break;
 
+        case HB_AMIXDOWN_MONO:
+            pv->flags_out = DCA_MONO;
+            break;
+
         default:
-            pv->flags_out = HB_AMIXDOWN_GET_DCA_FORMAT( audio->config.out.mixdown );
+            pv->flags_out = DCA_STEREO;
             break;
     }
 
     /* pass the number of channels used into the private work data */
-    pv->out_discrete_channels = HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT( audio->config.out.mixdown );
+    pv->out_discrete_channels = hb_mixdown_get_discrete_channel_count( audio->config.out.mixdown );
 
     return 0;
 }
index fc692e4be4c4c30bcf4805aaa884579311c08b58..d7c7b96e8414117ab279dca895cd41aeb6226c3e 100644 (file)
@@ -47,7 +47,7 @@ static int encavcodecaInit( hb_work_object_t * w, hb_job_t * job )
 
     pv->job = job;
 
-    pv->out_discrete_channels = HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT(audio->config.out.mixdown);
+    pv->out_discrete_channels = hb_mixdown_get_discrete_channel_count( audio->config.out.mixdown );
 
     codec = avcodec_find_encoder( w->codec_param );
     if( !codec )
index 38b44f08d903b0311435fec8329ff52952ef8bfe..a4f724a84394b9115c89dd608d791056708bf463 100644 (file)
@@ -69,7 +69,7 @@ int encfaacInit( hb_work_object_t * w, hb_job_t * job )
     pv->job   = job;
 
        /* pass the number of channels used into the private work data */
-    pv->out_discrete_channels = HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT(audio->config.out.mixdown);
+    pv->out_discrete_channels = hb_mixdown_get_discrete_channel_count( audio->config.out.mixdown );
 
     /* if the sample rate is 'auto' and that has given us an invalid output */
     /* rate, map it to the next highest output rate or 48K if above the highest. */
index 04e6ae6d81f7842d346063e79cb78c98650d63a8..9cf7231a182cebe3c698f6511c9bcef8e89774b8 100644 (file)
@@ -69,7 +69,7 @@ int enclameInit( hb_work_object_t * w, hb_job_t * job )
     lame_set_in_samplerate( pv->lame, audio->config.out.samplerate );
     lame_set_out_samplerate( pv->lame, audio->config.out.samplerate );
 
-    pv->out_discrete_channels = HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT(audio->config.out.mixdown);
+    pv->out_discrete_channels = hb_mixdown_get_discrete_channel_count( audio->config.out.mixdown );
     // Lame's default encoding mode is JOINT_STEREO.  This subtracts signal
     // that is "common" to left and right (within some threshold) and encodes
     // it separately.  This improves quality at low bitrates, but hurts 
index d48373e094f3964cec1201b8fc34ccc9573d0c75..66351ee71417acc6efb47f4b1e3ea7da600bdad8 100644 (file)
@@ -50,7 +50,7 @@ int encvorbisInit( hb_work_object_t * w, hb_job_t * job )
 
     hb_work_private_t * pv = calloc( 1, sizeof( hb_work_private_t ) );
     w->private_data = pv;
-    pv->out_discrete_channels = HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT(audio->config.out.mixdown);
+    pv->out_discrete_channels = hb_mixdown_get_discrete_channel_count( audio->config.out.mixdown );
 
     pv->job   = job;
 
index 7e6884d8a410eed823cd588c6b1e8a10cf096bd7..3551269cdf54f9da9aac54b1d785a6d84e3caeab 100644 (file)
@@ -204,7 +204,7 @@ static int MKVInit( hb_mux_object_t * m )
 
         mux_data->codec = audio->config.out.codec;
 
-        switch (audio->config.out.codec & HB_ACODEC_MASK)
+        switch( audio->config.out.codec & HB_ACODEC_MASK )
         {
             case HB_ACODEC_DCA:
             case HB_ACODEC_DCA_HD:
@@ -269,7 +269,7 @@ static int MKVInit( hb_mux_object_t * m )
                 return 0;
         }
 
-        if (default_track_flag)
+        if( default_track_flag )
         {
             track->flagDefault = 1;
             default_track_flag = 0;
@@ -284,19 +284,18 @@ static int MKVInit( hb_mux_object_t * m )
         lang =  lang_for_code2( audio->config.lang.iso639_2 );
         track->language = lang->iso639_2b ? lang->iso639_2b : lang->iso639_2;
         track->extra.audio.samplingFreq = (float)audio->config.out.samplerate;
-        if (audio->config.out.codec & HB_ACODEC_PASS_FLAG)
+        if( audio->config.out.codec & HB_ACODEC_PASS_FLAG )
         {
-            track->extra.audio.channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(audio->config.in.channel_layout);
+            track->extra.audio.channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT( audio->config.in.channel_layout );
         }
         else
         {
-            track->extra.audio.channels = HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT(audio->config.out.mixdown);
+            track->extra.audio.channels = hb_mixdown_get_discrete_channel_count( audio->config.out.mixdown );
         }
-//        track->defaultDuration = job->arate * 1000;
         mux_data->track = mk_createTrack(m->file, track);
-        if ( audio->config.out.codec == HB_ACODEC_VORBIS ||
-             audio->config.out.codec == HB_ACODEC_FFFLAC )
-          free(track->codecPrivate);
+        if( audio->config.out.codec == HB_ACODEC_VORBIS ||
+            audio->config.out.codec == HB_ACODEC_FFFLAC )
+            free( track->codecPrivate );
     }
 
     char * subidx_fmt =
index df55db7fdced0d516714678abf616675ce4e5132..4c956ad212bbd90e193ef5048674ae9f9788be59 100644 (file)
@@ -414,15 +414,13 @@ static int MP4Init( hb_mux_object_t * m )
                 {
                     samplerate = audio->config.in.samplerate;
                     samples_per_frame = audio->config.in.samples_per_frame;
-                    channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
-                                            audio->config.in.channel_layout );
+                    channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT( audio->config.in.channel_layout );
                 }
                 else
                 {
                     samplerate = audio->config.out.samplerate;
                     samples_per_frame = audio->config.out.samples_per_frame;
-                    channels = HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT(
-                                            audio->config.out.mixdown );
+                    channels = hb_mixdown_get_discrete_channel_count( audio->config.out.mixdown );
                 }
                 mux_data->track = MP4AddAudioTrack( m->file, samplerate, 
                                                 samples_per_frame, audio_type );
index d6d0af0c921f03ad0b5ce949b0a9ac2e244f90d0..621c40c71c026aff774c16015b5251200d9abdae 100644 (file)
@@ -140,7 +140,7 @@ int encCoreAudioInit( hb_work_object_t * w, hb_job_t * job, enum AAC_MODE mode )
     pv->job = job;
 
     // pass the number of channels used into the private work data
-    pv->nchannels = HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT( audio->config.out.mixdown );
+    pv->nchannels = hb_mixdown_get_discrete_channel_count( audio->config.out.mixdown );
 
     bzero( &input, sizeof( AudioStreamBasicDescription ) );
     input.mSampleRate = ( Float64 ) audio->config.out.samplerate;
index 1a10e5e5ecbb75a0ca66fb7c5ffd7f63699ca581..a53936e6cf4a7c60039e661d8885e0bc4b4f8c65 100644 (file)
@@ -1032,11 +1032,11 @@ static void InitAudio( hb_job_t * job, hb_sync_common_t * common, int i )
         }
         else
         {
-            /* Not passthru, Initialize libsamplerate */
+            /* Not passthru, initialize libsamplerate */
             int error;
-            sync->state = src_new( SRC_SINC_MEDIUM_QUALITY, 
-                HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT(
-                    w->audio->config.out.mixdown), &error );
+            sync->state = src_new( SRC_SINC_MEDIUM_QUALITY,
+                                   hb_mixdown_get_discrete_channel_count( w->audio->config.out.mixdown ),
+                                   &error );
             sync->data.end_of_input = 0;
         }
     }
@@ -1069,10 +1069,10 @@ static hb_buffer_t * OutputAudioFrame( hb_audio_t *audio, hb_buffer_t *buf,
             /* do sample rate conversion */
             int count_in, count_out;
             hb_buffer_t * buf_raw = buf;
-            int channel_count = HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT(audio->config.out.mixdown) *
-                                sizeof( float );
+            int sample_size = hb_mixdown_get_discrete_channel_count( audio->config.out.mixdown ) *
+                              sizeof( float );
 
-            count_in  = buf_raw->size / channel_count;
+            count_in  = buf_raw->size / sample_size;
             /*
              * When using stupid rates like 44.1 there will always be some
              * truncation error. E.g., a 1536 sample AC3 frame will turn into a
@@ -1089,7 +1089,7 @@ static hb_buffer_t * OutputAudioFrame( hb_audio_t *audio, hb_buffer_t *buf,
             sync->data.src_ratio = (double)audio->config.out.samplerate /
                                    (double)audio->config.in.samplerate;
 
-            buf = hb_buffer_init( count_out * channel_count );
+            buf = hb_buffer_init( count_out * sample_size );
             sync->data.data_in  = (float *) buf_raw->data;
             sync->data.data_out = (float *) buf->data;
             if( src_process( sync->state, &sync->data ) )
@@ -1099,7 +1099,7 @@ static hb_buffer_t * OutputAudioFrame( hb_audio_t *audio, hb_buffer_t *buf,
             }
             hb_buffer_close( &buf_raw );
 
-            buf->size = sync->data.output_frames_gen * channel_count;
+            buf->size = sync->data.output_frames_gen * sample_size;
             duration = (double)( sync->data.output_frames_gen * 90000 ) /
                        audio->config.out.samplerate;
         }
@@ -1182,10 +1182,8 @@ static void InsertSilence( hb_work_object_t * w, int64_t duration )
         }
         else
         {
-            buf = hb_buffer_init( w->audio->config.out.samples_per_frame * 
-                                   sizeof( float ) *
-                                   HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT(
-                                         w->audio->config.out.mixdown) );
+            buf = hb_buffer_init( sizeof( float ) * w->audio->config.out.samples_per_frame *
+                                  hb_mixdown_get_discrete_channel_count( w->audio->config.out.mixdown ) );
             buf->s.start = sync->next_start;
             buf->s.stop  = buf->s.start + frame_dur;
             memset( buf->data, 0, buf->size );