[FFmpeg-cvslog] rtmp: Factorize the code by adding find_tracked_method

Samuel Pitoiset git at videolan.org
Sun Aug 12 13:48:48 CEST 2012


ffmpeg | branch: master | Samuel Pitoiset <samuel.pitoiset at gmail.com> | Sat Aug 11 12:41:32 2012 +0200| [a8103503b348966d0bd83cd57f2b4e661d5d6458] | committer: Martin Storsjö

rtmp: Factorize the code by adding find_tracked_method

Also fix the bytestream reader size parameter to take the
offset into account.

Signed-off-by: Martin Storsjö <martin at martin.st>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a8103503b348966d0bd83cd57f2b4e661d5d6458
---

 libavformat/rtmpproto.c |   40 ++++++++++++++++++++++++++--------------
 1 file changed, 26 insertions(+), 14 deletions(-)

diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c
index c85424e..910e523 100644
--- a/libavformat/rtmpproto.c
+++ b/libavformat/rtmpproto.c
@@ -154,6 +154,31 @@ static void del_tracked_method(RTMPContext *rt, int index)
     rt->nb_tracked_methods--;
 }
 
+static int find_tracked_method(URLContext *s, RTMPPacket *pkt, int offset,
+                               char **tracked_method)
+{
+    RTMPContext *rt = s->priv_data;
+    GetByteContext gbc;
+    double pkt_id;
+    int ret;
+    int i;
+
+    bytestream2_init(&gbc, pkt->data + offset, pkt->data_size - offset);
+    if ((ret = ff_amf_read_number(&gbc, &pkt_id)) < 0)
+        return ret;
+
+    for (i = 0; i < rt->nb_tracked_methods; i++) {
+        if (rt->tracked_methods[i].id != pkt_id)
+            continue;
+
+        *tracked_method = rt->tracked_methods[i].name;
+        del_tracked_method(rt, i);
+        break;
+    }
+
+    return 0;
+}
+
 static void free_tracked_methods(RTMPContext *rt)
 {
     int i;
@@ -1039,24 +1064,11 @@ static int handle_invoke_result(URLContext *s, RTMPPacket *pkt)
 {
     RTMPContext *rt = s->priv_data;
     char *tracked_method = NULL;
-    GetByteContext gbc;
-    double pkt_id;
     int ret = 0;
-    int i;
 
-    bytestream2_init(&gbc, pkt->data + 10, pkt->data_size);
-    if ((ret = ff_amf_read_number(&gbc, &pkt_id)) < 0)
+    if ((ret = find_tracked_method(s, pkt, 10, &tracked_method)) < 0)
         return ret;
 
-    for (i = 0; i < rt->nb_tracked_methods; i++) {
-        if (rt->tracked_methods[i].id != pkt_id)
-            continue;
-
-        tracked_method = rt->tracked_methods[i].name;
-        del_tracked_method(rt, i);
-        break;
-    }
-
     if (!tracked_method) {
         /* Ignore this reply when the current method is not tracked. */
         return ret;



More information about the ffmpeg-cvslog mailing list