Commit 91fb2fdd authored by Gildas Bazin's avatar Gildas Bazin

* modules/demux/mpeg/ts.c: fixed my last f*ckage + a bit of clean-up.
parent 9adb4abd
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* mpeg_ts.c : Transport Stream input module for vlc * mpeg_ts.c : Transport Stream input module for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2000-2001 VideoLAN * Copyright (C) 2000-2001 VideoLAN
* $Id: ts.c,v 1.22 2003/05/05 22:48:22 gbazin Exp $ * $Id: ts.c,v 1.23 2003/05/06 21:01:58 gbazin Exp $
* *
* Authors: Henri Fallon <henri@via.ecp.fr> * Authors: Henri Fallon <henri@via.ecp.fr>
* Johan Bilien <jobi@via.ecp.fr> * Johan Bilien <jobi@via.ecp.fr>
...@@ -1273,7 +1273,8 @@ static void TS_DVBPSI_HandlePMT( input_thread_t * p_input, ...@@ -1273,7 +1273,8 @@ static void TS_DVBPSI_HandlePMT( input_thread_t * p_input,
p_pgrm_demux = (pgrm_ts_data_t *)p_pgrm->p_demux_data; p_pgrm_demux = (pgrm_ts_data_t *)p_pgrm->p_demux_data;
p_pgrm_demux->i_pcr_pid = p_new_pmt->i_pcr_pid; p_pgrm_demux->i_pcr_pid = p_new_pmt->i_pcr_pid;
if( ( p_new_pmt->b_current_next && ( p_new_pmt->i_version != p_pgrm_demux->i_pmt_version ) ) || if( ( p_new_pmt->b_current_next &&
( p_new_pmt->i_version != p_pgrm_demux->i_pmt_version ) ) ||
p_pgrm_demux->i_pmt_version == PMT_UNINITIALIZED ) p_pgrm_demux->i_pmt_version == PMT_UNINITIALIZED )
{ {
dvbpsi_descriptor_t *p_dr = p_new_pmt->p_first_descriptor; dvbpsi_descriptor_t *p_dr = p_new_pmt->p_first_descriptor;
...@@ -1289,7 +1290,15 @@ static void TS_DVBPSI_HandlePMT( input_thread_t * p_input, ...@@ -1289,7 +1290,15 @@ static void TS_DVBPSI_HandlePMT( input_thread_t * p_input,
p_es = p_new_pmt->p_first_es; p_es = p_new_pmt->p_first_es;
while( p_es ) while( p_es )
{ {
int i_fourcc, i_cat, i_stream_id; vlc_fourcc_t i_fourcc;
int i_size, i_cat, i_stream_id = 0;
es_ts_data_t demux_data;
BITMAPINFOHEADER *p_bih = NULL;
WAVEFORMATEX *p_wf = NULL;
char psz_desc[30];
memset( &demux_data, 0, sizeof(es_ts_data_t) );
*psz_desc = 0;
switch( p_es->i_type ) switch( p_es->i_type )
{ {
...@@ -1372,60 +1381,47 @@ static void TS_DVBPSI_HandlePMT( input_thread_t * p_input, ...@@ -1372,60 +1381,47 @@ static void TS_DVBPSI_HandlePMT( input_thread_t * p_input,
i_stream_id = 0; i_stream_id = 0;
} }
/* Add this ES */ if( p_es->i_type == MPEG4_VIDEO_ES ||
p_new_es = input_AddES( p_input, p_pgrm, (u16)p_es->i_pid, p_es->i_type == MPEG4_AUDIO_ES )
i_cat, NULL, sizeof( es_ts_data_t ) );
if( p_new_es == NULL )
{
msg_Err( p_input, "could not add ES %d", p_es->i_pid );
p_input->b_error = 1;
return;
}
p_new_es->i_fourcc = i_fourcc;
p_new_es->i_stream_id = i_stream_id;
((es_ts_data_t *)p_new_es->p_demux_data)->i_continuity_counter = 0xFF;
if( p_es->i_type == MPEG4_VIDEO_ES || p_es->i_type == MPEG4_AUDIO_ES )
{ {
/* mpeg4 stream, search sl_descriptor */ /* mpeg4 stream, search sl_descriptor */
dvbpsi_descriptor_t *p_dr = p_es->p_first_descriptor; dvbpsi_descriptor_t *p_dr = p_es->p_first_descriptor;
es_ts_data_t *p_es_demux =
(es_ts_data_t*)p_new_es->p_demux_data;
while( p_dr && ( p_dr->i_tag != 0x1f ) ) while( p_dr && ( p_dr->i_tag != 0x1f ) ) p_dr = p_dr->p_next;
p_dr = p_dr->p_next;
if( p_dr && p_dr->i_length == 2 ) if( p_dr && p_dr->i_length == 2 )
{ {
int i_es_descr_index; int i_es_descr_index;
p_es_demux->i_es_id = demux_data.i_es_id =
( p_dr->p_data[0] << 8 ) | p_dr->p_data[1]; ( p_dr->p_data[0] << 8 ) | p_dr->p_data[1];
p_es_demux->p_es_descr = NULL; demux_data.p_es_descr = NULL;
msg_Warn( p_input, "found SL_descriptor" ); msg_Warn( p_input, "found SL_descriptor" );
for( i_es_descr_index = 0; i_es_descr_index < 255; i_es_descr_index++ ) for( i_es_descr_index = 0; i_es_descr_index < 255;
i_es_descr_index++ )
{ {
if( p_pgrm_demux->iod.es_descr[i_es_descr_index].b_ok && if( p_pgrm_demux->iod.es_descr[i_es_descr_index].b_ok &&
p_pgrm_demux->iod.es_descr[i_es_descr_index].i_es_id == p_es_demux->i_es_id ) p_pgrm_demux->iod.es_descr[i_es_descr_index].i_es_id == demux_data.i_es_id )
{ {
p_es_demux->p_es_descr = &p_pgrm_demux->iod.es_descr[i_es_descr_index]; demux_data.p_es_descr =
&p_pgrm_demux->iod.es_descr[i_es_descr_index];
break; break;
} }
} }
} }
if( p_es_demux->p_es_descr != NULL )
if( demux_data.p_es_descr != NULL )
{ {
vlc_fourcc_t i_fourcc; #define DESCR demux_data.p_es_descr->dec_descr
int i_cat; demux_data.b_mpeg4 = 1;
p_es_demux->b_mpeg4 = 1;
/* fix fourcc */ /* fix fourcc */
switch( p_es_demux->p_es_descr->dec_descr.i_streamType ) switch( DESCR.i_streamType )
{ {
case 0x04: /* VisualStream */ case 0x04: /* VisualStream */
i_cat = VIDEO_ES; i_cat = VIDEO_ES;
switch( p_es_demux->p_es_descr->dec_descr.i_objectTypeIndication ) switch( DESCR.i_objectTypeIndication )
{ {
case 0x20: case 0x20:
i_fourcc = VLC_FOURCC('m','p','4','v'); // mpeg4 i_fourcc = VLC_FOURCC('m','p','4','v'); // mpeg4
...@@ -1451,7 +1447,7 @@ static void TS_DVBPSI_HandlePMT( input_thread_t * p_input, ...@@ -1451,7 +1447,7 @@ static void TS_DVBPSI_HandlePMT( input_thread_t * p_input,
break; break;
case 0x05: /* AudioStream */ case 0x05: /* AudioStream */
i_cat = AUDIO_ES; i_cat = AUDIO_ES;
switch( p_es_demux->p_es_descr->dec_descr.i_objectTypeIndication ) switch( DESCR.i_objectTypeIndication )
{ {
case 0x40: case 0x40:
i_fourcc = VLC_FOURCC('m','p','4','a'); // mpeg4 i_fourcc = VLC_FOURCC('m','p','4','a'); // mpeg4
...@@ -1459,7 +1455,7 @@ static void TS_DVBPSI_HandlePMT( input_thread_t * p_input, ...@@ -1459,7 +1455,7 @@ static void TS_DVBPSI_HandlePMT( input_thread_t * p_input,
case 0x66: case 0x66:
case 0x67: case 0x67:
case 0x68: case 0x68:
i_fourcc = VLC_FOURCC('m','p','4','a'); // mpeg2 aac i_fourcc = VLC_FOURCC('m','p','4','a');// mpeg2 aac
break; break;
case 0x69: case 0x69:
i_fourcc = VLC_FOURCC('m','p','g','a'); // mpeg2 i_fourcc = VLC_FOURCC('m','p','g','a'); // mpeg2
...@@ -1478,18 +1474,12 @@ static void TS_DVBPSI_HandlePMT( input_thread_t * p_input, ...@@ -1478,18 +1474,12 @@ static void TS_DVBPSI_HandlePMT( input_thread_t * p_input,
break; break;
} }
p_new_es->i_fourcc = i_fourcc;
p_new_es->i_cat = i_cat;
switch( i_cat ) switch( i_cat )
{ {
case VIDEO_ES: case VIDEO_ES:
{
int i_size;
BITMAPINFOHEADER *p_bih;
i_size = sizeof( BITMAPINFOHEADER ) + i_size = sizeof( BITMAPINFOHEADER ) +
p_es_demux->p_es_descr->dec_descr.i_decoder_specific_info_len; DESCR.i_decoder_specific_info_len;
p_new_es->p_bitmapinfoheader = (void*)p_bih = malloc( i_size ); p_bih = malloc( i_size );
p_bih->biSize = i_size; p_bih->biSize = i_size;
p_bih->biWidth = 0; p_bih->biWidth = 0;
p_bih->biHeight = 0; p_bih->biHeight = 0;
...@@ -1502,29 +1492,23 @@ static void TS_DVBPSI_HandlePMT( input_thread_t * p_input, ...@@ -1502,29 +1492,23 @@ static void TS_DVBPSI_HandlePMT( input_thread_t * p_input,
p_bih->biClrUsed = 0; p_bih->biClrUsed = 0;
p_bih->biClrImportant = 0; p_bih->biClrImportant = 0;
memcpy( &p_bih[1], memcpy( &p_bih[1],
p_es_demux->p_es_descr->dec_descr.p_decoder_specific_info, DESCR.p_decoder_specific_info,
p_es_demux->p_es_descr->dec_descr.i_decoder_specific_info_len ); DESCR.i_decoder_specific_info_len );
}
break; break;
case AUDIO_ES: case AUDIO_ES:
{
int i_size;
WAVEFORMATEX *p_wf;
i_size = sizeof( WAVEFORMATEX ) + i_size = sizeof( WAVEFORMATEX ) +
p_es_demux->p_es_descr->dec_descr.i_decoder_specific_info_len; DESCR.i_decoder_specific_info_len;
p_new_es->p_waveformatex = (void*)p_wf = malloc( i_size ); p_wf = malloc( i_size );
p_wf->wFormatTag = 0xffff; p_wf->wFormatTag = 0xffff;
p_wf->nChannels = 0; p_wf->nChannels = 0;
p_wf->nSamplesPerSec = 0; p_wf->nSamplesPerSec = 0;
p_wf->nAvgBytesPerSec = 0; p_wf->nAvgBytesPerSec = 0;
p_wf->nBlockAlign = 1; p_wf->nBlockAlign = 1;
p_wf->wBitsPerSample = 0; p_wf->wBitsPerSample = 0;
p_wf->cbSize = p_es_demux->p_es_descr->dec_descr.i_decoder_specific_info_len; p_wf->cbSize = DESCR.i_decoder_specific_info_len;
memcpy( &p_wf[1], memcpy( &p_wf[1],
p_es_demux->p_es_descr->dec_descr.p_decoder_specific_info, DESCR.p_decoder_specific_info,
p_es_demux->p_es_descr->dec_descr.i_decoder_specific_info_len ); DESCR.i_decoder_specific_info_len );
}
break; break;
default: default:
break; break;
...@@ -1532,8 +1516,9 @@ static void TS_DVBPSI_HandlePMT( input_thread_t * p_input, ...@@ -1532,8 +1516,9 @@ static void TS_DVBPSI_HandlePMT( input_thread_t * p_input,
} }
else else
{ {
msg_Warn( p_input, "mpeg4 stream without (valid) sl_descriptor" ); msg_Warn( p_input,
p_es_demux->b_mpeg4 = 0; "mpeg4 stream without (valid) sl_descriptor" );
demux_data.b_mpeg4 = 0;
} }
} }
...@@ -1541,24 +1526,20 @@ static void TS_DVBPSI_HandlePMT( input_thread_t * p_input, ...@@ -1541,24 +1526,20 @@ static void TS_DVBPSI_HandlePMT( input_thread_t * p_input,
{ {
/* crapy ms codec stream, search private descriptor */ /* crapy ms codec stream, search private descriptor */
dvbpsi_descriptor_t *p_dr = p_es->p_first_descriptor; dvbpsi_descriptor_t *p_dr = p_es->p_first_descriptor;
es_ts_data_t *p_es_demux =
(es_ts_data_t*)p_new_es->p_demux_data;
while( p_dr && ( p_dr->i_tag != 0xa0 ) ) while( p_dr && ( p_dr->i_tag != 0xa0 ) ) p_dr = p_dr->p_next;
p_dr = p_dr->p_next;
if( p_dr && p_dr->i_length >= 8 ) if( p_dr && p_dr->i_length >= 8 )
{ {
int i_size;
int i_bih_size; int i_bih_size;
BITMAPINFOHEADER *p_bih; i_fourcc = (p_dr->p_data[0] << 24) |
(p_dr->p_data[1] << 16) | (p_dr->p_data[2] << 8) |
p_new_es->i_fourcc = ( p_dr->p_data[0] << 24 )| ( p_dr->p_data[1] << 16 )| p_dr->p_data[3];
( p_dr->p_data[2] << 8 )| ( p_dr->p_data[3] );
i_bih_size = ( ( p_dr->p_data[8] << 8)|( p_dr->p_data[9] ) ); i_bih_size = (p_dr->p_data[8] << 8) | p_dr->p_data[9];
i_size = sizeof( BITMAPINFOHEADER ) + i_bih_size; i_size = sizeof( BITMAPINFOHEADER ) + i_bih_size;
p_new_es->p_bitmapinfoheader = (void*)p_bih = malloc( i_size ); p_bih = malloc( i_size );
p_bih->biSize = i_size; p_bih->biSize = i_size;
p_bih->biWidth = ( p_dr->p_data[4] << 8 )|p_dr->p_data[5]; p_bih->biWidth = ( p_dr->p_data[4] << 8 )|p_dr->p_data[5];
p_bih->biHeight = ( p_dr->p_data[6] << 8 )|p_dr->p_data[7]; p_bih->biHeight = ( p_dr->p_data[6] << 8 )|p_dr->p_data[7];
...@@ -1570,24 +1551,22 @@ static void TS_DVBPSI_HandlePMT( input_thread_t * p_input, ...@@ -1570,24 +1551,22 @@ static void TS_DVBPSI_HandlePMT( input_thread_t * p_input,
p_bih->biYPelsPerMeter = 0; p_bih->biYPelsPerMeter = 0;
p_bih->biClrUsed = 0; p_bih->biClrUsed = 0;
p_bih->biClrImportant = 0; p_bih->biClrImportant = 0;
memcpy( &p_bih[1], memcpy( &p_bih[1], &p_dr->p_data[10], i_bih_size );
&p_dr->p_data[10],
i_bih_size );
} }
else else
{ {
msg_Warn( p_input, "private ms-codec stream without bih private sl_descriptor" ); msg_Warn( p_input, "private ms-codec stream without bih "
p_new_es->i_fourcc = 0; "private sl_descriptor" );
p_new_es->i_cat = UNKNOWN_ES; i_fourcc = 0;
i_cat = UNKNOWN_ES;
} }
} }
if( ( p_new_es->i_cat == AUDIO_ES ) if( i_cat == AUDIO_ES || i_cat == SPU_ES )
|| (p_new_es->i_cat == SPU_ES ) )
{ {
dvbpsi_descriptor_t *p_dr = p_es->p_first_descriptor; dvbpsi_descriptor_t *p_dr = p_es->p_first_descriptor;
while( p_dr && ( p_dr->i_tag != 0x0a ) ) while( p_dr && ( p_dr->i_tag != 0x0a ) ) p_dr = p_dr->p_next;
p_dr = p_dr->p_next;
if( p_dr ) if( p_dr )
{ {
dvbpsi_iso639_dr_t *p_decoded = dvbpsi_iso639_dr_t *p_decoded =
...@@ -1596,19 +1575,19 @@ static void TS_DVBPSI_HandlePMT( input_thread_t * p_input, ...@@ -1596,19 +1575,19 @@ static void TS_DVBPSI_HandlePMT( input_thread_t * p_input,
{ {
const iso639_lang_t * p_iso; const iso639_lang_t * p_iso;
p_iso = GetLang_2T((char*)p_decoded->i_iso_639_code); p_iso = GetLang_2T((char*)p_decoded->i_iso_639_code);
if(p_iso)
if( p_iso )
{ {
if(p_iso->psz_native_name[0]) if( p_iso->psz_native_name[0] )
strcpy( p_new_es->psz_desc, strncpy( psz_desc,
p_iso->psz_native_name ); p_iso->psz_native_name, 20 );
else else
strcpy( p_new_es->psz_desc, strncpy( psz_desc,
p_iso->psz_eng_name ); p_iso->psz_eng_name, 20 );
} }
else else
{ {
strncpy( p_new_es->psz_desc, strncpy( psz_desc, p_decoded->i_iso_639_code, 3 );
p_decoded->i_iso_639_code, 3 );
} }
} }
} }
...@@ -1616,23 +1595,42 @@ static void TS_DVBPSI_HandlePMT( input_thread_t * p_input, ...@@ -1616,23 +1595,42 @@ static void TS_DVBPSI_HandlePMT( input_thread_t * p_input,
{ {
case MPEG1_AUDIO_ES: case MPEG1_AUDIO_ES:
case MPEG2_AUDIO_ES: case MPEG2_AUDIO_ES:
strcat( p_new_es->psz_desc, " (mpeg)" ); strcat( psz_desc, " (mpeg)" );
break; break;
case LPCM_AUDIO_ES: case LPCM_AUDIO_ES:
case LPCMB_AUDIO_ES: case LPCMB_AUDIO_ES:
strcat( p_new_es->psz_desc, " (lpcm)" ); strcat( psz_desc, " (lpcm)" );
break; break;
case A52_AUDIO_ES: case A52_AUDIO_ES:
case A52DVB_AUDIO_ES: case A52DVB_AUDIO_ES:
case A52B_AUDIO_ES: case A52B_AUDIO_ES:
strcat( p_new_es->psz_desc, " (A52)" ); strcat( psz_desc, " (A52)" );
break; break;
case MPEG4_AUDIO_ES: case MPEG4_AUDIO_ES:
strcat( p_new_es->psz_desc, " (aac)" ); strcat( psz_desc, " (aac)" );
break; break;
} }
} }
/* Add this ES */
p_new_es = input_AddES( p_input, p_pgrm, (u16)p_es->i_pid,
i_cat, psz_desc, sizeof( es_ts_data_t ) );
if( p_new_es == NULL )
{
msg_Err( p_input, "could not add ES %d", p_es->i_pid );
p_input->b_error = 1;
return;
}
p_new_es->i_fourcc = i_fourcc;
p_new_es->i_stream_id = i_stream_id;
p_new_es->p_bitmapinfoheader = (void*)p_bih;
p_new_es->p_waveformatex = (void*)p_wf;
memcpy( p_new_es->p_demux_data, &demux_data,
sizeof(es_ts_data_t) );
((es_ts_data_t *)p_new_es->p_demux_data)->i_continuity_counter =
0xFF;
p_es = p_es->p_next; p_es = p_es->p_next;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment