Ticket #129: 0001-rtsp-Only-do-keepalive-using-GET_PARAMETER-if-the-se.patch

File 0001-rtsp-Only-do-keepalive-using-GET_PARAMETER-if-the-se.patch, 2.6 KB (added by Martin Storsjö, 15 years ago)
  • libavformat/rtsp.c

    From 4bcca1c8e0258aa04f0a70887d4b84d88d6a01c8 Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <martin@martin.st>
    Date: Mon, 9 May 2011 20:11:16 +0300
    Subject: [PATCH] rtsp: Only do keepalive using GET_PARAMETER if the server supports it
    
    This is more like what VLC does. If the server doesn't mention
    supporting GET_PARAMETER in response to an OPTIONS request,
    VLC doesn't send any keepalive requests at all. After this patch,
    libavformat will still send OPTIONS keepalives if GET_PARAMETER
    isn't explicitly said to be supported.
    
    Some RTSP cameras don't support GET_PARAMETER, and will
    close the connection if this is sent as keepalive request
    (but support OPTIONS just fine, but probably don't need any
    keepalive at all). Some other cameras don't support using
    OPTIONS as keepalive, but require GET_PARAMETER instead.
    ---
     libavformat/rtsp.c    |    4 ++++
     libavformat/rtsp.h    |    5 +++++
     libavformat/rtspdec.c |    4 +++-
     3 files changed, 12 insertions(+), 1 deletions(-)
    
    diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
    index 14111e6..2ebf7e0 100644
    a b void ff_rtsp_parse_line(RTSPMessageHeader *reply, const char *buf,  
    808808        p += strspn(p, SPACE_CHARS);
    809809        if (method && !strcmp(method, "PLAY"))
    810810            rtsp_parse_rtp_info(rt, p);
     811    } else if (av_stristart(p, "Public:", &p) && rt) {
     812        if (strstr(p, "GET_PARAMETER") &&
     813            method && !strcmp(method, "OPTIONS"))
     814            rt->get_parameter_supported = 1;
    811815    }
    812816}
    813817
  • libavformat/rtsp.h

    diff --git a/libavformat/rtsp.h b/libavformat/rtsp.h
    index e1f1df9..ff66502 100644
    a b typedef struct RTSPState {  
    331331     * Polling array for udp
    332332     */
    333333    struct pollfd *p;
     334
     335    /**
     336     * Whether the server supports the GET_PARAMETER method.
     337     */
     338    int get_parameter_supported;
    334339} RTSPState;
    335340
    336341/**
  • libavformat/rtspdec.c

    diff --git a/libavformat/rtspdec.c b/libavformat/rtspdec.c
    index 866f313..ccfc4d8 100644
    a b retry:  
    341341
    342342    /* send dummy request to keep TCP connection alive */
    343343    if ((av_gettime() - rt->last_cmd_time) / 1000000 >= rt->timeout / 2) {
    344         if (rt->server_type != RTSP_SERVER_REAL) {
     344        if (rt->server_type == RTSP_SERVER_WMS ||
     345           (rt->server_type != RTSP_SERVER_REAL &&
     346            rt->get_parameter_supported)) {
    345347            ff_rtsp_send_cmd_async(s, "GET_PARAMETER", rt->control_uri, NULL);
    346348        } else {
    347349            ff_rtsp_send_cmd_async(s, "OPTIONS", "*", NULL);