/*
* RTMP packet utilities
- * Copyright (c) 2009 Kostya Shishkov
+ * Copyright (c) 2009 Konstantin Shishkov
*
* This file is part of Libav.
*
enum RTMPChannel {
RTMP_NETWORK_CHANNEL = 2, ///< channel for network-related messages (bandwidth report, ping, etc)
RTMP_SYSTEM_CHANNEL, ///< channel for sending server control messages
- RTMP_SOURCE_CHANNEL, ///< channel for sending a/v to server
- RTMP_VIDEO_CHANNEL = 8, ///< channel for video data
RTMP_AUDIO_CHANNEL, ///< channel for audio data
+ RTMP_VIDEO_CHANNEL = 6, ///< channel for video data
+ RTMP_SOURCE_CHANNEL = 8, ///< channel for a/v invokes
};
/**
typedef enum RTMPPacketType {
RTMP_PT_CHUNK_SIZE = 1, ///< chunk size change
RTMP_PT_BYTES_READ = 3, ///< number of bytes read
- RTMP_PT_PING, ///< ping
- RTMP_PT_SERVER_BW, ///< server bandwidth
- RTMP_PT_CLIENT_BW, ///< client bandwidth
+ RTMP_PT_USER_CONTROL, ///< user control
+ RTMP_PT_WINDOW_ACK_SIZE, ///< window acknowledgement size
+ RTMP_PT_SET_PEER_BW, ///< peer bandwidth
RTMP_PT_AUDIO = 8, ///< audio packet
RTMP_PT_VIDEO, ///< video packet
RTMP_PT_FLEX_STREAM = 15, ///< Flex shared stream
int channel_id; ///< RTMP channel ID (nothing to do with audio/video channels though)
RTMPPacketType type; ///< packet payload type
uint32_t timestamp; ///< packet full timestamp
- uint32_t ts_delta; ///< timestamp increment to the previous one in milliseconds (latter only for media packets)
+ uint32_t ts_field; ///< 24-bit timestamp or increment to the previous one, in milliseconds (latter only for media packets). Clipped to a maximum of 0xFFFFFF, indicating an extended timestamp field.
uint32_t extra; ///< probably an additional channel ID used during streaming data
uint8_t *data; ///< packet payload
- int data_size; ///< packet payload size
+ int size; ///< packet payload size
+ int offset; ///< amount of data read so far
+ int read; ///< amount read, including headers
} RTMPPacket;
/**
* @param chunk_size current chunk size
* @param prev_pkt previously read packet headers for all channels
* (may be needed for restoring incomplete packet header)
+ * @param nb_prev_pkt number of allocated elements in prev_pkt
* @return number of bytes read on success, negative value otherwise
*/
int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p,
- int chunk_size, RTMPPacket *prev_pkt);
+ int chunk_size, RTMPPacket **prev_pkt,
+ int *nb_prev_pkt);
/**
* Read internal RTMP packet sent by the server.
*
* @param chunk_size current chunk size
* @param prev_pkt previously read packet headers for all channels
* (may be needed for restoring incomplete packet header)
+ * @param nb_prev_pkt number of allocated elements in prev_pkt
* @param c the first byte already read
* @return number of bytes read on success, negative value otherwise
*/
int ff_rtmp_packet_read_internal(URLContext *h, RTMPPacket *p, int chunk_size,
- RTMPPacket *prev_pkt, uint8_t c);
+ RTMPPacket **prev_pkt, int *nb_prev_pkt,
+ uint8_t c);
/**
* Send RTMP packet to the server.
* @param chunk_size current chunk size
* @param prev_pkt previously sent packet headers for all channels
* (may be used for packet header compressing)
+ * @param nb_prev_pkt number of allocated elements in prev_pkt
* @return number of bytes written on success, negative value otherwise
*/
int ff_rtmp_packet_write(URLContext *h, RTMPPacket *p,
- int chunk_size, RTMPPacket *prev_pkt);
+ int chunk_size, RTMPPacket **prev_pkt,
+ int *nb_prev_pkt);
/**
* Print information and contents of RTMP packet.
*/
void ff_rtmp_packet_dump(void *ctx, RTMPPacket *p);
+/**
+ * Enlarge the prev_pkt array to fit the given channel
+ *
+ * @param prev_pkt array with previously sent packet headers
+ * @param nb_prev_pkt number of allocated elements in prev_pkt
+ * @param channel the channel number that needs to be allocated
+ */
+int ff_rtmp_check_alloc_array(RTMPPacket **prev_pkt, int *nb_prev_pkt,
+ int channel);
+
/**
* @name Functions used to work with the AMF format (which is also used in .flv)
* @see amf_* funcs in libavformat/flvdec.c
*/
int ff_amf_read_number(GetByteContext *gbc, double *val);
+/**
+ * Get AMF string value.
+ *
+ * This function behaves the same as ff_amf_read_string except that
+ * it does not expect the AMF type prepended to the actual data.
+ * Appends a trailing null byte to output string in order to
+ * ease later parsing.
+ *
+ *@param[in,out] gbc GetByteContext initialized with AMF-formatted data
+ *@param[out] str read string
+ *@param[in] strsize buffer size available to store the read string
+ *@param[out] length read string length
+ *@return 0 on success or an AVERROR code on failure
+*/
+int ff_amf_get_string(GetByteContext *bc, uint8_t *str,
+ int strsize, int *length);
+
/**
* Read AMF string value.
*
*/
int ff_amf_read_null(GetByteContext *gbc);
+/**
+ * Match AMF string with a NULL-terminated string.
+ *
+ * @return 0 if the strings do not match.
+ */
+
+int ff_amf_match_string(const uint8_t *data, int size, const char *str);
/** @} */ // AMF funcs