1 /*****************************************************************************
2 * live555.cpp : LIVE555 Streaming Media support.
3 *****************************************************************************
4 * Copyright (C) 2003-2006 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
30 #include <vlc/input.h>
36 # include <winsock2.h>
39 #include "BasicUsageEnvironment.hh"
40 #include "GroupsockHelper.hh"
41 #include "liveMedia.hh"
44 #include "../access/mms/asf.h" /* Who said ugly ? */
47 #if (LIVEMEDIA_LIBRARY_VERSION_INT < 1089936000)
48 #define RECLAIM_ENV(env) delete (env)
50 #define RECLAIM_ENV(env) (env)->reclaim()
55 /*****************************************************************************
57 *****************************************************************************/
58 static int Open ( vlc_object_t * );
59 static void Close( vlc_object_t * );
61 #define CACHING_TEXT N_("Caching value (ms)")
62 #define CACHING_LONGTEXT N_( \
63 "Allows you to modify the default caching value for RTSP streams. This " \
64 "value should be set in millisecond units." )
66 #define KASENNA_TEXT N_( "Kasenna RTSP dialect")
67 #define KASENNA_LONGTEXT N_( "Kasenna servers use an old and unstandard " \
68 "dialect of RTSP. When you set this parameter, VLC will try this dialect "\
69 "for communication. In this mode you cannot connect to normal RTSP servers." )
71 #define USER_TEXT N_("RTSP user name")
72 #define USER_LONGTEXT N_("Allows you to modify the user name that will " \
73 "be used for authenticating the connection.")
74 #define PASS_TEXT N_("RTSP password")
75 #define PASS_LONGTEXT N_("Allows you to modify the password that will be " \
76 "used for the connection.")
79 set_description( _("RTP/RTSP/SDP demuxer (using Live555)" ) );
80 set_capability( "demux2", 50 );
81 set_shortname( "RTP/RTSP");
82 set_callbacks( Open, Close );
83 add_shortcut( "live" );
84 add_shortcut( "livedotcom" );
85 set_category( CAT_INPUT );
86 set_subcategory( SUBCAT_INPUT_DEMUX );
89 set_description( _("RTSP/RTP access and demux") );
90 add_shortcut( "rtsp" );
91 add_shortcut( "sdp" );
92 set_capability( "access_demux", 0 );
93 set_callbacks( Open, Close );
94 add_bool( "rtsp-tcp", 0, NULL,
95 N_("Use RTP over RTSP (TCP)"),
96 N_("Use RTP over RTSP (TCP)"), VLC_TRUE );
97 add_integer( "rtp-client-port", -1, NULL,
99 N_("Port to use for the RTP source of the session"), VLC_TRUE );
100 #if LIVEMEDIA_LIBRARY_VERSION_INT > 1130457500
101 add_bool( "rtsp-http", 0, NULL,
102 N_("Tunnel RTSP and RTP over HTTP"),
103 N_("Tunnel RTSP and RTP over HTTP"), VLC_TRUE );
104 add_integer( "rtsp-http-port", 80, NULL,
105 N_("HTTP tunnel port"),
106 N_("Port to use for tunneling the RTSP/RTP over HTTP."),
109 add_integer( "rtsp-caching", 4 * DEFAULT_PTS_DELAY / 1000, NULL,
110 CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
111 add_bool( "rtsp-kasenna", VLC_FALSE, NULL, KASENNA_TEXT,
112 KASENNA_LONGTEXT, VLC_TRUE );
113 add_string( "rtsp-user", NULL, NULL, USER_TEXT,
114 USER_LONGTEXT, VLC_TRUE );
115 add_string( "rtsp-pwd", NULL, NULL, PASS_TEXT,
116 PASS_LONGTEXT, VLC_TRUE );
120 * - Improve support of PS/TS
121 * - Support X-QT/X-QUICKTIME generic codec for audio.
123 * - Check memory leak, delete/free -> still one when using rtsp-tcp but I'm
124 * not sure if it comes from me.
128 /*****************************************************************************
130 *****************************************************************************/
136 vlc_bool_t b_quicktime;
143 stream_t *p_out_muxed; /* for muxed stream */
145 RTPSource *rtpSource;
146 FramedSource *readSource;
147 vlc_bool_t b_rtcp_sync;
150 unsigned int i_buffer;
158 struct timeout_thread_t
168 char *p_sdp; /* XXX mallocated */
169 char *psz_path; /* URL-encoded path */
172 TaskScheduler *scheduler;
173 UsageEnvironment *env ;
178 live_track_t **track; /* XXX mallocated */
181 mtime_t i_pcr_previous;
182 mtime_t i_pcr_repeatdate;
193 /* timeout thread information */
194 int i_timeout; /* session timeout value in seconds */
195 vlc_bool_t b_timeout_call;/* mark to send an RTSP call to prevent server timeout */
196 timeout_thread_t *p_timeout; /* the actual thread that makes sure we don't timeout */
199 vlc_bool_t b_multicast; /* true if one of the tracks is multicasted */
200 vlc_bool_t b_no_data; /* true if we never receive any data */
201 int i_no_data_ti; /* consecutive number of TaskInterrupt */
206 static int Demux ( demux_t * );
207 static int Control( demux_t *, int, va_list );
209 static int ParseASF( demux_t * );
210 static int RollOverTcp( demux_t * );
212 static void StreamRead( void *, unsigned int, unsigned int,
213 struct timeval, unsigned int );
214 static void StreamClose( void * );
215 static void TaskInterrupt( void * );
217 static void TimeoutPrevention( timeout_thread_t * );
219 #if LIVEMEDIA_LIBRARY_VERSION_INT >= 1117756800
220 static unsigned char* parseH264ConfigStr( char const* configStr,
221 unsigned int& configSize );
224 /*****************************************************************************
226 *****************************************************************************/
227 static int Open ( vlc_object_t *p_this )
229 demux_t *p_demux = (demux_t*)p_this;
230 demux_sys_t *p_sys = NULL;
232 MediaSubsessionIterator *iter;
233 MediaSubsession *sub;
235 vlc_bool_t b_rtsp_tcp;
238 char *psz_user = NULL;
239 char *psz_pwd = NULL;
247 /* See if it looks like a SDP
248 v, o, s fields are mandatory and in this order */
249 if( stream_Peek( p_demux->s, &p_peek, 7 ) < 7 ) return VLC_EGENERIC;
251 if( memcmp( (char*)p_peek, "v=0\r\n", 5 ) &&
252 memcmp( (char*)p_peek, "v=0\n", 4 ) &&
253 ( p_peek[0] < 'a' || p_peek[0] > 'z' || p_peek[1] != '=' ) )
260 var_Create( p_demux, "rtsp-caching", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
263 p_demux->pf_demux = Demux;
264 p_demux->pf_control= Control;
265 p_demux->p_sys = p_sys = (demux_sys_t*)malloc( sizeof( demux_sys_t ) );
266 if( !p_sys ) return VLC_ENOMEM;
269 p_sys->scheduler = NULL;
276 p_sys->i_pcr_start = 0;
277 p_sys->i_pcr_previous = 0;
278 p_sys->i_pcr_repeatdate = 0;
279 p_sys->i_pcr_repeats = 0;
282 p_sys->p_out_asf = NULL;
283 p_sys->b_no_data = VLC_TRUE;
284 p_sys->i_no_data_ti = 0;
285 p_sys->p_timeout = NULL;
286 p_sys->i_timeout = 0;
287 p_sys->b_timeout_call = VLC_FALSE;
288 p_sys->b_multicast = VLC_FALSE;
289 p_sys->psz_path = strdup(p_demux->psz_path);
292 if( ( p_sys->scheduler = BasicTaskScheduler::createNew() ) == NULL )
294 msg_Err( p_demux, "BasicTaskScheduler::createNew failed" );
297 if( !( p_sys->env = BasicUsageEnvironment::createNew(*p_sys->scheduler) ) )
299 msg_Err( p_demux, "BasicUsageEnvironment::createNew failed" );
303 if( strcasecmp( p_demux->psz_access, "sdp" ) )
305 char *p = p_sys->psz_path;
306 while( (p = strchr( p, ' ' )) != NULL ) *p = '+';
309 if( p_demux->s == NULL && !strcasecmp( p_demux->psz_access, "rtsp" ) )
313 #if LIVEMEDIA_LIBRARY_VERSION_INT > 1130457500
316 if( var_CreateGetBool( p_demux, "rtsp-http" ) )
317 i_http_port = var_CreateGetInteger( p_demux, "rtsp-http-port" );
319 if( ( p_sys->rtsp = RTSPClient::createNew(*p_sys->env, 1/*verbose*/,
320 "VLC media player", i_http_port ) ) == NULL )
322 if( ( p_sys->rtsp = RTSPClient::createNew(*p_sys->env, 1/*verbose*/,
323 "VLC media player" ) ) == NULL )
326 msg_Err( p_demux, "RTSPClient::createNew failed (%s)",
327 p_sys->env->getResultMsg() );
330 psz_url = (char*)malloc( strlen( p_sys->psz_path ) + 8 );
331 sprintf( psz_url, "rtsp://%s", p_sys->psz_path );
333 psz_options = p_sys->rtsp->sendOptionsCmd( psz_url );
334 if( psz_options ) delete [] psz_options;
336 psz_user = var_CreateGetString( p_demux, "rtsp-user" );
337 psz_pwd = var_CreateGetString( p_demux, "rtsp-pwd" );
339 if ((*psz_user) && (*psz_pwd))
340 p_sdp = (uint8_t*)p_sys->rtsp->describeWithPassword( psz_url,
343 p_sdp = (uint8_t*)p_sys->rtsp->describeURL( psz_url,
344 NULL, var_CreateGetBool( p_demux, "rtsp-kasenna" ) );
347 msg_Err( p_demux, "describeURL failed (%s)",
348 p_sys->env->getResultMsg() );
356 /* malloc-ated copy */
357 p_sys->p_sdp = strdup( (char*)p_sdp );
359 msg_Dbg( p_demux, "sdp=%s\n", p_sys->p_sdp );
361 else if( p_demux->s == NULL && !strcasecmp( p_demux->psz_access, "sdp" ) )
363 p_sys->p_sdp = strdup( p_sys->psz_path );
367 /* Gather the complete sdp file */
370 p_sdp = (uint8_t*)malloc( i_sdp_max );
373 int i_read = stream_Read( p_demux->s, &p_sdp[i_sdp],
374 i_sdp_max - i_sdp - 1 );
378 msg_Err( p_demux, "failed to read SDP" );
385 if( i_read < i_sdp_max - i_sdp - 1 )
392 p_sdp = (uint8_t*)realloc( p_sdp, i_sdp_max );
394 p_sys->p_sdp = (char*)p_sdp;
396 msg_Dbg( p_demux, "sdp=%s\n", p_sys->p_sdp );
398 if( !( p_sys->ms = MediaSession::createNew( *p_sys->env, p_sys->p_sdp ) ) )
400 msg_Err( p_demux, "MediaSession::createNew failed" );
404 b_rtsp_tcp = var_CreateGetBool( p_demux, "rtsp-tcp" );
406 /* Initialise each media subsession */
407 iter = new MediaSubsessionIterator( *p_sys->ms );
408 while( ( sub = iter->next() ) != NULL )
410 unsigned int i_buffer = 0;
414 i_client_port = var_CreateGetInteger( p_demux, "rtp-client-port" );
415 if( i_client_port != -1 )
416 sub->setClientPortNum( i_client_port );
418 /* Value taken from mplayer */
419 if( !strcmp( sub->mediumName(), "audio" ) )
421 else if( !strcmp( sub->mediumName(), "video" ) )
426 if( !strcmp( sub->codecName(), "X-ASF-PF" ) )
427 bInit = sub->initiate( 4 ); /* Constant ? */
429 bInit = sub->initiate();
431 if( strcasestr( sub->codecName(), "REAL" ) )
433 msg_Info( p_demux, "real codec detected, using real-RTSP instead" );
440 msg_Warn( p_demux, "RTP subsession '%s/%s' failed (%s)",
441 sub->mediumName(), sub->codecName(),
442 p_sys->env->getResultMsg() );
446 if( sub->rtpSource() )
448 int fd = sub->rtpSource()->RTPgs()->socketNum();
449 /* Increase the buffer size */
450 increaseReceiveBufferTo( *p_sys->env, fd, i_buffer );
453 msg_Dbg( p_demux, "RTP subsession '%s/%s'", sub->mediumName(),
456 /* Issue the SETUP */
459 p_sys->rtsp->setupMediaSubsession( *sub, False,
460 b_rtsp_tcp ? True : False );
462 if( !p_sys->b_multicast )
464 /* Check, because we need diff. rollover behaviour for multicast */
465 p_sys->b_multicast = IsMulticastAddress( sub->connectionEndpointAddress() );
473 if( !p_sys->rtsp->playMediaSession( *p_sys->ms ) )
475 msg_Err( p_demux, "PLAY failed %s", p_sys->env->getResultMsg() );
480 /* Retrieve the timeout value and set up a timeout prevention thread */
481 #if LIVEMEDIA_LIBRARY_VERSION_INT >= 1138089600
482 p_sys->i_timeout = p_sys->rtsp->sessionTimeoutParameter();
484 if( p_sys->i_timeout > 0 )
486 msg_Dbg( p_demux, "We have a timeout of %d seconds", p_sys->i_timeout );
487 p_sys->p_timeout = (timeout_thread_t *)vlc_object_create( p_demux, sizeof(timeout_thread_t) );
488 p_sys->p_timeout->p_sys = p_demux->p_sys; /* lol, object recursion :D */
489 if( vlc_thread_create( p_sys->p_timeout, "liveMedia-timeout", TimeoutPrevention,
490 VLC_THREAD_PRIORITY_LOW, VLC_TRUE ) )
492 msg_Err( p_demux, "cannot spawn liveMedia timeout thread" );
494 vlc_object_destroy( p_sys->p_timeout );
497 msg_Dbg( p_demux, "spawned timeout thread" );
498 vlc_object_attach( p_sys->p_timeout, p_demux );
502 /* Create all es struct */
504 while( ( sub = iter->next() ) != NULL )
508 if( sub->readSource() == NULL ) continue;
510 tk = (live_track_t*)malloc( sizeof( live_track_t ) );
511 tk->p_demux = p_demux;
514 tk->b_quicktime = VLC_FALSE;
515 tk->b_muxed = VLC_FALSE;
516 tk->b_asf = VLC_FALSE;
517 tk->b_rtcp_sync = VLC_FALSE;
518 tk->p_out_muxed = NULL;
520 tk->i_buffer = 65536;
521 tk->p_buffer = (uint8_t *)malloc( 65536 );
523 /* Value taken from mplayer */
524 if( !strcmp( sub->mediumName(), "audio" ) )
526 es_format_Init( &tk->fmt, AUDIO_ES, VLC_FOURCC('u','n','d','f') );
527 tk->fmt.audio.i_channels = sub->numChannels();
528 tk->fmt.audio.i_rate = sub->rtpTimestampFrequency();
530 if( !strcmp( sub->codecName(), "MPA" ) ||
531 !strcmp( sub->codecName(), "MPA-ROBUST" ) ||
532 !strcmp( sub->codecName(), "X-MP3-DRAFT-00" ) )
534 tk->fmt.i_codec = VLC_FOURCC( 'm', 'p', 'g', 'a' );
535 tk->fmt.audio.i_rate = 0;
537 else if( !strcmp( sub->codecName(), "AC3" ) )
539 tk->fmt.i_codec = VLC_FOURCC( 'a', '5', '2', ' ' );
540 tk->fmt.audio.i_rate = 0;
542 else if( !strcmp( sub->codecName(), "L16" ) )
544 tk->fmt.i_codec = VLC_FOURCC( 't', 'w', 'o', 's' );
545 tk->fmt.audio.i_bitspersample = 16;
547 else if( !strcmp( sub->codecName(), "L8" ) )
549 tk->fmt.i_codec = VLC_FOURCC( 'a', 'r', 'a', 'w' );
550 tk->fmt.audio.i_bitspersample = 8;
552 else if( !strcmp( sub->codecName(), "PCMU" ) )
554 tk->fmt.i_codec = VLC_FOURCC( 'u', 'l', 'a', 'w' );
556 else if( !strcmp( sub->codecName(), "PCMA" ) )
558 tk->fmt.i_codec = VLC_FOURCC( 'a', 'l', 'a', 'w' );
560 else if( !strncmp( sub->codecName(), "G726", 4 ) )
562 tk->fmt.i_codec = VLC_FOURCC( 'g', '7', '2', '6' );
563 tk->fmt.audio.i_rate = 8000;
564 tk->fmt.audio.i_channels = 1;
565 if( !strcmp( sub->codecName()+5, "40" ) )
566 tk->fmt.i_bitrate = 40000;
567 else if( !strcmp( sub->codecName()+5, "32" ) )
568 tk->fmt.i_bitrate = 32000;
569 else if( !strcmp( sub->codecName()+5, "24" ) )
570 tk->fmt.i_bitrate = 24000;
571 else if( !strcmp( sub->codecName()+5, "16" ) )
572 tk->fmt.i_bitrate = 16000;
574 else if( !strcmp( sub->codecName(), "AMR" ) )
576 tk->fmt.i_codec = VLC_FOURCC( 's', 'a', 'm', 'r' );
578 else if( !strcmp( sub->codecName(), "AMR-WB" ) )
580 tk->fmt.i_codec = VLC_FOURCC( 's', 'a', 'w', 'b' );
582 else if( !strcmp( sub->codecName(), "MP4A-LATM" ) )
584 unsigned int i_extra;
587 tk->fmt.i_codec = VLC_FOURCC( 'm', 'p', '4', 'a' );
589 if( ( p_extra = parseStreamMuxConfigStr( sub->fmtp_config(),
592 tk->fmt.i_extra = i_extra;
593 tk->fmt.p_extra = malloc( i_extra );
594 memcpy( tk->fmt.p_extra, p_extra, i_extra );
598 #if LIVEMEDIA_LIBRARY_VERSION_INT >= 1141257600
599 /* Because the "faad" decoder does not handle the LATM data length field
600 at the start of each returned LATM frame, tell the RTP source to omit it. */
601 ((MPEG4LATMAudioRTPSource*)sub->rtpSource())->omitLATMDataLengthField();
604 else if( !strcmp( sub->codecName(), "MPEG4-GENERIC" ) )
606 unsigned int i_extra;
609 tk->fmt.i_codec = VLC_FOURCC( 'm', 'p', '4', 'a' );
611 if( ( p_extra = parseGeneralConfigStr( sub->fmtp_config(),
614 tk->fmt.i_extra = i_extra;
615 tk->fmt.p_extra = malloc( i_extra );
616 memcpy( tk->fmt.p_extra, p_extra, i_extra );
620 else if( !strcmp( sub->codecName(), "X-ASF-PF" ) )
622 tk->b_asf = VLC_TRUE;
623 if( p_sys->p_out_asf == NULL )
624 p_sys->p_out_asf = stream_DemuxNew( p_demux, "asf",
628 else if( !strcmp( sub->mediumName(), "video" ) )
630 es_format_Init( &tk->fmt, VIDEO_ES, VLC_FOURCC('u','n','d','f') );
631 if( !strcmp( sub->codecName(), "MPV" ) )
633 tk->fmt.i_codec = VLC_FOURCC( 'm', 'p', 'g', 'v' );
635 else if( !strcmp( sub->codecName(), "H263" ) ||
636 !strcmp( sub->codecName(), "H263-1998" ) ||
637 !strcmp( sub->codecName(), "H263-2000" ) )
639 tk->fmt.i_codec = VLC_FOURCC( 'H', '2', '6', '3' );
641 else if( !strcmp( sub->codecName(), "H261" ) )
643 tk->fmt.i_codec = VLC_FOURCC( 'H', '2', '6', '1' );
645 else if( !strcmp( sub->codecName(), "H264" ) )
647 #if LIVEMEDIA_LIBRARY_VERSION_INT >= 1117756800
648 unsigned int i_extra = 0;
649 uint8_t *p_extra = NULL;
651 tk->fmt.i_codec = VLC_FOURCC( 'H', '2', '6', '4' );
652 tk->fmt.b_packetized = VLC_FALSE;
654 /* XXX not the right minimal version I fear */
655 #if LIVEMEDIA_LIBRARY_VERSION_INT >= 1117756800
656 if((p_extra=parseH264ConfigStr( sub->fmtp_spropparametersets(),
659 tk->fmt.i_extra = i_extra;
660 tk->fmt.p_extra = malloc( i_extra );
661 memcpy( tk->fmt.p_extra, p_extra, i_extra );
667 else if( !strcmp( sub->codecName(), "JPEG" ) )
669 tk->fmt.i_codec = VLC_FOURCC( 'M', 'J', 'P', 'G' );
671 else if( !strcmp( sub->codecName(), "MP4V-ES" ) )
673 unsigned int i_extra;
676 tk->fmt.i_codec = VLC_FOURCC( 'm', 'p', '4', 'v' );
678 if( ( p_extra = parseGeneralConfigStr( sub->fmtp_config(),
681 tk->fmt.i_extra = i_extra;
682 tk->fmt.p_extra = malloc( i_extra );
683 memcpy( tk->fmt.p_extra, p_extra, i_extra );
687 else if( !strcmp( sub->codecName(), "X-QT" ) ||
688 !strcmp( sub->codecName(), "X-QUICKTIME" ) ||
689 !strcmp( sub->codecName(), "X-QDM" ) ||
690 !strcmp( sub->codecName(), "X-SV3V-ES" ) ||
691 !strcmp( sub->codecName(), "X-SORENSONVIDEO" ) )
693 tk->b_quicktime = VLC_TRUE;
695 else if( !strcmp( sub->codecName(), "MP2T" ) )
697 tk->b_muxed = VLC_TRUE;
698 tk->p_out_muxed = stream_DemuxNew( p_demux, "ts", p_demux->out );
700 else if( !strcmp( sub->codecName(), "MP2P" ) ||
701 !strcmp( sub->codecName(), "MP1S" ) )
703 tk->b_muxed = VLC_TRUE;
704 tk->p_out_muxed = stream_DemuxNew( p_demux, "ps",
707 else if( !strcmp( sub->codecName(), "X-ASF-PF" ) )
709 tk->b_asf = VLC_TRUE;
710 if( p_sys->p_out_asf == NULL )
711 p_sys->p_out_asf = stream_DemuxNew( p_demux, "asf",
716 tk->p_es = es_out_Add( p_demux->out, &tk->fmt );
718 if( sub->rtcpInstance() != NULL )
720 sub->rtcpInstance()->setByeHandler( StreamClose, tk );
723 if( tk->p_es || tk->b_quicktime || tk->b_muxed || tk->b_asf )
725 tk->readSource = sub->readSource();
726 tk->rtpSource = sub->rtpSource();
729 p_sys->track = (live_track_t**)realloc( p_sys->track, sizeof( live_track_t ) * ( p_sys->i_track + 1 ) );
730 p_sys->track[p_sys->i_track++] = tk;
740 if( p_sys->p_out_asf && ParseASF( p_demux ) )
742 msg_Err( p_demux, "cannot find a usable asf header" );
743 /* TODO Clean tracks */
747 p_sys->i_length = (mtime_t)(p_sys->ms->playEndTime() * 1000000.0);
748 if( p_sys->i_length < 0 )
752 else if( p_sys->i_length > 0 )
755 /* p_input->stream.p_selected_area->i_size = 1000;*/ /* needed for now */
758 if( p_sys->i_track <= 0 )
760 msg_Err( p_demux, "no codec supported, aborting" );
767 if( p_sys->p_out_asf ) stream_DemuxDelete( p_sys->p_out_asf );
768 if( p_sys->ms ) Medium::close( p_sys->ms );
769 if( p_sys->rtsp ) Medium::close( p_sys->rtsp );
770 if( p_sys->env ) RECLAIM_ENV(p_sys->env);
771 if( p_sys->p_timeout )
773 p_sys->p_timeout->b_die = VLC_TRUE;
774 vlc_thread_join( p_sys->p_timeout );
775 vlc_object_detach( p_sys->p_timeout );
776 vlc_object_destroy( p_sys->p_timeout );
778 if( p_sys->scheduler ) delete p_sys->scheduler;
779 if( p_sys->p_sdp ) free( p_sys->p_sdp );
780 if( p_sys->psz_path ) free( p_sys->psz_path );
786 /*****************************************************************************
788 *****************************************************************************/
789 static void Close( vlc_object_t *p_this )
791 demux_t *p_demux = (demux_t*)p_this;
792 demux_sys_t *p_sys = p_demux->p_sys;
795 for( i = 0; i < p_sys->i_track; i++ )
797 live_track_t *tk = p_sys->track[i];
799 if( tk->b_muxed ) stream_DemuxDelete( tk->p_out_muxed );
800 free( tk->p_buffer );
804 if( p_sys->i_track ) free( p_sys->track );
805 if( p_sys->p_out_asf ) stream_DemuxDelete( p_sys->p_out_asf );
807 if( p_sys->rtsp && p_sys->ms )
810 p_sys->rtsp->teardownMediaSession( *p_sys->ms );
813 Medium::close( p_sys->ms );
815 if( p_sys->p_timeout )
817 p_sys->p_timeout->b_die = VLC_TRUE;
818 vlc_thread_join( p_sys->p_timeout );
819 vlc_object_detach( p_sys->p_timeout );
820 vlc_object_destroy( p_sys->p_timeout );
823 if( p_sys->rtsp ) Medium::close( p_sys->rtsp );
824 if( p_sys->env ) RECLAIM_ENV(p_sys->env);
825 if( p_sys->scheduler ) delete p_sys->scheduler;
826 if( p_sys->p_sdp ) free( p_sys->p_sdp );
827 if( p_sys->psz_path ) free( p_sys->psz_path );
831 /*****************************************************************************
833 *****************************************************************************/
834 static int Demux( demux_t *p_demux )
836 demux_sys_t *p_sys = p_demux->p_sys;
839 vlc_bool_t b_send_pcr = VLC_TRUE;
843 /* Check if we need to send the server a Keep-A-Live signal */
844 if( p_sys->b_timeout_call && p_sys->rtsp && p_sys->ms )
846 #if LIVEMEDIA_LIBRARY_VERSION_INT >= 1138089600
847 char *psz_bye = NULL;
848 p_sys->rtsp->getMediaSessionParameter( *p_sys->ms, NULL, psz_bye );
850 p_sys->b_timeout_call = VLC_FALSE;
853 for( i = 0; i < p_sys->i_track; i++ )
855 live_track_t *tk = p_sys->track[i];
857 if( tk->b_asf || tk->b_muxed )
858 b_send_pcr = VLC_FALSE;
864 else if( tk->i_pts != 0 && i_pcr > tk->i_pts )
869 if( i_pcr != p_sys->i_pcr && i_pcr > 0 )
871 p_sys->i_pcr = i_pcr;
874 es_out_Control( p_demux->out, ES_OUT_SET_PCR, i_pcr );
875 if( p_sys->i_pcr_start <= 0 || p_sys->i_pcr_start > i_pcr ||
876 ( p_sys->i_length > 0 && i_pcr - p_sys->i_pcr_start > p_sys->i_length ) )
878 p_sys->i_pcr_start = i_pcr;
882 /* When a On Demand QT stream ends, the last frame keeps going with the same PCR/PTS value */
883 /* This tests for that, so we can later decide to end this session */
884 if( i_pcr > 0 && p_sys->i_pcr == p_sys->i_pcr_previous )
886 if( p_sys->i_pcr_repeats == 0 )
887 p_sys->i_pcr_repeatdate = mdate();
888 p_sys->i_pcr_repeats++;
892 p_sys->i_pcr_previous = p_sys->i_pcr;
893 p_sys->i_pcr_repeatdate = 0;
894 p_sys->i_pcr_repeats = 0;
897 if( p_sys->i_pcr_repeats > 5 && mdate() > p_sys->i_pcr_repeatdate + 1000000 )
899 /* We need at least 5 repeats over at least a second of time before we EOF */
900 msg_Dbg( p_demux, "suspect EOF due to end of VoD session" );
904 /* First warm we want to read data */
906 for( i = 0; i < p_sys->i_track; i++ )
908 live_track_t *tk = p_sys->track[i];
910 if( tk->waiting == 0 )
913 tk->readSource->getNextFrame( tk->p_buffer, tk->i_buffer,
914 StreamRead, tk, StreamClose, tk );
917 /* Create a task that will be called if we wait more than 300ms */
918 task = p_sys->scheduler->scheduleDelayedTask( 300000, TaskInterrupt, p_demux );
921 p_sys->scheduler->doEventLoop( &p_sys->event );
923 /* remove the task */
924 p_sys->scheduler->unscheduleDelayedTask( task );
926 /* Check for gap in pts value */
927 for( i = 0; i < p_sys->i_track; i++ )
929 live_track_t *tk = p_sys->track[i];
931 if( !tk->b_muxed && !tk->b_rtcp_sync &&
932 tk->rtpSource && tk->rtpSource->hasBeenSynchronizedUsingRTCP() )
934 msg_Dbg( p_demux, "tk->rtpSource->hasBeenSynchronizedUsingRTCP()" );
936 es_out_Control( p_demux->out, ES_OUT_RESET_PCR );
937 tk->b_rtcp_sync = VLC_TRUE;
939 /* reset PCR and PCR start, mmh won't work well for multi-stream I fear */
941 p_sys->i_pcr_start = 0;
947 if( p_sys->b_multicast && p_sys->b_no_data && p_sys->i_no_data_ti > 120 )
949 /* FIXME Make this configurable
950 msg_Err( p_demux, "no multicast data received in 36s, aborting" );
954 else if( !p_sys->b_multicast && p_sys->b_no_data && p_sys->i_no_data_ti > 34 )
956 vlc_bool_t b_rtsp_tcp = var_GetBool( p_demux, "rtsp-tcp" );
958 if( !b_rtsp_tcp && p_sys->rtsp && p_sys->ms )
960 msg_Warn( p_demux, "no data received in 10s. Switching to TCP" );
961 if( RollOverTcp( p_demux ) )
963 msg_Err( p_demux, "TCP rollover failed, aborting" );
966 var_SetBool( p_demux, "rtsp-tcp", VLC_TRUE );
968 else if( p_sys->i_no_data_ti > 34 )
970 msg_Err( p_demux, "no data received in 10s, aborting" );
974 else if( !p_sys->b_multicast && p_sys->b_no_data&& p_sys->i_no_data_ti > 34 )
977 msg_Warn( p_demux, "no data received in 10s, eof ?" );
981 return p_demux->b_error ? 0 : 1;
984 /*****************************************************************************
986 *****************************************************************************/
987 static int Control( demux_t *p_demux, int i_query, va_list args )
989 demux_sys_t *p_sys = p_demux->p_sys;
992 vlc_bool_t *pb, b_bool;
997 pi64 = (int64_t*)va_arg( args, int64_t * );
998 *pi64 = p_sys->i_pcr - p_sys->i_pcr_start + p_sys->i_start;
1001 case DEMUX_GET_LENGTH:
1002 pi64 = (int64_t*)va_arg( args, int64_t * );
1003 *pi64 = p_sys->i_length;
1006 case DEMUX_GET_POSITION:
1007 pf = (double*)va_arg( args, double* );
1008 if( p_sys->i_length > 0 )
1010 *pf = (double)( p_sys->i_pcr - p_sys->i_pcr_start +
1011 p_sys->i_start ) / (double)(p_sys->i_length);
1019 case DEMUX_SET_POSITION:
1023 f = (double)va_arg( args, double );
1024 time = f * (double)p_sys->i_length / 1000000.0; /* in second */
1026 if( p_sys->rtsp && p_sys->i_length > 0 )
1028 if( !p_sys->rtsp->playMediaSession( *p_sys->ms, time ) )
1030 msg_Err( p_demux, "PLAY failed %s",
1031 p_sys->env->getResultMsg() );
1032 return VLC_EGENERIC;
1034 p_sys->i_start = (mtime_t)(f * (double)p_sys->i_length);
1035 p_sys->i_pcr_start = 0;
1043 /* Special for access_demux */
1044 case DEMUX_CAN_PAUSE:
1045 pb = (vlc_bool_t*)va_arg( args, vlc_bool_t * );
1046 if( p_sys->rtsp && p_sys->i_length )
1047 /* Not always true, but will be handled in SET_PAUSE_STATE */
1053 case DEMUX_CAN_CONTROL_PACE:
1054 pb = (vlc_bool_t*)va_arg( args, vlc_bool_t * );
1056 #if 0 /* Disable for now until we have a clock synchro algo
1057 * which works with something else than MPEG over UDP */
1064 case DEMUX_SET_PAUSE_STATE:
1067 d_npt = ( (double)( p_sys->i_pcr - p_sys->i_pcr_start +
1068 p_sys->i_start ) ) / 1000000.00;
1070 b_bool = (vlc_bool_t)va_arg( args, vlc_bool_t );
1071 if( p_sys->rtsp == NULL )
1072 return VLC_EGENERIC;
1074 if( ( b_bool && !p_sys->rtsp->pauseMediaSession( *p_sys->ms ) ) ||
1075 ( !b_bool && !p_sys->rtsp->playMediaSession( *p_sys->ms,
1076 d_npt > 0 ? d_npt : -1 ) ) )
1078 msg_Err( p_demux, "PLAY or PAUSE failed %s", p_sys->env->getResultMsg() );
1079 return VLC_EGENERIC;
1082 /* reset PCR and PCR start, mmh won't work well for multi-stream I fear */
1083 for( i = 0; i < p_sys->i_track; i++ )
1085 p_sys->track[i]->i_pts = 0;
1087 p_sys->i_pcr_start = 0; /* FIXME Wrong */
1092 case DEMUX_GET_TITLE_INFO:
1093 case DEMUX_SET_TITLE:
1094 case DEMUX_SET_SEEKPOINT:
1095 return VLC_EGENERIC;
1097 case DEMUX_GET_PTS_DELAY:
1098 pi64 = (int64_t*)va_arg( args, int64_t * );
1099 *pi64 = (int64_t)var_GetInteger( p_demux, "rtsp-caching" ) * 1000;
1103 return VLC_EGENERIC;
1107 /*****************************************************************************
1108 * RollOverTcp: reopen the rtsp into TCP mode
1109 * XXX: ugly, a lot of code are duplicated from Open()
1110 *****************************************************************************/
1111 static int RollOverTcp( demux_t *p_demux )
1113 demux_sys_t *p_sys = p_demux->p_sys;
1114 MediaSubsessionIterator *iter;
1115 MediaSubsession *sub;
1123 /* We close the old RTSP session */
1124 p_sys->rtsp->teardownMediaSession( *p_sys->ms );
1126 Medium::close( p_sys->ms );
1127 Medium::close( p_sys->rtsp );
1132 /* Reopen rtsp client */
1133 if( ( p_sys->rtsp = RTSPClient::createNew(*p_sys->env, 1/*verbose*/,
1134 "VLC media player" ) ) == NULL )
1136 msg_Err( p_demux, "RTSPClient::createNew failed (%s)",
1137 p_sys->env->getResultMsg() );
1138 return VLC_EGENERIC;
1141 asprintf( &psz_url, "rtsp://%s", p_sys->psz_path );
1143 if( ( psz_options = p_sys->rtsp->sendOptionsCmd( psz_url ) ) )
1144 delete [] psz_options;
1146 psz_user = var_CreateGetString( p_demux, "rtsp-user" );
1147 psz_pwd = var_CreateGetString( p_demux, "rtsp-pwd" );
1149 if ((*psz_user) && (*psz_pwd))
1150 p_sdp = (uint8_t*)p_sys->rtsp->describeWithPassword( psz_url,
1153 p_sdp = (uint8_t*)p_sys->rtsp->describeURL( psz_url,
1154 NULL, var_CreateGetBool( p_demux, "rtsp-kasenna" ) );
1162 msg_Err( p_demux, "describeURL failed (%s)",
1163 p_sys->env->getResultMsg() );
1164 return VLC_EGENERIC;
1167 /* malloc-ated copy */
1168 p_sys->p_sdp = strdup( (char*)p_sdp );
1171 if( !( p_sys->ms = MediaSession::createNew( *p_sys->env, p_sys->p_sdp ) ) )
1173 msg_Err( p_demux, "MediaSession::createNew failed" );
1174 return VLC_EGENERIC;
1177 /* Initialise each media subsession */
1178 iter = new MediaSubsessionIterator( *p_sys->ms );
1179 while( ( sub = iter->next() ) != NULL )
1183 if( !strcmp( sub->codecName(), "X-ASF-PF" ) )
1184 bInit = sub->initiate( 4 ); /* Constant ? */
1186 bInit = sub->initiate();
1190 msg_Warn( p_demux, "RTP subsession '%s/%s' failed (%s)",
1191 sub->mediumName(), sub->codecName(),
1192 p_sys->env->getResultMsg() );
1195 msg_Dbg( p_demux, "RTP subsession '%s/%s'", sub->mediumName(),
1198 /* Issue the SETUP */
1199 p_sys->rtsp->setupMediaSubsession( *sub, False, True /* tcp */ );
1203 if( !p_sys->rtsp->playMediaSession( *p_sys->ms ) )
1205 msg_Err( p_demux, "PLAY failed %s", p_sys->env->getResultMsg() );
1206 return VLC_EGENERIC;
1209 /* Update all tracks */
1212 while( ( sub = iter->next() ) != NULL )
1216 if( sub->readSource() == NULL )
1218 if( i_tk >= p_sys->i_track )
1220 msg_Err( p_demux, "WTF !" );
1224 tk = p_sys->track[i_tk];
1229 tk->b_rtcp_sync = VLC_FALSE;
1231 if( sub->rtcpInstance() != NULL )
1232 sub->rtcpInstance()->setByeHandler( StreamClose, tk );
1234 tk->readSource = sub->readSource();
1235 tk->rtpSource = sub->rtpSource();
1246 /*****************************************************************************
1248 *****************************************************************************/
1249 static void StreamRead( void *p_private, unsigned int i_size,
1250 unsigned int i_truncated_bytes, struct timeval pts,
1251 unsigned int duration )
1253 live_track_t *tk = (live_track_t*)p_private;
1254 demux_t *p_demux = tk->p_demux;
1255 demux_sys_t *p_sys = p_demux->p_sys;
1258 mtime_t i_pts = (uint64_t)pts.tv_sec * UI64C(1000000) +
1259 (uint64_t)pts.tv_usec;
1261 /* XXX Beurk beurk beurk Avoid having negative value XXX */
1262 i_pts &= UI64C(0x00ffffffffffffff);
1264 if( tk->b_quicktime && tk->p_es == NULL )
1266 QuickTimeGenericRTPSource *qtRTPSource =
1267 (QuickTimeGenericRTPSource*)tk->rtpSource;
1268 QuickTimeGenericRTPSource::QTState &qtState = qtRTPSource->qtState;
1269 uint8_t *sdAtom = (uint8_t*)&qtState.sdAtom[4];
1271 if( qtState.sdAtomSize < 16 + 32 )
1274 p_sys->event = 0xff;
1278 tk->fmt.i_codec = VLC_FOURCC(sdAtom[0],sdAtom[1],sdAtom[2],sdAtom[3]);
1279 tk->fmt.video.i_width = (sdAtom[28] << 8) | sdAtom[29];
1280 tk->fmt.video.i_height = (sdAtom[30] << 8) | sdAtom[31];
1282 tk->fmt.i_extra = qtState.sdAtomSize - 16;
1283 tk->fmt.p_extra = malloc( tk->fmt.i_extra );
1284 memcpy( tk->fmt.p_extra, &sdAtom[12], tk->fmt.i_extra );
1286 tk->p_es = es_out_Add( p_demux->out, &tk->fmt );
1290 fprintf( stderr, "StreamRead size=%d pts=%lld\n",
1292 pts.tv_sec * 1000000LL + pts.tv_usec );
1295 /* grow buffer if it looks like buffer is too small, but don't eat
1296 * up all the memory on strange streams */
1297 if( i_truncated_bytes > 0 && tk->i_buffer < 2000000 )
1300 msg_Dbg( p_demux, "lost %d bytes", i_truncated_bytes );
1301 msg_Dbg( p_demux, "increasing buffer size to %d", tk->i_buffer * 2 );
1303 p_tmp = realloc( tk->p_buffer, tk->i_buffer );
1306 msg_Warn( p_demux, "realloc failed" );
1310 tk->p_buffer = (uint8_t*)p_tmp;
1313 if( i_size > tk->i_buffer )
1315 msg_Warn( p_demux, "buffer overflow" );
1317 /* FIXME could i_size be > buffer size ? */
1318 if( tk->fmt.i_codec == VLC_FOURCC('s','a','m','r') ||
1319 tk->fmt.i_codec == VLC_FOURCC('s','a','w','b') )
1321 AMRAudioSource *amrSource = (AMRAudioSource*)tk->readSource;
1323 p_block = block_New( p_demux, i_size + 1 );
1324 p_block->p_buffer[0] = amrSource->lastFrameHeader();
1325 memcpy( p_block->p_buffer + 1, tk->p_buffer, i_size );
1327 else if( tk->fmt.i_codec == VLC_FOURCC('H','2','6','1') )
1329 #if LIVEMEDIA_LIBRARY_VERSION_INT >= 1081468800
1330 H261VideoRTPSource *h261Source = (H261VideoRTPSource*)tk->rtpSource;
1331 uint32_t header = h261Source->lastSpecialHeader();
1333 uint32_t header = 0;
1334 msg_Warn( p_demux, "need livemedia library >= \"2004.04.09\"" );
1336 p_block = block_New( p_demux, i_size + 4 );
1337 memcpy( p_block->p_buffer, &header, 4 );
1338 memcpy( p_block->p_buffer + 4, tk->p_buffer, i_size );
1340 if( tk->rtpSource->curPacketMarkerBit() )
1341 p_block->i_flags |= BLOCK_FLAG_END_OF_FRAME;
1343 else if( tk->fmt.i_codec == VLC_FOURCC('H','2','6','4') )
1345 if( (tk->p_buffer[0] & 0x1f) >= 24 )
1346 msg_Warn( p_demux, "unsupported NAL type for H264" );
1348 /* Normal NAL type */
1349 p_block = block_New( p_demux, i_size + 4 );
1350 p_block->p_buffer[0] = 0x00;
1351 p_block->p_buffer[1] = 0x00;
1352 p_block->p_buffer[2] = 0x00;
1353 p_block->p_buffer[3] = 0x01;
1354 memcpy( &p_block->p_buffer[4], tk->p_buffer, i_size );
1356 else if( tk->b_asf )
1358 int i_copy = __MIN( p_sys->asfh.i_min_data_packet_size, (int)i_size );
1359 p_block = block_New( p_demux, p_sys->asfh.i_min_data_packet_size );
1361 memcpy( p_block->p_buffer, tk->p_buffer, i_copy );
1365 p_block = block_New( p_demux, i_size );
1366 memcpy( p_block->p_buffer, tk->p_buffer, i_size );
1369 //p_block->i_rate = p_input->stream.control.i_rate;
1371 if( i_pts != tk->i_pts && !tk->b_muxed )
1373 p_block->i_dts = ( tk->fmt.i_cat == VIDEO_ES ) ? 0 : i_pts;
1374 p_block->i_pts = i_pts;
1379 stream_DemuxSend( tk->p_out_muxed, p_block );
1381 else if( tk->b_asf )
1383 stream_DemuxSend( p_sys->p_out_asf, p_block );
1387 es_out_Send( p_demux->out, tk->p_es, p_block );
1390 /* warm that's ok */
1391 p_sys->event = 0xff;
1393 /* we have read data */
1395 p_demux->p_sys->b_no_data = VLC_FALSE;
1396 p_demux->p_sys->i_no_data_ti = 0;
1398 if( i_pts > 0 && !tk->b_muxed )
1404 /*****************************************************************************
1406 *****************************************************************************/
1407 static void StreamClose( void *p_private )
1409 live_track_t *tk = (live_track_t*)p_private;
1410 demux_t *p_demux = tk->p_demux;
1411 demux_sys_t *p_sys = p_demux->p_sys;
1413 msg_Dbg( p_demux, "StreamClose" );
1415 p_sys->event = 0xff;
1416 p_demux->b_error = VLC_TRUE;
1420 /*****************************************************************************
1422 *****************************************************************************/
1423 static void TaskInterrupt( void *p_private )
1425 demux_t *p_demux = (demux_t*)p_private;
1427 p_demux->p_sys->i_no_data_ti++;
1430 p_demux->p_sys->event = 0xff;
1433 /*****************************************************************************
1435 *****************************************************************************/
1436 static void TimeoutPrevention( timeout_thread_t *p_timeout )
1438 p_timeout->b_die = VLC_FALSE;
1439 p_timeout->i_remain = (int64_t)p_timeout->p_sys->i_timeout -2;
1440 p_timeout->i_remain *= 1000000;
1442 vlc_thread_ready( p_timeout );
1445 while( !p_timeout->b_die )
1447 if( p_timeout->i_remain <= 0 )
1449 p_timeout->i_remain = (int64_t)p_timeout->p_sys->i_timeout -2;
1450 p_timeout->i_remain *= 1000000;
1451 p_timeout->p_sys->b_timeout_call = VLC_TRUE;
1452 msg_Dbg( p_timeout, "reset the timeout timer" );
1454 p_timeout->i_remain -= 200000;
1455 msleep( 200000 ); /* 200 ms */
1459 /*****************************************************************************
1461 *****************************************************************************/
1462 static int b64_decode( char *dest, char *src );
1464 static int ParseASF( demux_t *p_demux )
1466 demux_sys_t *p_sys = p_demux->p_sys;
1468 const char *psz_marker = "a=pgmpu:data:application/vnd.ms.wms-hdr.asfv1;base64,";
1469 char *psz_asf = strcasestr( p_sys->p_sdp, psz_marker );
1473 /* Parse the asf header */
1474 if( psz_asf == NULL )
1475 return VLC_EGENERIC;
1477 psz_asf += strlen( psz_marker );
1478 psz_asf = strdup( psz_asf ); /* Duplicate it */
1479 psz_end = strchr( psz_asf, '\n' );
1481 while( psz_end > psz_asf && ( *psz_end == '\n' || *psz_end == '\r' ) )
1484 if( psz_asf >= psz_end )
1487 return VLC_EGENERIC;
1490 /* Always smaller */
1491 p_header = block_New( p_demux, psz_end - psz_asf );
1492 p_header->i_buffer = b64_decode( (char*)p_header->p_buffer, psz_asf );
1493 //msg_Dbg( p_demux, "Size=%d Hdrb64=%s", p_header->i_buffer, psz_asf );
1494 if( p_header->i_buffer <= 0 )
1497 return VLC_EGENERIC;
1500 /* Parse it to get packet size */
1501 E_(asf_HeaderParse)( &p_sys->asfh, p_header->p_buffer, p_header->i_buffer );
1503 /* Send it to demuxer */
1504 stream_DemuxSend( p_sys->p_out_asf, p_header );
1510 #if LIVEMEDIA_LIBRARY_VERSION_INT >= 1117756800
1511 static unsigned char* parseH264ConfigStr( char const* configStr,
1512 unsigned int& configSize )
1519 if( configStr == NULL || *configStr == '\0' )
1522 psz = dup = strdup( configStr );
1524 unsigned char *cfg = new unsigned char[5 * strlen(psz)];
1527 char *p = strchr( psz, ',' );
1531 cfg[configSize++] = 0x00;
1532 cfg[configSize++] = 0x00;
1533 cfg[configSize++] = 0x00;
1534 cfg[configSize++] = 0x01;
1535 configSize += b64_decode( (char*)&cfg[configSize], psz );
1542 if( dup ) free( dup );
1547 /*char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";*/
1548 static int b64_decode( char *dest, char *src )
1550 const char *dest_start = dest;
1554 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 00-0F */
1555 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 10-1F */
1556 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63, /* 20-2F */
1557 52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1, /* 30-3F */
1558 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14, /* 40-4F */
1559 15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1, /* 50-5F */
1560 -1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40, /* 60-6F */
1561 41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1, /* 70-7F */
1562 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 80-8F */
1563 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 90-9F */
1564 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* A0-AF */
1565 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* B0-BF */
1566 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* C0-CF */
1567 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* D0-DF */
1568 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* E0-EF */
1569 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 /* F0-FF */
1572 for( i_level = 0; *src != '\0'; src++ )
1576 c = b64[(unsigned int)*src];
1588 *dest++ = ( last << 2 ) | ( ( c >> 4)&0x03 );
1592 *dest++ = ( ( last << 4 )&0xf0 ) | ( ( c >> 2 )&0x0f );
1596 *dest++ = ( ( last &0x03 ) << 6 ) | c;
1604 return dest - dest_start;