Revision 53620bba

View differences:

libavformat/rtsp.c
846 846
    av_free(rt->rtsp_streams);
847 847
}
848 848

  
849
static int rtsp_read_header(AVFormatContext *s,
850
                            AVFormatParameters *ap)
849
/**
850
 * @returns 0 on success, <0 on error, 1 if protocol is unavailable.
851
 */
852
static int
853
make_setup_request (AVFormatContext *s, const char *host, int port, int protocol_mask)
851 854
{
852 855
    RTSPState *rt = s->priv_data;
853
    char host[1024], path[1024], tcpname[1024], cmd[2048], *option_list, *option;
854
    URLContext *rtsp_hd;
855
    int port, i, j, ret, err;
856
    RTSPHeader reply1, *reply = &reply1;
857
    unsigned char *content = NULL;
856
    int j, i, err;
858 857
    RTSPStream *rtsp_st;
859
    int protocol_mask = 0;
860 858
    AVStream *st;
861

  
862
    /* extract hostname and port */
863
    url_split(NULL, 0, NULL, 0,
864
              host, sizeof(host), &port, path, sizeof(path), s->filename);
865
    if (port < 0)
866
        port = RTSP_DEFAULT_PORT;
867

  
868
    /* search for options */
869
    option_list = strchr(path, '?');
870
    if (option_list) {
871
        /* remove the options from the path */
872
        *option_list++ = 0;
873
        while(option_list) {
874
            /* move the option pointer */
875
            option = option_list;
876
            option_list = strchr(option_list, '&');
877
            if (option_list)
878
                *(option_list++) = 0;
879
            /* handle the options */
880
            if (strcmp(option, "udp") == 0)
881
                protocol_mask = (1<< RTSP_PROTOCOL_RTP_UDP);
882
            else if (strcmp(option, "multicast") == 0)
883
                protocol_mask = (1<< RTSP_PROTOCOL_RTP_UDP_MULTICAST);
884
            else if (strcmp(option, "tcp") == 0)
885
                protocol_mask = (1<< RTSP_PROTOCOL_RTP_TCP);
886
        }
887
    }
888

  
889
    if (!protocol_mask)
890
        protocol_mask = rtsp_default_protocols;
891

  
892
    /* open the tcp connexion */
893
    snprintf(tcpname, sizeof(tcpname), "tcp://%s:%d", host, port);
894
    if (url_open(&rtsp_hd, tcpname, URL_RDWR) < 0)
895
        return AVERROR(EIO);
896
    rt->rtsp_hd = rtsp_hd;
897
    rt->seq = 0;
898

  
899
    /* describe the stream */
900
    snprintf(cmd, sizeof(cmd),
901
             "DESCRIBE %s RTSP/1.0\r\n"
902
             "Accept: application/sdp\r\n",
903
             s->filename);
904
    rtsp_send_cmd(s, cmd, reply, &content);
905
    if (!content) {
906
        err = AVERROR_INVALIDDATA;
907
        goto fail;
908
    }
909
    if (reply->status_code != RTSP_STATUS_OK) {
910
        err = AVERROR_INVALIDDATA;
911
        goto fail;
912
    }
913

  
914
    /* now we got the SDP description, we parse it */
915
    ret = sdp_parse(s, (const char *)content);
916
    av_freep(&content);
917
    if (ret < 0) {
918
        err = AVERROR_INVALIDDATA;
919
        goto fail;
920
    }
859
    RTSPHeader reply1, *reply = &reply1;
860
    char cmd[2048];
921 861

  
922 862
    /* for each stream, make the setup request */
923 863
    /* XXX: we assume the same server is used for the control of each
......
1060 1000
        }
1061 1001
    }
1062 1002

  
1003
    return 0;
1004

  
1005
fail:
1006
    return err;
1007
}
1008

  
1009
static int rtsp_read_header(AVFormatContext *s,
1010
                            AVFormatParameters *ap)
1011
{
1012
    RTSPState *rt = s->priv_data;
1013
    char host[1024], path[1024], tcpname[1024], cmd[2048], *option_list, *option;
1014
    URLContext *rtsp_hd;
1015
    int port, ret, err;
1016
    RTSPHeader reply1, *reply = &reply1;
1017
    unsigned char *content = NULL;
1018
    int protocol_mask = 0;
1019

  
1020
    /* extract hostname and port */
1021
    url_split(NULL, 0, NULL, 0,
1022
              host, sizeof(host), &port, path, sizeof(path), s->filename);
1023
    if (port < 0)
1024
        port = RTSP_DEFAULT_PORT;
1025

  
1026
    /* search for options */
1027
    option_list = strchr(path, '?');
1028
    if (option_list) {
1029
        /* remove the options from the path */
1030
        *option_list++ = 0;
1031
        while(option_list) {
1032
            /* move the option pointer */
1033
            option = option_list;
1034
            option_list = strchr(option_list, '&');
1035
            if (option_list)
1036
                *(option_list++) = 0;
1037
            /* handle the options */
1038
            if (strcmp(option, "udp") == 0)
1039
                protocol_mask = (1<< RTSP_PROTOCOL_RTP_UDP);
1040
            else if (strcmp(option, "multicast") == 0)
1041
                protocol_mask = (1<< RTSP_PROTOCOL_RTP_UDP_MULTICAST);
1042
            else if (strcmp(option, "tcp") == 0)
1043
                protocol_mask = (1<< RTSP_PROTOCOL_RTP_TCP);
1044
        }
1045
    }
1046

  
1047
    if (!protocol_mask)
1048
        protocol_mask = rtsp_default_protocols;
1049

  
1050
    /* open the tcp connexion */
1051
    snprintf(tcpname, sizeof(tcpname), "tcp://%s:%d", host, port);
1052
    if (url_open(&rtsp_hd, tcpname, URL_RDWR) < 0)
1053
        return AVERROR(EIO);
1054
    rt->rtsp_hd = rtsp_hd;
1055
    rt->seq = 0;
1056

  
1057
    /* describe the stream */
1058
    snprintf(cmd, sizeof(cmd),
1059
             "DESCRIBE %s RTSP/1.0\r\n"
1060
             "Accept: application/sdp\r\n",
1061
             s->filename);
1062
    rtsp_send_cmd(s, cmd, reply, &content);
1063
    if (!content) {
1064
        err = AVERROR_INVALIDDATA;
1065
        goto fail;
1066
    }
1067
    if (reply->status_code != RTSP_STATUS_OK) {
1068
        err = AVERROR_INVALIDDATA;
1069
        goto fail;
1070
    }
1071

  
1072
    /* now we got the SDP description, we parse it */
1073
    ret = sdp_parse(s, (const char *)content);
1074
    av_freep(&content);
1075
    if (ret < 0) {
1076
        err = AVERROR_INVALIDDATA;
1077
        goto fail;
1078
    }
1079

  
1080
    err = make_setup_request(s, host, port, protocol_mask);
1081
    if (err)
1082
        goto fail;
1083

  
1063 1084
    rt->state = RTSP_STATE_IDLE;
1064 1085
    rt->seek_timestamp = 0; /* default is to start stream at position
1065 1086
                               zero */

Also available in: Unified diff