diff options
Diffstat (limited to 'libhb')
-rw-r--r-- | libhb/common.c | 2 | ||||
-rw-r--r-- | libhb/common.h | 4 | ||||
-rw-r--r-- | libhb/deca52.c | 12 | ||||
-rw-r--r-- | libhb/muxmp4.c | 105 | ||||
-rw-r--r-- | libhb/scan.c | 2 |
5 files changed, 123 insertions, 2 deletions
diff --git a/libhb/common.c b/libhb/common.c index 7cb6ec9a6..7d26905a6 100644 --- a/libhb/common.c +++ b/libhb/common.c @@ -727,6 +727,8 @@ void hb_audio_config_init(hb_audio_config_t * audiocfg) audiocfg->in.bitrate = -1; audiocfg->in.samplerate = -1; audiocfg->in.channel_layout = 0; + audiocfg->in.version = 0; + audiocfg->in.mode = 0; audiocfg->flags.ac3 = 0; audiocfg->lang.description[0] = 0; audiocfg->lang.simple[0] = 0; diff --git a/libhb/common.h b/libhb/common.h index c674fd831..adf7a2da4 100644 --- a/libhb/common.h +++ b/libhb/common.h @@ -339,6 +339,8 @@ struct hb_audio_config_s int track; /* Input track number */ PRIVATE uint32_t codec; /* Input audio codec */ PRIVATE uint32_t codec_param; /* per-codec config info */ + PRIVATE uint32_t version; /* Bitsream version */ + PRIVATE uint32_t mode; /* Bitstream mode, codec dependent encoding */ PRIVATE int samplerate; /* Input sample rate (Hz) */ PRIVATE int bitrate; /* Input bitrate (kbps) */ PRIVATE int channel_layout; @@ -534,6 +536,8 @@ typedef struct hb_work_info_s int rate; int rate_base; int flags; + int version; + int mode; union { struct { // info only valid for video decoders int width; diff --git a/libhb/deca52.c b/libhb/deca52.c index 55a3a1ed5..55590242e 100644 --- a/libhb/deca52.c +++ b/libhb/deca52.c @@ -291,6 +291,7 @@ static int deca52BSInfo( hb_work_object_t *w, const hb_buffer_t *b, int i; int rate = 0, bitrate = 0, flags = 0; int old_rate = 0, old_bitrate = 0; + uint8_t raw; memset( info, 0, sizeof(*info) ); @@ -314,6 +315,7 @@ static int deca52BSInfo( hb_work_object_t *w, const hb_buffer_t *b, old_rate = rate; old_bitrate = bitrate; + raw = b->data[i+5]; } } if ( rate == 0 || bitrate == 0 ) @@ -322,11 +324,21 @@ static int deca52BSInfo( hb_work_object_t *w, const hb_buffer_t *b, return 0; } + /* + * bsid | bsmod | acmod | cmixlev | surmixlev | dsurmod | lfeon | dialnorm | compre + * 5 3 3 2 2 2 1 5 1 + * [ byte1 ][ byte2 ][ byte3 ] + */ + + info->name = "AC-3"; info->rate = rate; info->rate_base = 1; info->bitrate = bitrate; info->flags = flags; + info->version = raw >> 3; /* bsid is the first 5 bits */ + info->mode = raw & 0x7; /* bsmod is the following 3 bits */ + if ( (flags & A52_CHANNEL_MASK) == A52_DOLBY ) { info->flags |= AUDIO_F_DOLBY; diff --git a/libhb/muxmp4.c b/libhb/muxmp4.c index 79517844f..afc1f333b 100644 --- a/libhb/muxmp4.c +++ b/libhb/muxmp4.c @@ -4,8 +4,8 @@ Homepage: <http://handbrake.fr/>. It may be used under the terms of the GNU General Public License. */ -/* libmp4v2 header */ #include "mp4v2/mp4v2.h" +#include "a52dec/a52.h" #include "hb.h" @@ -306,9 +306,110 @@ static int MP4Init( hb_mux_object_t * m ) if( audio->config.out.codec == HB_ACODEC_AC3 ) { + uint8_t fscod = 0; + uint8_t bsid = audio->config.in.version; + uint8_t bsmod = audio->config.in.mode; + uint8_t acmod = audio->config.flags.ac3 & 0x7; + uint8_t lfeon = (audio->config.flags.ac3 & A52_LFE) ? 1 : 0; + uint8_t bit_rate_code = 0; + + /* + * Rewrite AC3 information into correct format for dac3 atom + */ + switch( audio->config.in.samplerate ) + { + case 48000: + fscod = 0; + break; + case 44100: + fscod = 1; + break; + case 32000: + fscod = 2; + break; + default: + /* + * Error value, tells decoder to not decode this audio. + */ + fscod = 3; + break; + } + + switch( audio->config.in.bitrate ) + { + case 32000: + bit_rate_code = 0; + break; + case 40000: + bit_rate_code = 1; + break; + case 48000: + bit_rate_code = 2; + break; + case 56000: + bit_rate_code = 3; + break; + case 64000: + bit_rate_code = 4; + break; + case 80000: + bit_rate_code = 5; + break; + case 96000: + bit_rate_code = 6; + break; + case 112000: + bit_rate_code = 7; + break; + case 128000: + bit_rate_code = 8; + break; + case 160000: + bit_rate_code = 9; + break; + case 192000: + bit_rate_code = 10; + break; + case 224000: + bit_rate_code = 11; + break; + case 256000: + bit_rate_code = 12; + break; + case 320000: + bit_rate_code = 13; + break; + case 384000: + bit_rate_code = 14; + break; + case 448000: + bit_rate_code = 15; + break; + case 512000: + bit_rate_code = 16; + break; + case 576000: + bit_rate_code = 17; + break; + case 640000: + bit_rate_code = 18; + break; + default: + hb_error("Unknown AC3 bitrate"); + bit_rate_code = 0; + break; + } + mux_data->track = MP4AddAC3AudioTrack( m->file, - m->samplerate, 1536, MP4_MPEG4_AUDIO_TYPE ); + m->samplerate, + fscod, + bsid, + bsmod, + acmod, + lfeon, + bit_rate_code); + if (audio->config.out.name == NULL) { MP4SetTrackBytesProperty( m->file, mux_data->track, diff --git a/libhb/scan.c b/libhb/scan.c index 1877803a1..388caa29d 100644 --- a/libhb/scan.c +++ b/libhb/scan.c @@ -814,6 +814,8 @@ static void LookForAudio( hb_title_t * title, hb_buffer_t * b ) audio->config.in.samplerate = info.rate; audio->config.in.bitrate = info.bitrate; audio->config.in.channel_layout = info.channel_layout; + audio->config.in.version = info.version; + audio->config.in.mode = info.mode; audio->config.flags.ac3 = info.flags; // update the audio description string based on the info we found |