[FFmpeg-soc] [soc]: r4479 - rtmp/rtmpdec.c

kostya subversion at mplayerhq.hu
Thu Jun 18 06:28:28 CEST 2009


Author: kostya
Date: Thu Jun 18 06:28:28 2009
New Revision: 4479

Log:
Parse and perform some actions on incoming RTMP packets

Modified:
   rtmp/rtmpdec.c

Modified: rtmp/rtmpdec.c
==============================================================================
--- rtmp/rtmpdec.c	Thu Jun 18 06:23:31 2009	(r4478)
+++ rtmp/rtmpdec.c	Thu Jun 18 06:28:28 2009	(r4479)
@@ -465,6 +465,47 @@ static int flv_set_video_codec(AVFormatC
     return 0;
 }
 
+static int rtmp_parse_result(AVFormatContext *s, RTMPState *rt, RTMPPacket *pkt)
+{
+    int i, t;
+
+    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 (%d)\n",
+                   pkt->data_size);
+            return -1;
+        }
+        t = AV_RB32(pkt->data);
+        for (i = 0; i < RTMP_CHANNELS; i++) {
+            rt->rhist.chunk_size[i] = t;
+            rt->whist.chunk_size[i] = t;
+        }
+        break;
+    case RTMP_PT_INVOKE:
+        if (!memcmp(pkt->data, "\002\000\006_error", 9)) {//TODO: search data for error description
+            return -1;
+        }
+        if (!memcmp(pkt->data, "\002\000\007_result", 10)) {
+            switch (rt->state) {
+            case STATE_HANDSHAKED:
+                gen_create_stream(s, rt);
+                rt->state = STATE_CONNECTING;
+                break;
+            case STATE_CONNECTING:
+                gen_play(s, rt);
+                rt->state = STATE_PLAYING;
+                break;
+            }
+        }
+        if (!memcmp(pkt->data, "\002\000\008onStatus", 11)) {
+            //TODO: catch stream close event
+        }
+        break;
+    }
+    return 0;
+}
+
 static int rtmp_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
     RTMPState *rt = s->priv_data;
@@ -486,10 +527,11 @@ static int rtmp_read_packet(AVFormatCont
             }
         }
 
-#ifdef DEBUG
-if(rpkt.type != RTMP_PT_VIDEO && rpkt.type != RTMP_PT_AUDIO) rtmp_packet_inspect(s, &rpkt);
-//if(rpkt.data_size)for(i = 0; i < rpkt.data_size;i++)av_log(NULL,0," %02X",rpkt.data[i]);av_log(NULL,0,"\n");
-#endif
+        ret = rtmp_parse_result(s, rt, &rpkt);
+        if (ret < 0) {//serious error in packet
+            rtmp_packet_destroy(&rpkt);
+            return -1;
+        }
 
         if (rpkt.type == RTMP_PT_CHUNK_SIZE)
             for(i=0;i<RTMP_CHANNELS;i++)rt->rhist.chunk_size[i/*rpkt.stream_id*/] = AV_RB32(rpkt.data);


More information about the FFmpeg-soc mailing list