[FFmpeg-cvslog] r15235 - in trunk/libavformat: rdt.c rdt.h rtsp.c

rbultje subversion
Sun Sep 7 03:22:18 CEST 2008


Author: rbultje
Date: Sun Sep  7 03:22:18 2008
New Revision: 15235

Log:
Implement a RDT-specific SET_PARAMETER command that subscribes to the
first stream in a RTSP/RDT session. See discussion in "Realmedia patch"
thread on ML.



Modified:
   trunk/libavformat/rdt.c
   trunk/libavformat/rdt.h
   trunk/libavformat/rtsp.c

Modified: trunk/libavformat/rdt.c
==============================================================================
--- trunk/libavformat/rdt.c	(original)
+++ trunk/libavformat/rdt.c	Sun Sep  7 03:22:18 2008
@@ -134,6 +134,18 @@ rdt_load_mdpr (rdt_data *rdt, AVStream *
     return 0;
 }
 
+void
+ff_rdt_subscribe_rule (RTPDemuxContext *s, char *cmd, int size,
+                       int stream_nr, int rule_nr)
+{
+    rdt_data *rdt = s->dynamic_protocol_context;
+
+    av_strlcatf(cmd, size, "stream=%d;rule=%d,stream=%d;rule=%d",
+                stream_nr, rule_nr, stream_nr, rule_nr + 1);
+
+    rdt_load_mdpr(rdt, s->st, 0);
+}
+
 static unsigned char *
 rdt_parse_b64buf (unsigned int *target_len, const char *p)
 {
@@ -157,7 +169,6 @@ rdt_parse_sdp_line (AVStream *stream, vo
 
     if (av_strstart(p, "OpaqueData:buffer;", &p)) {
         rdt->mlti_data = rdt_parse_b64buf(&rdt->mlti_data_size, p);
-        rdt_load_mdpr(rdt, stream, 0);
     } else if (av_strstart(p, "StartTime:integer;", &p))
         stream->first_dts = atoi(p);
 

Modified: trunk/libavformat/rdt.h
==============================================================================
--- trunk/libavformat/rdt.h	(original)
+++ trunk/libavformat/rdt.h	Sun Sep  7 03:22:18 2008
@@ -42,4 +42,16 @@ void ff_rdt_calc_response_and_checksum(c
  */
 void av_register_rdt_dynamic_payload_handlers(void);
 
+/**
+ * Add subscription information to Subscribe parameter string.
+ *
+ * @param s RDT context
+ * @param cmd string to write the subscription information into.
+ * @param size size of cmd.
+ * @param stream_nr stream number.
+ * @param rule_nr rule number to conform to.
+ */
+void ff_rdt_subscribe_rule(RTPDemuxContext *s, char *cmd, int size,
+                           int stream_nr, int rule_nr);
+
 #endif /* AVFORMAT_RDT_H */

Modified: trunk/libavformat/rtsp.c
==============================================================================
--- trunk/libavformat/rtsp.c	(original)
+++ trunk/libavformat/rtsp.c	Sun Sep  7 03:22:18 2008
@@ -65,6 +65,7 @@ typedef struct RTSPState {
     enum RTSPServerType server_type;
     char last_reply[2048]; /* XXX: allocate ? */
     RTPDemuxContext *cur_rtp;
+    int need_subscription;
 } RTSPState;
 
 typedef struct RTSPStream {
@@ -1034,6 +1035,9 @@ make_setup_request (AVFormatContext *s, 
         }
     }
 
+    if (rt->server_type == RTSP_SERVER_RDT)
+        rt->need_subscription = 1;
+
     return 0;
 
 fail:
@@ -1295,6 +1299,31 @@ static int rtsp_read_packet(AVFormatCont
     int ret, len;
     uint8_t buf[RTP_MAX_PACKET_LENGTH];
 
+    if (rt->server_type == RTSP_SERVER_RDT && rt->need_subscription) {
+        int i;
+        RTSPHeader reply1, *reply = &reply1;
+        char cmd[1024];
+
+        snprintf(cmd, sizeof(cmd),
+                 "SET_PARAMETER %s RTSP/1.0\r\n"
+                 "Subscribe: ",
+                 s->filename);
+        for (i = 0; i < rt->nb_rtsp_streams; i++) {
+            if (i != 0) av_strlcat(cmd, ",", sizeof(cmd));
+            ff_rdt_subscribe_rule(
+                rt->rtsp_streams[i]->rtp_ctx,
+                cmd, sizeof(cmd), i, 0);
+        }
+        av_strlcat(cmd, "\r\n", sizeof(cmd));
+        rtsp_send_cmd(s, cmd, reply, NULL);
+        if (reply->status_code != RTSP_STATUS_OK)
+            return AVERROR_INVALIDDATA;
+        rt->need_subscription = 0;
+
+        if (rt->state == RTSP_STATE_PLAYING)
+            rtsp_read_play (s);
+    }
+
     /* get next frames from the same RTP packet */
     if (rt->cur_rtp) {
         ret = rtp_parse_packet(rt->cur_rtp, pkt, NULL, 0);
@@ -1342,6 +1371,7 @@ static int rtsp_read_play(AVFormatContex
 
     av_log(s, AV_LOG_DEBUG, "hello state=%d\n", rt->state);
 
+    if (!(rt->server_type == RTSP_SERVER_RDT && rt->need_subscription)) {
     if (rt->state == RTSP_STATE_PAUSED) {
         snprintf(cmd, sizeof(cmd),
                  "PLAY %s RTSP/1.0\r\n",
@@ -1357,6 +1387,7 @@ static int rtsp_read_play(AVFormatContex
     if (reply->status_code != RTSP_STATUS_OK) {
         return -1;
     }
+    }
     rt->state = RTSP_STATE_PLAYING;
     return 0;
 }
@@ -1372,7 +1403,7 @@ static int rtsp_read_pause(AVFormatConte
 
     if (rt->state != RTSP_STATE_PLAYING)
         return 0;
-
+    else if (!(rt->server_type == RTSP_SERVER_RDT && rt->need_subscription)) {
     snprintf(cmd, sizeof(cmd),
              "PAUSE %s RTSP/1.0\r\n",
              s->filename);
@@ -1380,6 +1411,7 @@ static int rtsp_read_pause(AVFormatConte
     if (reply->status_code != RTSP_STATUS_OK) {
         return -1;
     }
+    }
     rt->state = RTSP_STATE_PAUSED;
     return 0;
 }




More information about the ffmpeg-cvslog mailing list