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

mstorsjo subversion
Fri Oct 1 19:41:32 CEST 2010


Author: mstorsjo
Date: Fri Oct  1 19:41:31 2010
New Revision: 25288

Log:
rtsp: Use a dynamically allocated receive buffer

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

Modified: trunk/libavformat/rtsp.c
==============================================================================
--- trunk/libavformat/rtsp.c	Fri Oct  1 18:02:10 2010	(r25287)
+++ trunk/libavformat/rtsp.c	Fri Oct  1 19:41:31 2010	(r25288)
@@ -53,6 +53,7 @@ int rtsp_default_protocols = (1 << RTSP_
 #define READ_PACKET_TIMEOUT_S 10
 #define MAX_TIMEOUTS READ_PACKET_TIMEOUT_S * 1000 / SELECT_TIMEOUT_MS
 #define SDP_MAX_SIZE 16384
+#define RECVBUF_SIZE 10 * RTP_MAX_PACKET_LENGTH
 
 static void get_word_until_chars(char *buf, int buf_size,
                                  const char *sep, const char **pp)
@@ -498,6 +499,7 @@ void ff_rtsp_close_streams(AVFormatConte
         av_close_input_stream (rt->asf_ctx);
         rt->asf_ctx = NULL;
     }
+    av_free(rt->recvbuf);
 }
 
 static void *rtsp_rtp_mux_open(AVFormatContext *s, AVStream *st,
@@ -1794,7 +1796,6 @@ static int rtsp_fetch_packet(AVFormatCon
 {
     RTSPState *rt = s->priv_data;
     int ret, len;
-    uint8_t buf[10 * RTP_MAX_PACKET_LENGTH];
     RTSPStream *rtsp_st;
 
     if (rt->nb_byes == rt->nb_rtsp_streams)
@@ -1817,16 +1818,22 @@ static int rtsp_fetch_packet(AVFormatCon
 
     /* read next RTP packet */
  redo:
+    if (!rt->recvbuf) {
+        rt->recvbuf = av_malloc(RECVBUF_SIZE);
+        if (!rt->recvbuf)
+            return AVERROR(ENOMEM);
+    }
+
     switch(rt->lower_transport) {
     default:
 #if CONFIG_RTSP_DEMUXER
     case RTSP_LOWER_TRANSPORT_TCP:
-        len = tcp_read_packet(s, &rtsp_st, buf, sizeof(buf));
+        len = tcp_read_packet(s, &rtsp_st, rt->recvbuf, RECVBUF_SIZE);
         break;
 #endif
     case RTSP_LOWER_TRANSPORT_UDP:
     case RTSP_LOWER_TRANSPORT_UDP_MULTICAST:
-        len = udp_read_packet(s, &rtsp_st, buf, sizeof(buf));
+        len = udp_read_packet(s, &rtsp_st, rt->recvbuf, RECVBUF_SIZE);
         if (len >=0 && rtsp_st->transport_priv && rt->transport == RTSP_TRANSPORT_RTP)
             rtp_check_and_send_back_rr(rtsp_st->transport_priv, len);
         break;
@@ -1836,9 +1843,9 @@ static int rtsp_fetch_packet(AVFormatCon
     if (len == 0)
         return AVERROR_EOF;
     if (rt->transport == RTSP_TRANSPORT_RDT) {
-        ret = ff_rdt_parse_packet(rtsp_st->transport_priv, pkt, buf, len);
+        ret = ff_rdt_parse_packet(rtsp_st->transport_priv, pkt, rt->recvbuf, len);
     } else {
-        ret = rtp_parse_packet(rtsp_st->transport_priv, pkt, buf, len);
+        ret = rtp_parse_packet(rtsp_st->transport_priv, pkt, rt->recvbuf, len);
         if (ret < 0) {
             /* Either bad packet, or a RTCP packet. Check if the
              * first_rtcp_ntp_time field was initialized. */

Modified: trunk/libavformat/rtsp.h
==============================================================================
--- trunk/libavformat/rtsp.h	Fri Oct  1 18:02:10 2010	(r25287)
+++ trunk/libavformat/rtsp.h	Fri Oct  1 19:41:31 2010	(r25288)
@@ -309,6 +309,9 @@ typedef struct RTSPState {
      * An EOF is propagated back if nb_byes == nb_streams.
      * This is reset after a seek. */
     int nb_byes;
+
+    /** Reusable buffer for receiving packets */
+    uint8_t* recvbuf;
 } RTSPState;
 
 /**



More information about the ffmpeg-cvslog mailing list