rtsp: Start implementing support for RTSP 2.0

Properly handle protocol version in the connection

Add the following headers types:
  * Pipelined-Request
  * Media-Properties
  * Seek-Style
  * Accept-Ranges

https://bugzilla.gnome.org/show_bug.cgi?id=781446
This commit is contained in:
Thibault Saunier 2017-04-20 17:42:17 -03:00
parent 43985b363d
commit 20fae3f1e0
4 changed files with 43 additions and 11 deletions

View file

@ -109,6 +109,7 @@ struct _GstRTSPConnection
/*< private > */
/* URL for the remote connection */
GstRTSPUrl *url;
GstRTSPVersion version;
gboolean server;
GSocketClient *client;
@ -314,6 +315,7 @@ gst_rtsp_connection_create (const GstRTSPUrl * url, GstRTSPConnection ** conn)
newconn->username = NULL;
newconn->passwd = NULL;
newconn->auth_params = NULL;
newconn->version = 0;
*conn = newconn;
@ -1454,10 +1456,12 @@ message_to_string (GstRTSPConnection * conn, GstRTSPMessage * message)
switch (message->type) {
case GST_RTSP_MESSAGE_REQUEST:
/* create request string, add CSeq */
g_string_append_printf (str, "%s %s RTSP/1.0\r\n"
g_string_append_printf (str, "%s %s RTSP/%s\r\n"
"CSeq: %d\r\n",
gst_rtsp_method_as_text (message->type_data.request.method),
message->type_data.request.uri, conn->cseq++);
message->type_data.request.uri,
gst_rtsp_version_as_text (message->type_data.request.version),
conn->cseq++);
/* add session id if we have one */
if (conn->session_id[0] != '\0') {
gst_rtsp_message_remove_header (message, GST_RTSP_HDR_SESSION, -1);
@ -1469,7 +1473,8 @@ message_to_string (GstRTSPConnection * conn, GstRTSPMessage * message)
break;
case GST_RTSP_MESSAGE_RESPONSE:
/* create response string */
g_string_append_printf (str, "RTSP/1.0 %d %s\r\n",
g_string_append_printf (str, "RTSP/%s %d %s\r\n",
gst_rtsp_version_as_text (message->type_data.response.version),
message->type_data.response.code, message->type_data.response.reason);
break;
case GST_RTSP_MESSAGE_HTTP_REQUEST:
@ -1626,6 +1631,7 @@ static GstRTSPResult
parse_protocol_version (gchar * protocol, GstRTSPMsgType * type,
GstRTSPVersion * version)
{
GstRTSPVersion rversion;
GstRTSPResult res = GST_RTSP_OK;
gchar *ver;
@ -1640,8 +1646,10 @@ parse_protocol_version (gchar * protocol, GstRTSPMsgType * type,
if (sscanf (ver, "%u.%u%c", &major, &minor, &dummychar) != 2)
res = GST_RTSP_EPARSE;
rversion = major * 0x10 + minor;
if (g_ascii_strcasecmp (protocol, "RTSP") == 0) {
if (major != 1 || minor != 0) {
if (rversion != GST_RTSP_VERSION_1_0 && rversion != GST_RTSP_VERSION_2_0) {
*version = GST_RTSP_VERSION_INVALID;
res = GST_RTSP_ERROR;
}
@ -1651,17 +1659,17 @@ parse_protocol_version (gchar * protocol, GstRTSPMsgType * type,
else if (*type == GST_RTSP_MESSAGE_RESPONSE)
*type = GST_RTSP_MESSAGE_HTTP_RESPONSE;
if (major == 1 && minor == 1) {
*version = GST_RTSP_VERSION_1_1;
} else if (major != 1 || minor != 0) {
*version = GST_RTSP_VERSION_INVALID;
if (rversion != GST_RTSP_VERSION_1_0 &&
rversion != GST_RTSP_VERSION_1_1 && rversion != GST_RTSP_VERSION_2_0)
res = GST_RTSP_ERROR;
}
} else
res = GST_RTSP_EPARSE;
} else
res = GST_RTSP_EPARSE;
if (res == GST_RTSP_OK)
*version = rversion;
return res;
}

View file

@ -57,6 +57,7 @@
#include <string.h>
#include "gstrtspdefs.h"
#include <gst/gst.h>
struct rtsp_header
{
@ -176,6 +177,12 @@ static struct rtsp_header rtsp_headers[] = {
/* Since 1.4 */
{"KeyMgmt", FALSE},
/* Since 1.XX */
{"Pipelined-Requests", FALSE},
{"Media-Properties", FALSE},
{"Seek-Style", FALSE},
{"Accept-Ranges", FALSE},
{NULL, FALSE}
};
@ -338,6 +345,10 @@ gst_rtsp_version_as_text (GstRTSPVersion version)
case GST_RTSP_VERSION_1_1:
return "1.1";
case GST_RTSP_VERSION_2_0:
return "2.0";
default:
return "0.0";
}

View file

@ -71,7 +71,7 @@ G_STMT_START { \
* @GST_RTSP_ERESOLV: a host resolve error occured
* @GST_RTSP_ENOTIMPL: function not implemented
* @GST_RTSP_ESYS: a system error occured, errno contains more details
* @GST_RTSP_EPARSE: a persing error occured
* @GST_RTSP_EPARSE: a parsing error occured
* @GST_RTSP_EWSASTART: windows networking could not start
* @GST_RTSP_EWSAVERSION: windows networking stack has wrong version
* @GST_RTSP_EEOF: end-of-file was reached
@ -158,13 +158,15 @@ typedef enum {
* @GST_RTSP_VERSION_INVALID: unknown/invalid version
* @GST_RTSP_VERSION_1_0: version 1.0
* @GST_RTSP_VERSION_1_1: version 1.1.
* @GST_RTSP_VERSION_2_0: version 2.0.
*
* The supported RTSP versions.
*/
typedef enum {
GST_RTSP_VERSION_INVALID = 0x00,
GST_RTSP_VERSION_1_0 = 0x10,
GST_RTSP_VERSION_1_1 = 0x11
GST_RTSP_VERSION_1_1 = 0x11,
GST_RTSP_VERSION_2_0 = 0x20
} GstRTSPVersion;
/**
@ -332,6 +334,12 @@ typedef enum {
/* Since 1.4 */
GST_RTSP_HDR_KEYMGMT, /* KeyMgmt */
/* Since 1.X */
GST_RTSP_HDR_PIPELINED_REQUESTS, /* Pipelined-Requests Rr opt. SETUP */
GST_RTSP_HDR_MEDIA_PROPERTIES, /* Media-Properties Rr opt. SETUP */
GST_RTSP_HDR_SEEK_STYLE, /* Seek-Type Rr opt. PLAY */
GST_RTSP_HDR_ACCEPT_RANGES, /* Accept-Ranges Rr opt. SETUP, GET_PARAMETER */
GST_RTSP_HDR_LAST
} GstRTSPHeaderField;

View file

@ -40,6 +40,11 @@ G_BEGIN_DECLS
#define GST_RTSP_EXTENSION_GET_INTERFACE(inst) \
(G_TYPE_INSTANCE_GET_INTERFACE ((inst), GST_TYPE_RTSP_EXTENSION, GstRTSPExtensionInterface))
/**
* GstRTSPExtension:
*
* An interface representing RTSP extensions.
*/
typedef struct _GstRTSPExtension GstRTSPExtension;
typedef struct _GstRTSPExtensionInterface GstRTSPExtensionInterface;