OSDN Git Service

SunOS support fixed with new ffmpeg and x264
[handbrake-jp/handbrake-jp-git.git] / libhb / decsub.c
index eb3b35a..98ffa1a 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id: decsub.c,v 1.12 2005/04/14 17:37:54 titer Exp $
 
    This file is part of the HandBrake source code.
-   Homepage: <http://handbrake.m0k.org/>.
+   Homepage: <http://handbrake.fr/>.
    It may be used under the terms of the GNU General Public License. */
 
 #include "hb.h"
@@ -36,7 +36,7 @@ static hb_buffer_t * Decode( hb_work_object_t * );
 int decsubInit( hb_work_object_t * w, hb_job_t * job )
 {
     hb_work_private_t * pv;
-    
+
     pv              = calloc( 1, sizeof( hb_work_private_t ) );
     w->private_data = pv;
 
@@ -51,9 +51,16 @@ int decsubWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
 {
     hb_work_private_t * pv = w->private_data;
     hb_buffer_t * in = *buf_in;
-
     int size_sub, size_rle;
 
+    if ( in->size <= 0 )
+    {
+        /* EOF on input stream - send it downstream & say that we're done */
+        *buf_out = in;
+        *buf_in = NULL;
+        return HB_WORK_DONE;
+    }
+
     pv->stream_id = in->id;
 
     size_sub = ( in->data[0] << 8 ) | in->data[1];
@@ -95,6 +102,11 @@ int decsubWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
         /* We got a complete subtitle, decode it */
         *buf_out = Decode( w );
 
+        if( buf_out && *buf_out )
+        {
+            (*buf_out)->sequence = in->sequence;
+        }
+
         /* Wait for the next one */
         pv->size_sub = 0;
         pv->size_got = 0;
@@ -141,12 +153,12 @@ static void ParseControls( hb_work_object_t * w )
     pv->pts_start = 0;
     pv->pts_stop  = 0;
     pv->pts_forced  = 0;
-       
+
     pv->alpha[3] = 0;
     pv->alpha[2] = 0;
     pv->alpha[1] = 0;
     pv->alpha[0] = 0;
-    
+
     for( i = pv->size_rle; ; )
     {
         date = ( pv->buf[i] << 8 ) | pv->buf[i+1]; i += 2;
@@ -177,9 +189,9 @@ static void ParseControls( hb_work_object_t * w )
                     /*
                      * If we are doing a subtitle scan then note down
                      */
-                    if( job->subtitle_scan )
+                    if( job->indepth_scan )
                     {
-                        for( n=0; n < hb_list_count(title->list_subtitle); n++ ) 
+                        for( n=0; n < hb_list_count(title->list_subtitle); n++ )
                         {
                             subtitle = hb_list_item( title->list_subtitle, n);
                             if( pv->stream_id == subtitle->id ) {
@@ -198,13 +210,13 @@ static void ParseControls( hb_work_object_t * w )
                     break;
 
                 case 0x02: // 0x02 - STP_DSP - Stop Display, no arguments
-                                       if(!pv->pts_stop)
-                                               pv->pts_stop = pv->pts + date * 900;
+                    if(!pv->pts_stop)
+                        pv->pts_stop = pv->pts + date * 900;
                     break;
 
                 case 0x03: // 0x03 - SET_COLOR - Set Colour indices
-                {              
-                    /* 
+                {
+                    /*
                      * SET_COLOR - provides four indices into the CLUT
                      * for the current PGC to associate with the four
                      * pixel values
@@ -240,45 +252,45 @@ static void ParseControls( hb_work_object_t * w )
                                3-j,
                                pv->lum[3-j],
                                pv->chromaU[3-j],
-                               pv->chromaV[3-j]); 
+                               pv->chromaV[3-j]);
                         */
-                    } 
+                    }
                     i += 2;
                     break;
                 }
                 case 0x04: // 0x04 - SET_CONTR - Set Contrast
                 {
-                    /* 
+                    /*
                      * SET_CONTR - directly provides the four contrast
                      * (alpha blend) values to associate with the four
                      * pixel values
                      */
                     uint8_t    alpha[4];
-                    
+
                     alpha[3] = (pv->buf[i+0]>>4)&0x0f;
                     alpha[2] = (pv->buf[i+0])&0x0f;
                     alpha[1] = (pv->buf[i+1]>>4)&0x0f;
                     alpha[0] = (pv->buf[i+1])&0x0f;
-                    
-                    
+
+
                     int lastAlpha = pv->alpha[3] + pv->alpha[2] + pv->alpha[1] + pv->alpha[0];
                     int currAlpha = alpha[3] + alpha[2] + alpha[1] + alpha[0];
-                    
+
                     // fading-in, save the highest alpha value
-                    if( currAlpha > lastAlpha ) 
+                    if( currAlpha > lastAlpha )
                     {
                         pv->alpha[3] = alpha[3];
                         pv->alpha[2] = alpha[2];
                         pv->alpha[1] = alpha[1];
                         pv->alpha[0] = alpha[0];
                     }
-                    
+
                     // fading-out
-                    if( currAlpha < lastAlpha && !pv->pts_stop ) 
+                    if( currAlpha < lastAlpha && !pv->pts_stop )
                     {
                         pv->pts_stop = pv->pts + date * 900;
                     }
-                    
+
                     i += 2;
                     break;
                 }
@@ -299,7 +311,7 @@ static void ParseControls( hb_work_object_t * w )
                 }
             }
         }
-               
+
 
 
         if( i > next )
@@ -463,7 +475,7 @@ static hb_buffer_t * Decode( hb_work_object_t * w )
     /* Get infos about the subtitle */
     ParseControls( w );
 
-    if( job->subtitle_scan || ( job->subtitle_force && pv->pts_forced == 0 ) )
+    if( job->indepth_scan || ( job->subtitle_force && pv->pts_forced == 0 ) )
     {
         /*
          * Don't encode subtitles when doing a scan.
@@ -480,7 +492,7 @@ static hb_buffer_t * Decode( hb_work_object_t * w )
 #define GET_NEXT_NIBBLE code = ( code << 4 ) | ( ( ( *offset & 1 ) ? \
 ( pv->buf[((*offset)>>1)] & 0xF ) : ( pv->buf[((*offset)>>1)] >> 4 ) ) ); \
 (*offset)++
-    
+
     offsets[0] = pv->offsets[0] * 2;
     offsets[1] = pv->offsets[1] * 2;