OSDN Git Service

add bootstrap step to libdca
[handbrake-jp/handbrake-jp-git.git] / libhb / stream.c
index 733727c..d53bf45 100644 (file)
@@ -58,7 +58,11 @@ static const stream2codec_t st2codec[256] = {
     st(0x0e, N, 0,                 0,              "ISO 13818-1 auxiliary"),
     st(0x0f, A, HB_ACODEC_MPGA,    CODEC_ID_AAC,   "ISO 13818-7 AAC Audio"),
     st(0x10, V, WORK_DECAVCODECV,  CODEC_ID_MPEG4, "MPEG4"),
+#if defined(OLD_LATM_PATCH)
     st(0x11, A, HB_ACODEC_MPGA,    CODEC_ID_AAC_LATM, "MPEG4 LATM AAC"),
+#else
+    st(0x11, N, 0,                 0,              "MPEG4 LATM AAC"),
+#endif
     st(0x12, U, 0,                 0,              "MPEG4 generic"),
 
     st(0x14, N, 0,                 0,              "ISO 13818-6 DSM-CC download"),
@@ -68,11 +72,11 @@ static const stream2codec_t st2codec[256] = {
     st(0x80, N, HB_ACODEC_MPGA,    CODEC_ID_PCM_BLURAY, "DigiCipher II Video"),
     st(0x81, A, HB_ACODEC_AC3,     0,              "AC-3"),
     st(0x82, A, HB_ACODEC_DCA,     0,              "HDMV DTS"),
-    st(0x83, A, HB_ACODEC_LPCM,    0,              "LPCM"),
-    st(0x84, A, 0,                 0,              "SDDS"),
+    st(0x83, A, HB_ACODEC_LPCM,    0,              "LPCM/TrueHD"),
+    st(0x84, A, 0,                 0,              "SDDS/EAC3"),
     st(0x85, U, 0,                 0,              "ATSC Program ID"),
     st(0x86, A, HB_ACODEC_DCA,     0,              "DTS-HD"),
-    st(0x87, A, 0,                 0,              "E-AC-3"),
+    st(0x87, A, HB_ACODEC_MPGA,    CODEC_ID_EAC3,  "EAC3"),
 
     st(0x8a, A, HB_ACODEC_DCA,     0,              "DTS"),
 
@@ -695,6 +699,14 @@ hb_stream_t * hb_bd_stream_open( hb_title_t *title )
             d->ts_multiplexed[d->ts_number_pids] = 0x71;
             d->ts_stream_type[d->ts_number_pids] = 0x82;
         }
+        if ( d->ts_stream_type[d->ts_number_pids] == 0x84 &&
+             title->reg_desc == STR4_TO_UINT32("HDMV") )
+        {
+            // EAC3 audio in bluray has an stype of 0x84
+            // which conflicts with SDDS
+            // To distinguish, Bluray streams have a reg_desc of HDMV
+            d->ts_stream_type[d->ts_number_pids] = 0x87;
+        }
 
         d->ts_number_pids++;
     }
@@ -1680,6 +1692,16 @@ static hb_audio_t *hb_ts_stream_set_audio_id_and_codec(hb_stream_t *stream,
                 stream->ts_stream_type[idx] = 0x82;
                 kind = A;
             }
+            if ( stype == 0x84 && 
+                 stream->pmt_info.reg_desc == STR4_TO_UINT32("HDMV") )
+            {
+                // EAC3 audio in bluray has an stype of 0x84
+                // which conflicts with SDDS
+                // To distinguish, Bluray streams have a reg_desc of HDMV
+                stype = 0x87;
+                stream->ts_stream_type[idx] = 0x87;
+                kind = A;
+            }
         }
         else if ((buf[3] & 0xe0) == 0xc0)
         {
@@ -1976,6 +1998,10 @@ static void decode_element_descriptors(hb_stream_t* stream, int esindx,
                 stream->ts_stream_type[esindx] = 0x81;
                 break;
 
+            case 0x7a:  // DVB EAC-3 descriptor
+                stream->ts_stream_type[esindx] = 0x87;
+                break;
+
             default:
                 break;
         }
@@ -2543,6 +2569,7 @@ int hb_ts_decode_pkt( hb_stream_t *stream, const uint8_t * pkt, hb_buffer_t *obu
                              ( pkt[10] >> 7 );
             ++stream->ts_pcr_in;
             stream->ts_found_pcr = 1;
+            stream->ts_flags |= TS_HAS_PCR;
         }
     }
 
@@ -2667,7 +2694,7 @@ int hb_ts_decode_pkt( hb_stream_t *stream, const uint8_t * pkt, hb_buffer_t *obu
                     return 0;
                 }
                 // if we have a dts use it otherwise use the pts
-                stream->ts_pcr = pes_timestamp( pes + ( pes[7] & 0x40? 14 : 9 ) );
+                stream->ts_pcr = pes_timestamp( pes + ( pes[7] & 0x40?14:9 ) );
                 ++stream->ts_pcr_in;
             }
         }
@@ -2870,6 +2897,9 @@ static void ffmpeg_remap_stream( hb_stream_t *stream, hb_title_t *title )
 
 void *hb_ffmpeg_context( int codec_param )
 {
+    if ( ffmpeg_streams == NULL )
+        return NULL;
+
     int slot = codec_param & (ffmpeg_sl_size - 1);
     int stream_index = codec_param >> ffmpeg_sl_bits;
     return ffmpeg_streams[slot]->ffmpeg_ic->streams[stream_index]->codec;
@@ -2877,6 +2907,9 @@ void *hb_ffmpeg_context( int codec_param )
 
 void *hb_ffmpeg_avstream( int codec_param )
 {
+    if ( ffmpeg_streams == NULL )
+        return NULL;
+
     int slot = codec_param & (ffmpeg_sl_size - 1);
     int stream_index = codec_param >> ffmpeg_sl_bits;
     return ffmpeg_streams[slot]->ffmpeg_ic->streams[stream_index];
@@ -2898,7 +2931,7 @@ static int ffmpeg_open( hb_stream_t *stream, hb_title_t *title )
     {
         return 0;
     }
-    if ( av_find_stream_info( ic ) < 0 )
+    if ( hb_av_find_stream_info( ic ) < 0 )
         goto fail;
 
     stream->ffmpeg_ic = ic;
@@ -3170,9 +3203,55 @@ static void add_ffmpeg_subtitle( hb_title_t *title, hb_stream_t *stream, int id
     strcpy( subtitle->lang, language->eng_name );
     strncpy( subtitle->iso639_2, language->iso639_2, 4 );
     
+    // Copy the extradata for the subtitle track
+    subtitle->extradata = malloc( codec->extradata_size );
+    memcpy( subtitle->extradata, codec->extradata, codec->extradata_size );
+    subtitle->extradata_size = codec->extradata_size;
+    
     hb_list_add(title->list_subtitle, subtitle);
 }
 
+static char *get_ffmpeg_metadata_value( AVMetadata *m, char *key )
+{
+    AVMetadataTag *tag = NULL;
+    while ( (tag = av_metadata_get(m, "", tag, AV_METADATA_IGNORE_SUFFIX)) )
+    {
+        if ( !strcmp( key, tag->key ) )
+        {
+            return tag->value;
+        }
+    }
+    return NULL;
+}
+
+static void add_ffmpeg_attachment( hb_title_t *title, hb_stream_t *stream, int id )
+{
+    AVStream *st = stream->ffmpeg_ic->streams[id];
+    AVCodecContext *codec = st->codec;
+    
+    enum attachtype type;
+    switch ( codec->codec_id )
+    {
+        case CODEC_ID_TTF:
+            type = FONT_TTF_ATTACH;
+            break;
+        default:
+            // Ignore unrecognized attachment type
+            return;
+    }
+    
+    hb_attachment_t *attachment = calloc( 1, sizeof(*attachment) );
+    
+    // Copy the attachment name and data
+    attachment->type = type;
+    attachment->name = strdup( get_ffmpeg_metadata_value( st->metadata, "filename" ) );
+    attachment->data = malloc( codec->extradata_size );
+    memcpy( attachment->data, codec->extradata, codec->extradata_size );
+    attachment->size = codec->extradata_size;
+    
+    hb_list_add(title->list_attachment, attachment);
+}
+
 static hb_title_t *ffmpeg_title_scan( hb_stream_t *stream )
 {
     AVFormatContext *ic = stream->ffmpeg_ic;
@@ -3233,6 +3312,10 @@ static hb_title_t *ffmpeg_title_scan( hb_stream_t *stream )
         {
             add_ffmpeg_subtitle( title, stream, i );
         }
+        else if ( ic->streams[i]->codec->codec_type == CODEC_TYPE_ATTACHMENT )
+        {
+            add_ffmpeg_attachment( title, stream, i );
+        }
     }
 
     title->container_name = strdup( ic->iformat->name );