OSDN Git Service

Fix a hang in sync
[handbrake-jp/handbrake-jp-git.git] / libhb / muxmkv.c
index ace68f4..073b39f 100644 (file)
@@ -34,27 +34,6 @@ struct hb_mux_data_s
     int       sub_format;
 };
 
-static int yuv2rgb(int yuv)
-{
-    double y, Cr, Cb;
-    int r, g, b;
-
-    y =  (yuv >> 16) & 0xff;
-    Cb = (yuv >>  8) & 0xff;
-    Cr = (yuv      ) & 0xff;
-
-    r = 1.164 * (y - 16)                      + 2.018 * (Cb - 128);
-    g = 1.164 * (y - 16) - 0.813 * (Cr - 128) - 0.391 * (Cb - 128);
-    b = 1.164 * (y - 16) + 1.596 * (Cr - 128);
-    r = (r < 0) ? 0 : r;
-    g = (g < 0) ? 0 : g;
-    b = (b < 0) ? 0 : b;
-    r = (r > 255) ? 255 : r;
-    g = (g > 255) ? 255 : g;
-    b = (b > 255) ? 255 : b;
-    return (r << 16) | (g << 8) | b;
-}
-
 /**********************************************************************
  * MKVInit
  **********************************************************************
@@ -188,11 +167,13 @@ static int MKVInit( hb_mux_object_t * m )
         switch (audio->config.out.codec)
         {
             case HB_ACODEC_DCA:
+            case HB_ACODEC_DCA_PASS:
                 track->codecPrivate = NULL;
                 track->codecPrivateSize = 0;
                 track->codecID = MK_ACODEC_DTS;
                 break;
             case HB_ACODEC_AC3:
+            case HB_ACODEC_AC3_PASS:
                 track->codecPrivate = NULL;
                 track->codecPrivateSize = 0;
                 track->codecID = MK_ACODEC_AC3;
@@ -249,8 +230,8 @@ static int MKVInit( hb_mux_object_t * m )
         track->trackType = MK_TRACK_AUDIO;
         track->language = audio->config.lang.iso639_2;
         track->extra.audio.samplingFreq = (float)audio->config.out.samplerate;
-        if (audio->config.out.codec == HB_ACODEC_AC3 ||
-            audio->config.out.codec == HB_ACODEC_DCA)
+        if (audio->config.out.codec == HB_ACODEC_AC3_PASS ||
+            audio->config.out.codec == HB_ACODEC_DCA_PASS)
         {
             track->extra.audio.channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(audio->config.in.channel_layout);
         }
@@ -287,7 +268,7 @@ static int MKVInit( hb_mux_object_t * m )
         int             len;
 
         subtitle = hb_list_item( title->list_subtitle, i );
-        if (subtitle->dest != PASSTHRUSUB)
+        if (subtitle->config.dest != PASSTHRUSUB)
             continue;
 
         memset(track, 0, sizeof(mk_TrackConfig));
@@ -296,9 +277,9 @@ static int MKVInit( hb_mux_object_t * m )
             case PICTURESUB:
                 track->codecID = MK_SUBTITLE_VOBSUB;
                 for (j = 0; j < 16; j++)
-                    rgb[j] = yuv2rgb(title->palette[j]);
+                    rgb[j] = hb_yuv2rgb(subtitle->palette[j]);
                 len = snprintf(subidx, 2048, subidx_fmt, 
-                        title->width, title->height,
+                        subtitle->width, subtitle->height,
                         0, 0, "OFF",
                         rgb[0], rgb[1], rgb[2], rgb[3],
                         rgb[4], rgb[5], rgb[6], rgb[7],
@@ -313,6 +294,10 @@ static int MKVInit( hb_mux_object_t * m )
             default:
                 continue;
         }
+        if ( subtitle->config.default_track )
+        {
+            track->flagDefault = 1;
+        }
 
         mux_data = calloc(1, sizeof( hb_mux_data_t ) );
         subtitle->mux_data = mux_data;
@@ -395,31 +380,33 @@ static int MKVMux( hb_mux_object_t * m, hb_mux_data_t * mux_data,
             }
             mk_addFrameData(m->file, mux_data->track, op->packet, op->bytes);
             mk_setFrameFlags(m->file, mux_data->track, timecode, 1, 0);
+            hb_buffer_close( &buf );
             return 0;
         }
     }
     else if ( mux_data->subtitle )
     {
+        uint64_t   duration;
         timecode = buf->start * TIMECODE_SCALE;
         if( mk_startFrame(m->file, mux_data->track) < 0)
         {
             hb_error( "Failed to write frame to output file, Disk Full?" );
             *job->die = 1;
         }
+
+        duration = buf->stop * TIMECODE_SCALE - timecode;
         if( mux_data->sub_format == TEXTSUB )
         {
-            uint64_t   duration;
-
-            duration = buf->stop * TIMECODE_SCALE - timecode;
             mk_addFrameData(m->file, mux_data->track, buf->data, buf->size);
             mk_setFrameFlags(m->file, mux_data->track, timecode, 1, duration);
         }
         else
         {
             mk_addFrameData(m->file, mux_data->track, buf->data, buf->size);
-            mk_setFrameFlags(m->file, mux_data->track, timecode, 1, 0);
+            mk_setFrameFlags(m->file, mux_data->track, timecode, 1, duration);
         }
         mk_flushFrame(m->file, mux_data->track);
+        hb_buffer_close( &buf );
         return 0;
     }
     else
@@ -438,6 +425,7 @@ static int MKVMux( hb_mux_object_t * m, hb_mux_data_t * mux_data,
             }
             mk_addFrameData(m->file, mux_data->track, op->packet, op->bytes);
             mk_setFrameFlags(m->file, mux_data->track, timecode, 1, 0);
+            hb_buffer_close( &buf );
             return 0;
         }
     }
@@ -453,6 +441,7 @@ static int MKVMux( hb_mux_object_t * m, hb_mux_data_t * mux_data,
                        mux_data == job->mux_data) ? 
                             (buf->frametype == HB_FRAME_IDR) : 
                             ((buf->frametype & HB_FRAME_KEY) != 0)), 0 );
+    hb_buffer_close( &buf );
     return 0;
 }