]> granicus.if.org Git - handbrake/commitdiff
ETSI TS 102 366 V1.2.1 compliant AC3 in MP4, replaces older hacked version that was...
authoreddyg <eddyg.hb@myreflection.org>
Wed, 29 Oct 2008 21:22:53 +0000 (21:22 +0000)
committereddyg <eddyg.hb@myreflection.org>
Wed, 29 Oct 2008 21:22:53 +0000 (21:22 +0000)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@1879 b64f7644-9d1e-0410-96f1-a4d463321fa5

contrib/version_libmp4v2.txt
libhb/common.c
libhb/common.h
libhb/deca52.c
libhb/muxmp4.c
libhb/scan.c

index 431eaec02d97de043f61aada006d276478139a1a..f0017bb7fbd00ea80b09547ba9e6504fa591d29a 100644 (file)
@@ -1 +1 @@
-http://download.m0k.org/handbrake/contrib/libmp4v2-r37.tar.gz
+http://download.m0k.org/handbrake/contrib/libmp4v2-r38.tar.gz
index 7cb6ec9a6cc23e5f8765130fc8678442b20b1bf6..7d26905a61a33168e5248fe9ed083c2e5819304d 100644 (file)
@@ -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;
index c674fd831cce5edb8ce4d1e7d37f9ce67cee16e8..adf7a2da499b4693f84fb3ed124ef2035cb86500 100644 (file)
@@ -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;
index 55a3a1ed543aa4e08f198a10fd4f5f3cd62da88e..55590242ec3146de132ee98dd9b826aa1f7127b4 100644 (file)
@@ -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;
index 79517844fa003da8bb894a3874a64b1f0ef292f2..afc1f333b960c281b5bbbe92af8f48b5d633bbb8 100644 (file)
@@ -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,
index 1877803a10b09b377aa47ef6d46078e5cc999960..388caa29d77ca0bc468b003550b2c66984aaeddd 100644 (file)
@@ -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