1 /*****************************************************************************
2 * asf.c : ASFv01 file input module for vlc
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
5 * $Id: asf.c,v 1.31 2003/08/17 23:02:52 fenrir Exp $
6 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
21 *****************************************************************************/
23 /*****************************************************************************
25 *****************************************************************************/
26 #include <stdlib.h> /* malloc(), free() */
27 #include <string.h> /* strdup() */
29 #include <sys/types.h>
32 #include <vlc/input.h>
37 /*****************************************************************************
39 *****************************************************************************/
40 static int Activate ( vlc_object_t * );
41 static void Deactivate ( vlc_object_t * );
42 static int Demux ( input_thread_t * );
44 /*****************************************************************************
46 *****************************************************************************/
48 set_description( _("ASF v1.0 demuxer (file only)") );
49 set_capability( "demux", 200 );
50 set_callbacks( Activate, Deactivate );
51 add_shortcut( "asf" );
54 /*****************************************************************************
55 * Activate: check file and initializes ASF structures
56 *****************************************************************************/
57 static int Activate( vlc_object_t * p_this )
59 input_thread_t *p_input = (input_thread_t *)p_this;
66 vlc_bool_t b_seekable;
68 /* Initialize access plug-in structures. */
69 if( p_input->i_mtu == 0 )
72 p_input->i_bufsize = INPUT_DEFAULT_BUFSIZE;
75 p_input->pf_demux = Demux;
77 /* a little test to see if it could be a asf stream */
78 if( input_Peek( p_input, &p_peek, 16 ) < 16 )
80 msg_Warn( p_input, "ASF v1.0 plugin discarded (cannot peek)" );
83 GetGUID( &guid, p_peek );
84 if( !CmpGUID( &guid, &asf_object_header_guid ) )
86 msg_Warn( p_input, "ASF v1.0 plugin discarded (not a valid file)" );
90 /* create our structure that will contains all data */
91 if( !( p_input->p_demux_data =
92 p_demux = malloc( sizeof( demux_sys_t ) ) ) )
94 msg_Err( p_input, "out of memory" );
97 memset( p_demux, 0, sizeof( demux_sys_t ) );
101 /* Now load all object ( except raw data ) */
102 if( p_input->stream.b_seekable && p_input->stream.i_method == INPUT_METHOD_FILE )
104 b_seekable = VLC_TRUE;
108 b_seekable = VLC_FALSE;
110 if( !ASF_ReadObjectRoot( p_input, &p_demux->root, b_seekable ) )
112 msg_Warn( p_input, "ASF v1.0 plugin discarded (not a valid file)" );
116 /* Check if we have found all mandatory asf object */
117 if( !p_demux->root.p_hdr || !p_demux->root.p_data )
119 ASF_FreeObjectRoot( p_input, &p_demux->root );
121 msg_Warn( p_input, "ASF v1.0 plugin discarded (not a valid file)" );
125 if( !( p_demux->p_fp = ASF_FindObject( p_demux->root.p_hdr,
126 &asf_object_file_properties_guid, 0 ) ) )
128 ASF_FreeObjectRoot( p_input, &p_demux->root );
130 msg_Warn( p_input, "ASF v1.0 plugin discarded (missing file_properties object)" );
134 if( p_demux->p_fp->i_min_data_packet_size != p_demux->p_fp->i_max_data_packet_size )
136 ASF_FreeObjectRoot( p_input, &p_demux->root );
138 msg_Warn( p_input, "ASF v1.0 plugin discarded (invalid file_properties object)" );
142 p_demux->i_streams = ASF_CountObject( p_demux->root.p_hdr,
143 &asf_object_stream_properties_guid );
144 if( !p_demux->i_streams )
146 ASF_FreeObjectRoot( p_input, &p_demux->root );
148 msg_Warn( p_input, "ASF plugin discarded (cannot find any stream!)" );
153 input_info_category_t *p_cat = input_InfoCategory( p_input, "Asf" );
154 msg_Dbg( p_input, "found %d streams", p_demux->i_streams );
155 input_AddInfo( p_cat, _("Number of streams"), "%d" , p_demux->i_streams );
158 /* create one program */
159 vlc_mutex_lock( &p_input->stream.stream_lock );
160 if( input_InitStream( p_input, 0 ) == -1)
162 vlc_mutex_unlock( &p_input->stream.stream_lock );
163 msg_Err( p_input, "cannot init stream" );
166 if( input_AddProgram( p_input, 0, 0) == NULL )
168 vlc_mutex_unlock( &p_input->stream.stream_lock );
169 msg_Err( p_input, "cannot add program" );
172 p_input->stream.p_selected_program = p_input->stream.pp_programs[0];
173 p_input->stream.i_mux_rate = 0 ; /* FIXME */
174 vlc_mutex_unlock( &p_input->stream.stream_lock );
176 for( i_stream = 0; i_stream < p_demux->i_streams; i_stream ++ )
178 asf_stream_t *p_stream;
179 asf_object_stream_properties_t *p_sp;
180 char psz_cat[sizeof("Stream ")+10];
181 input_info_category_t *p_cat;
182 sprintf( psz_cat, "Stream %d", i_stream );
183 p_cat = input_InfoCategory( p_input, psz_cat);
185 p_sp = ASF_FindObject( p_demux->root.p_hdr,
186 &asf_object_stream_properties_guid,
190 p_demux->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;
197 vlc_mutex_lock( &p_input->stream.stream_lock );
198 p_stream->p_es = NULL;
200 vlc_mutex_unlock( &p_input->stream.stream_lock );
201 if( CmpGUID( &p_sp->i_stream_type, &asf_object_stream_type_audio ) )
204 if( p_sp->p_type_specific_data )
206 i_codec = GetWLE( p_sp->p_type_specific_data );
213 p_stream->i_cat = AUDIO_ES;
214 p_stream->p_es = input_AddES( p_input,
215 p_input->stream.p_selected_program,
216 p_sp->i_stream_number, AUDIO_ES, NULL, 0 );
218 input_AddInfo( p_cat, _("Type"), _("Audio") );
220 "adding new audio stream(codec:0x%x,ID:%d)",
222 p_sp->i_stream_number );
226 p_stream->p_es->i_fourcc =
227 VLC_FOURCC( 'a', 'r', 'a', 'w' );
231 p_stream->p_es->i_fourcc =
232 VLC_FOURCC( 'm','p','g','a' );
235 p_stream->p_es->i_fourcc =
236 VLC_FOURCC( 'a','5','2',' ' );
239 p_stream->p_es->i_fourcc =
240 VLC_FOURCC( 'w','m','a','1' );
243 p_stream->p_es->i_fourcc =
244 VLC_FOURCC( 'w','m','a','2' );
247 p_stream->p_es->i_fourcc =
248 VLC_FOURCC( 'm','s',(i_codec >> 8)&0xff,i_codec&0xff );
250 input_AddInfo( p_cat, _("Codec"), "%.4s", (char*)&p_stream->p_es->i_fourcc );
251 if( p_sp->i_type_specific_data_length > 0 )
257 i_size = p_sp->i_type_specific_data_length;
259 p_wf = malloc( i_size );
260 p_stream->p_es->p_waveformatex = (void*)p_wf;
261 p_data = p_sp->p_type_specific_data;
263 p_wf->wFormatTag = GetWLE( p_data );
264 p_wf->nChannels = GetWLE( p_data + 2 );
265 input_AddInfo( p_cat, _("Channels"), "%d", p_wf->nChannels );
266 p_wf->nSamplesPerSec = GetDWLE( p_data + 4 );
267 input_AddInfo( p_cat, _("Sample Rate"), "%d", p_wf->nSamplesPerSec );
268 p_wf->nAvgBytesPerSec = GetDWLE( p_data + 8 );
269 input_AddInfo( p_cat, _("Avg. byterate"), "%d", p_wf->nAvgBytesPerSec );
270 p_wf->nBlockAlign = GetWLE( p_data + 12 );
271 p_wf->wBitsPerSample = GetWLE( p_data + 14 );
272 input_AddInfo( p_cat, _("Bits Per Sample"), "%d", p_wf->wBitsPerSample );
273 p_wf->cbSize = __MIN( GetWLE( p_data + 16 ), i_size - sizeof( WAVEFORMATEX ));
274 if( p_wf->cbSize > 0 )
276 memcpy( &p_wf[1], p_data + sizeof( WAVEFORMATEX ), p_wf->cbSize );
281 if( CmpGUID( &p_sp->i_stream_type, &asf_object_stream_type_video ) )
283 p_stream->i_cat = VIDEO_ES;
284 p_stream->p_es = input_AddES( p_input,
285 p_input->stream.p_selected_program,
286 p_sp->i_stream_number, VIDEO_ES, NULL, 0 );
288 input_AddInfo( p_cat, _("Type"), _("Video") );
289 msg_Dbg( p_input, "adding new video stream(ID:%d)",
290 p_sp->i_stream_number );
291 if( p_sp->p_type_specific_data )
293 p_stream->p_es->i_fourcc =
294 VLC_FOURCC( p_sp->p_type_specific_data[27],
295 p_sp->p_type_specific_data[28],
296 p_sp->p_type_specific_data[29],
297 p_sp->p_type_specific_data[30] );
301 p_stream->p_es->i_fourcc =
302 VLC_FOURCC( 'u','n','d','f' );
304 input_AddInfo( p_cat, _("Codec"), "%.4s", (char*)&p_stream->p_es->i_fourcc );
305 if( p_sp->i_type_specific_data_length > 11 )
307 BITMAPINFOHEADER *p_bih;
311 i_size = p_sp->i_type_specific_data_length - 11;
313 p_bih = malloc( i_size );
314 p_stream->p_es->p_bitmapinfoheader = (void*)p_bih;
315 p_data = p_sp->p_type_specific_data + 11;
317 p_bih->biSize = GetDWLE( p_data );
318 input_AddInfo( p_cat, _("Size"), "%d", p_bih->biSize );
319 p_bih->biWidth = GetDWLE( p_data + 4 );
320 p_bih->biHeight = GetDWLE( p_data + 8 );
321 input_AddInfo( p_cat, _("Resolution"), "%dx%d", p_bih->biWidth, p_bih->biHeight );
322 p_bih->biPlanes = GetDWLE( p_data + 12 );
323 input_AddInfo( p_cat, _("Planes"), "%d", p_bih->biPlanes );
324 p_bih->biBitCount = GetDWLE( p_data + 14 );
325 input_AddInfo( p_cat, _("Bits Per Pixel"), "%d", p_bih->biBitCount );
326 p_bih->biCompression= GetDWLE( p_data + 16 );
327 p_bih->biSizeImage = GetDWLE( p_data + 20 );
328 input_AddInfo( p_cat, _("Image Size"), "%d", p_bih->biSizeImage );
329 p_bih->biXPelsPerMeter = GetDWLE( p_data + 24 );
330 input_AddInfo( p_cat, _("X pixels per meter"), "%d", p_bih->biXPelsPerMeter );
331 p_bih->biYPelsPerMeter = GetDWLE( p_data + 28 );
332 input_AddInfo( p_cat, _("Y pixels per meter"), "%d", p_bih->biYPelsPerMeter );
333 p_bih->biClrUsed = GetDWLE( p_data + 32 );
334 p_bih->biClrImportant = GetDWLE( p_data + 36 );
336 if( i_size > sizeof( BITMAPINFOHEADER ) )
338 memcpy( (uint8_t*)p_bih + sizeof( BITMAPINFOHEADER ),
339 p_data + sizeof( BITMAPINFOHEADER ),
340 i_size - sizeof( BITMAPINFOHEADER ) );
347 p_stream->i_cat = UNKNOWN_ES;
348 msg_Dbg( p_input, "ignoring unknown stream(ID:%d)",
349 p_sp->i_stream_number );
352 vlc_mutex_lock( &p_input->stream.stream_lock );
355 input_SelectES( p_input, p_stream->p_es );
357 vlc_mutex_unlock( &p_input->stream.stream_lock );
361 p_demux->i_data_begin = p_demux->root.p_data->i_object_pos + 50;
362 if( p_demux->root.p_data->i_object_size != 0 )
364 p_demux->i_data_end = p_demux->root.p_data->i_object_pos +
365 p_demux->root.p_data->i_object_size;
369 p_demux->i_data_end = -1;
373 // go to first packet
374 ASF_SeekAbsolute( p_input, p_demux->i_data_begin );
376 vlc_mutex_lock( &p_input->stream.stream_lock );
377 /* try to calculate movie time */
378 if( p_demux->p_fp->i_data_packets_count > 0 )
383 /* real number of packets */
384 i_count = ( p_input->stream.p_selected_area->i_size -
385 p_demux->i_data_begin ) /
386 p_demux->p_fp->i_min_data_packet_size;
387 /* calculate the time duration in s */
388 i_length = (mtime_t)p_demux->p_fp->i_play_duration / 10 *
390 (mtime_t)p_demux->p_fp->i_data_packets_count /
394 p_input->stream.i_mux_rate =
395 p_input->stream.p_selected_area->i_size / 50 / i_length;
399 p_input->stream.i_mux_rate = 0;
406 p_input->stream.i_mux_rate = 0;
411 p_input->stream.p_selected_program->b_is_ok = 1;
412 vlc_mutex_unlock( &p_input->stream.stream_lock );
418 static mtime_t GetMoviePTS( demux_sys_t *p_demux )
424 for( i_stream = 0; i_stream < 128 ; i_stream++ )
426 #define p_stream p_demux->stream[i_stream]
427 if( p_stream && p_stream->p_es && p_stream->p_es->p_decoder_fifo && p_stream->i_time > 0)
431 i_time = p_stream->i_time;
435 i_time = __MIN( i_time, p_stream->i_time );
444 /*****************************************************************************
445 * Demux: read packet and send them to decoders
446 *****************************************************************************/
447 #define GETVALUE2b( bits, var, def ) \
448 switch( (bits)&0x03 ) \
450 case 1: var = p_peek[i_skip]; i_skip++; break; \
451 case 2: var = GetWLE( p_peek + i_skip ); i_skip+= 2; break; \
452 case 3: var = GetDWLE( p_peek + i_skip ); i_skip+= 4; break; \
454 default: var = def; break;\
457 static int DemuxPacket( input_thread_t *p_input, vlc_bool_t b_play_audio )
459 demux_sys_t *p_demux = p_input->p_demux_data;
460 int i_data_packet_min = p_demux->p_fp->i_min_data_packet_size;
464 int i_packet_size_left;
466 int i_packet_property;
468 int b_packet_multiple_payload;
470 int i_packet_sequence;
471 int i_packet_padding_length;
473 uint32_t i_packet_send_time;
474 uint16_t i_packet_duration;
477 int i_payload_length_type;
480 if( input_Peek( p_input, &p_peek, i_data_packet_min ) < i_data_packet_min )
483 msg_Warn( p_input, "cannot peek while getting new packet, EOF ?" );
488 /* *** parse error correction if present *** */
491 unsigned int i_error_correction_length_type;
492 unsigned int i_error_correction_data_length;
493 unsigned int i_opaque_data_present;
495 i_error_correction_data_length = p_peek[0] & 0x0f; // 4bits
496 i_opaque_data_present = ( p_peek[0] >> 4 )& 0x01; // 1bit
497 i_error_correction_length_type = ( p_peek[0] >> 5 ) & 0x03; // 2bits
498 i_skip += 1; // skip error correction flags
500 if( i_error_correction_length_type != 0x00 ||
501 i_opaque_data_present != 0 ||
502 i_error_correction_data_length != 0x02 )
504 goto loop_error_recovery;
507 i_skip += i_error_correction_data_length;
511 msg_Warn( p_input, "p_peek[0]&0x80 != 0x80" );
515 if( i_skip + 2 >= i_data_packet_min )
517 goto loop_error_recovery;
520 i_packet_flags = p_peek[i_skip]; i_skip++;
521 i_packet_property = p_peek[i_skip]; i_skip++;
523 b_packet_multiple_payload = i_packet_flags&0x01;
525 /* read some value */
526 GETVALUE2b( i_packet_flags >> 5, i_packet_length, i_data_packet_min );
527 GETVALUE2b( i_packet_flags >> 1, i_packet_sequence, 0 );
528 GETVALUE2b( i_packet_flags >> 3, i_packet_padding_length, 0 );
530 i_packet_send_time = GetDWLE( p_peek + i_skip ); i_skip += 4;
531 i_packet_duration = GetWLE( p_peek + i_skip ); i_skip += 2;
533 // i_packet_size_left = i_packet_length; // XXX données reellement lu
534 /* FIXME I have to do that for some file, I don't known why */
535 i_packet_size_left = i_data_packet_min;
537 if( b_packet_multiple_payload )
539 i_payload_count = p_peek[i_skip] & 0x3f;
540 i_payload_length_type = ( p_peek[i_skip] >> 6 )&0x03;
546 i_payload_length_type = 0x02; // unused
549 for( i_payload = 0; i_payload < i_payload_count ; i_payload++ )
551 asf_stream_t *p_stream;
554 int i_media_object_number;
555 int i_media_object_offset;
556 int i_replicated_data_length;
557 int i_payload_data_length;
558 int i_payload_data_pos;
559 int i_sub_payload_data_length;
565 if( i_skip >= i_packet_size_left )
567 /* prevent some segfault with invalid file */
571 i_stream_number = p_peek[i_skip] & 0x7f;
574 GETVALUE2b( i_packet_property >> 4, i_media_object_number, 0 );
575 GETVALUE2b( i_packet_property >> 2, i_tmp, 0 );
576 GETVALUE2b( i_packet_property, i_replicated_data_length, 0 );
578 if( i_replicated_data_length > 1 ) // should be at least 8 bytes
580 i_pts = (mtime_t)GetDWLE( p_peek + i_skip + 4 ) * 1000;
581 i_skip += i_replicated_data_length;
584 i_media_object_offset = i_tmp;
586 if( i_skip >= i_packet_size_left )
591 else if( i_replicated_data_length == 1 )
594 msg_Dbg( p_input, "found compressed payload" );
596 i_pts = (mtime_t)i_tmp * 1000;
597 i_pts_delta = (mtime_t)p_peek[i_skip] * 1000; i_skip++;
599 i_media_object_offset = 0;
603 i_pts = (mtime_t)i_packet_send_time * 1000;
606 i_media_object_offset = i_tmp;
609 i_pts = __MAX( i_pts - p_demux->p_fp->i_preroll * 1000, 0 );
610 if( b_packet_multiple_payload )
612 GETVALUE2b( i_payload_length_type, i_payload_data_length, 0 );
616 i_payload_data_length = i_packet_length -
617 i_packet_padding_length - i_skip;
620 if( i_payload_data_length < 0 || i_skip + i_payload_data_length > i_packet_size_left )
627 "payload(%d/%d) stream_number:%d media_object_number:%d media_object_offset:%d replicated_data_length:%d payload_data_length %d",
631 i_media_object_number,
632 i_media_object_offset,
633 i_replicated_data_length,
634 i_payload_data_length );
637 if( !( p_stream = p_demux->stream[i_stream_number] ) )
640 "undeclared stream[Id 0x%x]", i_stream_number );
641 i_skip += i_payload_data_length;
642 continue; // over payload
645 if( !p_stream->p_es || !p_stream->p_es->p_decoder_fifo )
647 i_skip += i_payload_data_length;
652 for( i_payload_data_pos = 0;
653 i_payload_data_pos < i_payload_data_length &&
654 i_packet_size_left > 0;
655 i_payload_data_pos += i_sub_payload_data_length )
657 data_packet_t *p_data;
659 // read sub payload length
660 if( i_replicated_data_length == 1 )
662 i_sub_payload_data_length = p_peek[i_skip]; i_skip++;
663 i_payload_data_pos++;
667 i_sub_payload_data_length = i_payload_data_length;
670 /* FIXME I don't use i_media_object_number, sould I ? */
671 if( p_stream->p_pes && i_media_object_offset == 0 )
673 /* send complete packet to decoder */
674 if( p_stream->p_pes->i_pes_size > 0 )
676 if( p_stream->p_es->p_decoder_fifo &&
677 ( b_play_audio || p_stream->i_cat != AUDIO_ES ) )
679 p_stream->p_pes->i_rate =
680 p_input->stream.control.i_rate;
681 input_DecodePES( p_stream->p_es->p_decoder_fifo,
686 input_DeletePES( p_input->p_method_data,
689 p_stream->p_pes = NULL;
693 if( !p_stream->p_pes ) // add a new PES
696 ( (mtime_t)i_pts + i_payload * (mtime_t)i_pts_delta );
698 p_stream->p_pes = input_NewPES( p_input->p_method_data );
699 p_stream->p_pes->i_dts =
700 p_stream->p_pes->i_pts =
701 input_ClockGetTS( p_input,
702 p_input->stream.p_selected_program,
703 p_stream->i_time * 9 /100 );
705 //msg_Err( p_input, "stream[0x%2x] pts=%lld", i_stream_number, p_stream->p_pes->i_pts );
706 p_stream->p_pes->p_next = NULL;
707 p_stream->p_pes->i_nb_data = 0;
708 p_stream->p_pes->i_pes_size = 0;
711 i_read = i_sub_payload_data_length + i_skip;
712 if( input_SplitBuffer( p_input, &p_data, i_read ) < i_read )
714 msg_Warn( p_input, "cannot read data" );
717 p_data->p_payload_start += i_skip;
718 i_packet_size_left -= i_read;
721 if( !p_stream->p_pes->p_first )
723 p_stream->p_pes->p_first = p_stream->p_pes->p_last = p_data;
727 p_stream->p_pes->p_last->p_next = p_data;
728 p_stream->p_pes->p_last = p_data;
730 p_stream->p_pes->i_pes_size += i_sub_payload_data_length;
731 p_stream->p_pes->i_nb_data++;
734 if( i_packet_size_left > 0 )
736 if( input_Peek( p_input, &p_peek, i_packet_size_left ) < i_packet_size_left )
739 msg_Warn( p_input, "cannot peek, EOF ?" );
746 if( i_packet_size_left > 0 )
748 if( !ASF_SkipBytes( p_input, i_packet_size_left ) )
750 msg_Warn( p_input, "cannot skip data, EOF ?" );
758 msg_Warn( p_input, "unsupported packet header" );
759 if( p_demux->p_fp->i_min_data_packet_size != p_demux->p_fp->i_max_data_packet_size )
761 msg_Err( p_input, "unsupported packet header, fatal error" );
764 ASF_SkipBytes( p_input, i_data_packet_min );
769 static int Demux( input_thread_t *p_input )
771 demux_sys_t *p_demux = p_input->p_demux_data;
772 vlc_bool_t b_play_audio;
776 b_stream = VLC_FALSE;
777 for( i = 0; i < 128; i++ )
779 if( p_demux->stream[i] &&
780 p_demux->stream[i]->p_es &&
781 p_demux->stream[i]->p_es->p_decoder_fifo )
788 msg_Warn( p_input, "no stream selected, exiting..." );
792 /* catch seek from user */
793 if( p_input->stream.p_selected_program->i_synchro_state == SYNCHRO_REINIT )
797 msleep( p_input->i_pts_delay );
798 i_offset = ASF_TellAbsolute( p_input ) - p_demux->i_data_begin;
804 /* XXX work only when i_min_data_packet_size == i_max_data_packet_size */
805 i_offset += p_demux->p_fp->i_min_data_packet_size -
806 i_offset % p_demux->p_fp->i_min_data_packet_size;
807 ASF_SeekAbsolute( p_input, p_demux->i_data_begin + i_offset );
809 p_demux->i_time = -1;
810 for( i = 0; i < 128 ; i++ )
812 #define p_stream p_demux->stream[i]
815 p_stream->i_time = -1;
821 /* Check if we need to send the audio data to decoder */
822 b_play_audio = !p_input->stream.control.b_mute;
827 mtime_t i_time_begin = GetMoviePTS( p_demux );
835 if( ( i_result = DemuxPacket( p_input, b_play_audio ) ) <= 0 )
839 if( i_time_begin == -1 )
841 i_time_begin = GetMoviePTS( p_demux );
845 i_length = GetMoviePTS( p_demux ) - i_time_begin;
846 if( i_length < 0 || i_length >= 40 * 1000 )
853 p_demux->i_time = GetMoviePTS( p_demux );
854 if( p_demux->i_time >= 0 )
856 /* update pcr XXX in mpeg scale so in 90000 unit/s */
857 p_demux->i_pcr = p_demux->i_time * 9 / 100;
859 /* first wait for the good time to read next packets */
860 input_ClockManageRef( p_input,
861 p_input->stream.p_selected_program,
868 /*****************************************************************************
869 * MP4End: frees unused data
870 *****************************************************************************/
871 static void Deactivate( vlc_object_t * p_this )
874 if( p ) { free( p ); }
876 input_thread_t * p_input = (input_thread_t *)p_this;
877 demux_sys_t *p_demux = p_input->p_demux_data;
880 msg_Dbg( p_input, "Freeing all memory" );
881 ASF_FreeObjectRoot( p_input, &p_demux->root );
882 for( i_stream = 0; i_stream < 128; i_stream++ )
884 #define p_stream p_demux->stream[i_stream]
887 if( p_stream->p_pes )
889 input_DeletePES( p_input->p_method_data, p_stream->p_pes );
895 FREE( p_input->p_demux_data );