From 935e858c5d75a8101c9667e21f5ab05ac6942fab Mon Sep 17 00:00:00 2001
From: Josh Allmann <joshua.allmann@gmail.com>
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 |   26 ++++++++++++++++++++++++++
 libavformat/rtpdec.h |    6 ++++++
 2 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c
index 456e2e4..fd8d390 100644
--- a/libavformat/rtpdec.c
+++ b/libavformat/rtpdec.c
@@ -531,3 +531,29 @@ void rtp_parse_close(RTPDemuxContext *s)
     }
     av_free(s);
 }
+
+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))
+{
+    char attr[256];
+    char value[4096];
+    int res;
+
+    // remove protocol identifier
+    p += strspn(p, SPACE_CHARS);                 // strip spaces
+    while (!(res = strspn(p, SPACE_CHARS))) p++; // protocol identifier
+    p += res;                                    // strip trailing spaces
+
+    while (ff_rtsp_next_attr_and_value(&p,
+                                       attr, sizeof(attr),
+                                       value, sizeof(value))) {
+
+        res = parse_fmtp(s, st_index, data, attr, value);
+        if (res < 0)
+            return res;
+    }
+    return 0;
+}
diff --git a/libavformat/rtpdec.h b/libavformat/rtpdec.h
index 439fcc2..34ad8ba 100644
--- a/libavformat/rtpdec.h
+++ b/libavformat/rtpdec.h
@@ -172,6 +172,12 @@ 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(AVFormatContext *s, int st_index,
+                  void *data, const char *p,
+                  int (*parse_fmtp)(AVFormatContext *s, int st_index,
+                                    PayloadContext *data,
+                                    char *attr, char *value));
+
 void av_register_rtp_dynamic_payload_handlers(void);
 
 #endif /* AVFORMAT_RTPDEC_H */
-- 
1.7.0.4

