comparison rtsp.c @ 3150:095003bbe73e libavformat

Change protocol_mask into protocol, since we always just try a single one per iteration in make_setup_request(), and cycling between the different protocols is now done in the calling function, therefore the need for a mask goes away. This also makes the function somewhat simpler to read. Discussed and approved in "[PATCH] RTSP alternate protocol 3/4".
author rbultje
date Wed, 19 Mar 2008 14:07:31 +0000
parents 5a7a7406ab1f
children 65236eababe9
comparison
equal deleted inserted replaced
3149:5a7a7406ab1f 3150:095003bbe73e
848 848
849 /** 849 /**
850 * @returns 0 on success, <0 on error, 1 if protocol is unavailable. 850 * @returns 0 on success, <0 on error, 1 if protocol is unavailable.
851 */ 851 */
852 static int 852 static int
853 make_setup_request (AVFormatContext *s, const char *host, int port, int protocol_mask) 853 make_setup_request (AVFormatContext *s, const char *host, int port, int protocol)
854 { 854 {
855 RTSPState *rt = s->priv_data; 855 RTSPState *rt = s->priv_data;
856 int j, i, err; 856 int j, i, err;
857 RTSPStream *rtsp_st; 857 RTSPStream *rtsp_st;
858 AVStream *st; 858 AVStream *st;
870 870
871 /* compute available transports */ 871 /* compute available transports */
872 transport[0] = '\0'; 872 transport[0] = '\0';
873 873
874 /* RTP/UDP */ 874 /* RTP/UDP */
875 if (protocol_mask & (1 << RTSP_PROTOCOL_RTP_UDP)) { 875 if (protocol == RTSP_PROTOCOL_RTP_UDP) {
876 char buf[256]; 876 char buf[256];
877 877
878 /* first try in specified port range */ 878 /* first try in specified port range */
879 if (RTSP_RTP_PORT_MIN != 0) { 879 if (RTSP_RTP_PORT_MIN != 0) {
880 while(j <= RTSP_RTP_PORT_MAX) { 880 while(j <= RTSP_RTP_PORT_MAX) {
901 "RTP/AVP/UDP;unicast;client_port=%d-%d", 901 "RTP/AVP/UDP;unicast;client_port=%d-%d",
902 port, port + 1); 902 port, port + 1);
903 } 903 }
904 904
905 /* RTP/TCP */ 905 /* RTP/TCP */
906 else if (protocol_mask & (1 << RTSP_PROTOCOL_RTP_TCP)) { 906 else if (protocol == RTSP_PROTOCOL_RTP_TCP) {
907 if (transport[0] != '\0') 907 if (transport[0] != '\0')
908 av_strlcat(transport, ",", sizeof(transport)); 908 av_strlcat(transport, ",", sizeof(transport));
909 snprintf(transport + strlen(transport), sizeof(transport) - strlen(transport) - 1, 909 snprintf(transport + strlen(transport), sizeof(transport) - strlen(transport) - 1,
910 "RTP/AVP/TCP"); 910 "RTP/AVP/TCP");
911 } 911 }
912 912
913 else if (protocol_mask & (1 << RTSP_PROTOCOL_RTP_UDP_MULTICAST)) { 913 else if (protocol == RTSP_PROTOCOL_RTP_UDP_MULTICAST) {
914 if (transport[0] != '\0') 914 if (transport[0] != '\0')
915 av_strlcat(transport, ",", sizeof(transport)); 915 av_strlcat(transport, ",", sizeof(transport));
916 snprintf(transport + strlen(transport), 916 snprintf(transport + strlen(transport),
917 sizeof(transport) - strlen(transport) - 1, 917 sizeof(transport) - strlen(transport) - 1,
918 "RTP/AVP/UDP;multicast"); 918 "RTP/AVP/UDP;multicast");
942 rt->protocol = reply->transports[0].protocol; 942 rt->protocol = reply->transports[0].protocol;
943 } 943 }
944 944
945 /* close RTP connection if not choosen */ 945 /* close RTP connection if not choosen */
946 if (reply->transports[0].protocol != RTSP_PROTOCOL_RTP_UDP && 946 if (reply->transports[0].protocol != RTSP_PROTOCOL_RTP_UDP &&
947 (protocol_mask & (1 << RTSP_PROTOCOL_RTP_UDP))) { 947 (protocol == RTSP_PROTOCOL_RTP_UDP)) {
948 url_close(rtsp_st->rtp_handle); 948 url_close(rtsp_st->rtp_handle);
949 rtsp_st->rtp_handle = NULL; 949 rtsp_st->rtp_handle = NULL;
950 } 950 }
951 951
952 switch(reply->transports[0].protocol) { 952 switch(reply->transports[0].protocol) {
1086 err = AVERROR_INVALIDDATA; 1086 err = AVERROR_INVALIDDATA;
1087 goto fail; 1087 goto fail;
1088 } 1088 }
1089 1089
1090 do { 1090 do {
1091 int protocol = protocol_mask & ~(protocol_mask - 1); 1091 int protocol = ff_log2_tab[protocol_mask & ~(protocol_mask - 1)];
1092 1092
1093 err = make_setup_request(s, host, port, protocol); 1093 err = make_setup_request(s, host, port, protocol);
1094 if (err < 0) 1094 if (err < 0)
1095 goto fail; 1095 goto fail;
1096 protocol_mask &= ~protocol; 1096 protocol_mask &= ~(1 << protocol);
1097 if (protocol_mask == 0 && err == 1) { 1097 if (protocol_mask == 0 && err == 1) {
1098 err = AVERROR(EPROTONOSUPPORT); 1098 err = AVERROR(EPROTONOSUPPORT);
1099 goto fail; 1099 goto fail;
1100 } 1100 }
1101 } while (err); 1101 } while (err);