OSDN Git Service

x264 bump to r1339-82b80ef
[handbrake-jp/handbrake-jp-git.git] / libhb / platform / macosx / encca_aac.c
index 69b29ec..5012104 100644 (file)
@@ -29,6 +29,7 @@ struct hb_work_private_s
     hb_list_t *list;
     unsigned long isamples, isamplesiz, omaxpacket, nchannels;
     uint64_t pts, ibytes;
+    Float64 osamplerate;
 };
 
 #define MP4ESDescrTag                   0x03
@@ -57,7 +58,7 @@ static int readDescr(UInt8 **buffer, int *tag)
 }
 
 // based off of mov_read_esds from mov.c in ffmpeg's libavformat
-static long ReadESDSDescExt(void* descExt, UInt8 **buffer, int *size, int versionFlags)
+static long ReadESDSDescExt(void* descExt, UInt8 **buffer, UInt32 *size, int versionFlags)
 {
        UInt8 *esds = (UInt8 *) descExt;
        int tag, len;
@@ -121,8 +122,8 @@ int encCoreAudioInit( hb_work_object_t * w, hb_job_t * job )
     input.mBitsPerChannel = 32;
 
     bzero( &output, sizeof( AudioStreamBasicDescription ) );
-    output.mSampleRate = ( Float64 ) audio->config.out.samplerate;
     output.mFormatID = kAudioFormatMPEG4AAC;
+    output.mSampleRate = ( Float64 ) audio->config.out.samplerate;
     output.mChannelsPerFrame = pv->nchannels;
     // let CoreAudio decide the rest...
 
@@ -130,9 +131,19 @@ int encCoreAudioInit( hb_work_object_t * w, hb_job_t * job )
     err = AudioConverterNew( &input, &output, &pv->converter );
     if( err != noErr)
     {
-        hb_log( "Error creating an AudioConverter %x %d", err, output.mBytesPerFrame );
-        *job->die = 1;
-        return 0;
+        // Retry without the samplerate
+        bzero( &output, sizeof( AudioStreamBasicDescription ) );
+        output.mFormatID = kAudioFormatMPEG4AAC;
+        output.mChannelsPerFrame = pv->nchannels;
+
+        err = AudioConverterNew( &input, &output, &pv->converter );
+
+        if( err != noErr)
+        {
+            hb_log( "Error creating an AudioConverter err=%"PRId64" %"PRIu64, (int64_t)err, (uint64_t)output.mBytesPerFrame );
+            *job->die = 1;
+            return 0;
+        }
     }
 
     if( audio->config.out.mixdown == HB_AMIXDOWN_6CH && audio->config.in.codec == HB_ACODEC_AC3 )
@@ -154,7 +165,7 @@ int encCoreAudioInit( hb_work_object_t * w, hb_job_t * job )
 
     // get available bitrates
     AudioValueRange *bitrates;
-    ssize_t bitrateCounts, n;
+    ssize_t bitrateCounts;
     err = AudioConverterGetPropertyInfo( pv->converter, kAudioConverterApplicableEncodeBitRates,
                                          &tmpsiz, NULL);
     bitrates = malloc( tmpsiz );
@@ -184,8 +195,9 @@ int encCoreAudioInit( hb_work_object_t * w, hb_job_t * job )
                                &tmpsiz, &output );
 
     // set sizes
-    pv->isamplesiz = input.mBytesPerPacket;
-    pv->isamples   = output.mFramesPerPacket;
+    pv->isamplesiz  = input.mBytesPerPacket;
+    pv->isamples    = output.mFramesPerPacket;
+    pv->osamplerate = output.mSampleRate;
 
     // get maximum output size
     AudioConverterGetProperty( pv->converter,
@@ -200,7 +212,7 @@ int encCoreAudioInit( hb_work_object_t * w, hb_job_t * job )
                                &tmp, w->config->aac.bytes );
     // CoreAudio returns a complete ESDS, but we only need
     // the DecoderSpecific info.
-    UInt8* buffer;
+    UInt8* buffer = NULL;
     ReadESDSDescExt(w->config->aac.bytes, &buffer, &tmpsiz, 0);
     w->config->aac.length = tmpsiz;
     memmove( w->config->aac.bytes, buffer,
@@ -299,7 +311,7 @@ static hb_buffer_t * Encode( hb_work_object_t * w )
         return NULL;
 
     obuf->start = pv->pts;
-    pv->pts += 90000LL * pv->isamples / w->audio->config.out.samplerate;
+    pv->pts += 90000LL * pv->isamples / pv->osamplerate;
     obuf->stop  = pv->pts;
     obuf->size  = odesc.mDataByteSize;
     obuf->frametype = HB_FRAME_AUDIO;