* mpeg_ts.c : Transport Stream input module for vlc
*****************************************************************************
* Copyright (C) 2000-2001 VideoLAN
- * $Id: ts.c,v 1.25 2003/05/31 00:10:11 fenrir Exp $
+ * $Id: ts.c,v 1.38 2003/10/27 13:35:15 nitrox Exp $
*
* Authors: Henri Fallon <henri@via.ecp.fr>
* Johan Bilien <jobi@via.ecp.fr>
* Preamble
*****************************************************************************/
#include <stdlib.h>
-#include <string.h>
-
-#ifdef HAVE_STDINT_H
-# include <stdint.h> /* uint8_t */
-#endif
-
#include <vlc/vlc.h>
#include <vlc/input.h>
/* Set the demux function */
p_input->pf_demux = Demux;
+ p_input->pf_demux_control = demux_vaControlDefault;
+#if 0
+ /* XXX Unused already done by src/input.c */
/* Initialize access plug-in structures. */
if( p_input->i_mtu == 0 )
{
/* Improve speed. */
+ msg_Dbg( p_input, "using default mtu (%d) with bufsize (%d)\n",
+ p_input->i_mtu, INPUT_DEFAULT_BUFSIZE );
p_input->i_bufsize = INPUT_DEFAULT_BUFSIZE;
}
+#endif
/* Have a peep at the show. */
if( input_Peek( p_input, &p_peek, 1 ) < 1 )
* The PAT es is indepedent of any program. */
p_pat_es = input_AddES( p_input, NULL, 0x00,
UNKNOWN_ES, NULL, sizeof( es_ts_data_t ) );
+ p_pat_es->i_fourcc = VLC_FOURCC( 'p', 'a', 't', ' ' );
p_demux_data = (es_ts_data_t *)p_pat_es->p_demux_data;
p_demux_data->b_psi = 1;
p_demux_data->i_psi_type = PSI_IS_PAT;
{
/* unit_start set to 1 -> presence of a pointer field
* (see ISO/IEC 13818 (2.4.4.2) which should be set to 0x00 */
- if( (u8)p[0] != 0x00 )
+ if( (uint8_t)p[0] != 0x00 )
{
msg_Warn( p_input,
"non-zero pointer field found, trying to continue" );
- p+=(u8)p[0];
+ p+=(uint8_t)p[0];
}
else
{
/* This is the begining of a new section */
- if( ((u8)(p[1]) & 0xc0) != 0x80 )
+ if( ((uint8_t)(p[1]) & 0xc0) != 0x80 )
{
msg_Warn( p_input, "invalid PSI packet" );
p_psi->b_trash = 1;
p_psi->i_section_length = ((p[1] & 0xF) << 8) | p[2];
p_psi->b_section_complete = 0;
p_psi->i_read_in_section = 0;
- p_psi->i_section_number = (u8)p[6];
+ p_psi->i_section_number = (uint8_t)p[6];
if( p_psi->b_is_complete || p_psi->i_section_number == 0 )
{
p_psi->b_is_complete = 0;
p_psi->b_trash = 0;
p_psi->i_version_number = ( p[5] >> 1 ) & 0x1f;
- p_psi->i_last_section_number = (u8)p[7];
+ p_psi->i_last_section_number = (uint8_t)p[7];
/* We'll write at the begining of the buffer */
p_psi->p_current = p_psi->buffer;
"PSI version differs inside same PAT" );
p_psi->b_trash = 1;
}
- if( p_psi->i_section_number + 1 != (u8)p[6] )
+ if( p_psi->i_section_number + 1 != (uint8_t)p[6] )
{
msg_Warn( p_input,
"PSI Section discontinuity, packet lost?" );
do
{
- i_section_length = ((u32)(p_current_data[1] & 0xF) << 8) |
+ i_section_length = ((uint32_t)(p_current_data[1] & 0xF) << 8) |
p_current_data[2];
- i_current_section = (u8)p_current_data[6];
+ i_current_section = (uint8_t)p_current_data[6];
for( i_loop = 0;
( i_loop < (i_section_length - 9) / 4 ) && !b_changed;
i_loop++ )
{
- i_program_id = ( (u32)*(p_current_data + i_loop * 4 + 8) << 8 )
+ i_program_id = ( (uint32_t)*(p_current_data + i_loop * 4 + 8) << 8 )
| *(p_current_data + i_loop * 4 + 9);
- i_pmt_pid = ( ((u32)*(p_current_data + i_loop * 4 + 10) & 0x1F)
+ i_pmt_pid = ( ((uint32_t)*(p_current_data + i_loop * 4 + 10) & 0x1F)
<< 8 )
| *(p_current_data + i_loop * 4 + 11);
do
{
- i_section_length = ((u32)(p_current_data[1] & 0xF) << 8) |
+ i_section_length = ((uint32_t)(p_current_data[1] & 0xF) << 8) |
p_current_data[2];
- i_current_section = (u8)p_current_data[6];
+ i_current_section = (uint8_t)p_current_data[6];
for( i_loop = 0; i_loop < (i_section_length - 9) / 4 ; i_loop++ )
{
- i_program_id = ( (u32)*(p_current_data + i_loop * 4 + 8) << 8 )
+ i_program_id = ( (uint32_t)*(p_current_data + i_loop * 4 + 8) << 8 )
| *(p_current_data + i_loop * 4 + 9);
- i_pmt_pid = ( ((u32)*(p_current_data + i_loop * 4 + 10) & 0x1F)
+ i_pmt_pid = ( ((uint32_t)*(p_current_data + i_loop * 4 + 10) & 0x1F)
<< 8 )
| *(p_current_data + i_loop * 4 + 11);
p_pgrm_demux->i_pmt_version = PMT_UNINITIALIZED;
/* Add the PMT ES to this program */
- p_current_es = input_AddES( p_input, p_pgrm,(u16)i_pmt_pid,
+ p_current_es = input_AddES( p_input, p_pgrm,(uint16_t)i_pmt_pid,
UNKNOWN_ES, NULL, sizeof( es_ts_data_t) );
+ p_current_es->i_fourcc = VLC_FOURCC( 'p', 'm', 't', ' ' );
p_es_demux = (es_ts_data_t *)p_current_es->p_demux_data;
p_es_demux->b_psi = 1;
p_es_demux->i_psi_type = PSI_IS_PMT;
p_current_section = p_psi->buffer;
p_current_data = p_psi->buffer;
- p_pgrm_data->i_pcr_pid = ( ((u32)*(p_current_section + 8) & 0x1F) << 8 ) |
+ p_pgrm_data->i_pcr_pid = ( ((uint32_t)*(p_current_section + 8) & 0x1F) << 8 ) |
*(p_current_section + 9);
/* Then add what we received in this PMT */
do
{
- i_section_length = ( ((u32)*(p_current_data + 1) & 0xF) << 8 ) |
+ i_section_length = ( ((uint32_t)*(p_current_data + 1) & 0xF) << 8 ) |
*(p_current_data + 2);
- i_current_section = (u8)p_current_data[6];
- i_prog_info_length = ( ((u32)*(p_current_data + 10) & 0xF) << 8 ) |
+ i_current_section = (uint8_t)p_current_data[6];
+ i_prog_info_length = ( ((uint32_t)*(p_current_data + 10) & 0xF) << 8 ) |
*(p_current_data + 11);
/* For the moment we ignore program descriptors */
while( p_current_data < p_current_section + i_section_length -1 )
{
i_stream_type = (int)p_current_data[0];
- i_pid = ( ((u32)*(p_current_data + 1) & 0x1F) << 8 ) |
+ i_pid = ( ((uint32_t)*(p_current_data + 1) & 0x1F) << 8 ) |
*(p_current_data + 2);
- i_es_info_length = ( ((u32)*(p_current_data + 3) & 0xF) << 8 ) |
+ i_es_info_length = ( ((uint32_t)*(p_current_data + 3) & 0xF) << 8 ) |
*(p_current_data + 4);
/* Tell the interface what kind of stream it is and select
i_cat = AUDIO_ES;
break;
case A52_AUDIO_ES:
- case A52DVB_AUDIO_ES:
if ( !b_vls_compat )
i_fourcc = VLC_FOURCC('a','5','2',' ');
else
}
/* Add this ES to the program */
- p_new_es = input_AddES( p_input, p_es->p_pgrm, (u16)i_pid,
+ p_new_es = input_AddES( p_input, p_es->p_pgrm, (uint16_t)i_pid,
i_cat, NULL, sizeof( es_ts_data_t ) );
((es_ts_data_t *)p_new_es->p_demux_data)->i_continuity_counter = 0xFF;
if( !p_input->stream.p_selected_program )
{
pgrm_descriptor_t * p_pgrm_to_select;
- u16 i_id = (u16)config_GetInt( p_input, "program" );
+ uint16_t i_id = (uint16_t)config_GetInt( p_input, "program" );
if( i_id != 0 ) /* if user specified a program */
{
p_stream_data = (stream_ts_data_t *)p_input->stream.p_demux_data;
- if ( ( p_new_pat->b_current_next && ( p_new_pat->i_version != p_stream_data->i_pat_version ) ) ||
- p_stream_data->i_pat_version == PAT_UNINITIALIZED )
+ if( ( p_new_pat->b_current_next &&
+ ( p_new_pat->i_version != p_stream_data->i_pat_version ) ) ||
+ p_stream_data->i_pat_version == PAT_UNINITIALIZED )
{
+ msg_Dbg( p_input, "Processing PAT version %d", p_new_pat->i_version );
+
/* Delete all programs */
while( p_input->stream.i_pgrm_number )
{
MP4_IODClean( &p_pgrm_demux_old->iod );
}
+ /* Delete old PMT decoder */
+ if( p_pgrm_demux_old->p_pmt_handle )
+ dvbpsi_DetachPMT( p_pgrm_demux_old->p_pmt_handle );
+
input_DelProgram( p_input, p_input->stream.pp_programs[0] );
}
while( p_pgrm )
{
+ msg_Dbg( p_input, "New program: %d", p_pgrm->i_number );
+
/* If program = 0, we're having info about NIT not PMT */
if( p_pgrm->i_number )
{
/* Add the PMT ES to this program */
p_current_es = input_AddES( p_input, p_new_pgrm,
- (u16)p_pgrm->i_pid, UNKNOWN_ES,
+ (uint16_t)p_pgrm->i_pid, UNKNOWN_ES,
NULL, sizeof(es_ts_data_t) );
+ p_current_es->i_fourcc = VLC_FOURCC( 'p', 'm', 't', ' ' );
p_es_demux = (es_ts_data_t *)p_current_es->p_demux_data;
p_es_demux->b_psi = 1;
p_es_demux->i_psi_type = PSI_IS_PMT;
-
- p_es_demux->p_psi_section = malloc( sizeof( psi_section_t ) );
- if ( p_es_demux->p_psi_section == NULL )
- {
- msg_Err( p_input, "out of memory" );
- p_input->b_error = 1;
- return;
- }
-
- p_es_demux->p_psi_section->b_is_complete = 0;
+ p_es_demux->p_psi_section = NULL;
p_es_demux->i_continuity_counter = 0xFF;
/* Create a PMT decoder */
p_pgrm_demux->i_pmt_version == PMT_UNINITIALIZED )
{
dvbpsi_descriptor_t *p_dr = p_new_pmt->p_first_descriptor;
+ int i_loop;
+
+ msg_Dbg( p_input, "Processing PMT for program %d version %d",
+ p_new_pmt->i_program_number, p_new_pmt->i_version );
+
+ /* Delete all ES in this program except the PSI. We start from the
+ * end because i_es_number gets decremented after each deletion. */
+ for( i_loop = p_pgrm->i_es_number ; i_loop > 0 ; )
+ {
+ es_ts_data_t * p_es_demux;
+
+ i_loop--;
+ p_es_demux = (es_ts_data_t *)
+ p_pgrm->pp_es[i_loop]->p_demux_data;
+ if ( !p_es_demux->b_psi )
+ {
+ input_DelES( p_input, p_pgrm->pp_es[i_loop] );
+ }
+ }
+
/* IOD */
while( p_dr && ( p_dr->i_tag != 0x1d ) )
p_dr = p_dr->p_next;
i_cat = AUDIO_ES;
break;
case A52_AUDIO_ES:
- case A52DVB_AUDIO_ES:
if ( !b_vls_compat )
i_fourcc = VLC_FOURCC('a','5','2',' ');
else
i_stream_id = 0xfa;
break;
case MSCODEC_VIDEO_ES:
- i_fourcc = VLC_FOURCC(0,0,0,0); // fixed later
+ i_fourcc = VLC_FOURCC(0,0,0,0); /* fixed later */
i_cat = VIDEO_ES;
i_stream_id = 0xa0;
break;
+ case PES_PRIVATE_ES:
+ /* We need to check a descriptor to find the real codec */
+ i_fourcc = VLC_FOURCC(0,0,0,0); /* fixed later */
+ i_cat = UNKNOWN_ES;
+ i_stream_id = 0xbd;
+ break;
default:
i_fourcc = 0;
i_cat = UNKNOWN_ES;
if( p_dr && p_dr->i_length >= 8 )
{
int i_bih_size;
- i_fourcc = VLC_FOURCC( p_dr->p_data[0], p_dr->p_data[1], p_dr->p_data[2], p_dr->p_data[3] );
+ i_fourcc = VLC_FOURCC( p_dr->p_data[0], p_dr->p_data[1],
+ p_dr->p_data[2], p_dr->p_data[3] );
i_bih_size = (p_dr->p_data[8] << 8) | p_dr->p_data[9];
i_size = sizeof( BITMAPINFOHEADER ) + i_bih_size;
i_cat = UNKNOWN_ES;
}
}
+ else if( p_es->i_type == PES_PRIVATE_ES )
+ {
+ dvbpsi_descriptor_t *p_dr = p_es->p_first_descriptor;
+ /* We have to find a descriptor giving the right codec */
+
+ for(p_dr = p_es->p_first_descriptor; p_dr; p_dr = p_dr->p_next)
+ {
+ if( p_dr->i_tag == 0x6a )
+ {
+ /* A52 */
+ i_fourcc = VLC_FOURCC( 'a', '5', '2', ' ' );
+ i_cat = AUDIO_ES;
+ }
+ else if( p_dr->i_tag == 0x59 )
+ {
+ /* DVB subtitle */
+ i_fourcc = VLC_FOURCC( 'd', 'v', 'b', 's' );
+ i_cat = SPU_ES;
+ }
+ }
+ if( i_fourcc == VLC_FOURCC(0,0,0,0) )
+ {
+ msg_Warn( p_input,
+ "Unknown codec/type for Private PES stream" );
+ }
+ }
if( i_cat == AUDIO_ES || i_cat == SPU_ES )
{
const iso639_lang_t * p_iso;
p_iso = GetLang_2T((char*)p_decoded->i_iso_639_code);
- if( p_iso )
+ if( p_iso && strcmp(p_iso->psz_native_name,"Unknown"))
{
if( p_iso->psz_native_name[0] )
strncpy( psz_desc,
}
else
{
- strncpy( psz_desc, p_decoded->i_iso_639_code, 3 );
+ p_iso = GetLang_2B(
+ (char*)p_decoded->i_iso_639_code);
+ if ( p_iso )
+ {
+ if( p_iso->psz_native_name[0] )
+ strncpy( psz_desc,
+ p_iso->psz_native_name, 20 );
+ else
+ strncpy( psz_desc,
+ p_iso->psz_eng_name, 20 );
+ }
+ else
+ {
+ strncpy( psz_desc, p_decoded->i_iso_639_code, 3 );
+ }
}
}
}
strcat( psz_desc, " (lpcm)" );
break;
case A52_AUDIO_ES:
- case A52DVB_AUDIO_ES:
case A52B_AUDIO_ES:
strcat( psz_desc, " (A52)" );
break;
}
/* Add this ES */
- p_new_es = input_AddES( p_input, p_pgrm, (u16)p_es->i_pid,
+ p_new_es = input_AddES( p_input, p_pgrm, (uint16_t)p_es->i_pid,
i_cat, psz_desc, sizeof( es_ts_data_t ) );
if( p_new_es == NULL )
{
if( !p_input->stream.p_selected_program )
{
pgrm_descriptor_t * p_pgrm_to_select;
- u16 i_id = (u16)config_GetInt( p_input, "program" );
+ uint16_t i_id = (uint16_t)config_GetInt( p_input, "program" );
if( i_id != 0 ) /* if user specified a program */
{
p_input->pf_set_program( p_input, p_pgrm_to_select );
}
else
- p_input->pf_set_program( p_input, p_pgrm );
+ p_input->pf_set_program( p_input, p_pgrm );
}
/* if the pmt belongs to the currently selected program, we
* reselect it to update its ES */