| 1597 | } |
| 1598 | |
| 1599 | int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, |
| 1600 | int lower_transport, const char *real_challenge) |
| 1601 | { |
| 1602 | RTSPState *rt = s->priv_data; |
| 1603 | int rtx = 0, j, i, err, interleave = 0, port_off = 0; |
| 1604 | RTSPStream *rtsp_st; |
| 1605 | RTSPMessageHeader reply1, *reply = &reply1; |
| 1606 | char cmd[MAX_URL_SIZE]; |
| 1607 | const char *trans_pref; |
| 1608 | |
| 1609 | memset(&reply1, 0, sizeof(reply1)); |
| 1610 | |
| 1611 | if (rt->transport == RTSP_TRANSPORT_RDT) |
| 1612 | trans_pref = "x-pn-tng"; |
| 1613 | else if (rt->transport == RTSP_TRANSPORT_RAW) |
| 1614 | trans_pref = "RAW/RAW"; |
| 1615 | else |
| 1616 | trans_pref = "RTP/AVP"; |
| 1617 | |
| 1618 | /* default timeout: 1 minute */ |
| 1619 | rt->timeout = 60; |
| 1620 | |
| 1621 | /* Choose a random starting offset within the first half of the |
| 1622 | * port range, to allow for a number of ports to try even if the offset |
| 1623 | * happens to be at the end of the random range. */ |
| 1624 | if (rt->rtp_port_max - rt->rtp_port_min >= 4) { |
| 1625 | port_off = av_get_random_seed() % ((rt->rtp_port_max - rt->rtp_port_min)/2); |
| 1626 | /* even random offset */ |
| 1627 | port_off -= port_off & 0x01; |
| 1628 | } |
| 1629 | |
| 1630 | for (j = rt->rtp_port_min + port_off, i = 0; i < rt->nb_rtsp_streams; ++i) { |
| 1631 | char transport[MAX_URL_SIZE]; |
| 1632 | |
| 1633 | /* |
| 1634 | * WMS serves all UDP data over a single connection, the RTX, which |
| 1635 | * isn't necessarily the first in the SDP but has to be the first |
| 1636 | * to be set up, else the second/third SETUP will fail with a 461. |
| 1637 | */ |
| 1638 | if (lower_transport == RTSP_LOWER_TRANSPORT_UDP && |
| 1639 | rt->server_type == RTSP_SERVER_WMS) { |
| 1640 | if (i == 0) { |
| 1641 | /* rtx first */ |
| 1642 | for (rtx = 0; rtx < rt->nb_rtsp_streams; rtx++) { |
| 1643 | int len = strlen(rt->rtsp_streams[rtx]->control_url); |
| 1644 | if (len >= 4 && |
| 1645 | !strcmp(rt->rtsp_streams[rtx]->control_url + len - 4, |
| 1646 | "/rtx")) |
| 1647 | break; |
| 1648 | } |
| 1649 | if (rtx == rt->nb_rtsp_streams) |
| 1650 | return -1; /* no RTX found */ |
| 1651 | rtsp_st = rt->rtsp_streams[rtx]; |
| 1652 | } else |
| 1653 | rtsp_st = rt->rtsp_streams[i > rtx ? i : i - 1]; |
| 1654 | } else |
| 1655 | rtsp_st = rt->rtsp_streams[i]; |
| 1656 |
no test coverage detected