Hi,

On 25 June 2010 16:10, Luca Barbato <[email protected]> wrote:
> On 06/26/2010 12:28 AM, Josh Allmann wrote:
>> Hi,
>>
>> This cleans up FMTP parsing code somewhat. I only did it for H.264 and
>> MPEG-4/AAC; if this approach is OK, I'll do the rest (Xiph, AMR, etc).
>>
>> 0002 -- self explanatory. It is likely I will have to change
>> value[4096] to be malloc'd due to massive Xiph extradata.
>
> +int ff_parse_fmtp(AVFormatContext *s, int st_index,
> +                  void *data, const char *p,
> +                  int (*parse_fmtp)(AVFormatContext *s, int st_index,
> +                                    PayloadContext *data,
> +                                    char *attr, char *value))
>
> Why void data? why AVFormatContext *s, int st_index ? When passing the
> stream isn't enough?
>

Fixed void data.

I was trying to play it safe with passing the format context, but
seems none of the depacketizers need it, so changed to AVStream.

> +    while (!(res = strspn(p, SPACE_CHARS))) p++; // protocol identifier
>
> are you sure you need that?
>

Reverted to the old way of doing things:

+    while (*p && *p != ' ') p++; // eat protocol identifier

>
>> 003-005 -- H.264 related
>
> 0003 Ok
>
> 0004
>
> -            sdp_parse_fmtp_config_h264(stream, h264_data, attr, value);
> -        }
> +        return ff_parse_fmtp(s, st_index, h264_data, p,
> +                      &sdp_parse_fmtp_config_h264);
>
> sdp_parse_fmtp_config_h264 takes a stream as argument ff_parse_fmtp
> parse_fmtp doesn't seem to match the function.
>

Not sure what you mean (I changed the function signature for
sdp_parse_fmtp_config in the other hunk), but that's moot since
ff_parse_fmtp takes a stream now.
From fc8dbe211bc6d536fae8dba75c83d24ee32c93d8 Mon Sep 17 00:00:00 2001
From: Josh Allmann <[email protected]>
Date: Fri, 25 Jun 2010 14:24:58 -0700
Subject: [PATCH 1/7] Move space_chars from avformat/internal to rtpdec.

---
 libavformat/internal.h     |    2 --
 libavformat/rtpdec.h       |    2 ++
 libavformat/rtpdec_mpeg4.c |    1 -
 3 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/libavformat/internal.h b/libavformat/internal.h
index 8a164bd..4489ffe 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -174,6 +174,4 @@ void ff_sdp_write_media(char *buff, int size, AVCodecContext *c,
 int ff_write_chained(AVFormatContext *dst, int dst_stream, AVPacket *pkt,
                      AVFormatContext *src);
 
-#define SPACE_CHARS " \t\r\n"
-
 #endif /* AVFORMAT_INTERNAL_H */
diff --git a/libavformat/rtpdec.h b/libavformat/rtpdec.h
index 8a62034..439fcc2 100644
--- a/libavformat/rtpdec.h
+++ b/libavformat/rtpdec.h
@@ -26,6 +26,8 @@
 #include "avformat.h"
 #include "rtp.h"
 
+#define SPACE_CHARS " \t\r\n"
+
 typedef struct PayloadContext PayloadContext;
 typedef struct RTPDynamicProtocolHandler_s RTPDynamicProtocolHandler;
 
diff --git a/libavformat/rtpdec_mpeg4.c b/libavformat/rtpdec_mpeg4.c
index dec45b4..cb22b32 100644
--- a/libavformat/rtpdec_mpeg4.c
+++ b/libavformat/rtpdec_mpeg4.c
@@ -28,7 +28,6 @@
  */
 
 #include "rtpdec_mpeg4.h"
-#include "internal.h"
 #include "libavutil/avstring.h"
 #include "libavcodec/get_bits.h"
 #include <strings.h>
-- 
1.7.0.4

From 950f79d1243ea5aa5cdb93d535b87960a919b189 Mon Sep 17 00:00:00 2001
From: Josh Allmann <[email protected]>
Date: Fri, 25 Jun 2010 15:07:42 -0700
Subject: [PATCH 2/7] Added generic function for iterating over FMTP extradata. This will clean up code that is common among RTP depacketizers.

---
 libavformat/rtpdec.c |   25 +++++++++++++++++++++++++
 libavformat/rtpdec.h |    5 +++++
 2 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c
index 456e2e4..74858f6 100644
--- a/libavformat/rtpdec.c
+++ b/libavformat/rtpdec.c
@@ -531,3 +531,28 @@ void rtp_parse_close(RTPDemuxContext *s)
     }
     av_free(s);
 }
+
+int ff_parse_fmtp(AVStream *stream, PayloadContext *data, const char *p,
+                  int (*parse_fmtp)(AVStream *stream,
+                                    PayloadContext *data,
+                                    char *attr, char *value))
+{
+    char attr[256];
+    char value[4096];
+    int res;
+
+    // remove protocol identifier
+    while (*p && *p == ' ') p++; // strip spaces
+    while (*p && *p != ' ') p++; // eat protocol identifier
+    while (*p && *p == ' ') p++; // strip trailing spaces
+
+    while (ff_rtsp_next_attr_and_value(&p,
+                                       attr, sizeof(attr),
+                                       value, sizeof(value))) {
+
+        res = parse_fmtp(stream, data, attr, value);
+        if (res < 0)
+            return res;
+    }
+    return 0;
+}
diff --git a/libavformat/rtpdec.h b/libavformat/rtpdec.h
index 439fcc2..86af2b9 100644
--- a/libavformat/rtpdec.h
+++ b/libavformat/rtpdec.h
@@ -172,6 +172,11 @@ void ff_register_dynamic_payload_handler(RTPDynamicProtocolHandler *handler);
 
 int ff_rtsp_next_attr_and_value(const char **p, char *attr, int attr_size, char *value, int value_size); ///< from rtsp.c, but used by rtp dynamic protocol handlers.
 
+int ff_parse_fmtp(AVStream *stream, PayloadContext *data, const char *p,
+                  int (*parse_fmtp)(AVStream *stream,
+                                    PayloadContext *data,
+                                    char *attr, char *value));
+
 void av_register_rtp_dynamic_payload_handlers(void);
 
 #endif /* AVFORMAT_RTPDEC_H */
-- 
1.7.0.4

From d556761a788c8087f44c572bfb12494448cf905a Mon Sep 17 00:00:00 2001
From: Josh Allmann <[email protected]>
Date: Fri, 25 Jun 2010 15:03:06 -0700
Subject: [PATCH 3/7] Return ENOMEM if H.264 RTP fails to allocate memory for SDP extradata.

---
 libavformat/rtpdec_h264.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/libavformat/rtpdec_h264.c b/libavformat/rtpdec_h264.c
index 49db08a..a6e0de8 100644
--- a/libavformat/rtpdec_h264.c
+++ b/libavformat/rtpdec_h264.c
@@ -69,7 +69,7 @@ struct PayloadContext {
 #define DEAD_COOKIE (0xdeaddead)        ///< Cookie for the extradata; once it is freed.
 
 /* ---------------- private code */
-static void sdp_parse_fmtp_config_h264(AVStream * stream,
+static int sdp_parse_fmtp_config_h264(AVStream * stream,
                                        PayloadContext * h264_data,
                                        char *attr, char *value)
 {
@@ -155,11 +155,13 @@ static void sdp_parse_fmtp_config_h264(AVStream * stream,
                     codec->extradata_size+= sizeof(start_sequence)+packet_size;
                 } else {
                     av_log(codec, AV_LOG_ERROR, "Unable to allocate memory for extradata!");
+                    return AVERROR(ENOMEM);
                 }
             }
         }
         av_log(codec, AV_LOG_DEBUG, "Extradata set to %p (size: %d)!", codec->extradata, codec->extradata_size);
     }
+    return 0;
 }
 
 // return 0 on packet, no more left, 1 on packet, 1 on partial packet...
-- 
1.7.0.4

From 876deb6d627f34b673069e787c6da7e200a014c1 Mon Sep 17 00:00:00 2001
From: Josh Allmann <[email protected]>
Date: Fri, 25 Jun 2010 15:10:49 -0700
Subject: [PATCH 4/7] Clean up FMTP parsing code in H.264 RTP depacketizer.

---
 libavformat/rtpdec_h264.c |   16 ++--------------
 1 files changed, 2 insertions(+), 14 deletions(-)

diff --git a/libavformat/rtpdec_h264.c b/libavformat/rtpdec_h264.c
index a6e0de8..6cce6e6 100644
--- a/libavformat/rtpdec_h264.c
+++ b/libavformat/rtpdec_h264.c
@@ -385,20 +385,8 @@ static int parse_h264_sdp_line(AVFormatContext *s, int st_index,
         codec->height = atoi(p + 1); // skip the -
         codec->pix_fmt = PIX_FMT_YUV420P;
     } else if (av_strstart(p, "fmtp:", &p)) {
-        char attr[256];
-        char value[4096];
-
-        // remove the protocol identifier..
-        while (*p && *p == ' ') p++; // strip spaces.
-        while (*p && *p != ' ') p++; // eat protocol identifier
-        while (*p && *p == ' ') p++; // strip trailing spaces.
-
-        /* loop on each attribute */
-        while (ff_rtsp_next_attr_and_value
-               (&p, attr, sizeof(attr), value, sizeof(value))) {
-            /* grab the codec extra_data from the config parameter of the fmtp line */
-            sdp_parse_fmtp_config_h264(stream, h264_data, attr, value);
-        }
+        return ff_parse_fmtp(stream, h264_data, p,
+                             &sdp_parse_fmtp_config_h264);
     } else if (av_strstart(p, "cliprect:", &p)) {
         // could use this if we wanted.
     }
-- 
1.7.0.4

From d43adae9478ade263af082a946a4a4453a09e06b Mon Sep 17 00:00:00 2001
From: Josh Allmann <[email protected]>
Date: Fri, 25 Jun 2010 15:16:05 -0700
Subject: [PATCH 5/7] h264 rtp cosmetics

---
 libavformat/rtpdec_h264.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/rtpdec_h264.c b/libavformat/rtpdec_h264.c
index 6cce6e6..a75cfcb 100644
--- a/libavformat/rtpdec_h264.c
+++ b/libavformat/rtpdec_h264.c
@@ -70,8 +70,8 @@ struct PayloadContext {
 
 /* ---------------- private code */
 static int sdp_parse_fmtp_config_h264(AVStream * stream,
-                                       PayloadContext * h264_data,
-                                       char *attr, char *value)
+                                      PayloadContext * h264_data,
+                                      char *attr, char *value)
 {
     AVCodecContext *codec = stream->codec;
     assert(codec->codec_id == CODEC_ID_H264);
-- 
1.7.0.4

From 25bdda2e1c8b699c6dbaf864f7982849830aa9cc Mon Sep 17 00:00:00 2001
From: Josh Allmann <[email protected]>
Date: Fri, 25 Jun 2010 15:11:36 -0700
Subject: [PATCH 6/7] Clean up FMTP parsing code in MPEG-4/AAC RTP depacketizer.

---
 libavformat/rtpdec_mpeg4.c |   33 ++++++++++++++-------------------
 1 files changed, 14 insertions(+), 19 deletions(-)

diff --git a/libavformat/rtpdec_mpeg4.c b/libavformat/rtpdec_mpeg4.c
index cb22b32..f709310 100644
--- a/libavformat/rtpdec_mpeg4.c
+++ b/libavformat/rtpdec_mpeg4.c
@@ -219,24 +219,12 @@ static int aac_parse_packet(AVFormatContext *ctx,
     return 0;
 }
 
-static int parse_sdp_line(AVFormatContext *s, int st_index,
-                          PayloadContext *data, const char *line)
+static int parse_fmtp(AVStream *stream, PayloadContext *data,
+                      char *attr, char *value)
 {
-    const char *p;
-    char value[4096], attr[25];
-    int res = 0, i;
-    AVStream *st = s->streams[st_index];
-    AVCodecContext* codec = st->codec;
-
-    if (av_strstart(line, "fmtp:", &p)) {
-        // remove protocol identifier
-        while (*p && *p == ' ') p++; // strip spaces
-        while (*p && *p != ' ') p++; // eat protocol identifier
-        while (*p && *p == ' ') p++; // strip trailing spaces
-
-        while (ff_rtsp_next_attr_and_value(&p,
-                                           attr, sizeof(attr),
-                                           value, sizeof(value))) {
+    AVCodecContext *codec = stream->codec;
+    int res, i;
+
             if (!strcmp(attr, "config")) {
                 res = parse_fmtp_config(codec, value);
 
@@ -257,11 +245,18 @@ static int parse_sdp_line(AVFormatContext *s, int st_index,
                     }
                 }
             }
+    return 0;
         }
-    }
 
-    return 0;
+static int parse_sdp_line(AVFormatContext *s, int st_index,
+                          PayloadContext *data, const char *line)
+{
+    const char *p;
+
+    if (av_strstart(line, "fmtp:", &p))
+        return ff_parse_fmtp(s->streams[st_index], data, p, &parse_fmtp);
 
+    return 0;
 }
 
 RTPDynamicProtocolHandler ff_mp4v_es_dynamic_handler = {
-- 
1.7.0.4

From dcba4bc6ebd8ffa410831783cd1cb4cda12baf8c Mon Sep 17 00:00:00 2001
From: Josh Allmann <[email protected]>
Date: Fri, 25 Jun 2010 15:16:53 -0700
Subject: [PATCH 7/7] mpeg4/aac rtp cosmetics.

---
 libavformat/rtpdec_mpeg4.c |   35 ++++++++++++++++++-----------------
 1 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/libavformat/rtpdec_mpeg4.c b/libavformat/rtpdec_mpeg4.c
index f709310..3d68cca 100644
--- a/libavformat/rtpdec_mpeg4.c
+++ b/libavformat/rtpdec_mpeg4.c
@@ -225,28 +225,29 @@ static int parse_fmtp(AVStream *stream, PayloadContext *data,
     AVCodecContext *codec = stream->codec;
     int res, i;
 
-            if (!strcmp(attr, "config")) {
-                res = parse_fmtp_config(codec, value);
+    if (!strcmp(attr, "config")) {
+        res = parse_fmtp_config(codec, value);
 
-                if (res < 0)
-                    return res;
-            }
+        if (res < 0)
+            return res;
+    }
 
-            if (codec->codec_id == CODEC_ID_AAC) {
-                /* Looking for a known attribute */
-                for (i = 0; attr_names[i].str; ++i) {
-                    if (!strcasecmp(attr, attr_names[i].str)) {
-                        if (attr_names[i].type == ATTR_NAME_TYPE_INT) {
-                            *(int *)((char *)data+
-                                attr_names[i].offset) = atoi(value);
-                        } else if (attr_names[i].type == ATTR_NAME_TYPE_STR)
-                            *(char **)((char *)data+
-                                attr_names[i].offset) = av_strdup(value);
-                    }
+    if (codec->codec_id == CODEC_ID_AAC) {
+        /* Looking for a known attribute */
+        for (i = 0; attr_names[i].str; ++i) {
+            if (!strcasecmp(attr, attr_names[i].str)) {
+                if (attr_names[i].type == ATTR_NAME_TYPE_INT) {
+                    *(int *)((char *)data+
+                        attr_names[i].offset) = atoi(value);
+                } else if (attr_names[i].type == ATTR_NAME_TYPE_STR) {
+                    *(char **)((char *)data+
+                        attr_names[i].offset) = av_strdup(value);
                 }
             }
-    return 0;
         }
+    }
+    return 0;
+}
 
 static int parse_sdp_line(AVFormatContext *s, int st_index,
                           PayloadContext *data, const char *line)
-- 
1.7.0.4

_______________________________________________
FFmpeg-soc mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc

Reply via email to