[FFmpeg-soc] [soc]: r4564 - in rtmp: rtmppkt.h rtmpproto.c

kostya subversion at mplayerhq.hu
Wed Jul 1 13:11:50 CEST 2009


Author: kostya
Date: Wed Jul  1 13:11:50 2009
New Revision: 4564

Log:
Document some parts of code

Modified:
   rtmp/rtmppkt.h
   rtmp/rtmpproto.c

Modified: rtmp/rtmppkt.h
==============================================================================
--- rtmp/rtmppkt.h	Wed Jul  1 12:46:31 2009	(r4563)
+++ rtmp/rtmppkt.h	Wed Jul  1 13:11:50 2009	(r4564)
@@ -27,6 +27,10 @@
 /* maximum possible number of different RTMP channels */
 #define RTMP_CHANNELS 64
 
+/**
+ * channels used to for RTMP packets with different purposes (i.e. data, network
+ * control, remote procedure calls, etc.)
+ */
 enum RTMPChannel {
     RTMP_NETWORK_CHANNEL = 2,   ///< channel for network-related messages (bandwidth report, ping, etc)
     RTMP_SYSTEM_CHANNEL,        ///< channel for sending server control messages
@@ -34,6 +38,9 @@ enum RTMPChannel {
     RTMP_AUDIO_CHANNEL,         ///< channel for audio data
 };
 
+/**
+ * known RTMP packet types
+ */
 typedef enum RTMPPacketType {
     RTMP_PT_CHUNK_SIZE   =  1,  ///< chunk size change
     RTMP_PT_BYTES_READ   =  3,  ///< number of bytes read
@@ -51,33 +58,39 @@ typedef enum RTMPPacketType {
     RTMP_PT_METADATA     = 22,  ///< FLV metadata
 } RTMPPacketType;
 
+/**
+ * possible RTMP packet header sizes
+ */
 enum RTMPPacketSize {
-    RTMP_PS_TWELVEBYTES = 0,
-    RTMP_PS_EIGHTBYTES,
-    RTMP_PS_FOURBYTES,
-    RTMP_PS_ONEBYTE
+    RTMP_PS_TWELVEBYTES = 0, ///< packet has 12-byte header
+    RTMP_PS_EIGHTBYTES,      ///< packet has 8-byte header
+    RTMP_PS_FOURBYTES,       ///< packet has 4-byte header
+    RTMP_PS_ONEBYTE          ///< packet is really a next chunk of a packet
 };
 
+/**
+ * AMF types used in RTMP packets
+ */
 typedef enum AMFType {
-    AMF_NUMBER = 0,
-    AMF_BOOLEAN,
-    AMF_STRING,
-    AMF_OBJECT,
-    AMF_MOVIE,
-    AMF_NULL,
-    AMF_UNDEFINED,
-    AMF_REFERENCE,
-    AMF_ECMA_ARRAY,
-    AMF_OBJECT_END,
-    AMF_STRICT_ARRAY,
-    AMF_DATE,
-    AMF_LONG_STRING,
-    AMF_UNSUPPORTED,
-    AMD_RECORD_SET,
-    AMF_XML_OBJECT,
-    AMF_TYPED_OBJECT,
+    AMF_NUMBER = 0,   ///< number (double precision)
+    AMF_BOOLEAN,      ///< boolean value
+    AMF_STRING,       ///< Pascal-style string with length < 65536
+    AMF_OBJECT,       ///< AMF object, contains property names and values
+    AMF_MOVIE,        ///< Flash object
+    AMF_NULL,         ///< NULL value
+    AMF_UNDEFINED,    ///< undefined (return?) value
+    AMF_REFERENCE,    ///< reference
+    AMF_ECMA_ARRAY,   ///< ECMA array, almost like AMF object but has number of entries
+    AMF_OBJECT_END,   ///< marker for end of AMF object or ECMA array
+    AMF_STRICT_ARRAY, ///< strict array
+    AMF_DATE,         ///< date
+    AMF_LONG_STRING,  ///< Pascal-style string with possible length up to 4GB
+    AMF_UNSUPPORTED,  ///< unsipported feature indicator
+    AMD_RECORD_SET,   ///< record set
+    AMF_XML_OBJECT,   ///< XML object
+    AMF_TYPED_OBJECT, ///< typed object
 
-    AMF_STRING_IN_OBJECT = 99,
+    AMF_STRING_IN_OBJECT = 99, ///< internal type used for AMF object field names
 } AMFType;
 
 /**
@@ -92,22 +105,79 @@ typedef struct RTMPPacket {
     int            data_size;  ///< packet payload size
 } RTMPPacket;
 
+/**
+ * Creates new RTMP packet with given attributes.
+ *
+ * @param pkt        packet
+ * @param channel_id packet channel ID
+ * @param type       packet type
+ * @param timestamp  packet timestamp
+ * @param size       packet size
+ * @return zero on success, -1 otherwise
+ */
 int rtmp_packet_create(RTMPPacket *pkt, int channel_id, RTMPPacketType type,
                        int timestamp, int size);
 
+/**
+ * Frees RTMP packet.
+ *
+ * @param pkt packet
+ */
 void rtmp_packet_destroy(RTMPPacket *pkt);
 
+/**
+ * Reads RTMP packet.
+ *
+ * @param h          reader context
+ * @param p          packet
+ * @param chunk_size current chunk size
+ * @param prev_pkt   previously read packet headers for all channels
+ *                   (may be needed for restoring incomplete packet header)
+ * @return zero on success, -1 otherwise
+ */
 int rtmp_packet_read(URLContext *h, RTMPPacket *p,
                      int chunk_size, RTMPPacket *prev_pkt);
 
+/**
+ * Sends RTMP packet.
+ *
+ * @param h          reader context
+ * @param p          packet to send
+ * @param chunk_size current chunk size
+ * @param prev_pkt   previously sent packet headers for all channels
+ *                   (may be used for packet header compressing)
+ * @return zero on success, -1 otherwise
+ */
 int rtmp_packet_write(URLContext *h, RTMPPacket *p,
                       int chunk_size, RTMPPacket *prev_pkt);
 
+/**
+ * Calculates number of bytes needed to skip first AMF entry in data.
+ *
+ * @param data input data
+ * @return number of bytes used by first AMF entry
+ */
 int rtmp_amf_skip_data(const uint8_t *data);
 
+/**
+ * Retrieves value of given AMF object field in string form.
+ *
+ * @param data     AMF object data
+ * @param name     name of field to retrieve
+ * @param dst      buffer for storing result
+ * @param dst_size output buffer size
+ * @return 0 if search and retrieval succeeded, -1 otherwise
+ */
 int rtmp_amf_find_field(const uint8_t *data, const uint8_t *name,
                         uint8_t *dst, int dst_size);
 
+/**
+ * Write AMF tag to buffer.
+ *
+ * @param dst  pointer to the input buffer (will be modified)
+ * @param type tag type
+ * @param data optional tag value
+ */
 void rtmp_amf_write_tag(uint8_t **dst, AMFType type, const void *data);
 
 void rtmp_packet_inspect(RTMPPacket *pkt);

Modified: rtmp/rtmpproto.c
==============================================================================
--- rtmp/rtmpproto.c	Wed Jul  1 12:46:31 2009	(r4563)
+++ rtmp/rtmpproto.c	Wed Jul  1 13:11:50 2009	(r4564)
@@ -41,28 +41,32 @@
 #include "rtmp.h"
 #include "rtmppkt.h"
 
+/** RTMP protocol handler state */
 typedef enum {
-    STATE_START,
-    STATE_HANDSHAKED,
-    STATE_CONNECTING,
-    STATE_READY,
-    STATE_PLAYING,
+    STATE_START,      ///< client has not done anything
+    STATE_HANDSHAKED, ///< client has performed handshake
+    STATE_CONNECTING, ///< client connected to server successfully
+    STATE_READY,      ///< client has sent all needed commands and waits for server reply
+    STATE_PLAYING,    ///< client has started receiving multimedia data from server
 } ClientState;
 
+/** protocol handler context */
 typedef struct RTMPContext {
-    URLContext*   rtmp_hd;
-    RTMPPacket    prev_pkt[2][RTMP_CHANNELS];
-    int           chunk_size;
-    char          playpath[256];
-    ClientState   state;
-    int           main_channel_id;
-    uint8_t*      flv_data;
-    int           flv_size;
-    int           flv_off;
-    uint32_t      video_ts, audio_ts;
+    URLContext*   rtmp_hd;                    ///< context for TCP stream
+    RTMPPacket    prev_pkt[2][RTMP_CHANNELS]; ///< packet history used when reading and sending packets
+    int           chunk_size;                 ///< chunk size
+    char          playpath[256];              ///< RTMP playpath
+    ClientState   state;                      ///< current state
+    int           main_channel_id;            ///< an additional channel id which is used for some invokes
+    uint8_t*      flv_data;                   ///< buffer with data for demuxer
+    int           flv_size;                   ///< current buffer size
+    int           flv_off;                    ///< number of bytes read from current buffer
+    uint32_t      video_ts;                   ///< current video timestamp
+    uint32_t      audio_ts;                   ///< current audio timestamp
 } RTMPContext;
 
-#define PLAYER_KEY_OPEN_PART_LEN 30
+#define PLAYER_KEY_OPEN_PART_LEN 30   ///< length of partial key used for first client digest signing
+/** Client key used for digest signing */
 static const uint8_t rtmp_player_key[] =
 {
     0x47, 0x65, 0x6E, 0x75, 0x69, 0x6E, 0x65, 0x20, 0x41, 0x64, 0x6F, 0x62, 0x65,
@@ -72,7 +76,8 @@ static const uint8_t rtmp_player_key[] =
     0x6F, 0xAB, 0x93, 0xB8, 0xE6, 0x36, 0xCF, 0xEB, 0x31, 0xAE
 };
 
-#define SERVER_KEY_OPEN_PART_LEN 36
+#define SERVER_KEY_OPEN_PART_LEN 36   ///< length of partial key used for first server digest signing
+/** Key used for RTMP server digest signing */
 static const uint8_t rtmp_server_key[] =
 {
     0x47, 0x65, 0x6E, 0x75, 0x69, 0x6E, 0x65, 0x20, 0x41, 0x64, 0x6F, 0x62, 0x65,
@@ -461,6 +466,7 @@ static int get_packet(URLContext *s, int
                 rt->audio_ts += rpkt.timestamp;
                 ts = rt->audio_ts;
             }
+            // generate packet header and put data into buffer for FLV demuxer
             rt->flv_off  = 0;
             rt->flv_size = rpkt.data_size + 15;
             rt->flv_data = p = av_realloc(rt->flv_data, rt->flv_size);
@@ -473,6 +479,7 @@ static int get_packet(URLContext *s, int
             bytestream_put_be32(&p, 0);
             has_data = 1;
         } else if (rpkt.type == RTMP_PT_METADATA) {
+            // we got raw FLV data, make it available for FLV demuxer
             rt->flv_off  = 0;
             rt->flv_size = rpkt.data_size;
             rt->flv_data = av_realloc(rt->flv_data, rt->flv_size);
@@ -560,6 +567,7 @@ static int rtmp_open(URLContext *s, cons
 
         if (get_packet(s, 1) < 0)
             goto fail;
+        // generate FLV header for demuxer
         rt->flv_data = av_realloc(rt->flv_data, 13);
         rt->flv_size = 13;
         rt->flv_off  = 0;


More information about the FFmpeg-soc mailing list