+/*****************************************************************************
+ * input_ParsePS: read the PS header
+ *****************************************************************************/
+es_descriptor_t * input_ParsePS( input_thread_t * p_input,
+ data_packet_t * p_data )
+{
+ u32 i_code;
+ es_descriptor_t * p_es = NULL;
+
+ i_code = U32_AT( p_data->p_buffer );
+ if( i_code > 0x1BC ) /* ES start code */
+ {
+ u16 i_id;
+ int i_dummy;
+
+ /* This is a PES packet. Find out if we want it or not. */
+ i_id = GetID( p_data );
+
+ vlc_mutex_lock( &p_input->stream.stream_lock );
+ if( p_input->stream.pp_programs[0]->b_is_ok )
+ {
+ /* Look only at the selected ES. */
+ for( i_dummy = 0; i_dummy < INPUT_MAX_SELECTED_ES; i_dummy++ )
+ {
+ if( p_input->pp_selected_es[i_dummy] != NULL
+ && p_input->pp_selected_es[i_dummy]->i_id == i_id )
+ {
+ p_es = p_input->pp_selected_es[i_dummy];
+ break;
+ }
+ }
+ }
+ else
+ {
+ /* Search all ES ; if not found -> AddES */
+ for( i_dummy = 0; i_dummy < INPUT_MAX_ES; i_dummy++ )
+ {
+ if( p_input->p_es[i_dummy].i_id != EMPTY_ID
+ && p_input->p_es[i_dummy].i_id == i_id )
+ {
+ p_es = &p_input->p_es[i_dummy];
+ break;
+ }
+ }
+
+ if( p_es == NULL )
+ {
+ p_es = input_AddES( p_input, p_input->stream.pp_programs[0],
+ i_id, 0 );
+ if( p_es != NULL )
+ {
+ p_es->i_stream_id = p_data->p_buffer[3];
+
+ /* Set stream type and auto-spawn. */
+ if( (i_id & 0xF0) == 0xE0 )
+ {
+ /* MPEG video */
+ p_es->i_type = MPEG2_VIDEO_ES;
+#ifdef AUTO_SPAWN
+ input_SelectES( p_input, p_es );
+#endif
+ }
+ else if( (i_id & 0xE0) == 0xC0 )
+ {
+ /* MPEG audio */
+ p_es->i_type = MPEG2_AUDIO_ES;
+#ifdef AUTO_SPAWN
+ input_SelectES( p_input, p_es );
+#endif
+ }
+ else if( (i_id & 0xF0FF) == 0x80BD )
+ {
+ /* AC3 audio */
+ p_es->i_type = AC3_AUDIO_ES;
+#ifdef AUTO_SPAWN
+ input_SelectES( p_input, p_es );
+#endif
+ }
+ else if( (i_id & 0xF0FF) == 0x20BD )
+ {
+ /* Subtitles video */
+ p_es->i_type = DVD_SPU_ES;
+#ifdef AUTO_SPAWN
+ input_SelectES( p_input, p_es );
+#endif
+ }
+ else
+ {
+ p_es->i_type = UNKNOWN_ES;
+ }
+ }
+ }
+ } /* stream.b_is_ok */
+ vlc_mutex_unlock( &p_input->stream.stream_lock );
+ } /* i_code > 0xBC */
+
+ return( p_es );
+}
+