1 /*****************************************************************************
2 * live.cpp : live.com support.
3 *****************************************************************************
4 * Copyright (C) 2003-2004 VideoLAN
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>
35 # include <winsock2.h>
38 #include "BasicUsageEnvironment.hh"
39 #include "GroupsockHelper.hh"
40 #include "liveMedia.hh"
44 /*****************************************************************************
46 *****************************************************************************/
47 static int DemuxOpen ( vlc_object_t * );
48 static void DemuxClose( vlc_object_t * );
50 static int AccessOpen ( vlc_object_t * );
51 static void AccessClose( vlc_object_t * );
53 #define CACHING_TEXT N_("Caching value (ms)")
54 #define CACHING_LONGTEXT N_( \
55 "Allows you to modify the default caching value for RTSP streams. This " \
56 "value should be set in miliseconds units." )
59 set_description( _("live.com (RTSP/RTP/SDP) demuxer" ) );
60 set_capability( "demux2", 50 );
61 set_callbacks( DemuxOpen, DemuxClose );
62 add_shortcut( "live" );
65 set_description( _("RTSP/RTP describe") );
66 add_shortcut( "rtsp" );
67 add_shortcut( "sdp" );
68 set_capability( "access", 0 );
69 set_callbacks( AccessOpen, AccessClose );
70 add_bool( "rtsp-tcp", 0, NULL,
71 N_("Use RTP over RTSP (TCP)"),
72 N_("Use RTP over RTSP (TCP)"), VLC_TRUE );
73 add_integer( "rtsp-caching", 4 * DEFAULT_PTS_DELAY / 1000, NULL,
74 CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
78 * - Improve support of PS/TS
79 * - Support X-QT/X-QUICKTIME generic codec for audio.
81 * - Check memory leak, delete/free -> still one when using rtsp-tcp but I'm
82 * not sure if it comes from me.
86 /*****************************************************************************
87 * Local prototypes for access
88 *****************************************************************************/
97 static ssize_t Read ( input_thread_t *, byte_t *, size_t );
98 static ssize_t MRLRead( input_thread_t *, byte_t *, size_t );
100 /*****************************************************************************
102 *****************************************************************************/
103 static int AccessOpen( vlc_object_t *p_this )
105 input_thread_t *p_input = (input_thread_t *)p_this;
108 TaskScheduler *scheduler = NULL;
109 UsageEnvironment *env = NULL;
110 RTSPClient *rtsp = NULL;
115 if( p_input->psz_access == NULL || ( strcasecmp( p_input->psz_access, "rtsp" ) && strcasecmp( p_input->psz_access, "sdp" ) ) )
117 msg_Warn( p_input, "RTSP access discarded" );
120 if( !strcasecmp( p_input->psz_access, "rtsp" ) )
122 if( ( scheduler = BasicTaskScheduler::createNew() ) == NULL )
124 msg_Err( p_input, "BasicTaskScheduler::createNew failed" );
127 if( ( env = BasicUsageEnvironment::createNew(*scheduler) ) == NULL )
130 msg_Err( p_input, "BasicUsageEnvironment::createNew failed" );
133 if( ( rtsp = RTSPClient::createNew(*env, 1/*verbose*/, "VLC Media Player" ) ) == NULL )
137 msg_Err( p_input, "RTSPClient::createNew failed" );
141 psz_url = (char*)malloc( strlen( p_input->psz_name ) + 8 );
142 sprintf( psz_url, "rtsp://%s", p_input->psz_name );
144 p_sys = (access_sys_t*)malloc( sizeof( access_sys_t ) );
145 p_sys->p_sdp = rtsp->describeURL( psz_url );
147 if( p_sys->p_sdp == NULL )
149 msg_Err( p_input, "describeURL failed (%s)", env->getResultMsg() );
158 p_sys->i_sdp = strlen( p_sys->p_sdp );
161 //fprintf( stderr, "sdp=%s\n", p_sys->p_sdp );
166 var_Create( p_input, "rtsp-tcp", VLC_VAR_BOOL|VLC_VAR_DOINHERIT );
167 var_Get( p_input, "rtsp-tcp", &val );
169 p_input->p_access_data = p_sys;
172 /* Set exported functions */
173 p_input->pf_read = Read;
174 p_input->pf_seek = NULL;
175 p_input->pf_set_program = input_SetProgram;
176 p_input->pf_set_area = NULL;
177 p_input->p_private = NULL;
179 p_input->psz_demux = "live";
181 /* Finished to set some variable */
182 vlc_mutex_lock( &p_input->stream.stream_lock );
183 /* FIXME that's not true but eg over tcp, server send data too fast */
184 p_input->stream.b_pace_control = val.b_bool;
185 p_input->stream.p_selected_area->i_tell = 0;
186 p_input->stream.b_seekable = 1; /* Hack to display time */
187 p_input->stream.p_selected_area->i_size = p_sys->i_sdp;
188 p_input->stream.i_method = INPUT_METHOD_NETWORK;
189 vlc_mutex_unlock( &p_input->stream.stream_lock );
191 /* Update default_pts to a suitable value for RTSP access */
192 var_Create( p_input, "rtsp-caching", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
193 var_Get( p_input, "rtsp-caching", &val );
194 p_input->i_pts_delay = val.i_int * 1000;
200 p_input->p_access_data = (access_sys_t*)0;
202 p_input->pf_read = MRLRead;
203 p_input->pf_seek = NULL;
204 p_input->pf_set_program = input_SetProgram;
205 p_input->pf_set_area = NULL;
206 p_input->p_private = NULL;
207 p_input->psz_demux = "live";
208 /* Finished to set some variable */
209 vlc_mutex_lock( &p_input->stream.stream_lock );
210 p_input->stream.b_pace_control = VLC_TRUE;
211 p_input->stream.p_selected_area->i_tell = 0;
212 p_input->stream.b_seekable = VLC_FALSE;
213 p_input->stream.p_selected_area->i_size = strlen(p_input->psz_name);
214 p_input->stream.i_method = INPUT_METHOD_NETWORK;
215 vlc_mutex_unlock( &p_input->stream.stream_lock );
221 /*****************************************************************************
223 *****************************************************************************/
224 static void AccessClose( vlc_object_t *p_this )
226 input_thread_t *p_input = (input_thread_t *)p_this;
227 access_sys_t *p_sys = p_input->p_access_data;
228 if( !strcasecmp( p_input->psz_access, "rtsp" ) )
230 delete[] p_sys->p_sdp;
235 /*****************************************************************************
237 *****************************************************************************/
238 static ssize_t Read ( input_thread_t *p_input, byte_t *p_buffer, size_t i_len )
240 access_sys_t *p_sys = p_input->p_access_data;
241 int i_copy = __MIN( (int)i_len, p_sys->i_sdp - p_sys->i_pos );
245 memcpy( p_buffer, &p_sys->p_sdp[p_sys->i_pos], i_copy );
246 p_sys->i_pos += i_copy;
250 /*****************************************************************************
251 * MRLRead: read data from the mrl
252 *****************************************************************************/
253 static ssize_t MRLRead ( input_thread_t *p_input, byte_t *p_buffer, size_t i_len )
255 int i_done = (int)p_input->p_access_data;
256 int i_copy = __MIN( (int)i_len, (int)strlen(p_input->psz_name) - i_done );
260 memcpy( p_buffer, &p_input->psz_name[i_done], i_copy );
262 p_input->p_access_data = (access_sys_t*)i_done;
268 /*****************************************************************************
269 * Local prototypes for demux2
270 *****************************************************************************/
275 vlc_bool_t b_quicktime;
281 stream_t *p_out_muxed; /* for muxed stream */
283 RTPSource *rtpSource;
284 FramedSource *readSource;
285 vlc_bool_t b_rtcp_sync;
287 uint8_t buffer[65536];
296 char *p_sdp; /* XXX mallocated */
299 TaskScheduler *scheduler;
300 UsageEnvironment *env ;
304 live_track_t **track; /* XXX mallocated */
314 static int Demux ( demux_t * );
315 static int Control( demux_t *, int, va_list );
317 /*****************************************************************************
319 *****************************************************************************/
320 static int DemuxOpen ( vlc_object_t *p_this )
322 demux_t *p_demux = (demux_t*)p_this;
325 MediaSubsessionIterator *iter;
326 MediaSubsession *sub;
336 /* See if it looks like a SDP
337 v, o, s fields are mandatory and in this order */
338 if( stream_Peek( p_demux->s, &p_peek, 7 ) < 7 )
340 msg_Err( p_demux, "cannot peek" );
343 if( strncmp( (char*)p_peek, "v=0\r\n", 5 ) && strncmp( (char*)p_peek, "v=0\n", 4 ) &&
344 ( strcasecmp( p_demux->psz_access, "rtsp" ) || p_peek[0] < 'a' || p_peek[0] > 'z' || p_peek[1] != '=' ) )
346 msg_Warn( p_demux, "SDP module discarded" );
350 p_demux->pf_demux = Demux;
351 p_demux->pf_control= Control;
352 p_demux->p_sys = p_sys = (demux_sys_t*)malloc( sizeof( demux_sys_t ) );
354 p_sys->scheduler = NULL;
361 p_sys->i_pcr_start = 0;
365 /* Gather the complete sdp file */
368 p_sdp = (uint8_t*)malloc( i_sdp_max );
371 int i_read = stream_Read( p_demux->s, &p_sdp[i_sdp], i_sdp_max - i_sdp - 1 );
375 msg_Err( p_demux, "failed to read SDP" );
382 if( i_read < i_sdp_max - i_sdp - 1 )
389 p_sdp = (uint8_t*)realloc( p_sdp, i_sdp_max );
391 p_sys->p_sdp = (char*)p_sdp;
393 fprintf( stderr, "sdp=%s\n", p_sys->p_sdp );
395 if( ( p_sys->scheduler = BasicTaskScheduler::createNew() ) == NULL )
397 msg_Err( p_demux, "BasicTaskScheduler::createNew failed" );
400 if( ( p_sys->env = BasicUsageEnvironment::createNew(*p_sys->scheduler) ) == NULL )
402 msg_Err( p_demux, "BasicUsageEnvironment::createNew failed" );
405 if( !strcasecmp( p_demux->psz_access, "rtsp" ) )
410 if( ( p_sys->rtsp = RTSPClient::createNew(*p_sys->env, 1/*verbose*/, "VLC Media Player" ) ) == NULL )
412 msg_Err( p_demux, "RTSPClient::createNew failed (%s)", p_sys->env->getResultMsg() );
415 psz_url = (char*)malloc( strlen( p_demux->psz_path ) + 8 );
416 sprintf( psz_url, "rtsp://%s", p_demux->psz_path );
418 psz_options = p_sys->rtsp->sendOptionsCmd( psz_url );
419 /* FIXME psz_options -> delete or free */
422 if( ( p_sys->ms = MediaSession::createNew(*p_sys->env, p_sys->p_sdp ) ) == NULL )
424 msg_Err( p_demux, "MediaSession::createNew failed" );
428 var_Create( p_demux, "rtsp-tcp", VLC_VAR_BOOL|VLC_VAR_DOINHERIT );
429 var_Get( p_demux, "rtsp-tcp", &val );
431 /* Initialise each media subsession */
432 iter = new MediaSubsessionIterator( *p_sys->ms );
433 while( ( sub = iter->next() ) != NULL )
435 unsigned int i_buffer = 0;
437 /* Value taken from mplayer */
438 if( !strcmp( sub->mediumName(), "audio" ) )
442 else if( !strcmp( sub->mediumName(), "video" ) )
451 if( !sub->initiate() )
453 msg_Warn( p_demux, "RTP subsession '%s/%s' failed(%s)", sub->mediumName(), sub->codecName(), p_sys->env->getResultMsg() );
457 int fd = sub->rtpSource()->RTPgs()->socketNum();
459 msg_Dbg( p_demux, "RTP subsession '%s/%s'", sub->mediumName(), sub->codecName() );
461 /* Increase the buffer size */
462 increaseReceiveBufferTo( *p_sys->env, fd, i_buffer );
463 /* Issue the SETUP */
466 p_sys->rtsp->setupMediaSubsession( *sub, False, val.b_bool ? True : False );
474 if( !p_sys->rtsp->playMediaSession( *p_sys->ms ) )
476 msg_Err( p_demux, "PLAY failed %s", p_sys->env->getResultMsg() );
481 /* Create all es struct */
483 while( ( sub = iter->next() ) != NULL )
487 if( sub->readSource() == NULL )
492 tk = (live_track_t*)malloc( sizeof( live_track_t ) );
493 tk->p_demux = p_demux;
496 tk->b_quicktime = VLC_FALSE;
497 tk->b_muxed = VLC_FALSE;
498 tk->b_rtcp_sync = VLC_FALSE;
499 tk->p_out_muxed = NULL;
502 /* Value taken from mplayer */
503 if( !strcmp( sub->mediumName(), "audio" ) )
505 es_format_Init( &tk->fmt, AUDIO_ES, VLC_FOURCC( 'u', 'n', 'd', 'f' ) );
506 tk->fmt.audio.i_channels = sub->numChannels();
507 tk->fmt.audio.i_rate = sub->rtpSource()->timestampFrequency();
509 if( !strcmp( sub->codecName(), "MPA" ) ||
510 !strcmp( sub->codecName(), "MPA-ROBUST" ) ||
511 !strcmp( sub->codecName(), "X-MP3-DRAFT-00" ) )
513 tk->fmt.i_codec = VLC_FOURCC( 'm', 'p', 'g', 'a' );
514 tk->fmt.audio.i_rate = 0;
516 else if( !strcmp( sub->codecName(), "AC3" ) )
518 tk->fmt.i_codec = VLC_FOURCC( 'a', '5', '2', ' ' );
519 tk->fmt.audio.i_rate = 0;
521 else if( !strcmp( sub->codecName(), "L16" ) )
523 tk->fmt.i_codec = VLC_FOURCC( 't', 'w', 'o', 's' );
524 tk->fmt.audio.i_bitspersample = 16;
526 else if( !strcmp( sub->codecName(), "L8" ) )
528 tk->fmt.i_codec = VLC_FOURCC( 'a', 'r', 'a', 'w' );
529 tk->fmt.audio.i_bitspersample = 8;
531 else if( !strcmp( sub->codecName(), "PCMU" ) )
533 tk->fmt.i_codec = VLC_FOURCC( 'u', 'l', 'a', 'w' );
535 else if( !strcmp( sub->codecName(), "PCMA" ) )
537 tk->fmt.i_codec = VLC_FOURCC( 'a', 'l', 'a', 'w' );
539 else if( !strcmp( sub->codecName(), "MP4A-LATM" ) )
541 unsigned int i_extra;
544 tk->fmt.i_codec = VLC_FOURCC( 'm', 'p', '4', 'a' );
546 if( ( p_extra = parseStreamMuxConfigStr( sub->fmtp_config(), i_extra ) ) )
548 tk->fmt.i_extra = i_extra;
549 tk->fmt.p_extra = malloc( i_extra );
550 memcpy( tk->fmt.p_extra, p_extra, i_extra );
554 else if( !strcmp( sub->codecName(), "MPEG4-GENERIC" ) )
556 unsigned int i_extra;
559 tk->fmt.i_codec = VLC_FOURCC( 'm', 'p', '4', 'a' );
561 if( ( p_extra = parseGeneralConfigStr( sub->fmtp_config(), i_extra ) ) )
563 tk->fmt.i_extra = i_extra;
564 tk->fmt.p_extra = malloc( i_extra );
565 memcpy( tk->fmt.p_extra, p_extra, i_extra );
570 else if( !strcmp( sub->mediumName(), "video" ) )
572 es_format_Init( &tk->fmt, VIDEO_ES, VLC_FOURCC( 'u', 'n', 'd', 'f' ) );
573 if( !strcmp( sub->codecName(), "MPV" ) )
575 tk->fmt.i_codec = VLC_FOURCC( 'm', 'p', 'g', 'v' );
577 else if( !strcmp( sub->codecName(), "H263" ) ||
578 !strcmp( sub->codecName(), "H263-1998" ) )
580 tk->fmt.i_codec = VLC_FOURCC( 'h', '2', '6', '3' );
582 else if( !strcmp( sub->codecName(), "H261" ) )
584 tk->fmt.i_codec = VLC_FOURCC( 'h', '2', '6', '1' );
586 else if( !strcmp( sub->codecName(), "JPEG" ) )
588 tk->fmt.i_codec = VLC_FOURCC( 'M', 'J', 'P', 'G' );
590 else if( !strcmp( sub->codecName(), "MP4V-ES" ) )
592 unsigned int i_extra;
595 tk->fmt.i_codec = VLC_FOURCC( 'm', 'p', '4', 'v' );
597 if( ( p_extra = parseGeneralConfigStr( sub->fmtp_config(), i_extra ) ) )
599 tk->fmt.i_extra = i_extra;
600 tk->fmt.p_extra = malloc( i_extra );
601 memcpy( tk->fmt.p_extra, p_extra, i_extra );
605 else if( !strcmp( sub->codecName(), "X-QT" ) || !strcmp( sub->codecName(), "X-QUICKTIME" ) )
607 tk->b_quicktime = VLC_TRUE;
609 else if( !strcmp( sub->codecName(), "MP2T" ) )
611 tk->b_muxed = VLC_TRUE;
612 tk->p_out_muxed = stream_DemuxNew( p_demux, "ts2", p_demux->out );
614 else if( !strcmp( sub->codecName(), "MP2P" ) || !strcmp( sub->codecName(), "MP1S" ) ) /* FIXME check MP1S */
616 tk->b_muxed = VLC_TRUE;
617 tk->p_out_muxed = stream_DemuxNew( p_demux, "ps2", p_demux->out );
621 if( tk->fmt.i_codec != VLC_FOURCC( 'u', 'n', 'd', 'f' ) )
623 tk->p_es = es_out_Add( p_demux->out, &tk->fmt );
626 if( tk->p_es || tk->b_quicktime || tk->b_muxed )
628 tk->readSource = sub->readSource();
629 tk->rtpSource = sub->rtpSource();
632 p_sys->track = (live_track_t**)realloc( p_sys->track, sizeof( live_track_t ) * ( p_sys->i_track + 1 ) );
633 p_sys->track[p_sys->i_track++] = tk;
643 p_sys->i_length = (mtime_t)(p_sys->ms->playEndTime() * 1000000.0);
644 if( p_sys->i_length < 0 )
648 else if( p_sys->i_length > 0 )
651 /* p_input->stream.p_selected_area->i_size = 1000;*/ /* needed for now */
654 if( p_sys->i_track <= 0 )
656 msg_Err( p_demux, "no codec supported, aborting" );
665 Medium::close( p_sys->ms );
669 Medium::close( p_sys->rtsp );
675 if( p_sys->scheduler )
677 delete p_sys->scheduler;
681 free( p_sys->p_sdp );
689 /*****************************************************************************
691 *****************************************************************************/
692 static void DemuxClose( vlc_object_t *p_this )
694 demux_t *p_demux = (demux_t*)p_this;
695 demux_sys_t *p_sys = p_demux->p_sys;
698 for( i = 0; i < p_sys->i_track; i++ )
700 live_track_t *tk = p_sys->track[i];
704 stream_DemuxDelete( tk->p_out_muxed );
711 free( p_sys->track );
714 if( p_sys->rtsp && p_sys->ms )
717 p_sys->rtsp->teardownMediaSession( *p_sys->ms );
719 Medium::close( p_sys->ms );
722 Medium::close( p_sys->rtsp );
729 if( p_sys->scheduler )
731 delete p_sys->scheduler;
735 free( p_sys->p_sdp );
741 static void StreamRead( void *p_private, unsigned int i_size, struct timeval pts );
742 static void StreamClose( void *p_private );
743 static void TaskInterrupt( void *p_private );
745 /*****************************************************************************
747 *****************************************************************************/
748 static int Demux( demux_t *p_demux )
750 demux_sys_t *p_sys = p_demux->p_sys;
756 for( i = 0; i < p_sys->i_track; i++ )
758 live_track_t *tk = p_sys->track[i];
764 else if( tk->i_pts != 0 && i_pcr > tk->i_pts )
769 if( i_pcr != p_sys->i_pcr && i_pcr > 0 )
771 p_sys->i_pcr = i_pcr;
773 es_out_Control( p_demux->out, ES_OUT_SET_PCR, i_pcr );
774 if( p_sys->i_pcr_start <= 0 || p_sys->i_pcr_start > i_pcr )
776 p_sys->i_pcr_start = i_pcr;
780 /* First warm we want to read data */
782 for( i = 0; i < p_sys->i_track; i++ )
784 live_track_t *tk = p_sys->track[i];
786 if( tk->waiting == 0 )
789 tk->readSource->getNextFrame( tk->buffer, 65536,
794 /* Create a task that will be called if we wait more than 300ms */
795 task = p_sys->scheduler->scheduleDelayedTask( 300000, TaskInterrupt, p_demux );
798 p_sys->scheduler->doEventLoop( &p_sys->event );
800 /* remove the task */
801 p_sys->scheduler->unscheduleDelayedTask( task );
803 /* Check for gap in pts value */
804 for( i = 0; i < p_sys->i_track; i++ )
806 live_track_t *tk = p_sys->track[i];
808 if( !tk->b_muxed && !tk->b_rtcp_sync && tk->rtpSource->hasBeenSynchronizedUsingRTCP() )
810 msg_Dbg( p_demux, "tk->rtpSource->hasBeenSynchronizedUsingRTCP()" );
812 es_out_Control( p_demux->out, ES_OUT_RESET_PCR );
813 tk->b_rtcp_sync = VLC_TRUE;
815 /* reset PCR and PCR start, mmh won't work well for multi-stream I fear */
817 p_sys->i_pcr_start = 0;
823 return p_demux->b_error ? 0 : 1;
826 /*****************************************************************************
828 *****************************************************************************/
829 static int Control( demux_t *p_demux, int i_query, va_list args )
831 demux_sys_t *p_sys = p_demux->p_sys;
838 pi64 = (int64_t*)va_arg( args, int64_t * );
839 *pi64 = p_sys->i_pcr - p_sys->i_pcr_start + p_sys->i_start;
842 case DEMUX_GET_LENGTH:
843 pi64 = (int64_t*)va_arg( args, int64_t * );
844 *pi64 = p_sys->i_length;
847 case DEMUX_GET_POSITION:
848 pf = (double*)va_arg( args, double* );
849 if( p_sys->i_length > 0 )
851 *pf = (double)( p_sys->i_pcr - p_sys->i_pcr_start + p_sys->i_start)/
852 (double)(p_sys->i_length);
860 case DEMUX_SET_POSITION:
864 f = (double)va_arg( args, double );
865 time = f * (double)p_sys->i_length / 1000000.0; /* in second */
867 if( p_sys->rtsp && p_sys->i_length > 0 )
869 MediaSubsessionIterator *iter = new MediaSubsessionIterator( *p_sys->ms );
870 MediaSubsession *sub;
873 while( ( sub = iter->next() ) != NULL )
875 p_sys->rtsp->playMediaSubsession( *sub, time );
878 p_sys->i_start = (mtime_t)(f * (double)p_sys->i_length);
879 p_sys->i_pcr_start = 0;
881 for( i = 0; i < p_sys->i_track; i++ )
883 p_sys->track[i]->i_pts = 0;
895 /*****************************************************************************
897 *****************************************************************************/
898 static void StreamRead( void *p_private, unsigned int i_size, struct timeval pts )
900 live_track_t *tk = (live_track_t*)p_private;
901 demux_t *p_demux = tk->p_demux;
902 demux_sys_t *p_sys = p_demux->p_sys;
905 mtime_t i_pts = (uint64_t)pts.tv_sec * UI64C(1000000) + (uint64_t)pts.tv_usec;
907 /* XXX Beurk beurk beurk Avoid having negative value XXX */
908 i_pts &= UI64C(0x00ffffffffffffff);
910 if( tk->b_quicktime && tk->p_es == NULL )
912 QuickTimeGenericRTPSource *qtRTPSource = (QuickTimeGenericRTPSource*)tk->rtpSource;
913 QuickTimeGenericRTPSource::QTState &qtState = qtRTPSource->qtState;
914 uint8_t *sdAtom = (uint8_t*)&qtState.sdAtom[4];
916 if( qtState.sdAtomSize < 16 + 32 )
923 tk->fmt.i_codec = VLC_FOURCC( sdAtom[0], sdAtom[1], sdAtom[2], sdAtom[3] );
924 tk->fmt.video.i_width = (sdAtom[28] << 8) | sdAtom[29];
925 tk->fmt.video.i_height = (sdAtom[30] << 8) | sdAtom[31];
927 tk->fmt.i_extra = qtState.sdAtomSize - 16;
928 tk->fmt.p_extra = malloc( tk->fmt.i_extra );
929 memcpy( tk->fmt.p_extra, &sdAtom[12], tk->fmt.i_extra );
931 tk->p_es = es_out_Add( p_demux->out, &tk->fmt );
935 fprintf( stderr, "StreamRead size=%d pts=%lld\n",
937 pts.tv_sec * 1000000LL + pts.tv_usec );
939 if( tk->fmt.i_codec == VLC_FOURCC('h','2','6','1') )
946 msg_Warn( p_demux, "buffer overflow" );
948 /* FIXME could i_size be > buffer size ? */
949 p_block = block_New( p_demux, i_size );
950 if( tk->fmt.i_codec == VLC_FOURCC('h','2','6','1') )
952 H261VideoRTPSource *h261Source = (H261VideoRTPSource*)tk->rtpSource;
953 uint32_t header = h261Source->lastSpecialHeader();
954 memcpy( p_block->p_buffer, &header, 4 );
955 memcpy( p_block->p_buffer + 4, tk->buffer, i_size );
959 memcpy( p_block->p_buffer, tk->buffer, i_size );
961 if( tk->rtpSource->curPacketMarkerBit() )
963 p_block->i_flags |= BLOCK_FLAG_HEADER;
965 //p_block->i_rate = p_input->stream.control.i_rate;
967 if( i_pts != tk->i_pts && !tk->b_muxed )
969 p_block->i_dts = i_pts;
970 p_block->i_pts = i_pts;
972 //fprintf( stderr, "tk -> dpts=%lld\n", i_pts - tk->i_pts );
976 stream_DemuxSend( tk->p_out_muxed, p_block );
980 es_out_Send( p_demux->out, tk->p_es, p_block );
986 /* we have read data */
989 if( i_pts > 0 && !tk->b_muxed )
995 /*****************************************************************************
997 *****************************************************************************/
998 static void StreamClose( void *p_private )
1000 live_track_t *tk = (live_track_t*)p_private;
1001 demux_t *p_demux = tk->p_demux;
1002 demux_sys_t *p_sys = p_demux->p_sys;
1004 fprintf( stderr, "StreamClose\n" );
1006 p_sys->event = 0xff;
1007 p_demux->b_error = VLC_TRUE;
1011 /*****************************************************************************
1013 *****************************************************************************/
1014 static void TaskInterrupt( void *p_private )
1016 demux_t *p_demux = (demux_t*)p_private;
1018 fprintf( stderr, "TaskInterrupt\n" );
1021 p_demux->p_sys->event = 0xff;