[FFmpeg-devel] [PATCH] rtsp.c small cleanups

Ronald S. Bultje rsbultje
Sat Mar 21 04:35:24 CET 2009


Hi,

Attached are small cleanups for rtsp.c.

(1) use skip_spaces(&p); instead of while (redir_isspace(*p)) p++;
(2) merge get_word() and get_word_sep() into a general function,
remove the redir_isspace() function by a macro that calls strchr()
(3) stupid bug in hex_to_data()
(4) reindent fix
(5) removing a useless comment about something deprecated
(6) removing slash-skipping code because the called function
get_word_sep() does that already.
(7) free extradata if it already exists, fixes theoretical memleak
(8) remove sdp_read_packet() and replace it with rtsp_read_packet()
because that's all it does

This was my general quick read of rtsp.c. I intend to next see if
rtsp.c conforms correctly to all standards and if I should do any
additional work. Might lead to some changes in the SDP parsing code or
the order or type of RTSP commands that we send. I might also analyze
rtpdec.c at some point.

Please comment,
Ronald
-------------- next part --------------
Index: ffmpeg-svn/libavformat/rtsp.c
===================================================================
--- ffmpeg-svn.orig/libavformat/rtsp.c	2009-03-20 23:08:48.000000000 -0400
+++ ffmpeg-svn/libavformat/rtsp.c	2009-03-20 23:11:12.000000000 -0400
@@ -1763,8 +1763,7 @@
 {
     const char *p;
     p = pd->buf;
-    while (redir_isspace(*p))
-        p++;
+    skip_spaces(&p);
     if (av_strstart(p, "http://", NULL) ||
         av_strstart(p, "rtsp://", NULL))
         return AVPROBE_SCORE_MAX;
-------------- next part --------------
Index: ffmpeg-svn/libavformat/rtsp.c
===================================================================
--- ffmpeg-svn.orig/libavformat/rtsp.c	2009-03-20 23:05:03.000000000 -0400
+++ ffmpeg-svn/libavformat/rtsp.c	2009-03-20 23:08:48.000000000 -0400
@@ -57,11 +57,8 @@
     return 0;
 }
 
-static int redir_isspace(int c)
-{
-    return c == ' ' || c == '\t' || c == '\n' || c == '\r';
-}
-
+#define SPACE_CHARS " \t\r\n"
+#define redir_isspace(c) strchr(SPACE_CHARS, c)
 static void skip_spaces(const char **pp)
 {
     const char *p;
@@ -71,15 +68,13 @@
     *pp = p;
 }
 
-static void get_word_sep(char *buf, int buf_size, const char *sep,
-                         const char **pp)
+static void get_word_until_chars(char *buf, int buf_size,
+                                 const char *sep, const char **pp)
 {
     const char *p;
     char *q;
 
     p = *pp;
-    if (*p == '/')
-        p++;
     skip_spaces(&p);
     q = buf;
     while (!strchr(sep, *p) && *p != '\0') {
@@ -92,22 +87,16 @@
     *pp = p;
 }
 
-static void get_word(char *buf, int buf_size, const char **pp)
+static void get_word_sep(char *buf, int buf_size, const char *sep,
+                         const char **pp)
 {
-    const char *p;
-    char *q;
+    if (**pp == '/') (*pp)++;
+    get_word_until_chars(buf, buf_size, sep, pp);
+}
 
-    p = *pp;
-    skip_spaces(&p);
-    q = buf;
-    while (!redir_isspace(*p) && *p != '\0') {
-        if ((q - buf) < buf_size - 1)
-            *q++ = *p;
-        p++;
-    }
-    if (buf_size > 0)
-        *q = '\0';
-    *pp = p;
+static void get_word(char *buf, int buf_size, const char **pp)
+{
+    get_word_until_chars(buf, buf_size, SPACE_CHARS, pp);
 }
 
 /* parse the rtpmap description: <codec_name>/<clock_rate>[/<other
-------------- next part --------------
Index: ffmpeg-svn/libavformat/rtsp.c
===================================================================
--- ffmpeg-svn.orig/libavformat/rtsp.c	2009-03-20 23:11:58.000000000 -0400
+++ ffmpeg-svn/libavformat/rtsp.c	2009-03-20 23:15:12.000000000 -0400
@@ -174,7 +174,7 @@
     v = 1;
     for(;;) {
         skip_spaces(&p);
-        if (p == '\0')
+        if (*p == '\0')
             break;
         c = toupper((unsigned char)*p++);
         if (c >= '0' && c <= '9')
-------------- next part --------------
Index: ffmpeg-svn/libavformat/rtsp.c
===================================================================
--- ffmpeg-svn.orig/libavformat/rtsp.c	2009-03-20 23:15:52.000000000 -0400
+++ ffmpeg-svn/libavformat/rtsp.c	2009-03-20 23:23:34.000000000 -0400
@@ -243,8 +243,7 @@
 int rtsp_next_attr_and_value(const char **p, char *attr, int attr_size, char *value, int value_size)
 {
     skip_spaces(p);
-    if(**p)
-    {
+    if(**p) {
         get_word_sep(attr, attr_size, "=", p);
         if (**p == '=')
             (*p)++;
-------------- next part --------------
Index: ffmpeg-svn/libavformat/rtsp.c
===================================================================
--- ffmpeg-svn.orig/libavformat/rtsp.c	2009-03-20 08:09:31.000000000 -0400
+++ ffmpeg-svn/libavformat/rtsp.c	2009-03-20 08:11:43.000000000 -0400
@@ -43,9 +43,6 @@
 
 static int rtsp_read_play(AVFormatContext *s);
 
-/* XXX: currently, the only way to change the protocols consists in
-   changing this variable */
-
 #if LIBAVFORMAT_VERSION_INT < (53 << 16)
 int rtsp_default_protocols = (1 << RTSP_LOWER_TRANSPORT_UDP);
 #endif
-------------- next part --------------
Index: ffmpeg-svn/libavformat/rtsp.c
===================================================================
--- ffmpeg-svn.orig/libavformat/rtsp.c	2009-03-20 23:24:52.000000000 -0400
+++ ffmpeg-svn/libavformat/rtsp.c	2009-03-20 23:24:59.000000000 -0400
@@ -584,14 +584,11 @@
 
         get_word_sep(transport_protocol, sizeof(transport_protocol),
                      "/", &p);
-        if (*p == '/')
-            p++;
         if (!strcasecmp (transport_protocol, "rtp")) {
             get_word_sep(profile, sizeof(profile), "/;,", &p);
             lower_transport[0] = '\0';
             /* rtp/avp/<protocol> */
             if (*p == '/') {
-                p++;
                 get_word_sep(lower_transport, sizeof(lower_transport),
                              ";,", &p);
             }
-------------- next part --------------
Index: ffmpeg-svn/libavformat/rtsp.c
===================================================================
--- ffmpeg-svn.orig/libavformat/rtsp.c	2009-03-20 23:15:12.000000000 -0400
+++ ffmpeg-svn/libavformat/rtsp.c	2009-03-20 23:15:52.000000000 -0400
@@ -202,6 +202,8 @@
             if (!strcmp(attr, "config")) {
                 /* decode the hexa encoded parameter */
                 int len = hex_to_data(NULL, value);
+                if (codec->extradata)
+                    av_free(codec->extradata);
                 codec->extradata = av_mallocz(len + FF_INPUT_BUFFER_PADDING_SIZE);
                 if (!codec->extradata)
                     return;
-------------- next part --------------
Index: ffmpeg-svn/libavformat/rtsp.c
===================================================================
--- ffmpeg-svn.orig/libavformat/rtsp.c	2009-03-20 23:24:59.000000000 -0400
+++ ffmpeg-svn/libavformat/rtsp.c	2009-03-20 23:25:19.000000000 -0400
@@ -1728,12 +1728,6 @@
     return err;
 }
 
-static int sdp_read_packet(AVFormatContext *s,
-                            AVPacket *pkt)
-{
-    return rtsp_read_packet(s, pkt);
-}
-
 static int sdp_read_close(AVFormatContext *s)
 {
     RTSPState *rt = s->priv_data;
@@ -1748,7 +1742,7 @@
     sizeof(RTSPState),
     sdp_probe,
     sdp_read_header,
-    sdp_read_packet,
+    rtsp_read_packet,
     sdp_read_close,
 };
 #endif



More information about the ffmpeg-devel mailing list