1 /*****************************************************************************
2 * live.cpp : live.com support.
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: livedotcom.cpp,v 1.17 2004/02/23 20:45:52 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>
32 #include <codecs.h> /* BITMAPINFOHEADER, WAVEFORMATEX */
36 # include <winsock2.h>
39 #include "BasicUsageEnvironment.hh"
40 #include "GroupsockHelper.hh"
41 #include "liveMedia.hh"
45 /*****************************************************************************
47 *****************************************************************************/
48 static int DemuxOpen ( vlc_object_t * );
49 static void DemuxClose( vlc_object_t * );
51 static int AccessOpen ( vlc_object_t * );
52 static void AccessClose( vlc_object_t * );
54 #define CACHING_TEXT N_("Caching value (ms)")
55 #define CACHING_LONGTEXT N_( \
56 "Allows you to modify the default caching value for rtsp streams. This " \
57 "value should be set in miliseconds units." )
60 set_description( _("live.com (RTSP/RTP/SDP) demuxer" ) );
61 set_capability( "demux", 50 );
62 set_callbacks( DemuxOpen, DemuxClose );
63 add_shortcut( "live" );
66 set_description( _("RTSP/RTP describe") );
67 add_shortcut( "rtsp" );
68 add_shortcut( "sdp" );
69 set_capability( "access", 0 );
70 set_callbacks( AccessOpen, AccessClose );
71 add_bool( "rtsp-tcp", 0, NULL,
72 N_("Use rtp over rtsp (tcp)"),
73 N_("Use rtp over rtsp (tcp)"), VLC_TRUE );
74 add_integer( "rtsp-caching", 4 * DEFAULT_PTS_DELAY / 1000, NULL,
75 CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
79 * - Support PS/TS (need to rework the TS/PS demuxer a lot).
80 * - Support X-QT/X-QUICKTIME generic codec for audio.
82 * - Check memory leak, delete/free -> still one when using rtsp-tcp but I'm
83 * not sure if it comes from me.
87 /*****************************************************************************
89 *****************************************************************************/
100 input_thread_t *p_input;
102 vlc_bool_t b_quicktime;
107 RTPSource *rtpSource;
108 FramedSource *readSource;
109 vlc_bool_t b_rtcp_sync;
111 uint8_t buffer[65536];
120 char *p_sdp; /* XXX mallocated */
123 TaskScheduler *scheduler;
124 UsageEnvironment *env ;
128 live_track_t **track; /* XXX mallocated */
138 static ssize_t Read ( input_thread_t *, byte_t *, size_t );
139 static ssize_t MRLRead( input_thread_t *, byte_t *, size_t );
141 static int Demux ( input_thread_t * );
142 static int Control( input_thread_t *, int, va_list );
146 /*****************************************************************************
148 *****************************************************************************/
149 static int AccessOpen( vlc_object_t *p_this )
151 input_thread_t *p_input = (input_thread_t *)p_this;
154 TaskScheduler *scheduler = NULL;
155 UsageEnvironment *env = NULL;
156 RTSPClient *rtsp = NULL;
161 if( p_input->psz_access == NULL || ( strcasecmp( p_input->psz_access, "rtsp" ) && strcasecmp( p_input->psz_access, "sdp" ) ) )
163 msg_Warn( p_input, "RTSP access discarded" );
166 if( !strcasecmp( p_input->psz_access, "rtsp" ) )
168 if( ( scheduler = BasicTaskScheduler::createNew() ) == NULL )
170 msg_Err( p_input, "BasicTaskScheduler::createNew failed" );
173 if( ( env = BasicUsageEnvironment::createNew(*scheduler) ) == NULL )
176 msg_Err( p_input, "BasicUsageEnvironment::createNew failed" );
179 if( ( rtsp = RTSPClient::createNew(*env, 1/*verbose*/, "VLC Media Player" ) ) == NULL )
183 msg_Err( p_input, "RTSPClient::createNew failed" );
187 psz_url = (char*)malloc( strlen( p_input->psz_name ) + 8 );
188 sprintf( psz_url, "rtsp://%s", p_input->psz_name );
190 p_sys = (access_sys_t*)malloc( sizeof( access_sys_t ) );
191 p_sys->p_sdp = rtsp->describeURL( psz_url );
193 if( p_sys->p_sdp == NULL )
195 msg_Err( p_input, "describeURL failed (%s)", env->getResultMsg() );
204 p_sys->i_sdp = strlen( p_sys->p_sdp );
207 //fprintf( stderr, "sdp=%s\n", p_sys->p_sdp );
212 var_Create( p_input, "rtsp-tcp", VLC_VAR_BOOL|VLC_VAR_DOINHERIT );
213 var_Get( p_input, "rtsp-tcp", &val );
215 p_input->p_access_data = p_sys;
218 /* Set exported functions */
219 p_input->pf_read = Read;
220 p_input->pf_seek = NULL;
221 p_input->pf_set_program = input_SetProgram;
222 p_input->pf_set_area = NULL;
223 p_input->p_private = NULL;
225 p_input->psz_demux = "live";
227 /* Finished to set some variable */
228 vlc_mutex_lock( &p_input->stream.stream_lock );
229 /* FIXME that's not true but eg over tcp, server send data too fast */
230 p_input->stream.b_pace_control = val.b_bool;
231 p_input->stream.p_selected_area->i_tell = 0;
232 p_input->stream.b_seekable = 1; /* Hack to display time */
233 p_input->stream.p_selected_area->i_size = 0;
234 p_input->stream.i_method = INPUT_METHOD_NETWORK;
235 vlc_mutex_unlock( &p_input->stream.stream_lock );
237 /* Update default_pts to a suitable value for RTSP access */
238 var_Create( p_input, "rtsp-caching", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
239 var_Get( p_input, "rtsp-caching", &val );
240 p_input->i_pts_delay = val.i_int * 1000;
246 p_input->p_access_data = (access_sys_t*)0;
248 p_input->pf_read = MRLRead;
249 p_input->pf_seek = NULL;
250 p_input->pf_set_program = input_SetProgram;
251 p_input->pf_set_area = NULL;
252 p_input->p_private = NULL;
253 p_input->psz_demux = "live";
254 /* Finished to set some variable */
255 vlc_mutex_lock( &p_input->stream.stream_lock );
256 p_input->stream.b_pace_control = VLC_TRUE;
257 p_input->stream.p_selected_area->i_tell = 0;
258 p_input->stream.b_seekable = VLC_FALSE;
259 p_input->stream.p_selected_area->i_size = 0;
260 p_input->stream.i_method = INPUT_METHOD_NETWORK;
261 vlc_mutex_unlock( &p_input->stream.stream_lock );
267 /*****************************************************************************
269 *****************************************************************************/
270 static void AccessClose( vlc_object_t *p_this )
272 input_thread_t *p_input = (input_thread_t *)p_this;
273 access_sys_t *p_sys = p_input->p_access_data;
274 if( !strcasecmp( p_input->psz_access, "rtsp" ) )
276 delete[] p_sys->p_sdp;
281 /*****************************************************************************
283 *****************************************************************************/
284 static ssize_t Read ( input_thread_t *p_input, byte_t *p_buffer, size_t i_len )
286 access_sys_t *p_sys = p_input->p_access_data;
287 int i_copy = __MIN( (int)i_len, p_sys->i_sdp - p_sys->i_pos );
291 memcpy( p_buffer, &p_sys->p_sdp[p_sys->i_pos], i_copy );
292 p_sys->i_pos += i_copy;
296 /*****************************************************************************
297 * MRLRead: read data from the mrl
298 *****************************************************************************/
299 static ssize_t MRLRead ( input_thread_t *p_input, byte_t *p_buffer, size_t i_len )
301 int i_done = (int)p_input->p_access_data;
302 int i_copy = __MIN( (int)i_len, (int)strlen(p_input->psz_name) - i_done );
306 memcpy( p_buffer, &p_input->psz_name[i_done], i_copy );
308 p_input->p_access_data = (access_sys_t*)i_done;
314 /*****************************************************************************
316 *****************************************************************************/
317 static int DemuxOpen ( vlc_object_t *p_this )
319 input_thread_t *p_input = (input_thread_t *)p_this;
322 MediaSubsessionIterator *iter;
323 MediaSubsession *sub;
333 /* See if it looks like a SDP
334 v, o, s fields are mandatory and in this order */
335 if( stream_Peek( p_input->s, &p_peek, 7 ) < 7 )
337 msg_Err( p_input, "cannot peek" );
340 if( strncmp( (char*)p_peek, "v=0\r\n", 5 ) && strncmp( (char*)p_peek, "v=0\n", 4 ) &&
341 ( p_input->psz_access == NULL || strcasecmp( p_input->psz_access, "rtsp" ) ||
342 p_peek[0] < 'a' || p_peek[0] > 'z' || p_peek[1] != '=' ) )
344 msg_Warn( p_input, "SDP module discarded" );
348 p_input->pf_demux = Demux;
349 p_input->pf_demux_control = Control;
350 p_input->p_demux_data = p_sys = (demux_sys_t*)malloc( sizeof( demux_sys_t ) );
352 p_sys->scheduler = NULL;
359 p_sys->i_pcr_start = 0;
363 /* Gather the complete sdp file */
364 vlc_mutex_lock( &p_input->stream.stream_lock );
365 if( input_InitStream( p_input, 0 ) == -1)
367 vlc_mutex_unlock( &p_input->stream.stream_lock );
368 msg_Err( p_input, "cannot init stream" );
371 vlc_mutex_unlock( &p_input->stream.stream_lock );
375 p_sdp = (uint8_t*)malloc( i_sdp_max );
378 int i_read = stream_Read( p_input->s, &p_sdp[i_sdp], i_sdp_max - i_sdp - 1 );
382 msg_Err( p_input, "failed to read SDP" );
389 if( i_read < i_sdp_max - i_sdp - 1 )
396 p_sdp = (uint8_t*)realloc( p_sdp, i_sdp_max );
398 p_sys->p_sdp = (char*)p_sdp;
400 fprintf( stderr, "sdp=%s\n", p_sys->p_sdp );
402 if( ( p_sys->scheduler = BasicTaskScheduler::createNew() ) == NULL )
404 msg_Err( p_input, "BasicTaskScheduler::createNew failed" );
407 if( ( p_sys->env = BasicUsageEnvironment::createNew(*p_sys->scheduler) ) == NULL )
409 msg_Err( p_input, "BasicUsageEnvironment::createNew failed" );
412 if( p_input->psz_access != NULL && !strcasecmp( p_input->psz_access, "rtsp" ) )
417 if( ( p_sys->rtsp = RTSPClient::createNew(*p_sys->env, 1/*verbose*/, "VLC Media Player" ) ) == NULL )
419 msg_Err( p_input, "RTSPClient::createNew failed (%s)", p_sys->env->getResultMsg() );
422 psz_url = (char*)malloc( strlen( p_input->psz_name ) + 8 );
423 sprintf( psz_url, "rtsp://%s", p_input->psz_name );
425 psz_options = p_sys->rtsp->sendOptionsCmd( psz_url );
426 /* FIXME psz_options -> delete or free */
429 if( ( p_sys->ms = MediaSession::createNew(*p_sys->env, p_sys->p_sdp ) ) == NULL )
431 msg_Err( p_input, "MediaSession::createNew failed" );
435 var_Create( p_input, "rtsp-tcp", VLC_VAR_BOOL|VLC_VAR_DOINHERIT );
436 var_Get( p_input, "rtsp-tcp", &val );
438 /* Initialise each media subsession */
439 iter = new MediaSubsessionIterator( *p_sys->ms );
440 while( ( sub = iter->next() ) != NULL )
442 unsigned int i_buffer = 0;
444 /* Value taken from mplayer */
445 if( !strcmp( sub->mediumName(), "audio" ) )
449 else if( !strcmp( sub->mediumName(), "video" ) )
458 if( !sub->initiate() )
460 msg_Warn( p_input, "RTP subsession '%s/%s' failed(%s)", sub->mediumName(), sub->codecName(), p_sys->env->getResultMsg() );
464 int fd = sub->rtpSource()->RTPgs()->socketNum();
466 msg_Dbg( p_input, "RTP subsession '%s/%s'", sub->mediumName(), sub->codecName() );
468 /* Increase the buffer size */
469 increaseReceiveBufferTo( *p_sys->env, fd, i_buffer );
470 /* Issue the SETUP */
473 p_sys->rtsp->setupMediaSubsession( *sub, False, val.b_bool ? True : False );
481 if( !p_sys->rtsp->playMediaSession( *p_sys->ms ) )
483 msg_Err( p_input, "PLAY failed %s", p_sys->env->getResultMsg() );
488 /* Create all es struct */
490 while( ( sub = iter->next() ) != NULL )
494 if( sub->readSource() == NULL )
499 tk = (live_track_t*)malloc( sizeof( live_track_t ) );
500 tk->p_input = p_input;
503 tk->b_quicktime = VLC_FALSE;
504 tk->b_rtcp_sync = VLC_FALSE;
506 /* Value taken from mplayer */
507 if( !strcmp( sub->mediumName(), "audio" ) )
509 es_format_Init( &tk->fmt, AUDIO_ES, VLC_FOURCC( 'u', 'n', 'd', 'f' ) );
510 tk->fmt.audio.i_channels = sub->numChannels();
511 tk->fmt.audio.i_rate = sub->rtpSource()->timestampFrequency();
513 if( !strcmp( sub->codecName(), "MPA" ) ||
514 !strcmp( sub->codecName(), "MPA-ROBUST" ) ||
515 !strcmp( sub->codecName(), "X-MP3-DRAFT-00" ) )
517 tk->fmt.i_codec = VLC_FOURCC( 'm', 'p', 'g', 'a' );
518 tk->fmt.audio.i_rate = 0;
520 else if( !strcmp( sub->codecName(), "AC3" ) )
522 tk->fmt.i_codec = VLC_FOURCC( 'a', '5', '2', ' ' );
523 tk->fmt.audio.i_rate = 0;
525 else if( !strcmp( sub->codecName(), "L16" ) )
527 tk->fmt.i_codec = VLC_FOURCC( 't', 'w', 'o', 's' );
528 tk->fmt.audio.i_bitspersample = 16;
530 else if( !strcmp( sub->codecName(), "L8" ) )
532 tk->fmt.i_codec = VLC_FOURCC( 'a', 'r', 'a', 'w' );
533 tk->fmt.audio.i_bitspersample = 8;
535 else if( !strcmp( sub->codecName(), "PCMU" ) )
537 tk->fmt.i_codec = VLC_FOURCC( 'u', 'l', 'a', 'w' );
539 else if( !strcmp( sub->codecName(), "PCMA" ) )
541 tk->fmt.i_codec = VLC_FOURCC( 'a', 'l', 'a', 'w' );
543 else if( !strcmp( sub->codecName(), "MP4A-LATM" ) )
545 unsigned int i_extra;
548 tk->fmt.i_codec = VLC_FOURCC( 'm', 'p', '4', 'a' );
550 if( ( p_extra = parseStreamMuxConfigStr( sub->fmtp_config(), i_extra ) ) )
552 tk->fmt.i_extra = i_extra;
553 tk->fmt.p_extra = malloc( i_extra );
554 memcpy( tk->fmt.p_extra, p_extra, i_extra );
558 else if( !strcmp( sub->codecName(), "MPEG4-GENERIC" ) )
560 unsigned int i_extra;
563 tk->fmt.i_codec = VLC_FOURCC( 'm', 'p', '4', 'a' );
565 if( ( p_extra = parseGeneralConfigStr( sub->fmtp_config(), i_extra ) ) )
567 tk->fmt.i_extra = i_extra;
568 tk->fmt.p_extra = malloc( i_extra );
569 memcpy( tk->fmt.p_extra, p_extra, i_extra );
574 else if( !strcmp( sub->mediumName(), "video" ) )
576 es_format_Init( &tk->fmt, VIDEO_ES, VLC_FOURCC( 'u', 'n', 'd', 'f' ) );
577 if( !strcmp( sub->codecName(), "MPV" ) )
579 tk->fmt.i_codec = VLC_FOURCC( 'm', 'p', 'g', 'v' );
581 else if( !strcmp( sub->codecName(), "H263" ) ||
582 !strcmp( sub->codecName(), "H263-1998" ) )
584 tk->fmt.i_codec = VLC_FOURCC( 'h', '2', '6', '3' );
586 else if( !strcmp( sub->codecName(), "H261" ) )
588 tk->fmt.i_codec = VLC_FOURCC( 'h', '2', '6', '1' );
590 else if( !strcmp( sub->codecName(), "JPEG" ) )
592 tk->fmt.i_codec = VLC_FOURCC( 'M', 'J', 'P', 'G' );
594 else if( !strcmp( sub->codecName(), "MP4V-ES" ) )
596 unsigned int i_extra;
599 tk->fmt.i_codec = VLC_FOURCC( 'm', 'p', '4', 'v' );
601 if( ( p_extra = parseGeneralConfigStr( sub->fmtp_config(), i_extra ) ) )
603 tk->fmt.i_extra = i_extra;
604 tk->fmt.p_extra = malloc( i_extra );
605 memcpy( tk->fmt.p_extra, p_extra, i_extra );
609 else if( !strcmp( sub->codecName(), "X-QT" ) || !strcmp( sub->codecName(), "X-QUICKTIME" ) )
611 tk->b_quicktime = VLC_TRUE;
615 if( tk->fmt.i_codec != VLC_FOURCC( 'u', 'n', 'd', 'f' ) )
617 tk->p_es = es_out_Add( p_input->p_es_out, &tk->fmt );
624 if( tk->p_es || tk->b_quicktime )
626 TAB_APPEND( p_sys->i_track, p_sys->track, tk );
627 tk->readSource = sub->readSource();
628 tk->rtpSource = sub->rtpSource();
638 p_sys->i_length = (mtime_t)(p_sys->ms->playEndTime() * 1000000.0);
639 if( p_sys->i_length < 0 )
643 else if( p_sys->i_length > 0 )
645 p_input->stream.p_selected_area->i_size = 1000; /* needed for now */
648 if( p_sys->i_track <= 0 )
650 msg_Err( p_input, "no codec supported, aborting" );
659 Medium::close( p_sys->ms );
663 Medium::close( p_sys->rtsp );
669 if( p_sys->scheduler )
671 delete p_sys->scheduler;
675 free( p_sys->p_sdp );
683 /*****************************************************************************
685 *****************************************************************************/
686 static void DemuxClose( vlc_object_t *p_this )
688 input_thread_t *p_input = (input_thread_t *)p_this;
689 demux_sys_t *p_sys = p_input->p_demux_data;
692 for( i = 0; i < p_sys->i_track; i++ )
694 live_track_t *tk = p_sys->track[i];
700 free( p_sys->track );
703 if( p_sys->rtsp && p_sys->ms )
706 p_sys->rtsp->teardownMediaSession( *p_sys->ms );
708 Medium::close( p_sys->ms );
711 Medium::close( p_sys->rtsp );
718 if( p_sys->scheduler )
720 delete p_sys->scheduler;
724 free( p_sys->p_sdp );
730 static void StreamRead( void *p_private, unsigned int i_size, struct timeval pts );
731 static void StreamClose( void *p_private );
732 static void TaskInterrupt( void *p_private );
734 /*****************************************************************************
736 *****************************************************************************/
737 static int Demux ( input_thread_t *p_input )
739 demux_sys_t *p_sys = p_input->p_demux_data;
745 for( i = 0; i < p_sys->i_track; i++ )
747 live_track_t *tk = p_sys->track[i];
753 else if( tk->i_pts != 0 && i_pcr > tk->i_pts )
758 if( i_pcr != p_sys->i_pcr && i_pcr > 0 )
760 input_ClockManageRef( p_input,
761 p_input->stream.p_selected_program,
763 p_sys->i_pcr = i_pcr;
764 if( p_sys->i_pcr_start <= 0 || p_sys->i_pcr_start > i_pcr )
766 p_sys->i_pcr_start = i_pcr;
770 /* First warm we want to read data */
772 for( i = 0; i < p_sys->i_track; i++ )
774 live_track_t *tk = p_sys->track[i];
776 if( tk->waiting == 0 )
779 tk->readSource->getNextFrame( tk->buffer, 65536,
784 /* Create a task that will be called if we wait more than 300ms */
785 task = p_sys->scheduler->scheduleDelayedTask( 300000, TaskInterrupt, p_input );
788 p_sys->scheduler->doEventLoop( &p_sys->event );
790 /* remove the task */
791 p_sys->scheduler->unscheduleDelayedTask( task );
793 /* Check for gap in pts value */
794 for( i = 0; i < p_sys->i_track; i++ )
796 live_track_t *tk = p_sys->track[i];
798 if( !tk->b_rtcp_sync && tk->rtpSource->hasBeenSynchronizedUsingRTCP() )
800 msg_Dbg( p_input, "tk->rtpSource->hasBeenSynchronizedUsingRTCP()" );
801 p_input->stream.p_selected_program->i_synchro_state = SYNCHRO_REINIT;
802 tk->b_rtcp_sync = VLC_TRUE;
804 /* reset PCR and PCR start, mmh won't work well for multi-stream I fear */
806 p_sys->i_pcr_start = 0;
812 return p_input->b_error ? 0 : 1;
815 static int Control( input_thread_t *p_input, int i_query, va_list args )
817 demux_sys_t *p_sys = p_input->p_demux_data;
824 pi64 = (int64_t*)va_arg( args, int64_t * );
825 *pi64 = p_sys->i_pcr - p_sys->i_pcr_start + p_sys->i_start;
828 case DEMUX_GET_LENGTH:
829 pi64 = (int64_t*)va_arg( args, int64_t * );
830 *pi64 = p_sys->i_length;
833 case DEMUX_GET_POSITION:
834 pf = (double*)va_arg( args, double* );
835 if( p_sys->i_length > 0 )
837 *pf = (double)( p_sys->i_pcr - p_sys->i_pcr_start + p_sys->i_start)/
838 (double)(p_sys->i_length);
846 case DEMUX_SET_POSITION:
850 f = (double)va_arg( args, double );
851 time = f * (double)p_sys->i_length / 1000000.0; /* in second */
853 if( p_sys->rtsp && p_sys->i_length > 0 )
855 MediaSubsessionIterator *iter = new MediaSubsessionIterator( *p_sys->ms );
856 MediaSubsession *sub;
859 while( ( sub = iter->next() ) != NULL )
861 p_sys->rtsp->playMediaSubsession( *sub, time );
864 p_sys->i_start = (mtime_t)(f * (double)p_sys->i_length);
865 p_sys->i_pcr_start = 0;
867 for( i = 0; i < p_sys->i_track; i++ )
869 p_sys->track[i]->i_pts = 0;
877 return demux_vaControlDefault( p_input, i_query, args );
881 /*****************************************************************************
883 *****************************************************************************/
884 static void StreamRead( void *p_private, unsigned int i_size, struct timeval pts )
886 live_track_t *tk = (live_track_t*)p_private;
887 input_thread_t *p_input = tk->p_input;
888 demux_sys_t *p_sys = p_input->p_demux_data;
891 mtime_t i_pts = (uint64_t)pts.tv_sec * UI64C(1000000) + (uint64_t)pts.tv_usec;
893 /* XXX Beurk beurk beurk Avoid having negative value XXX */
894 i_pts &= UI64C(0x00ffffffffffffff);
896 if( tk->b_quicktime && tk->p_es == NULL )
898 QuickTimeGenericRTPSource *qtRTPSource = (QuickTimeGenericRTPSource*)tk->rtpSource;
899 QuickTimeGenericRTPSource::QTState &qtState = qtRTPSource->qtState;
900 uint8_t *sdAtom = (uint8_t*)&qtState.sdAtom[4];
902 if( qtState.sdAtomSize < 16 + 32 )
909 tk->fmt.i_codec = VLC_FOURCC( sdAtom[0], sdAtom[1], sdAtom[2], sdAtom[3] );
910 tk->fmt.video.i_width = (sdAtom[28] << 8) | sdAtom[29];
911 tk->fmt.video.i_height = (sdAtom[30] << 8) | sdAtom[31];
913 tk->fmt.i_extra = qtState.sdAtomSize - 16;
914 tk->fmt.p_extra = malloc( tk->fmt.i_extra );
915 memcpy( tk->fmt.p_extra, &sdAtom[12], tk->fmt.i_extra );
917 tk->p_es = es_out_Add( p_input->p_es_out, &tk->fmt );
921 fprintf( stderr, "StreamRead size=%d pts=%lld\n",
923 pts.tv_sec * 1000000LL + pts.tv_usec );
927 msg_Warn( p_input, "buffer overflow" );
929 /* FIXME could i_size be > buffer size ? */
930 p_block = block_New( p_input, i_size );
932 memcpy( p_block->p_buffer, tk->buffer, i_size );
933 //p_block->i_rate = p_input->stream.control.i_rate;
935 if( i_pts != tk->i_pts )
938 p_block->i_pts = input_ClockGetTS( p_input,
939 p_input->stream.p_selected_program,
947 //fprintf( stderr, "tk -> dpts=%lld\n", i_pts - tk->i_pts );
949 es_out_Send( p_input->p_es_out, tk->p_es, p_block );
954 /* we have read data */
963 /*****************************************************************************
965 *****************************************************************************/
966 static void StreamClose( void *p_private )
968 live_track_t *tk = (live_track_t*)p_private;
969 input_thread_t *p_input = tk->p_input;
970 demux_sys_t *p_sys = p_input->p_demux_data;
972 fprintf( stderr, "StreamClose\n" );
975 p_input->b_error = VLC_TRUE;
979 /*****************************************************************************
981 *****************************************************************************/
982 static void TaskInterrupt( void *p_private )
984 input_thread_t *p_input = (input_thread_t*)p_private;
986 fprintf( stderr, "TaskInterrupt\n" );
989 p_input->p_demux_data->event = 0xff;