From 2a3458590fc686866894572b3229ca1ca8a80736 Mon Sep 17 00:00:00 2001
From: Josh Allmann <joshua.allmann@gmail.com>
Date: Mon, 28 Jun 2010 00:30:45 -0700
Subject: [PATCH 10/11] Clean up FMTP parsing code for AMR RTP depacketizer.

---
 libavformat/rtpdec_amr.c |   39 ++++++++++++++++++++-------------------
 1 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/libavformat/rtpdec_amr.c b/libavformat/rtpdec_amr.c
index a7b36c7..0d38a4a 100644
--- a/libavformat/rtpdec_amr.c
+++ b/libavformat/rtpdec_amr.c
@@ -120,34 +120,20 @@ static int amr_handle_packet(AVFormatContext *ctx,
     return 0;
 }
 
-static int amr_parse_sdp_line(AVFormatContext *s, int st_index,
-                              PayloadContext *data, const char *line)
+static int amr_parse_fmtp(AVStream *stream, PayloadContext *data,
+                          char *attr, char *value)
 {
-    const char *p;
-    char attr[25], value[25];
-
-    /* Parse an fmtp line this one:
-     * a=fmtp:97 octet-align=1; interleaving=0
-     * That is, a normal fmtp: line followed by semicolon & space
-     * separated key/value pairs.
-     */
-    if (av_strstart(line, "fmtp:", &p)) {
         int octet_align = 0;
         int crc = 0;
         int interleaving = 0;
         int channels = 1;
 
-        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))) {
             /* Some AMR SDP configurations contain "octet-align", without
              * the trailing =1. Therefore, if the value is empty,
              * interpret it as "1".
              */
             if (!strcmp(value, "")) {
-                av_log(s, AV_LOG_WARNING, "AMR fmtp attribute %s had "
+                av_log(stream, AV_LOG_WARNING, "AMR fmtp attribute %s had "
                                           "nonstandard empty value\n", attr);
                 strcpy(value, "1");
             }
@@ -159,11 +145,26 @@ static int amr_parse_sdp_line(AVFormatContext *s, int st_index,
                 interleaving = atoi(value);
             else if (!strcmp(attr, "channels"))
                 channels = atoi(value);
-        }
         if (!octet_align || crc || interleaving || channels != 1) {
-            av_log(s, AV_LOG_ERROR, "Unsupported RTP/AMR configuration!\n");
+            av_log(stream, AV_LOG_ERROR, "Unsupported RTP/AMR configuration!\n");
             return -1;
         }
+    return 0;
+}
+
+static int amr_parse_sdp_line(AVFormatContext *s, int st_index,
+                              PayloadContext *data, const char *line)
+{
+    const char *p;
+
+    /* Parse an fmtp line this one:
+     * a=fmtp:97 octet-align=1; interleaving=0
+     * That is, a normal fmtp: line followed by semicolon & space
+     * separated key/value pairs.
+     */
+    if (av_strstart(line, "fmtp:", &p)) {
+        return ff_parse_fmtp(s->streams[st_index], data, p,
+                             &amr_parse_fmtp);
     }
     return 0;
 }
-- 
1.7.0.4

