]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/rtsp.c
Delete unnecessary 'extern' keywords.
[ffmpeg] / libavformat / rtsp.c
index 6e4d36a6a683bf3dba05d07d8ae23893854a555a..33f0e5539e288d4ca247c976bc69557b7c464c47 100644 (file)
@@ -51,6 +51,12 @@ enum RTSPServerType {
     RTSP_SERVER_LAST
 };
 
+enum RTSPTransport {
+    RTSP_TRANSPORT_RTP,
+    RTSP_TRANSPORT_RDT,
+    RTSP_TRANSPORT_LAST
+};
+
 typedef struct RTSPState {
     URLContext *rtsp_hd; /* RTSP TCP connexion handle */
     int nb_rtsp_streams;
@@ -63,16 +69,17 @@ typedef struct RTSPState {
     //    ByteIOContext rtsp_gb;
     int seq;        /* RTSP command sequence number */
     char session_id[512];
+    enum RTSPTransport transport;
     enum RTSPLowerTransport lower_transport;
     enum RTSPServerType server_type;
     char last_reply[2048]; /* XXX: allocate ? */
-    RTPDemuxContext *cur_rtp;
+    void *cur_tx;
     int need_subscription;
 } RTSPState;
 
 typedef struct RTSPStream {
     URLContext *rtp_handle; /* RTP stream handle */
-    RTPDemuxContext *rtp_ctx; /* RTP parse context */
+    void *tx_ctx; /* RTP/RDT parse context */
 
     int stream_index; /* corresponding stream index, if any. -1 if none (MPEG2TS case) */
     int interleaved_min, interleaved_max;  /* interleave ids, if TCP transport */
@@ -85,7 +92,7 @@ typedef struct RTSPStream {
     rtp_payload_data_t rtp_payload_data; /* rtp payload parsing infos from SDP */
 
     RTPDynamicProtocolHandler *dynamic_handler; ///< Only valid if it's a dynamic protocol. (This is the handler structure)
-    void *dynamic_protocol_context; ///< Only valid if it's a dynamic protocol. (This is any private data associated with the dynamic protocol)
+    PayloadContext *dynamic_protocol_context; ///< Only valid if it's a dynamic protocol. (This is any private data associated with the dynamic protocol)
 } RTSPStream;
 
 static int rtsp_read_play(AVFormatContext *s);
@@ -286,7 +293,7 @@ typedef struct attrname_map
 /* All known fmtp parmeters and the corresping RTPAttrTypeEnum */
 #define ATTR_NAME_TYPE_INT 0
 #define ATTR_NAME_TYPE_STR 1
-static attrname_map_t attr_names[]=
+static const attrname_map_t attr_names[]=
 {
     {"SizeLength",       ATTR_NAME_TYPE_INT, offsetof(rtp_payload_data_t, sizelength)},
     {"IndexLength",      ATTR_NAME_TYPE_INT, offsetof(rtp_payload_data_t, indexlength)},
@@ -382,7 +389,8 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1,
     RTSPState *rt = s->priv_data;
     char buf1[64], st_type[64];
     const char *p;
-    int codec_type, payload_type, i;
+    enum CodecType codec_type;
+    int payload_type, i;
     AVStream *st;
     RTSPStream *rtsp_st;
     struct in_addr sdp_ip;
@@ -538,6 +546,9 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1,
             rtsp_parse_range_npt(p, &start, &end);
             s->start_time= start;
             s->duration= (end==AV_NOPTS_VALUE)?AV_NOPTS_VALUE:end-start; // AV_NOPTS_VALUE means live broadcast (and can't seek)
+        } else if (av_strstart(p, "IsRealDataType:integer;",&p)) {
+            if (atoi(p) == 1)
+                rt->transport = RTSP_TRANSPORT_RDT;
         } else if (s->nb_streams > 0) {
             rtsp_st = s->streams[s->nb_streams - 1]->priv_data;
             if (rtsp_st->dynamic_handler &&
@@ -636,11 +647,14 @@ static void rtsp_parse_transport(RTSPHeader *reply, const char *p)
                 p++;
                 get_word_sep(lower_transport, sizeof(lower_transport),
                              ";,", &p);
-                }
-        } else if (!strcasecmp (transport_protocol, "x-pn-tng")) {
+            }
+            th->transport = RTSP_TRANSPORT_RTP;
+        } else if (!strcasecmp (transport_protocol, "x-pn-tng") ||
+                   !strcasecmp (transport_protocol, "x-real-rdt")) {
             /* x-pn-tng/<protocol> */
             get_word_sep(lower_transport, sizeof(lower_transport), "/;,", &p);
             profile[0] = '\0';
+            th->transport = RTSP_TRANSPORT_RDT;
         }
         if (!strcasecmp(lower_transport, "TCP"))
             th->lower_transport = RTSP_LOWER_TRANSPORT_TCP;
@@ -859,8 +873,12 @@ static void rtsp_close_streams(RTSPState *rt)
     for(i=0;i<rt->nb_rtsp_streams;i++) {
         rtsp_st = rt->rtsp_streams[i];
         if (rtsp_st) {
-            if (rtsp_st->rtp_ctx)
-                rtp_parse_close(rtsp_st->rtp_ctx);
+            if (rtsp_st->tx_ctx) {
+                if (rt->transport == RTSP_TRANSPORT_RDT)
+                    ff_rdt_parse_close(rtsp_st->tx_ctx);
+                else
+                    rtp_parse_close(rtsp_st->tx_ctx);
+            }
             if (rtsp_st->rtp_handle)
                 url_close(rtsp_st->rtp_handle);
             if (rtsp_st->dynamic_handler && rtsp_st->dynamic_protocol_context)
@@ -873,6 +891,7 @@ static void rtsp_close_streams(RTSPState *rt)
 static int
 rtsp_open_transport_ctx(AVFormatContext *s, RTSPStream *rtsp_st)
 {
+    RTSPState *rt = s->priv_data;
     AVStream *st = NULL;
 
     /* open the RTP context */
@@ -880,14 +899,23 @@ rtsp_open_transport_ctx(AVFormatContext *s, RTSPStream *rtsp_st)
         st = s->streams[rtsp_st->stream_index];
     if (!st)
         s->ctx_flags |= AVFMTCTX_NOHEADER;
-    rtsp_st->rtp_ctx = rtp_parse_open(s, st, rtsp_st->rtp_handle, rtsp_st->sdp_payload_type, &rtsp_st->rtp_payload_data);
 
-    if (!rtsp_st->rtp_ctx) {
+    if (rt->transport == RTSP_TRANSPORT_RDT)
+        rtsp_st->tx_ctx = ff_rdt_parse_open(s, st->index,
+                                            rtsp_st->dynamic_protocol_context,
+                                            rtsp_st->dynamic_handler);
+    else
+        rtsp_st->tx_ctx = rtp_parse_open(s, st, rtsp_st->rtp_handle,
+                                         rtsp_st->sdp_payload_type,
+                                         &rtsp_st->rtp_payload_data);
+
+    if (!rtsp_st->tx_ctx) {
          return AVERROR(ENOMEM);
-    } else {
+    } else if (rt->transport != RTSP_TRANSPORT_RDT) {
         if(rtsp_st->dynamic_handler) {
-            rtsp_st->rtp_ctx->dynamic_protocol_context= rtsp_st->dynamic_protocol_context;
-            rtsp_st->rtp_ctx->parse_packet= rtsp_st->dynamic_handler->parse_packet;
+            rtp_parse_set_dynamic_protocol(rtsp_st->tx_ctx,
+                                           rtsp_st->dynamic_protocol_context,
+                                           rtsp_st->dynamic_handler);
         }
     }
 
@@ -908,7 +936,7 @@ make_setup_request (AVFormatContext *s, const char *host, int port,
     char cmd[2048];
     const char *trans_pref;
 
-    if (rt->server_type == RTSP_SERVER_REAL)
+    if (rt->transport == RTSP_TRANSPORT_RDT)
         trans_pref = "x-pn-tng";
     else
         trans_pref = "RTP/AVP";
@@ -952,7 +980,7 @@ make_setup_request (AVFormatContext *s, const char *host, int port,
                 av_strlcat(transport, "unicast;", sizeof(transport));
             av_strlcatf(transport, sizeof(transport),
                      "client_port=%d", port);
-            if (rt->server_type == RTSP_SERVER_RTP)
+            if (rt->transport == RTSP_TRANSPORT_RTP)
                 av_strlcatf(transport, sizeof(transport), "-%d", port + 1);
         }
 
@@ -993,12 +1021,14 @@ make_setup_request (AVFormatContext *s, const char *host, int port,
 
         /* XXX: same protocol for all streams is required */
         if (i > 0) {
-            if (reply->transports[0].lower_transport != rt->lower_transport) {
+            if (reply->transports[0].lower_transport != rt->lower_transport ||
+                reply->transports[0].transport != rt->transport) {
                 err = AVERROR_INVALIDDATA;
                 goto fail;
             }
         } else {
             rt->lower_transport = reply->transports[0].lower_transport;
+            rt->transport = reply->transports[0].transport;
         }
 
         /* close RTP connection if not choosen */
@@ -1250,6 +1280,9 @@ static int tcp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
     ret = url_readbuf(rt->rtsp_hd, buf, len);
     if (ret != len)
         return -1;
+    if (rt->transport == RTSP_TRANSPORT_RDT &&
+        ff_rdt_parse_header(buf, len, &id, NULL, NULL, NULL, NULL) < 0)
+        return -1;
 
     /* find the matching stream */
     for(i = 0; i < rt->nb_rtsp_streams; i++) {
@@ -1325,9 +1358,10 @@ static int rtsp_read_packet(AVFormatContext *s,
         for (i = 0; i < rt->nb_rtsp_streams; i++) {
             if (i != 0) av_strlcat(cmd, ",", sizeof(cmd));
             ff_rdt_subscribe_rule(cmd, sizeof(cmd), i, 0);
-            ff_rdt_subscribe_rule2(
-                rt->rtsp_streams[i]->rtp_ctx,
-                cmd, sizeof(cmd), i, 0);
+            if (rt->transport == RTSP_TRANSPORT_RDT)
+                ff_rdt_subscribe_rule2(
+                    rt->rtsp_streams[i]->tx_ctx,
+                    cmd, sizeof(cmd), i, 0);
         }
         av_strlcat(cmd, "\r\n", sizeof(cmd));
         rtsp_send_cmd(s, cmd, reply, NULL);
@@ -1340,18 +1374,18 @@ static int rtsp_read_packet(AVFormatContext *s,
     }
 
     /* get next frames from the same RTP packet */
-    if (rt->cur_rtp) {
-        if (rt->server_type == RTSP_SERVER_REAL)
-            ret = ff_rdt_parse_packet(rt->cur_rtp, pkt, NULL, 0);
+    if (rt->cur_tx) {
+        if (rt->transport == RTSP_TRANSPORT_RDT)
+            ret = ff_rdt_parse_packet(rt->cur_tx, pkt, NULL, 0);
         else
-            ret = rtp_parse_packet(rt->cur_rtp, pkt, NULL, 0);
+            ret = rtp_parse_packet(rt->cur_tx, pkt, NULL, 0);
         if (ret == 0) {
-            rt->cur_rtp = NULL;
+            rt->cur_tx = NULL;
             return 0;
         } else if (ret == 1) {
             return 0;
         } else {
-            rt->cur_rtp = NULL;
+            rt->cur_tx = NULL;
         }
     }
 
@@ -1365,21 +1399,21 @@ static int rtsp_read_packet(AVFormatContext *s,
     case RTSP_LOWER_TRANSPORT_UDP:
     case RTSP_LOWER_TRANSPORT_UDP_MULTICAST:
         len = udp_read_packet(s, &rtsp_st, buf, sizeof(buf));
-        if (len >=0 && rtsp_st->rtp_ctx)
-            rtp_check_and_send_back_rr(rtsp_st->rtp_ctx, len);
+        if (len >=0 && rtsp_st->tx_ctx && rt->transport == RTSP_TRANSPORT_RTP)
+            rtp_check_and_send_back_rr(rtsp_st->tx_ctx, len);
         break;
     }
     if (len < 0)
         return len;
-    if (rt->server_type == RTSP_SERVER_REAL)
-        ret = ff_rdt_parse_packet(rtsp_st->rtp_ctx, pkt, buf, len);
+    if (rt->transport == RTSP_TRANSPORT_RDT)
+        ret = ff_rdt_parse_packet(rtsp_st->tx_ctx, pkt, buf, len);
     else
-        ret = rtp_parse_packet(rtsp_st->rtp_ctx, pkt, buf, len);
+        ret = rtp_parse_packet(rtsp_st->tx_ctx, pkt, buf, len);
     if (ret < 0)
         goto redo;
     if (ret == 1) {
         /* more packets may follow, so we save the RTP context */
-        rt->cur_rtp = rtsp_st->rtp_ctx;
+        rt->cur_tx = rtsp_st->tx_ctx;
     }
     return 0;
 }