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

Samuel Pitoiset git at videolan.org
Thu Jul 26 21:55:12 CEST 2012


ffmpeg | branch: master | Samuel Pitoiset <samuel.pitoiset at gmail.com> | Sat Jul 21 12:59:52 2012 +0200| [7be2a7d8ff43fba8d64320c7b778da9f942a9c1b] | committer: Martin Storsjö

rtmp: Factorize the code by adding handle_chunk_size

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

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

 libavformat/rtmpproto.c |   45 ++++++++++++++++++++++++++++++---------------
 1 file changed, 30 insertions(+), 15 deletions(-)

diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c
index 31fa28b..871c24e 100644
--- a/libavformat/rtmpproto.c
+++ b/libavformat/rtmpproto.c
@@ -880,6 +880,34 @@ static int rtmp_handshake(URLContext *s, RTMPContext *rt)
     return 0;
 }
 
+static int handle_chunk_size(URLContext *s, RTMPPacket *pkt)
+{
+    RTMPContext *rt = s->priv_data;
+    int ret;
+
+    if (pkt->data_size != 4) {
+        av_log(s, AV_LOG_ERROR,
+               "Chunk size change packet is not 4 bytes long (%d)\n",
+               pkt->data_size);
+        return -1;
+    }
+
+    if (!rt->is_input) {
+        if ((ret = ff_rtmp_packet_write(rt->stream, pkt, rt->chunk_size,
+                                        rt->prev_pkt[1])) < 0)
+            return ret;
+    }
+
+    rt->chunk_size = AV_RB32(pkt->data);
+    if (rt->chunk_size <= 0) {
+        av_log(s, AV_LOG_ERROR, "Incorrect chunk size %d\n", rt->chunk_size);
+        return -1;
+    }
+    av_log(s, AV_LOG_DEBUG, "New chunk size = %d\n", rt->chunk_size);
+
+    return 0;
+}
+
 static int handle_ping(URLContext *s, RTMPPacket *pkt)
 {
     RTMPContext *rt = s->priv_data;
@@ -943,21 +971,8 @@ static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt)
 
     switch (pkt->type) {
     case RTMP_PT_CHUNK_SIZE:
-        if (pkt->data_size != 4) {
-            av_log(s, AV_LOG_ERROR,
-                   "Chunk size change packet is not 4 bytes long (%d)\n", pkt->data_size);
-            return -1;
-        }
-        if (!rt->is_input)
-            if ((ret = ff_rtmp_packet_write(rt->stream, pkt, rt->chunk_size,
-                                            rt->prev_pkt[1])) < 0)
-                return ret;
-        rt->chunk_size = AV_RB32(pkt->data);
-        if (rt->chunk_size <= 0) {
-            av_log(s, AV_LOG_ERROR, "Incorrect chunk size %d\n", rt->chunk_size);
-            return -1;
-        }
-        av_log(s, AV_LOG_DEBUG, "New chunk size = %d\n", rt->chunk_size);
+        if ((ret = handle_chunk_size(s, pkt)) < 0)
+            return ret;
         break;
     case RTMP_PT_PING:
         if ((ret = handle_ping(s, pkt)) < 0)



More information about the ffmpeg-cvslog mailing list