~ubuntu-branches/ubuntu/natty/vlc/natty

« back to all changes in this revision

Viewing changes to modules/stream_out/rtsp.c

  • Committer: Bazaar Package Importer
  • Author(s): Benjamin Drung
  • Date: 2010-06-25 01:09:16 UTC
  • mfrom: (1.1.30 upstream)
  • Revision ID: james.westby@ubuntu.com-20100625010916-asxhep2mutg6g6pd
Tags: 1.1.0-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - build and install the libx264 plugin
  - add Xb-Npp header to vlc package
  - Add apport hook to include more vlc dependencies in bug reports
* Drop xulrunner patches.
* Drop 502_xulrunner_191.diff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 * Copyright (C) 2003-2004 the VideoLAN team
5
5
 * Copyright © 2007 Rémi Denis-Courmont
6
6
 *
7
 
 * $Id: adb5696af5d0d283214979ac9db98c8462e47e11 $
 
7
 * $Id: a1cc95317051da7d790541f7943e66f8f86d9a59 $
8
8
 *
9
9
 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
10
10
 *
52
52
    httpd_host_t   *host;
53
53
    httpd_url_t    *url;
54
54
    char           *psz_path;
55
 
    const char     *track_fmt;
 
55
    unsigned        track_id;
56
56
    unsigned        port;
57
57
 
58
58
    int             sessionc;
84
84
    rtsp->host = NULL;
85
85
    rtsp->url = NULL;
86
86
    rtsp->psz_path = NULL;
 
87
    rtsp->track_id = 0;
87
88
    vlc_mutex_init( &rtsp->lock );
88
89
 
89
90
    rtsp->port = (url->i_port > 0) ? url->i_port : 554;
91
92
    if( rtsp->psz_path == NULL )
92
93
        goto error;
93
94
 
94
 
    assert( strlen( rtsp->psz_path ) > 0 );
95
 
    if( rtsp->psz_path[strlen( rtsp->psz_path ) - 1] == '/' )
96
 
        rtsp->track_fmt = "%strackID=%u";
97
 
    else
98
 
        rtsp->track_fmt = "%s/trackID=%u";
99
 
 
100
95
    msg_Dbg( p_stream, "RTSP stream: host %s port %d at %s",
101
96
             url->psz_host, rtsp->port, rtsp->psz_path );
102
97
 
150
145
    httpd_url_t      *url;
151
146
    const char       *dst;
152
147
    int               ttl;
 
148
    unsigned          track_id;
153
149
    uint32_t          ssrc;
154
150
    uint16_t          loport, hiport;
155
151
};
172
168
/* Unicast session track */
173
169
struct rtsp_strack_t
174
170
{
175
 
    sout_stream_id_t  *id;
 
171
    rtsp_stream_id_t  *id;
176
172
    int                fd;
177
173
    bool         playing;
178
174
};
179
175
 
180
176
 
 
177
char *RtspAppendTrackPath( rtsp_stream_id_t *id, const char *base )
 
178
{
 
179
    const char *sep = strlen( base ) > 0 && base[strlen( base ) - 1] == '/' ?
 
180
                      "" : "/";
 
181
    char *url;
 
182
 
 
183
    if( asprintf( &url, "%s%strackID=%u", base, sep, id->track_id ) == -1 )
 
184
        url = NULL;
 
185
    return url;
 
186
}
 
187
 
 
188
 
181
189
rtsp_stream_id_t *RtspAddId( rtsp_stream_t *rtsp, sout_stream_id_t *sid,
182
 
                             unsigned num, uint32_t ssrc,
 
190
                             uint32_t ssrc,
183
191
                             /* Multicast stuff - TODO: cleanup */
184
192
                             const char *dst, int ttl,
185
193
                             unsigned loport, unsigned hiport )
186
194
{
187
 
    char urlbuf[sizeof( "/trackID=123" ) + strlen( rtsp->psz_path )];
 
195
    char *urlbuf;
188
196
    rtsp_stream_id_t *id = malloc( sizeof( *id ) );
189
197
    httpd_url_t *url;
190
198
 
193
201
 
194
202
    id->stream = rtsp;
195
203
    id->sout_id = sid;
 
204
    id->track_id = rtsp->track_id;
196
205
    id->ssrc = ssrc;
197
206
    /* TODO: can we assume that this need not be strdup'd? */
198
207
    id->dst = dst;
203
212
        id->hiport = hiport;
204
213
    }
205
214
 
206
 
    /* FIXME: num screws up if any ES has been removed and re-added */
207
 
    snprintf( urlbuf, sizeof( urlbuf ), rtsp->track_fmt, rtsp->psz_path,
208
 
              num );
 
215
    urlbuf = RtspAppendTrackPath( id, rtsp->psz_path );
 
216
    if( urlbuf == NULL )
 
217
    {
 
218
        free( id );
 
219
        return NULL;
 
220
    }
 
221
 
209
222
    msg_Dbg( rtsp->owner, "RTSP: adding %s", urlbuf );
210
223
    url = id->url = httpd_UrlNewUnique( rtsp->host, urlbuf, NULL, NULL, NULL );
 
224
    free( urlbuf );
211
225
 
212
226
    if( url == NULL )
213
227
    {
222
236
    httpd_UrlCatch( url, HTTPD_MSG_GETPARAMETER, RtspCallbackId, (void *)id );
223
237
    httpd_UrlCatch( url, HTTPD_MSG_TEARDOWN, RtspCallbackId, (void *)id );
224
238
 
 
239
    rtsp->track_id++;
 
240
 
225
241
    return id;
226
242
}
227
243
 
237
253
 
238
254
        for( int j = 0; j < ses->trackc; j++ )
239
255
        {
240
 
            if( ses->trackv[j].id == id->sout_id )
 
256
            if( ses->trackv[j].id == id )
241
257
            {
242
258
                rtsp_strack_t *tr = ses->trackv + j;
243
 
                rtp_del_sink( tr->id, tr->fd );
 
259
                rtp_del_sink( tr->id->sout_id, tr->fd );
244
260
                REMOVE_ELEM( ses->trackv, ses->trackc, j );
245
261
            }
246
262
        }
304
320
    TAB_REMOVE( rtsp->sessionc, rtsp->sessionv, session );
305
321
 
306
322
    for( i = 0; i < session->trackc; i++ )
307
 
        rtp_del_sink( session->trackv[i].id, session->trackv[i].fd );
 
323
        rtp_del_sink( session->trackv[i].id->sout_id, session->trackv[i].fd );
308
324
 
309
325
    free( session->trackv );
310
326
    free( session );
382
398
    answer->i_body = 0;
383
399
    answer->p_body = NULL;
384
400
 
385
 
    httpd_MsgAdd( answer, "Server", "%s", PACKAGE_STRING );
 
401
    httpd_MsgAdd( answer, "Server", "VLC/%s", VERSION );
386
402
 
387
403
    /* Date: is always allowed, and sometimes mandatory with RTSP/2.0. */
388
404
    struct tm ut;
522
538
                    if( psz_session == NULL )
523
539
                    {
524
540
                        /* Create a dummy session ID */
525
 
                        snprintf( psz_sesbuf, sizeof( psz_sesbuf ), "%d",
526
 
                                  rand() );
 
541
                        snprintf( psz_sesbuf, sizeof( psz_sesbuf ), "%lu",
 
542
                                  vlc_mrand48() );
527
543
                        psz_session = psz_sesbuf;
528
544
                    }
529
545
                    answer->i_status = 200;
538
554
                {
539
555
                    char ip[NI_MAXNUMERICHOST], src[NI_MAXNUMERICHOST];
540
556
                    rtsp_session_t *ses = NULL;
541
 
                    rtsp_strack_t track = { id->sout_id, -1, false };
 
557
                    rtsp_strack_t track = { id, -1, false };
542
558
                    int sport;
543
559
 
544
560
                    if( httpd_ClientIP( cl, ip ) == NULL )
558
574
                        continue;
559
575
                    }
560
576
 
 
577
                    /* Ignore any unexpected incoming packet */
 
578
                    setsockopt (track.fd, SOL_SOCKET, SO_RCVBUF, &(int){ 0 },
 
579
                                sizeof (int));
561
580
                    net_GetSockAddress( track.fd, src, &sport );
562
581
 
563
582
                    vlc_mutex_lock( &rtsp->lock );
634
653
            ses = RtspClientGet( rtsp, psz_session );
635
654
            if( ses != NULL )
636
655
            {
 
656
                /* The "trackID" part must match what is done in
 
657
                 * RtspAppendTrackPath() */
637
658
                /* FIXME: we really need to limit the number of tracks... */
638
659
                char info[ses->trackc * ( strlen( control )
639
660
                              + sizeof("url=/trackID=123;seq=65535;"
640
661
                                       "rtptime=4294967295, ") ) + 1];
641
662
                size_t infolen = 0;
 
663
                int64_t ts = rtp_get_ts( rtsp->owner );
642
664
 
643
665
                for( int i = 0; i < ses->trackc; i++ )
644
666
                {
645
667
                    rtsp_strack_t *tr = ses->trackv + i;
646
 
                    if( ( id == NULL ) || ( tr->id == id->sout_id ) )
 
668
                    if( ( id == NULL ) || ( tr->id == id ) )
647
669
                    {
 
670
                        uint16_t seq;
648
671
                        if( !tr->playing )
649
672
                        {
650
673
                            tr->playing = true;
651
 
                            rtp_add_sink( tr->id, tr->fd, false );
 
674
                            rtp_add_sink( tr->id->sout_id, tr->fd, false,
 
675
                                          &seq );
652
676
                        }
653
 
                        /* This is racy, as the first packets may have
654
 
                         * already been sent before we fetch this info:
655
 
                         * these extra packets might confuse the client. */
 
677
                        else
 
678
                            seq = rtp_get_seq( tr->id->sout_id );
 
679
                        char *url = RtspAppendTrackPath( tr->id, control );
656
680
                        infolen += sprintf( info + infolen,
657
 
                                    "url=%s/trackID=%u;seq=%u;rtptime=%u, ",
658
 
                                            control,
659
 
                                            rtp_get_num( tr->id ),
660
 
                                            rtp_get_seq( tr->id ),
661
 
                                            rtp_get_ts( tr->id ) );
 
681
                                    "url=%s;seq=%u;rtptime=%u, ",
 
682
                                    url != NULL ? url : "", seq,
 
683
                                    rtp_compute_ts( tr->id->sout_id, ts ) );
 
684
                        free( url );
662
685
                    }
663
686
                }
664
687
                if( infolen > 0 )
709
732
                else /* Delete one track from the session */
710
733
                for( int i = 0; i < ses->trackc; i++ )
711
734
                {
712
 
                    if( ses->trackv[i].id == id->sout_id )
 
735
                    if( ses->trackv[i].id == id )
713
736
                    {
714
737
                        rtp_del_sink( id->sout_id, ses->trackv[i].fd );
715
738
                        REMOVE_ELEM( ses->trackv, ses->trackc, i );