]> granicus.if.org Git - handbrake/commitdiff
Rewrite pass-through timestamps in sync, put on subtitle->fifo_out for muxing. Also...
authoreddyg <eddyg.hb@myreflection.org>
Tue, 5 May 2009 04:49:28 +0000 (04:49 +0000)
committereddyg <eddyg.hb@myreflection.org>
Tue, 5 May 2009 04:49:28 +0000 (04:49 +0000)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@2384 b64f7644-9d1e-0410-96f1-a4d463321fa5

libhb/common.h
libhb/muxmp4.c
libhb/sync.c
libhb/work.c

index 6a2c8d51d64a824bbd8d23b3c0aebb7a3021efd7..81877d6d28aa148040a6ad683232a80fb46d75e1 100644 (file)
@@ -455,7 +455,8 @@ struct hb_subtitle_s
 #ifdef __LIBHB__
     /* Internal data */
     hb_fifo_t * fifo_in;  /* SPU ES */
-    hb_fifo_t * fifo_raw; /* Decodec SPU */
+    hb_fifo_t * fifo_raw; /* Decoded SPU */
+    hb_fifo_t * fifo_out; /* Correct Timestamps, ready to be muxed */
 #endif
 };
 
index 81ee2f8adddbb0fd594c00a3900b6b19c377eec4..bdeea8c423c160de794829991ca67bc3226809c7 100644 (file)
@@ -437,6 +437,7 @@ static int MP4Mux( hb_mux_object_t * m, hb_mux_data_t * mux_data,
     hb_job_t * job = m->job;
     int64_t duration;
     int64_t offset = 0;
+    int i;
 
     if( mux_data == job->mux_data )
     {
@@ -583,6 +584,34 @@ static int MP4Mux( hb_mux_object_t * m, hb_mux_data_t * mux_data,
         }
     }
 
+    for( i = 0; i < hb_list_count( job->list_subtitle ); i++ )
+    {
+        hb_subtitle_t *subtitle = hb_list_item( job->list_subtitle, i );
+        
+        if( subtitle && subtitle->format == TEXTSUB && 
+            subtitle->dest == PASSTHRUSUB )
+        {
+            /*
+             * Should be adding this one if the timestamp is right.
+             */
+            hb_buffer_t *sub;
+
+            while( ( sub = hb_fifo_see( subtitle->fifo_out )) != NULL )
+            {
+                if (sub->start < buf->start ) {
+                    sub = hb_fifo_get( subtitle->fifo_out );
+                    hb_log("MuxMP4: Text Sub:%lld: %s", sub->start, sub->data);
+                    hb_buffer_close( &sub );
+                } else {
+                    /*
+                     * Not time yet
+                     */
+                    break;
+                }
+            }
+        }
+    }
+
     return 0;
 }
 
@@ -590,7 +619,6 @@ static int MP4End( hb_mux_object_t * m )
 {
     hb_job_t   * job   = m->job;
     hb_title_t * title = job->title;
-    int i;
 
     /* Write our final chapter marker */
     if( m->job->chapter_markers )
@@ -667,37 +695,6 @@ static int MP4End( hb_mux_object_t * m )
         MP4TagsFree( tags );
     }
 
-    /*
-     * Display any text subs.
-     *
-     * This is placeholder code, what needs to happen is that we need to
-     * convert these PTS (which are pre-sync ones) into HB timestamps,
-     * I guess sync should do that?
-     *
-     * And then this needs to move into the Mux code above and insert
-     * subtitle samples into the MP4 at the correct times.
-     */
-    for( i = 0; i < hb_list_count( job->list_subtitle ); i++ )
-    {
-        hb_subtitle_t *subtitle = hb_list_item( job->list_subtitle, i );
-        
-        if( subtitle && subtitle->format == TEXTSUB && 
-            subtitle->dest == PASSTHRUSUB )
-        {
-            /*
-             * Should be adding this one if the timestamp is right.
-             */
-            hb_buffer_t *buffer;
-
-            while( (buffer = hb_fifo_get( subtitle->fifo_raw )) != NULL )
-            {
-                hb_log("MuxMP4: Text Sub: %s", buffer->data);
-
-                hb_buffer_close( &buffer );
-            }
-        }
-    }
-
     MP4Close( m->file );
 
     if ( job->mp4_optimize )
index 798c01b26b1867251de5303f026ebd0a66574483..b102b49f79d15e7bb65f16ee73fc41a278602a63 100644 (file)
@@ -394,7 +394,39 @@ static void SyncVideo( hb_work_object_t * w )
         for( i = 0; i < hb_list_count( job->list_subtitle ); i++)
         {
             subtitle = hb_list_item( job->list_subtitle, i );
-            if( subtitle->dest == RENDERSUB ) 
+
+            /*
+             * Rewrite timestamps on subtitles that need it (on raw queue).
+             */
+            if( subtitle->source == CCSUB )
+            {
+                /*
+                 * Rewrite timestamps on subtitles that came from Closed Captions
+                 * since they are using the MPEG2 timestamps.
+                 */
+                while( ( sub = hb_fifo_see( subtitle->fifo_raw ) ) )
+                {
+                    /*
+                     * Rewrite the timestamps as and when the video
+                     * (cur->start) reaches the same timestamp as a
+                     * closed caption (sub->start).
+                     *
+                     * What about discontinuity boundaries - not delt
+                     * with here - Van?
+                     */
+                    if( sub->start < cur->start )
+                    {
+                        sub = hb_fifo_get( subtitle->fifo_raw );
+                        sub->start = pv->next_start;
+                        hb_fifo_push( subtitle->fifo_out, sub );
+                    } else {
+                        sub = NULL;
+                        break;
+                    }
+                }
+            }
+
+            if( subtitle->source == VOBSUB ) 
             {
                 hb_buffer_t * sub2;
                 while( ( sub = hb_fifo_see( subtitle->fifo_raw ) ) )
@@ -528,11 +560,7 @@ static void SyncVideo( hb_work_object_t * w )
             if( sub )
             {
                 /*
-                 * Don't overwrite the current sub, we'll check the
-                 * other subtitle streams on the next video buffer. 
-                 *
-                 * It doesn't make much sense having multiple rendered
-                 * subtitle tracks anyway.
+                 * Got a sub to display...
                  */
                 break;
             }
@@ -575,14 +603,32 @@ static void SyncVideo( hb_work_object_t * w )
 
         /* If we have a subtitle for this picture, copy it */
         /* FIXME: we should avoid this memcpy */
-        if( sub )
+        if( sub && subtitle && 
+            subtitle->format == PICTURESUB )
         {
-            buf_tmp->sub         = hb_buffer_init( sub->size );
-            buf_tmp->sub->x      = sub->x;
-            buf_tmp->sub->y      = sub->y;
-            buf_tmp->sub->width  = sub->width;
-            buf_tmp->sub->height = sub->height;
-            memcpy( buf_tmp->sub->data, sub->data, sub->size );
+            if( subtitle->dest == RENDERSUB )
+            {
+                /*
+                 * Tack onto the video buffer for rendering
+                 */
+                buf_tmp->sub         = hb_buffer_init( sub->size );
+                buf_tmp->sub->x      = sub->x;
+                buf_tmp->sub->y      = sub->y;
+                buf_tmp->sub->width  = sub->width;
+                buf_tmp->sub->height = sub->height;
+                memcpy( buf_tmp->sub->data, sub->data, sub->size ); 
+            } else {
+                /*
+                 * Pass-Through, pop it off of the raw queue, rewrite times and
+                 * make it available to be muxed.
+                 */
+                uint64_t sub_duration;
+                sub = hb_fifo_get( subtitle->fifo_raw );
+                sub_duration = sub->stop - sub->start;
+                sub->start = buf_tmp->start;
+                sub->stop = sub->start + duration;
+                hb_fifo_push( subtitle->fifo_out, sub );
+            }
         }
 
         /* Push the frame to the renderer */
index b413c78fe5fd6319b97ef84d4ef2c607dd83684e..6159caf03fd9d32b800dfec35ada6da0eb66e5d1 100644 (file)
@@ -490,6 +490,7 @@ static void do_job( hb_job_t * job, int cpu_count )
         {
             subtitle->fifo_in  = hb_fifo_init( FIFO_CPU_MULT * cpu_count );
             subtitle->fifo_raw = hb_fifo_init( FIFO_CPU_MULT * cpu_count );
+            subtitle->fifo_out = hb_fifo_init( FIFO_CPU_MULT * cpu_count );
 
             /*
              * Disable forced subtitles if we didn't find any in the scan