Changeset 24b546fb5f93ecf019f67762d68f78016aeae7ac

Show
Ignore:
Timestamp:
01/09/07 21:34:09 (1 year ago)
Author:
Rémi Denis-Courmont <rem@videolan.org>
git-committer:
Rémi Denis-Courmont <rem@videolan.org> 1188675249 +0000
git-parent:

[88c0950bd9aedea022217b3aff7fc4a7a391e829]

git-author:
Rémi Denis-Courmont <rem@videolan.org> 1188675249 +0000
Message:

Factorize aggregate and non-aggregate RTSP code paths

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/stream_out/rtsp.c

    r88c0950 r24b546f  
    304304 
    305305 
    306 /** Aggregate RTSP callback */ 
    307 static int RtspCallback( httpd_callback_sys_t *p_args, 
    308                          httpd_client_t *cl, 
    309                          httpd_message_t *answer, 
    310                          const httpd_message_t *query ) 
    311 
    312     rtsp_stream_t *rtsp = (rtsp_stream_t *)p_args; 
     306/** Finds the next transport choice */ 
     307static inline const char *transport_next( const char *str ) 
     308
     309    /* Looks for comma */ 
     310    str = strchr( str, ',' ); 
     311    if( str == NULL ) 
     312        return NULL; /* No more transport options */ 
     313 
     314    str++; /* skips comma */ 
     315    while( strchr( "\r\n\t ", *str ) ) 
     316        str++; 
     317 
     318    return (*str) ? str : NULL; 
     319
     320 
     321 
     322/** Finds the next transport parameter */ 
     323static inline const char *parameter_next( const char *str ) 
     324
     325    while( strchr( ",;", *str ) == NULL ) 
     326        str++; 
     327 
     328    return (*str == ';') ? (str + 1) : NULL; 
     329
     330 
     331 
     332/** RTSP requests handler 
     333 * @param id selected track for non-aggregate URLs, 
     334 *           NULL for aggregate URLs 
     335 */ 
     336static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id, 
     337                        httpd_client_t *cl, 
     338                        httpd_message_t *answer, 
     339                        const httpd_message_t *query ) 
     340
     341    sout_stream_t *p_stream = id->stream->owner; 
     342    char psz_sesbuf[17]; 
    313343    const char *psz_session = NULL, *psz; 
    314344 
    315345    if( answer == NULL || query == NULL ) 
    316     { 
    317346        return VLC_SUCCESS; 
    318     } 
    319  
     347 
     348    /* */ 
    320349    answer->i_proto = HTTPD_PROTO_RTSP; 
    321350    answer->i_version= query->i_version; 
     
    334363    { 
    335364        case HTTPD_MSG_DESCRIBE: 
    336         { 
     365        {   /* Aggregate-only */ 
     366            if( id != NULL ) 
     367            { 
     368                answer->i_status = 460; 
     369                break; 
     370            } 
     371 
    337372            char ip[NI_MAXNUMERICHOST], *ptr; 
    338373            char control[sizeof("rtsp://[]:12345/") + sizeof( ip ) 
     
    363398 
    364399        case HTTPD_MSG_SETUP: 
    365             answer->i_status = 459; 
    366             break; 
    367  
    368         case HTTPD_MSG_PLAY: 
    369         { 
    370             rtsp_session_t *ses; 
    371             answer->i_status = 200; 
    372  
    373             psz_session = httpd_MsgGet( query, "Session" ); 
    374             if( httpd_MsgGet( query, "Range" ) != NULL ) 
     400            /* Non-aggregate-only */ 
     401            if( id == NULL ) 
    375402            { 
    376                 answer->i_status = 456; /* cannot seek */ 
     403                answer->i_status = 459; 
    377404                break; 
    378405            } 
    379406 
    380             vlc_mutex_lock( &rtsp->lock ); 
    381             ses = RtspClientGet( rtsp, psz_session ); 
    382             if( ses != NULL ) 
    383             { 
    384                 for( int i = 0; i < ses->trackc; i++ ) 
    385                 { 
    386                     rtsp_strack_t *tr = ses->trackv + i; 
    387                     if( !tr->playing ) 
    388                     { 
    389                         tr->playing = VLC_TRUE; 
    390                         rtp_add_sink( tr->id, tr->access ); 
    391                     } 
    392                 } 
    393             } 
    394             vlc_mutex_unlock( &rtsp->lock ); 
    395  
    396             if( httpd_MsgGet( query, "Scale" ) != NULL ) 
    397                 httpd_MsgAdd( answer, "Scale", "1." ); 
    398             break; 
    399         } 
    400  
    401         case HTTPD_MSG_PAUSE: 
    402             answer->i_status = 405; 
    403             httpd_MsgAdd( answer, "Allow", 
    404                           "DESCRIBE, TEARDOWN, PLAY, GET_PARAMETER" ); 
    405             break; 
    406  
    407         case HTTPD_MSG_GETPARAMETER: 
    408             if( query->i_body > 0 ) 
    409             { 
    410                 answer->i_status = 451; 
    411                 break; 
    412             } 
    413  
    414             answer->i_status = 200; 
    415             break; 
    416  
    417         case HTTPD_MSG_TEARDOWN: 
    418         { 
    419             rtsp_session_t *ses; 
    420  
    421             /* for now only multicast so easy again */ 
    422             answer->i_status = 200; 
    423  
    424407            psz_session = httpd_MsgGet( query, "Session" ); 
    425  
    426             vlc_mutex_lock( &rtsp->lock ); 
    427             ses = RtspClientGet( rtsp, psz_session ); 
    428             if( ses != NULL ) 
    429                 RtspClientDel( rtsp, ses ); 
    430             vlc_mutex_unlock( &rtsp->lock ); 
    431             break; 
    432         } 
    433  
    434         default: 
    435             return VLC_EGENERIC; 
    436     } 
    437  
    438     httpd_MsgAdd( answer, "Server", "%s", PACKAGE_STRING ); 
    439     httpd_MsgAdd( answer, "Content-Length", "%d", answer->i_body ); 
    440  
    441     psz = httpd_MsgGet( query, "Cseq" ); 
    442     if( psz != NULL ) 
    443         httpd_MsgAdd( answer, "Cseq", "%s", psz ); 
    444     psz = httpd_MsgGet( query, "Timestamp" ); 
    445     if( psz != NULL ) 
    446         httpd_MsgAdd( answer, "Timestamp", "%s", psz ); 
    447  
    448     httpd_MsgAdd( answer, "Cache-Control", "%s", "no-cache" ); 
    449  
    450     if( psz_session ) 
    451         httpd_MsgAdd( answer, "Session", "%s;timeout=5", psz_session ); 
    452     return VLC_SUCCESS; 
    453 } 
    454  
    455  
    456 /** Finds the next transport choice */ 
    457 static inline const char *transport_next( const char *str ) 
    458 { 
    459     /* Looks for comma */ 
    460     str = strchr( str, ',' ); 
    461     if( str == NULL ) 
    462         return NULL; /* No more transport options */ 
    463  
    464     str++; /* skips comma */ 
    465     while( strchr( "\r\n\t ", *str ) ) 
    466         str++; 
    467  
    468     return (*str) ? str : NULL; 
    469 } 
    470  
    471  
    472 /** Finds the next transport parameter */ 
    473 static inline const char *parameter_next( const char *str ) 
    474 { 
    475     while( strchr( ",;", *str ) == NULL ) 
    476         str++; 
    477  
    478     return (*str == ';') ? (str + 1) : NULL; 
    479 } 
    480  
    481  
    482 /** Non-aggregate RTSP callback */ 
    483 static int RtspCallbackId( httpd_callback_sys_t *p_args, 
    484                            httpd_client_t *cl, 
    485                            httpd_message_t *answer, 
    486                            const httpd_message_t *query ) 
    487 { 
    488     rtsp_stream_id_t *id = (rtsp_stream_id_t *)p_args; 
    489     rtsp_stream_t    *rtsp = id->stream; 
    490     sout_stream_t    *p_stream = id->stream->owner; 
    491     char psz_sesbuf[17]; 
    492     const char *psz_session, *psz; 
    493  
    494     if( answer == NULL || query == NULL ) 
    495         return VLC_SUCCESS; 
    496  
    497     /* */ 
    498     answer->i_proto = HTTPD_PROTO_RTSP; 
    499     answer->i_version= query->i_version; 
    500     answer->i_type   = HTTPD_MSG_ANSWER; 
    501     answer->i_body = 0; 
    502     answer->p_body = NULL; 
    503  
    504     psz_session = httpd_MsgGet( query, "Session" ); 
    505  
    506     if( httpd_MsgGet( query, "Require" ) != NULL ) 
    507     { 
    508         answer->i_status = 551; 
    509         httpd_MsgAdd( answer, "Unsupported", "%s", 
    510                       httpd_MsgGet( query, "Require" ) ); 
    511     } 
    512     else 
    513     switch( query->i_type ) 
    514     { 
    515         case HTTPD_MSG_SETUP: 
    516         { 
    517408            answer->i_status = 461; 
    518409 
     
    594485                        continue; 
    595486 
     487                    if( psz_session == NULL ) 
     488                    { 
     489                        /* Create a dummy session ID */ 
     490                        snprintf( psz_sesbuf, sizeof( psz_sesbuf ), "%d", 
     491                                  rand() ); 
     492                        psz_session = psz_sesbuf; 
     493                    } 
    596494                    answer->i_status = 200; 
    597495 
     
    656554                    } 
    657555 
    658                     INSERT_ELEM( ses->trackv, ses->trackc, ses->trackc, track ); 
     556                    INSERT_ELEM( ses->trackv, ses->trackc, ses->trackc, 
     557                                 track ); 
    659558                    vlc_mutex_unlock( &rtsp->lock ); 
    660559 
     
    690589            } 
    691590            break; 
    692         } 
    693591 
    694592        case HTTPD_MSG_PLAY: 
     
    711609                { 
    712610                    rtsp_strack_t *tr = ses->trackv + i; 
    713                     if( !tr->playing && ( tr->id == id->sout_id ) ) 
     611                    if( !tr->playing 
     612                     && ( ( id == NULL ) || ( tr->id == id->sout_id ) ) ) 
    714613                    { 
    715614                        tr->playing = VLC_TRUE; 
     
    728627            answer->i_status = 405; 
    729628            httpd_MsgAdd( answer, "Allow", 
    730                           "SETUP, TEARDOWN, PLAY, GET_PARAMETER" ); 
     629                          "%s, TEARDOWN, PLAY, GET_PARAMETER", 
     630                          ( id != NULL ) ? "SETUP" : "DESCRIBE" ); 
    731631            break; 
    732632 
     
    738638            } 
    739639 
     640            psz_session = httpd_MsgGet( query, "Session" ); 
    740641            answer->i_status = 200; 
    741642            break; 
     
    753654            if( ses != NULL ) 
    754655            { 
     656                if( id == NULL ) /* Delete the entire session */ 
     657                    RtspClientDel( rtsp, ses ); 
     658                else /* Delete one track from the session */ 
    755659                for( int i = 0; i < ses->trackc; i++ ) 
    756660                { 
     
    768672 
    769673        default: 
    770             answer->i_status = 460; 
    771             break; 
     674            return VLC_EGENERIC; 
    772675    } 
     676 
     677    httpd_MsgAdd( answer, "Server", "%s", PACKAGE_STRING ); 
     678    if( psz_session ) 
     679        httpd_MsgAdd( answer, "Session", "%s"/*;timeout=5*/, psz_session ); 
     680 
     681    httpd_MsgAdd( answer, "Content-Length", "%d", answer->i_body ); 
     682    httpd_MsgAdd( answer, "Cache-Control", "no-cache" ); 
    773683 
    774684    psz = httpd_MsgGet( query, "Cseq" ); 
     
    778688    if( psz != NULL ) 
    779689        httpd_MsgAdd( answer, "Timestamp", "%s", psz ); 
    780     httpd_MsgAdd( answer, "Server", "%s", PACKAGE_STRING ); 
    781     httpd_MsgAdd( answer, "Content-Length", "%d", answer->i_body ); 
    782     httpd_MsgAdd( answer, "Cache-Control", "%s", "no-cache" ); 
    783  
    784     if( psz_session ) 
    785         httpd_MsgAdd( answer, "Session", "%s"/*;timeout=5*/, psz_session ); 
     690 
    786691    return VLC_SUCCESS; 
    787692} 
     693 
     694 
     695/** Aggregate RTSP callback */ 
     696static int RtspCallback( httpd_callback_sys_t *p_args, 
     697                         httpd_client_t *cl, 
     698                         httpd_message_t *answer, 
     699                         const httpd_message_t *query ) 
     700{ 
     701    return RtspHandler( (rtsp_stream_t *)p_args, NULL, cl, answer, query ); 
     702} 
     703 
     704 
     705/** Non-aggregate RTSP callback */ 
     706static int RtspCallbackId( httpd_callback_sys_t *p_args, 
     707                           httpd_client_t *cl, 
     708                           httpd_message_t *answer, 
     709                           const httpd_message_t *query ) 
     710{ 
     711    rtsp_stream_id_t *id = (rtsp_stream_id_t *)p_args; 
     712    return RtspHandler( id->stream, id, cl, answer, query ); 
     713}