]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/rtmppkt.h
x86: Put COPY3_IF_LT under HAVE_6REGS
[ffmpeg] / libavformat / rtmppkt.h
index 431095d399b040f3eb1b88ccd3a97683456cfad7..149c153cad780520c780622457edc1db63d95eb9 100644 (file)
@@ -1,28 +1,30 @@
 /*
  * RTMP packet utilities
- * Copyright (c) 2009 Kostya Shishkov
+ * Copyright (c) 2009 Konstantin Shishkov
  *
- * This file is part of FFmpeg.
+ * This file is part of Libav.
  *
- * FFmpeg is free software; you can redistribute it and/or
+ * Libav is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
  *
- * FFmpeg is distributed in the hope that it will be useful,
+ * Libav is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
+ * License along with Libav; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #ifndef AVFORMAT_RTMPPKT_H
 #define AVFORMAT_RTMPPKT_H
 
+#include "libavcodec/bytestream.h"
 #include "avformat.h"
+#include "url.h"
 
 /** maximum possible number of different RTMP channels */
 #define RTMP_CHANNELS 65599
@@ -34,9 +36,9 @@
 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
 };
 
 /**
@@ -76,10 +78,12 @@ typedef struct RTMPPacket {
     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;
 
 /**
@@ -110,10 +114,27 @@ void ff_rtmp_packet_destroy(RTMPPacket *pkt);
  * @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 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)
+ * @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, int *nb_prev_pkt,
+                                 uint8_t c);
 
 /**
  * Send RTMP packet to the server.
@@ -123,10 +144,12 @@ int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p,
  * @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.
@@ -137,7 +160,17 @@ int ff_rtmp_packet_write(URLContext *h, RTMPPacket *p,
 void ff_rtmp_packet_dump(void *ctx, RTMPPacket *p);
 
 /**
- * @defgroup amffuncs functions used to work with AMF format (which is also used in .flv)
+ * 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
  * @{
  */
@@ -188,6 +221,15 @@ void ff_amf_write_number(uint8_t **dst, double num);
  */
 void ff_amf_write_string(uint8_t **dst, const char *str);
 
+/**
+ * Write a string consisting of two parts in AMF format to a buffer.
+ *
+ * @param dst pointer to the input buffer (will be modified)
+ * @param str1 first string to write, may be null
+ * @param str2 second string to write, may be null
+ */
+void ff_amf_write_string2(uint8_t **dst, const char *str1, const char *str2);
+
 /**
  * Write AMF NULL value to buffer.
  *
@@ -217,6 +259,72 @@ void ff_amf_write_field_name(uint8_t **dst, const char *str);
  */
 void ff_amf_write_object_end(uint8_t **dst);
 
+/**
+ * Read AMF boolean value.
+ *
+ *@param[in,out] gbc GetByteContext initialized with AMF-formatted data
+ *@param[out]    val 0 or 1
+ *@return 0 on success or an AVERROR code on failure
+*/
+int ff_amf_read_bool(GetByteContext *gbc, int *val);
+
+/**
+ * Read AMF number value.
+ *
+ *@param[in,out] gbc GetByteContext initialized with AMF-formatted data
+ *@param[out]    val read value
+ *@return 0 on success or an AVERROR code on failure
+*/
+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.
+ *
+ * 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_read_string(GetByteContext *gbc, uint8_t *str,
+                       int strsize, int *length);
+
+/**
+ * Read AMF NULL value.
+ *
+ *@param[in,out] gbc GetByteContext initialized with AMF-formatted data
+ *@return 0 on success or an AVERROR code on failure
+*/
+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
 
 #endif /* AVFORMAT_RTMPPKT_H */