Revision 4f40ec05 libavformat/rtspdec.c

View differences:

libavformat/rtspdec.c
229 229
    *prtsp_st = rtsp_st;
230 230
    return len;
231 231
}
232

  
233
static int resetup_tcp(AVFormatContext *s)
234
{
235
    RTSPState *rt = s->priv_data;
236
    char host[1024];
237
    int port;
238

  
239
    av_url_split(NULL, 0, NULL, 0, host, sizeof(host), &port, NULL, 0,
240
                 s->filename);
241
    ff_rtsp_undo_setup(s);
242
    return ff_rtsp_make_setup_request(s, host, port, RTSP_LOWER_TRANSPORT_TCP,
243
                                      rt->real_challenge);
244
}
245

  
232 246
static int rtsp_read_packet(AVFormatContext *s, AVPacket *pkt)
233 247
{
234 248
    RTSPState *rt = s->priv_data;
......
236 250
    RTSPMessageHeader reply1, *reply = &reply1;
237 251
    char cmd[1024];
238 252

  
253
retry:
239 254
    if (rt->server_type == RTSP_SERVER_REAL) {
240 255
        int i;
241 256

  
......
295 310
    }
296 311

  
297 312
    ret = ff_rtsp_fetch_packet(s, pkt);
298
    if (ret < 0)
313
    if (ret < 0) {
314
        if (ret == FF_NETERROR(ETIMEDOUT) && !rt->packets) {
315
            if (rt->lower_transport == RTSP_LOWER_TRANSPORT_UDP &&
316
                rt->lower_transport_mask & (1 << RTSP_LOWER_TRANSPORT_TCP)) {
317
                RTSPMessageHeader reply1, *reply = &reply1;
318
                av_log(s, AV_LOG_WARNING, "UDP timeout, retrying with TCP\n");
319
                if (rtsp_read_pause(s) != 0)
320
                    return -1;
321
                // TEARDOWN is required on Real-RTSP, but might make
322
                // other servers close the connection.
323
                if (rt->server_type == RTSP_SERVER_REAL)
324
                    ff_rtsp_send_cmd(s, "TEARDOWN", rt->control_uri, NULL,
325
                                     reply, NULL);
326
                rt->session_id[0] = '\0';
327
                if (resetup_tcp(s) == 0) {
328
                    rt->state = RTSP_STATE_IDLE;
329
                    rt->need_subscription = 1;
330
                    if (rtsp_read_play(s) != 0)
331
                        return -1;
332
                    goto retry;
333
                }
334
            }
335
        }
299 336
        return ret;
337
    }
338
    rt->packets++;
300 339

  
301 340
    /* send dummy request to keep TCP connection alive */
302 341
    if ((av_gettime() - rt->last_cmd_time) / 1000000 >= rt->timeout / 2) {

Also available in: Unified diff