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 millisecond 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 );
420 delete [] psz_options;
424 if( ( p_sys->ms = MediaSession::createNew(*p_sys->env, p_sys->p_sdp ) ) == NULL )
426 msg_Err( p_demux, "MediaSession::createNew failed" );
430 var_Create( p_demux, "rtsp-tcp", VLC_VAR_BOOL|VLC_VAR_DOINHERIT );
431 var_Get( p_demux, "rtsp-tcp", &val );
433 /* Initialise each media subsession */
434 iter = new MediaSubsessionIterator( *p_sys->ms );
435 while( ( sub = iter->next() ) != NULL )
437 unsigned int i_buffer = 0;
439 /* Value taken from mplayer */
440 if( !strcmp( sub->mediumName(), "audio" ) )
444 else if( !strcmp( sub->mediumName(), "video" ) )
453 if( !sub->initiate() )
455 msg_Warn( p_demux, "RTP subsession '%s/%s' failed(%s)", sub->mediumName(), sub->codecName(), p_sys->env->getResultMsg() );
459 int fd = sub->rtpSource()->RTPgs()->socketNum();
461 msg_Dbg( p_demux, "RTP subsession '%s/%s'", sub->mediumName(), sub->codecName() );
463 /* Increase the buffer size */
464 increaseReceiveBufferTo( *p_sys->env, fd, i_buffer );
465 /* Issue the SETUP */
468 p_sys->rtsp->setupMediaSubsession( *sub, False, val.b_bool ? True : False );
476 if( !p_sys->rtsp->playMediaSession( *p_sys->ms ) )
478 msg_Err( p_demux, "PLAY failed %s", p_sys->env->getResultMsg() );
483 /* Create all es struct */
485 while( ( sub = iter->next() ) != NULL )
489 if( sub->readSource() == NULL )
494 tk = (live_track_t*)malloc( sizeof( live_track_t ) );
495 tk->p_demux = p_demux;
498 tk->b_quicktime = VLC_FALSE;
499 tk->b_muxed = VLC_FALSE;
500 tk->b_rtcp_sync = VLC_FALSE;
501 tk->p_out_muxed = NULL;
504 /* Value taken from mplayer */
505 if( !strcmp( sub->mediumName(), "audio" ) )
507 es_format_Init( &tk->fmt, AUDIO_ES, VLC_FOURCC( 'u', 'n', 'd', 'f' ) );
508 tk->fmt.audio.i_channels = sub->numChannels();
509 tk->fmt.audio.i_rate = sub->rtpSource()->timestampFrequency();
511 if( !strcmp( sub->codecName(), "MPA" ) ||
512 !strcmp( sub->codecName(), "MPA-ROBUST" ) ||
513 !strcmp( sub->codecName(), "X-MP3-DRAFT-00" ) )
515 tk->fmt.i_codec = VLC_FOURCC( 'm', 'p', 'g', 'a' );
516 tk->fmt.audio.i_rate = 0;
518 else if( !strcmp( sub->codecName(), "AC3" ) )
520 tk->fmt.i_codec = VLC_FOURCC( 'a', '5', '2', ' ' );
521 tk->fmt.audio.i_rate = 0;
523 else if( !strcmp( sub->codecName(), "L16" ) )
525 tk->fmt.i_codec = VLC_FOURCC( 't', 'w', 'o', 's' );
526 tk->fmt.audio.i_bitspersample = 16;
528 else if( !strcmp( sub->codecName(), "L8" ) )
530 tk->fmt.i_codec = VLC_FOURCC( 'a', 'r', 'a', 'w' );
531 tk->fmt.audio.i_bitspersample = 8;
533 else if( !strcmp( sub->codecName(), "PCMU" ) )
535 tk->fmt.i_codec = VLC_FOURCC( 'u', 'l', 'a', 'w' );
537 else if( !strcmp( sub->codecName(), "PCMA" ) )
539 tk->fmt.i_codec = VLC_FOURCC( 'a', 'l', 'a', 'w' );
541 else if( !strcmp( sub->codecName(), "MP4A-LATM" ) )
543 unsigned int i_extra;
546 tk->fmt.i_codec = VLC_FOURCC( 'm', 'p', '4', 'a' );
548 if( ( p_extra = parseStreamMuxConfigStr( sub->fmtp_config(), i_extra ) ) )
550 tk->fmt.i_extra = i_extra;
551 tk->fmt.p_extra = malloc( i_extra );
552 memcpy( tk->fmt.p_extra, p_extra, i_extra );
556 else if( !strcmp( sub->codecName(), "MPEG4-GENERIC" ) )
558 unsigned int i_extra;
561 tk->fmt.i_codec = VLC_FOURCC( 'm', 'p', '4', 'a' );
563 if( ( p_extra = parseGeneralConfigStr( sub->fmtp_config(), i_extra ) ) )
565 tk->fmt.i_extra = i_extra;
566 tk->fmt.p_extra = malloc( i_extra );
567 memcpy( tk->fmt.p_extra, p_extra, i_extra );
572 else if( !strcmp( sub->mediumName(), "video" ) )
574 es_format_Init( &tk->fmt, VIDEO_ES, VLC_FOURCC( 'u', 'n', 'd', 'f' ) );
575 if( !strcmp( sub->codecName(), "MPV" ) )
577 tk->fmt.i_codec = VLC_FOURCC( 'm', 'p', 'g', 'v' );
579 else if( !strcmp( sub->codecName(), "H263" ) ||
580 !strcmp( sub->codecName(), "H263-1998" ) ||
581 !strcmp( sub->codecName(), "H263-2000" ) )
583 tk->fmt.i_codec = VLC_FOURCC( 'h', '2', '6', '3' );
585 else if( !strcmp( sub->codecName(), "H261" ) )
587 tk->fmt.i_codec = VLC_FOURCC( 'h', '2', '6', '1' );
589 else if( !strcmp( sub->codecName(), "JPEG" ) )
591 tk->fmt.i_codec = VLC_FOURCC( 'M', 'J', 'P', 'G' );
593 else if( !strcmp( sub->codecName(), "MP4V-ES" ) )
595 unsigned int i_extra;
598 tk->fmt.i_codec = VLC_FOURCC( 'm', 'p', '4', 'v' );
600 if( ( p_extra = parseGeneralConfigStr( sub->fmtp_config(), i_extra ) ) )
602 tk->fmt.i_extra = i_extra;
603 tk->fmt.p_extra = malloc( i_extra );
604 memcpy( tk->fmt.p_extra, p_extra, i_extra );
608 else if( !strcmp( sub->codecName(), "X-QT" ) || !strcmp( sub->codecName(), "X-QUICKTIME" ) )
610 tk->b_quicktime = VLC_TRUE;
612 else if( !strcmp( sub->codecName(), "MP2T" ) )
614 tk->b_muxed = VLC_TRUE;
615 tk->p_out_muxed = stream_DemuxNew( p_demux, "ts2", p_demux->out );
617 else if( !strcmp( sub->codecName(), "MP2P" ) || !strcmp( sub->codecName(), "MP1S" ) )
619 tk->b_muxed = VLC_TRUE;
620 tk->p_out_muxed = stream_DemuxNew( p_demux, "ps2", p_demux->out );
624 if( tk->fmt.i_codec != VLC_FOURCC( 'u', 'n', 'd', 'f' ) )
626 tk->p_es = es_out_Add( p_demux->out, &tk->fmt );
629 if( tk->p_es || tk->b_quicktime || tk->b_muxed )
631 tk->readSource = sub->readSource();
632 tk->rtpSource = sub->rtpSource();
635 p_sys->track = (live_track_t**)realloc( p_sys->track, sizeof( live_track_t ) * ( p_sys->i_track + 1 ) );
636 p_sys->track[p_sys->i_track++] = tk;
646 p_sys->i_length = (mtime_t)(p_sys->ms->playEndTime() * 1000000.0);
647 if( p_sys->i_length < 0 )
651 else if( p_sys->i_length > 0 )
654 /* p_input->stream.p_selected_area->i_size = 1000;*/ /* needed for now */
657 if( p_sys->i_track <= 0 )
659 msg_Err( p_demux, "no codec supported, aborting" );
668 Medium::close( p_sys->ms );
672 Medium::close( p_sys->rtsp );
678 if( p_sys->scheduler )
680 delete p_sys->scheduler;
684 free( p_sys->p_sdp );
692 /*****************************************************************************
694 *****************************************************************************/
695 static void DemuxClose( vlc_object_t *p_this )
697 demux_t *p_demux = (demux_t*)p_this;
698 demux_sys_t *p_sys = p_demux->p_sys;
701 for( i = 0; i < p_sys->i_track; i++ )
703 live_track_t *tk = p_sys->track[i];
707 stream_DemuxDelete( tk->p_out_muxed );
714 free( p_sys->track );
717 if( p_sys->rtsp && p_sys->ms )
720 p_sys->rtsp->teardownMediaSession( *p_sys->ms );
722 Medium::close( p_sys->ms );
725 Medium::close( p_sys->rtsp );
732 if( p_sys->scheduler )
734 delete p_sys->scheduler;
738 free( p_sys->p_sdp );
744 static void StreamRead( void *p_private, unsigned int i_size, struct timeval pts );
745 static void StreamClose( void *p_private );
746 static void TaskInterrupt( void *p_private );
748 /*****************************************************************************
750 *****************************************************************************/
751 static int Demux( demux_t *p_demux )
753 demux_sys_t *p_sys = p_demux->p_sys;
759 for( i = 0; i < p_sys->i_track; i++ )
761 live_track_t *tk = p_sys->track[i];
767 else if( tk->i_pts != 0 && i_pcr > tk->i_pts )
772 if( i_pcr != p_sys->i_pcr && i_pcr > 0 )
774 p_sys->i_pcr = i_pcr;
776 es_out_Control( p_demux->out, ES_OUT_SET_PCR, i_pcr );
777 if( p_sys->i_pcr_start <= 0 || p_sys->i_pcr_start > i_pcr )
779 p_sys->i_pcr_start = i_pcr;
783 /* First warm we want to read data */
785 for( i = 0; i < p_sys->i_track; i++ )
787 live_track_t *tk = p_sys->track[i];
789 if( tk->waiting == 0 )
792 tk->readSource->getNextFrame( tk->buffer, 65536,
797 /* Create a task that will be called if we wait more than 300ms */
798 task = p_sys->scheduler->scheduleDelayedTask( 300000, TaskInterrupt, p_demux );
801 p_sys->scheduler->doEventLoop( &p_sys->event );
803 /* remove the task */
804 p_sys->scheduler->unscheduleDelayedTask( task );
806 /* Check for gap in pts value */
807 for( i = 0; i < p_sys->i_track; i++ )
809 live_track_t *tk = p_sys->track[i];
811 if( !tk->b_muxed && !tk->b_rtcp_sync && tk->rtpSource->hasBeenSynchronizedUsingRTCP() )
813 msg_Dbg( p_demux, "tk->rtpSource->hasBeenSynchronizedUsingRTCP()" );
815 es_out_Control( p_demux->out, ES_OUT_RESET_PCR );
816 tk->b_rtcp_sync = VLC_TRUE;
818 /* reset PCR and PCR start, mmh won't work well for multi-stream I fear */
820 p_sys->i_pcr_start = 0;
826 return p_demux->b_error ? 0 : 1;
829 /*****************************************************************************
831 *****************************************************************************/
832 static int Control( demux_t *p_demux, int i_query, va_list args )
834 demux_sys_t *p_sys = p_demux->p_sys;
841 pi64 = (int64_t*)va_arg( args, int64_t * );
842 *pi64 = p_sys->i_pcr - p_sys->i_pcr_start + p_sys->i_start;
845 case DEMUX_GET_LENGTH:
846 pi64 = (int64_t*)va_arg( args, int64_t * );
847 *pi64 = p_sys->i_length;
850 case DEMUX_GET_POSITION:
851 pf = (double*)va_arg( args, double* );
852 if( p_sys->i_length > 0 )
854 *pf = (double)( p_sys->i_pcr - p_sys->i_pcr_start + p_sys->i_start)/
855 (double)(p_sys->i_length);
863 case DEMUX_SET_POSITION:
867 f = (double)va_arg( args, double );
868 time = f * (double)p_sys->i_length / 1000000.0; /* in second */
870 if( p_sys->rtsp && p_sys->i_length > 0 )
872 MediaSubsessionIterator *iter = new MediaSubsessionIterator( *p_sys->ms );
873 MediaSubsession *sub;
876 while( ( sub = iter->next() ) != NULL )
878 p_sys->rtsp->playMediaSubsession( *sub, time );
881 p_sys->i_start = (mtime_t)(f * (double)p_sys->i_length);
882 p_sys->i_pcr_start = 0;
884 for( i = 0; i < p_sys->i_track; i++ )
886 p_sys->track[i]->i_pts = 0;
898 /*****************************************************************************
900 *****************************************************************************/
901 static void StreamRead( void *p_private, unsigned int i_size, struct timeval pts )
903 live_track_t *tk = (live_track_t*)p_private;
904 demux_t *p_demux = tk->p_demux;
905 demux_sys_t *p_sys = p_demux->p_sys;
908 mtime_t i_pts = (uint64_t)pts.tv_sec * UI64C(1000000) + (uint64_t)pts.tv_usec;
910 /* XXX Beurk beurk beurk Avoid having negative value XXX */
911 i_pts &= UI64C(0x00ffffffffffffff);
913 if( tk->b_quicktime && tk->p_es == NULL )
915 QuickTimeGenericRTPSource *qtRTPSource = (QuickTimeGenericRTPSource*)tk->rtpSource;
916 QuickTimeGenericRTPSource::QTState &qtState = qtRTPSource->qtState;
917 uint8_t *sdAtom = (uint8_t*)&qtState.sdAtom[4];
919 if( qtState.sdAtomSize < 16 + 32 )
926 tk->fmt.i_codec = VLC_FOURCC( sdAtom[0], sdAtom[1], sdAtom[2], sdAtom[3] );
927 tk->fmt.video.i_width = (sdAtom[28] << 8) | sdAtom[29];
928 tk->fmt.video.i_height = (sdAtom[30] << 8) | sdAtom[31];
930 tk->fmt.i_extra = qtState.sdAtomSize - 16;
931 tk->fmt.p_extra = malloc( tk->fmt.i_extra );
932 memcpy( tk->fmt.p_extra, &sdAtom[12], tk->fmt.i_extra );
934 tk->p_es = es_out_Add( p_demux->out, &tk->fmt );
938 fprintf( stderr, "StreamRead size=%d pts=%lld\n",
940 pts.tv_sec * 1000000LL + pts.tv_usec );
942 if( tk->fmt.i_codec == VLC_FOURCC('h','2','6','1') )
949 msg_Warn( p_demux, "buffer overflow" );
951 /* FIXME could i_size be > buffer size ? */
952 p_block = block_New( p_demux, i_size );
953 if( tk->fmt.i_codec == VLC_FOURCC('h','2','6','1') )
955 #if LIVEMEDIA_LIBRARY_VERSION_INT >= 1081468800
956 H261VideoRTPSource *h261Source = (H261VideoRTPSource*)tk->rtpSource;
957 uint32_t header = h261Source->lastSpecialHeader();
960 msg_Warn( p_demux, "need livemedia library >= \"2004.04.09\"" );
962 memcpy( p_block->p_buffer, &header, 4 );
963 memcpy( p_block->p_buffer + 4, tk->buffer, i_size );
967 memcpy( p_block->p_buffer, tk->buffer, i_size );
969 if( tk->fmt.i_codec == VLC_FOURCC('h','2','6','1') &&
970 tk->rtpSource->curPacketMarkerBit() )
972 p_block->i_flags |= BLOCK_FLAG_END_OF_FRAME;
974 //p_block->i_rate = p_input->stream.control.i_rate;
976 if( i_pts != tk->i_pts && !tk->b_muxed )
978 p_block->i_dts = i_pts;
979 p_block->i_pts = i_pts;
981 //fprintf( stderr, "tk -> dpts=%lld\n", i_pts - tk->i_pts );
985 stream_DemuxSend( tk->p_out_muxed, p_block );
989 es_out_Send( p_demux->out, tk->p_es, p_block );
995 /* we have read data */
998 if( i_pts > 0 && !tk->b_muxed )
1004 /*****************************************************************************
1006 *****************************************************************************/
1007 static void StreamClose( void *p_private )
1009 live_track_t *tk = (live_track_t*)p_private;
1010 demux_t *p_demux = tk->p_demux;
1011 demux_sys_t *p_sys = p_demux->p_sys;
1013 fprintf( stderr, "StreamClose\n" );
1015 p_sys->event = 0xff;
1016 p_demux->b_error = VLC_TRUE;
1020 /*****************************************************************************
1022 *****************************************************************************/
1023 static void TaskInterrupt( void *p_private )
1025 demux_t *p_demux = (demux_t*)p_private;
1027 fprintf( stderr, "TaskInterrupt\n" );
1030 p_demux->p_sys->event = 0xff;