OSDN Git Service

Don't discard titles during scan just because of a read failure on one or more of...
[handbrake-jp/handbrake-jp-git.git] / libhb / deca52.c
index 5294a5b..de33b3e 100644 (file)
@@ -25,11 +25,13 @@ struct hb_work_private_s
     int           sync;
     int           size;
 
+    int64_t       next_expected_pts;
+
     uint8_t       frame[3840];
 
     hb_list_t   * list;
        
-       int           channelsused;
+       int           out_discrete_channels;
        
 };
 
@@ -69,30 +71,15 @@ int deca52Init( hb_work_object_t * w, hb_job_t * job )
        /* Decide what format we want out of a52dec
        work.c has already done some of this deduction for us in do_job() */
        
-       if (job->channelsused == 6) {
-               /* we're going to be encoding to AAC,
-               and have turned on the "preserve 5.1" flag */
-               pv->flags_out = A52_3F2R | A52_LFE;
-       } else if (job->channelsused == 1) {
-               /* we're going to be encoding to AAC, */
-               /* and want to keep the mono-ness of the source audio */
-               pv->flags_out = A52_MONO;
-       } else if (job->channelsused == 2 && job->channels == 5 && job->lfechannels == 1) {
-               /* we are mixing a 5.1 source down to stereo, so use dolby surround */
-               pv->flags_out = A52_DOLBY;
-       } else if (job->channelsused == 2 && ((job->ac3flags & A52_CHANNEL_MASK) == A52_DOLBY)) {
-               /* we have a dolby stereo surround source, so preserve it */
-               pv->flags_out = A52_DOLBY;
-       } else {
-               /* mix everything else down to plain stereo */
-               pv->flags_out = A52_STEREO;
-       }
+       pv->flags_out = HB_AMIXDOWN_GET_A52_FORMAT(w->amixdown);
 
        /* pass the number of channels used into the private work data */
-       pv->channelsused = job->channelsused;
+       /* will only be actually used if we're not doing AC3 passthru */
+       pv->out_discrete_channels = HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT(w->amixdown);
 
     pv->level     = 32768.0;
-
+    pv->next_expected_pts = 0;
+    
     return 0;
 }
 
@@ -105,6 +92,9 @@ void deca52Close( hb_work_object_t * w )
 {
     hb_work_private_t * pv = w->private_data;
     a52_free( pv->state );
+    hb_list_empty( &pv->list );
+    free( pv );
+    w->private_data = NULL;
 }
 
 /***********************************************************************
@@ -203,10 +193,21 @@ static hb_buffer_t * Decode( hb_work_object_t * w )
     a52_frame( pv->state, pv->frame, &pv->flags_out, &pv->level, 0 );
 
     /* 6 blocks per frame, 256 samples per block, channelsused channels */
-    buf        = hb_buffer_init( 6 * 256 * pv->channelsused * sizeof( float ) );
+    buf        = hb_buffer_init( 6 * 256 * pv->out_discrete_channels * sizeof( float ) );
+    if (pts == -1)
+    {
+      pts = pv->next_expected_pts;
+    }
     buf->start = pts + ( pos / pv->size ) * 6 * 256 * 90000 / pv->rate;
     buf->stop  = buf->start + 6 * 256 * 90000 / pv->rate;
 
+    /*
+       * To track AC3 PTS add this back in again.
+        *hb_log("AC3: pts is %lld, buf->start %lld buf->stop %lld", pts, buf->start, buf->stop); 
+        */
+    
+    pv->next_expected_pts = buf->stop;
+    
     for( i = 0; i < 6; i++ )
     {
         sample_t * samples_in;
@@ -214,16 +215,17 @@ static hb_buffer_t * Decode( hb_work_object_t * w )
 
         a52_block( pv->state );
         samples_in  = a52_samples( pv->state );
-        samples_out = ((float *) buf->data) + 256 * pv->channelsused * i;
+        samples_out = ((float *) buf->data) + 256 * pv->out_discrete_channels * i;
 
         /* Interleave */
         for( j = 0; j < 256; j++ )
         {
-                       for ( k = 0; k < pv->channelsused; k++ )
+                       for ( k = 0; k < pv->out_discrete_channels; k++ )
                        {
-                               samples_out[(pv->channelsused*j)+k]   = samples_in[(256*k)+j]; // DJA
+                               samples_out[(pv->out_discrete_channels*j)+k]   = samples_in[(256*k)+j];
                        }
         }
+
     }
 
     pv->sync = 0;