1 /*****************************************************************************
2 * asf.c : ASFv01 file input module for vlc
3 *****************************************************************************
4 * Copyright (C) 2002-2003 VideoLAN
5 * $Id: asf.c,v 1.36 2003/08/25 23:36:16 fenrir Exp $
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
30 #include <vlc/input.h>
33 #include "codecs.h" /* BITMAPINFOHEADER, WAVEFORMATEX */
36 /*****************************************************************************
38 *****************************************************************************/
39 static int Open ( vlc_object_t * );
40 static void Close ( vlc_object_t * );
43 set_description( _("ASF v1.0 demuxer") );
44 set_capability( "demux", 200 );
45 set_callbacks( Open, Close );
46 add_shortcut( "asf" );
50 /*****************************************************************************
52 *****************************************************************************/
53 static int Demux ( input_thread_t * );
55 typedef struct asf_stream_s
58 es_descriptor_t *p_es;
59 asf_object_stream_properties_t *p_sp;
63 pes_packet_t *p_pes; /* used to keep uncomplete frames */
69 mtime_t i_time; /* µs */
70 mtime_t i_length; /* length of file file */
72 asf_object_root_t *p_root;
73 asf_object_file_properties_t *p_fp;
75 unsigned int i_streams;
76 asf_stream_t *stream[128];
84 static mtime_t GetMoviePTS( demux_sys_t * );
85 static int DemuxPacket( input_thread_t *, vlc_bool_t b_play_audio );
87 /*****************************************************************************
88 * Open: check file and initializes ASF structures
89 *****************************************************************************/
90 static int Open( vlc_object_t * p_this )
92 input_thread_t *p_input = (input_thread_t *)p_this;
98 unsigned int i_stream;
100 asf_object_content_description_t *p_cd;
102 vlc_bool_t b_seekable;
104 input_info_category_t *p_cat;
106 /* a little test to see if it could be a asf stream */
107 if( input_Peek( p_input, &p_peek, 16 ) < 16 )
109 msg_Warn( p_input, "ASF plugin discarded (cannot peek)" );
112 ASF_GetGUID( &guid, p_peek );
113 if( !ASF_CmpGUID( &guid, &asf_object_header_guid ) )
115 msg_Warn( p_input, "ASF plugin discarded (not a valid file)" );
119 /* Set p_input field */
120 p_input->pf_demux = Demux;
121 p_input->p_demux_data = p_sys = malloc( sizeof( demux_sys_t ) );
122 memset( p_sys, 0, sizeof( demux_sys_t ) );
126 /* Create stream facilities */
127 if( ( p_sys->s = stream_OpenInput( p_input ) ) == NULL )
129 msg_Err( p_input, "cannot create stream" );
134 /* Now load all object ( except raw data ) */
135 stream_Control( p_sys->s, STREAM_CAN_FASTSEEK, &b_seekable );
136 if( (p_sys->p_root = ASF_ReadObjectRoot( p_sys->s, b_seekable )) == NULL )
138 msg_Warn( p_input, "ASF plugin discarded (not a valid file)" );
139 stream_Release( p_sys->s );
143 p_sys->p_fp = p_sys->p_root->p_fp;
145 if( p_sys->p_fp->i_min_data_packet_size != p_sys->p_fp->i_max_data_packet_size )
148 "ASF plugin discarded (invalid file_properties object)" );
152 p_sys->i_streams = ASF_CountObject( p_sys->p_root->p_hdr,
153 &asf_object_stream_properties_guid );
154 if( !p_sys->i_streams )
156 msg_Warn( p_input, "ASF plugin discarded (cannot find any stream!)" );
160 msg_Dbg( p_input, "found %d streams", p_sys->i_streams );
162 /* create one program */
163 vlc_mutex_lock( &p_input->stream.stream_lock );
164 if( input_InitStream( p_input, 0 ) == -1)
166 vlc_mutex_unlock( &p_input->stream.stream_lock );
167 msg_Err( p_input, "cannot init stream" );
170 if( input_AddProgram( p_input, 0, 0) == NULL )
172 vlc_mutex_unlock( &p_input->stream.stream_lock );
173 msg_Err( p_input, "cannot add program" );
176 p_input->stream.p_selected_program = p_input->stream.pp_programs[0];
177 p_input->stream.i_mux_rate = 0 ; /* updated later */
178 vlc_mutex_unlock( &p_input->stream.stream_lock );
180 for( i_stream = 0; i_stream < p_sys->i_streams; i_stream ++ )
182 asf_stream_t *p_stream;
183 asf_object_stream_properties_t *p_sp;
185 p_sp = ASF_FindObject( p_sys->p_root->p_hdr,
186 &asf_object_stream_properties_guid,
190 p_sys->stream[p_sp->i_stream_number] =
191 malloc( sizeof( asf_stream_t ) );
192 memset( p_stream, 0, sizeof( asf_stream_t ) );
194 p_stream->i_time = -1;
195 p_stream->p_sp = p_sp;
196 p_stream->p_es = NULL;
198 if( ASF_CmpGUID( &p_sp->i_stream_type, &asf_object_stream_type_audio ) )
201 if( p_sp->p_type_specific_data )
203 i_codec = GetWLE( p_sp->p_type_specific_data );
210 p_stream->i_cat = AUDIO_ES;
211 p_stream->p_es = input_AddES( p_input,
212 p_input->stream.p_selected_program,
213 p_sp->i_stream_number, AUDIO_ES, NULL, 0 );
216 "adding new audio stream(codec:0x%x,ID:%d)",
218 p_sp->i_stream_number );
219 wf_tag_to_fourcc( i_codec, &p_stream->p_es->i_fourcc, NULL );
221 if( p_sp->i_type_specific_data_length > 0 )
227 i_size = p_sp->i_type_specific_data_length;
229 p_wf = malloc( i_size );
230 p_stream->p_es->p_waveformatex = (void*)p_wf;
231 p_data = p_sp->p_type_specific_data;
233 p_wf->wFormatTag = GetWLE( p_data );
234 p_wf->nChannels = GetWLE( p_data + 2 );
235 p_wf->nSamplesPerSec = GetDWLE( p_data + 4 );
236 p_wf->nAvgBytesPerSec = GetDWLE( p_data + 8 );
237 p_wf->nBlockAlign = GetWLE( p_data + 12 );
238 p_wf->wBitsPerSample = GetWLE( p_data + 14 );
239 p_wf->cbSize = __MIN( GetWLE( p_data + 16 ), i_size - sizeof( WAVEFORMATEX ));
240 if( p_wf->cbSize > 0 )
242 memcpy( &p_wf[1], p_data + sizeof( WAVEFORMATEX ), p_wf->cbSize );
247 if( ASF_CmpGUID( &p_sp->i_stream_type, &asf_object_stream_type_video ) )
249 p_stream->i_cat = VIDEO_ES;
250 p_stream->p_es = input_AddES( p_input,
251 p_input->stream.p_selected_program,
252 p_sp->i_stream_number, VIDEO_ES, NULL, 0 );
254 msg_Dbg( p_input, "adding new video stream(ID:%d)",
255 p_sp->i_stream_number );
256 if( p_sp->p_type_specific_data )
258 p_stream->p_es->i_fourcc =
259 VLC_FOURCC( p_sp->p_type_specific_data[27],
260 p_sp->p_type_specific_data[28],
261 p_sp->p_type_specific_data[29],
262 p_sp->p_type_specific_data[30] );
266 p_stream->p_es->i_fourcc =
267 VLC_FOURCC( 'u','n','d','f' );
269 if( p_sp->i_type_specific_data_length > 11 )
271 BITMAPINFOHEADER *p_bih;
275 i_size = p_sp->i_type_specific_data_length - 11;
277 p_bih = malloc( i_size );
278 p_stream->p_es->p_bitmapinfoheader = (void*)p_bih;
279 p_data = p_sp->p_type_specific_data + 11;
281 p_bih->biSize = GetDWLE( p_data );
282 p_bih->biWidth = GetDWLE( p_data + 4 );
283 p_bih->biHeight = GetDWLE( p_data + 8 );
284 p_bih->biPlanes = GetDWLE( p_data + 12 );
285 p_bih->biBitCount = GetDWLE( p_data + 14 );
286 p_bih->biCompression= GetDWLE( p_data + 16 );
287 p_bih->biSizeImage = GetDWLE( p_data + 20 );
288 p_bih->biXPelsPerMeter = GetDWLE( p_data + 24 );
289 p_bih->biYPelsPerMeter = GetDWLE( p_data + 28 );
290 p_bih->biClrUsed = GetDWLE( p_data + 32 );
291 p_bih->biClrImportant = GetDWLE( p_data + 36 );
293 if( i_size > sizeof( BITMAPINFOHEADER ) )
296 p_data + sizeof( BITMAPINFOHEADER ),
297 i_size - sizeof( BITMAPINFOHEADER ) );
304 p_stream->i_cat = UNKNOWN_ES;
305 msg_Dbg( p_input, "ignoring unknown stream(ID:%d)",
306 p_sp->i_stream_number );
309 vlc_mutex_lock( &p_input->stream.stream_lock );
312 input_SelectES( p_input, p_stream->p_es );
314 vlc_mutex_unlock( &p_input->stream.stream_lock );
318 p_sys->i_data_begin = p_sys->p_root->p_data->i_object_pos + 50;
319 if( p_sys->p_root->p_data->i_object_size != 0 )
321 p_sys->i_data_end = p_sys->p_root->p_data->i_object_pos +
322 p_sys->p_root->p_data->i_object_size;
325 { /* live/broacast */
326 p_sys->i_data_end = -1;
330 /* go to first packet */
331 stream_Seek( p_sys->s, p_sys->i_data_begin );
333 /* try to calculate movie time */
334 if( p_sys->p_fp->i_data_packets_count > 0 )
337 int64_t i_size = stream_Size( p_sys->s );
339 if( p_sys->i_data_end > 0 && i_size > p_sys->i_data_end )
341 i_size = p_sys->i_data_end;
344 /* real number of packets */
345 i_count = ( i_size - p_sys->i_data_begin ) /
346 p_sys->p_fp->i_min_data_packet_size;
348 /* calculate the time duration in micro-s */
349 p_sys->i_length = (mtime_t)p_sys->p_fp->i_play_duration / 10 *
351 (mtime_t)p_sys->p_fp->i_data_packets_count;
353 if( p_sys->i_length > 0 )
355 p_input->stream.i_mux_rate =
356 i_size / 50 * (int64_t)1000000 / p_sys->i_length;
360 vlc_mutex_lock( &p_input->stream.stream_lock );
361 p_input->stream.p_selected_program->b_is_ok = 1;
362 vlc_mutex_unlock( &p_input->stream.stream_lock );
365 /* We add all info about this stream */
366 p_cat = input_InfoCategory( p_input, "Asf" );
367 if( p_sys->i_length > 0 )
369 int64_t i_second = p_sys->i_length / (int64_t)1000000;
371 input_AddInfo( p_cat, _("Length"), "%d:%d:%d",
372 (int)(i_second / 36000),
373 (int)(( i_second / 60 ) % 60),
374 (int)(i_second % 60) );
376 input_AddInfo( p_cat, _("Number of streams"), "%d" , p_sys->i_streams );
378 if( ( p_cd = ASF_FindObject( p_sys->p_root->p_hdr,
379 &asf_object_content_description_guid, 0 ) ) )
381 if( *p_cd->psz_title )
382 input_AddInfo( p_cat, _("Title"), p_cd->psz_title );
383 if( p_cd->psz_author )
384 input_AddInfo( p_cat, _("Author"), p_cd->psz_author );
385 if( p_cd->psz_copyright )
386 input_AddInfo( p_cat, _("Copyright"), p_cd->psz_copyright );
387 if( *p_cd->psz_description )
388 input_AddInfo( p_cat, _("Description"), p_cd->psz_description );
389 if( *p_cd->psz_rating )
390 input_AddInfo( p_cat, _("Rating"), p_cd->psz_rating );
393 for( i_stream = 0, i = 0; i < 128; i++ )
395 asf_stream_t *tk = p_sys->stream[i];
396 asf_object_codec_list_t *p_cl =
397 ASF_FindObject( p_sys->p_root->p_hdr,
398 &asf_object_codec_list_guid, 0 );
399 char psz_cat[sizeof(_("Stream "))+10];
401 if( p_sys->stream[i] == NULL )
405 sprintf( psz_cat, _("Stream %d"), i_stream );
406 p_cat = input_InfoCategory( p_input, psz_cat);
408 input_AddInfo( p_cat, _("Type"),
409 ( tk->i_cat == AUDIO_ES ? _("Audio") : _("Video") ) );
410 input_AddInfo( p_cat, _("Codec"), "%.4s",
411 (char*)&tk->p_es->i_fourcc );
412 if( p_cl && i_stream < p_cl->i_codec_entries_count )
414 input_AddInfo( p_cat, _("Codec name"),
415 p_cl->codec[i_stream].psz_name );
416 input_AddInfo( p_cat, _("Codec description"),
417 p_cl->codec[i_stream].psz_description );
420 if( tk->i_cat == AUDIO_ES && tk->p_es->p_waveformatex )
422 WAVEFORMATEX *p_wf = tk->p_es->p_waveformatex;
423 input_AddInfo( p_cat, _("Channels"), "%d", p_wf->nChannels );
424 input_AddInfo( p_cat, _("Sample Rate"), "%d", p_wf->nSamplesPerSec );
425 input_AddInfo( p_cat, _("Avg. byterate"), "%d", p_wf->nAvgBytesPerSec );
426 input_AddInfo( p_cat, _("Bits Per Sample"), "%d", p_wf->wBitsPerSample );
428 else if( tk->i_cat == VIDEO_ES && tk->p_es->p_bitmapinfoheader )
430 BITMAPINFOHEADER *p_bih = tk->p_es->p_bitmapinfoheader;
432 input_AddInfo( p_cat, _("Resolution"), "%dx%d",
433 p_bih->biWidth, p_bih->biHeight );
434 input_AddInfo( p_cat, _("Planes"), "%d", p_bih->biPlanes );
435 input_AddInfo( p_cat, _("Bits Per Pixel"), "%d", p_bih->biBitCount );
436 input_AddInfo( p_cat, _("Image Size"), "%d", p_bih->biSizeImage );
437 input_AddInfo( p_cat, _("X pixels per meter"), "%d",
438 p_bih->biXPelsPerMeter );
439 input_AddInfo( p_cat, _("Y pixels per meter"), "%d",
440 p_bih->biYPelsPerMeter );
449 ASF_FreeObjectRoot( p_sys->s, p_sys->p_root );
450 stream_Release( p_sys->s );
456 /*****************************************************************************
457 * Demux: read packet and send them to decoders
458 *****************************************************************************/
459 static int Demux( input_thread_t *p_input )
461 demux_sys_t *p_sys = p_input->p_demux_data;
462 vlc_bool_t b_play_audio;
466 b_stream = VLC_FALSE;
467 for( i = 0; i < 128; i++ )
469 if( p_sys->stream[i] &&
470 p_sys->stream[i]->p_es &&
471 p_sys->stream[i]->p_es->p_decoder_fifo )
478 msg_Warn( p_input, "no stream selected, exiting..." );
482 /* catch seek from user */
483 if( p_input->stream.p_selected_program->i_synchro_state == SYNCHRO_REINIT )
487 msleep( p_input->i_pts_delay );
489 i_offset = stream_Tell( p_sys->s ) - p_sys->i_data_begin;
494 if( i_offset % p_sys->p_fp->i_min_data_packet_size > 0 )
496 i_offset -= i_offset % p_sys->p_fp->i_min_data_packet_size;
499 if( stream_Seek( p_sys->s, i_offset + p_sys->i_data_begin ) )
501 msg_Warn( p_input, "cannot resynch after seek (EOF?)" );
506 for( i = 0; i < 128 ; i++ )
508 #define p_stream p_sys->stream[i]
511 p_stream->i_time = -1;
517 /* Check if we need to send the audio data to decoder */
518 b_play_audio = !p_input->stream.control.b_mute;
523 mtime_t i_time_begin = GetMoviePTS( p_sys );
531 if( ( i_result = DemuxPacket( p_input, b_play_audio ) ) <= 0 )
535 if( i_time_begin == -1 )
537 i_time_begin = GetMoviePTS( p_sys );
541 i_length = GetMoviePTS( p_sys ) - i_time_begin;
542 if( i_length < 0 || i_length >= 40 * 1000 )
549 p_sys->i_time = GetMoviePTS( p_sys );
550 if( p_sys->i_time >= 0 )
552 input_ClockManageRef( p_input,
553 p_input->stream.p_selected_program,
554 p_sys->i_time * 9 / 100 );
560 /*****************************************************************************
561 * Close: frees unused data
562 *****************************************************************************/
563 static void Close( vlc_object_t * p_this )
565 input_thread_t *p_input = (input_thread_t *)p_this;
566 demux_sys_t *p_sys = p_input->p_demux_data;
569 msg_Dbg( p_input, "Freeing all memory" );
571 ASF_FreeObjectRoot( p_sys->s, p_sys->p_root );
572 for( i_stream = 0; i_stream < 128; i_stream++ )
574 #define p_stream p_sys->stream[i_stream]
577 if( p_stream->p_pes )
579 input_DeletePES( p_input->p_method_data, p_stream->p_pes );
585 stream_Release( p_sys->s );
590 /*****************************************************************************
592 *****************************************************************************/
593 static mtime_t GetMoviePTS( demux_sys_t *p_sys )
599 for( i_stream = 0; i_stream < 128 ; i_stream++ )
601 #define p_stream p_sys->stream[i_stream]
602 if( p_stream && p_stream->p_es && p_stream->p_es->p_decoder_fifo && p_stream->i_time > 0)
606 i_time = p_stream->i_time;
610 i_time = __MIN( i_time, p_stream->i_time );
619 #define GETVALUE2b( bits, var, def ) \
620 switch( (bits)&0x03 ) \
622 case 1: var = p_peek[i_skip]; i_skip++; break; \
623 case 2: var = GetWLE( p_peek + i_skip ); i_skip+= 2; break; \
624 case 3: var = GetDWLE( p_peek + i_skip ); i_skip+= 4; break; \
626 default: var = def; break;\
629 static int DemuxPacket( input_thread_t *p_input, vlc_bool_t b_play_audio )
631 demux_sys_t *p_sys = p_input->p_demux_data;
632 int i_data_packet_min = p_sys->p_fp->i_min_data_packet_size;
636 int i_packet_size_left;
638 int i_packet_property;
640 int b_packet_multiple_payload;
642 int i_packet_sequence;
643 int i_packet_padding_length;
645 uint32_t i_packet_send_time;
646 uint16_t i_packet_duration;
649 int i_payload_length_type;
652 if( stream_Peek( p_sys->s, &p_peek, i_data_packet_min ) < i_data_packet_min )
655 msg_Warn( p_input, "cannot peek while getting new packet, EOF ?" );
660 /* *** parse error correction if present *** */
663 unsigned int i_error_correction_length_type;
664 unsigned int i_error_correction_data_length;
665 unsigned int i_opaque_data_present;
667 i_error_correction_data_length = p_peek[0] & 0x0f; // 4bits
668 i_opaque_data_present = ( p_peek[0] >> 4 )& 0x01; // 1bit
669 i_error_correction_length_type = ( p_peek[0] >> 5 ) & 0x03; // 2bits
670 i_skip += 1; // skip error correction flags
672 if( i_error_correction_length_type != 0x00 ||
673 i_opaque_data_present != 0 ||
674 i_error_correction_data_length != 0x02 )
676 goto loop_error_recovery;
679 i_skip += i_error_correction_data_length;
683 msg_Warn( p_input, "p_peek[0]&0x80 != 0x80" );
687 if( i_skip + 2 >= i_data_packet_min )
689 goto loop_error_recovery;
692 i_packet_flags = p_peek[i_skip]; i_skip++;
693 i_packet_property = p_peek[i_skip]; i_skip++;
695 b_packet_multiple_payload = i_packet_flags&0x01;
697 /* read some value */
698 GETVALUE2b( i_packet_flags >> 5, i_packet_length, i_data_packet_min );
699 GETVALUE2b( i_packet_flags >> 1, i_packet_sequence, 0 );
700 GETVALUE2b( i_packet_flags >> 3, i_packet_padding_length, 0 );
702 i_packet_send_time = GetDWLE( p_peek + i_skip ); i_skip += 4;
703 i_packet_duration = GetWLE( p_peek + i_skip ); i_skip += 2;
705 // i_packet_size_left = i_packet_length; // XXX données reellement lu
706 /* FIXME I have to do that for some file, I don't known why */
707 i_packet_size_left = i_data_packet_min;
709 if( b_packet_multiple_payload )
711 i_payload_count = p_peek[i_skip] & 0x3f;
712 i_payload_length_type = ( p_peek[i_skip] >> 6 )&0x03;
718 i_payload_length_type = 0x02; // unused
721 for( i_payload = 0; i_payload < i_payload_count ; i_payload++ )
723 asf_stream_t *p_stream;
726 int i_media_object_number;
727 int i_media_object_offset;
728 int i_replicated_data_length;
729 int i_payload_data_length;
730 int i_payload_data_pos;
731 int i_sub_payload_data_length;
737 if( i_skip >= i_packet_size_left )
739 /* prevent some segfault with invalid file */
743 i_stream_number = p_peek[i_skip] & 0x7f;
746 GETVALUE2b( i_packet_property >> 4, i_media_object_number, 0 );
747 GETVALUE2b( i_packet_property >> 2, i_tmp, 0 );
748 GETVALUE2b( i_packet_property, i_replicated_data_length, 0 );
750 if( i_replicated_data_length > 1 ) // should be at least 8 bytes
752 i_pts = (mtime_t)GetDWLE( p_peek + i_skip + 4 ) * 1000;
753 i_skip += i_replicated_data_length;
756 i_media_object_offset = i_tmp;
758 if( i_skip >= i_packet_size_left )
763 else if( i_replicated_data_length == 1 )
766 msg_Dbg( p_input, "found compressed payload" );
768 i_pts = (mtime_t)i_tmp * 1000;
769 i_pts_delta = (mtime_t)p_peek[i_skip] * 1000; i_skip++;
771 i_media_object_offset = 0;
775 i_pts = (mtime_t)i_packet_send_time * 1000;
778 i_media_object_offset = i_tmp;
781 i_pts = __MAX( i_pts - p_sys->p_fp->i_preroll * 1000, 0 );
782 if( b_packet_multiple_payload )
784 GETVALUE2b( i_payload_length_type, i_payload_data_length, 0 );
788 i_payload_data_length = i_packet_length -
789 i_packet_padding_length - i_skip;
792 if( i_payload_data_length < 0 || i_skip + i_payload_data_length > i_packet_size_left )
799 "payload(%d/%d) stream_number:%d media_object_number:%d media_object_offset:%d replicated_data_length:%d payload_data_length %d",
803 i_media_object_number,
804 i_media_object_offset,
805 i_replicated_data_length,
806 i_payload_data_length );
809 if( !( p_stream = p_sys->stream[i_stream_number] ) )
812 "undeclared stream[Id 0x%x]", i_stream_number );
813 i_skip += i_payload_data_length;
814 continue; // over payload
817 if( !p_stream->p_es || !p_stream->p_es->p_decoder_fifo )
819 i_skip += i_payload_data_length;
824 for( i_payload_data_pos = 0;
825 i_payload_data_pos < i_payload_data_length &&
826 i_packet_size_left > 0;
827 i_payload_data_pos += i_sub_payload_data_length )
829 data_packet_t *p_data;
831 // read sub payload length
832 if( i_replicated_data_length == 1 )
834 i_sub_payload_data_length = p_peek[i_skip]; i_skip++;
835 i_payload_data_pos++;
839 i_sub_payload_data_length = i_payload_data_length;
842 /* FIXME I don't use i_media_object_number, sould I ? */
843 if( p_stream->p_pes && i_media_object_offset == 0 )
845 /* send complete packet to decoder */
846 if( p_stream->p_pes->i_pes_size > 0 )
848 if( p_stream->p_es->p_decoder_fifo &&
849 ( b_play_audio || p_stream->i_cat != AUDIO_ES ) )
851 p_stream->p_pes->i_rate =
852 p_input->stream.control.i_rate;
853 input_DecodePES( p_stream->p_es->p_decoder_fifo,
858 input_DeletePES( p_input->p_method_data,
861 p_stream->p_pes = NULL;
865 if( !p_stream->p_pes ) // add a new PES
868 ( (mtime_t)i_pts + i_payload * (mtime_t)i_pts_delta );
870 p_stream->p_pes = input_NewPES( p_input->p_method_data );
871 p_stream->p_pes->i_dts =
872 p_stream->p_pes->i_pts =
873 input_ClockGetTS( p_input,
874 p_input->stream.p_selected_program,
875 p_stream->i_time * 9 /100 );
877 //msg_Err( p_input, "stream[0x%2x] pts=%lld", i_stream_number, p_stream->p_pes->i_pts );
878 p_stream->p_pes->p_next = NULL;
879 p_stream->p_pes->i_nb_data = 0;
880 p_stream->p_pes->i_pes_size = 0;
883 i_read = i_sub_payload_data_length + i_skip;
884 if((p_data = stream_DataPacket( p_sys->s,i_read,VLC_TRUE)) == NULL)
886 msg_Warn( p_input, "cannot read data" );
889 p_data->p_payload_start += i_skip;
890 i_packet_size_left -= i_read;
893 if( !p_stream->p_pes->p_first )
895 p_stream->p_pes->p_first = p_stream->p_pes->p_last = p_data;
899 p_stream->p_pes->p_last->p_next = p_data;
900 p_stream->p_pes->p_last = p_data;
902 p_stream->p_pes->i_pes_size += i_sub_payload_data_length;
903 p_stream->p_pes->i_nb_data++;
906 if( i_packet_size_left > 0 )
908 if( stream_Peek( p_sys->s, &p_peek, i_packet_size_left ) < i_packet_size_left )
911 msg_Warn( p_input, "cannot peek, EOF ?" );
918 if( i_packet_size_left > 0 )
920 if( stream_Read( p_sys->s, NULL, i_packet_size_left ) < i_packet_size_left )
922 msg_Warn( p_input, "cannot skip data, EOF ?" );
930 msg_Warn( p_input, "unsupported packet header" );
931 if( p_sys->p_fp->i_min_data_packet_size != p_sys->p_fp->i_max_data_packet_size )
933 msg_Err( p_input, "unsupported packet header, fatal error" );
936 stream_Read( p_sys->s, NULL, i_data_packet_min );