5123
|
1 /*
|
|
2 * RTMP packet utilities
|
|
3 * Copyright (c) 2009 Kostya Shishkov
|
|
4 *
|
|
5 * This file is part of FFmpeg.
|
|
6 *
|
|
7 * FFmpeg is free software; you can redistribute it and/or
|
|
8 * modify it under the terms of the GNU Lesser General Public
|
|
9 * License as published by the Free Software Foundation; either
|
|
10 * version 2.1 of the License, or (at your option) any later version.
|
|
11 *
|
|
12 * FFmpeg is distributed in the hope that it will be useful,
|
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
15 * Lesser General Public License for more details.
|
|
16 *
|
|
17 * You should have received a copy of the GNU Lesser General Public
|
|
18 * License along with FFmpeg; if not, write to the Free Software
|
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
20 */
|
|
21
|
|
22 #ifndef AVFORMAT_RTMPPKT_H
|
|
23 #define AVFORMAT_RTMPPKT_H
|
|
24
|
|
25 #include "avformat.h"
|
|
26
|
|
27 /** maximum possible number of different RTMP channels */
|
5297
|
28 #define RTMP_CHANNELS 65599
|
5123
|
29
|
|
30 /**
|
|
31 * channels used to for RTMP packets with different purposes (i.e. data, network
|
|
32 * control, remote procedure calls, etc.)
|
|
33 */
|
|
34 enum RTMPChannel {
|
|
35 RTMP_NETWORK_CHANNEL = 2, ///< channel for network-related messages (bandwidth report, ping, etc)
|
|
36 RTMP_SYSTEM_CHANNEL, ///< channel for sending server control messages
|
|
37 RTMP_VIDEO_CHANNEL = 8, ///< channel for video data
|
|
38 RTMP_AUDIO_CHANNEL, ///< channel for audio data
|
|
39 };
|
|
40
|
|
41 /**
|
|
42 * known RTMP packet types
|
|
43 */
|
|
44 typedef enum RTMPPacketType {
|
|
45 RTMP_PT_CHUNK_SIZE = 1, ///< chunk size change
|
|
46 RTMP_PT_BYTES_READ = 3, ///< number of bytes read
|
|
47 RTMP_PT_PING, ///< ping
|
|
48 RTMP_PT_SERVER_BW, ///< server bandwidth
|
|
49 RTMP_PT_CLIENT_BW, ///< client bandwidth
|
|
50 RTMP_PT_AUDIO = 8, ///< audio packet
|
|
51 RTMP_PT_VIDEO, ///< video packet
|
|
52 RTMP_PT_FLEX_STREAM = 15, ///< Flex shared stream
|
|
53 RTMP_PT_FLEX_OBJECT, ///< Flex shared object
|
|
54 RTMP_PT_FLEX_MESSAGE, ///< Flex shared message
|
|
55 RTMP_PT_NOTIFY, ///< some notification
|
|
56 RTMP_PT_SHARED_OBJ, ///< shared object
|
|
57 RTMP_PT_INVOKE, ///< invoke some stream action
|
|
58 RTMP_PT_METADATA = 22, ///< FLV metadata
|
|
59 } RTMPPacketType;
|
|
60
|
|
61 /**
|
|
62 * possible RTMP packet header sizes
|
|
63 */
|
|
64 enum RTMPPacketSize {
|
|
65 RTMP_PS_TWELVEBYTES = 0, ///< packet has 12-byte header
|
|
66 RTMP_PS_EIGHTBYTES, ///< packet has 8-byte header
|
|
67 RTMP_PS_FOURBYTES, ///< packet has 4-byte header
|
|
68 RTMP_PS_ONEBYTE ///< packet is really a next chunk of a packet
|
|
69 };
|
|
70
|
|
71 /**
|
|
72 * structure for holding RTMP packets
|
|
73 */
|
|
74 typedef struct RTMPPacket {
|
|
75 uint8_t channel_id; ///< RTMP channel ID (nothing to do with audio/video channels though)
|
|
76 RTMPPacketType type; ///< packet payload type
|
|
77 uint32_t timestamp; ///< packet full timestamp or timestamp increment to the previous one in milliseconds (latter only for media packets)
|
|
78 uint32_t extra; ///< probably an additional channel ID used during streaming data
|
|
79 uint8_t *data; ///< packet payload
|
|
80 int data_size; ///< packet payload size
|
|
81 } RTMPPacket;
|
|
82
|
|
83 /**
|
|
84 * Creates new RTMP packet with given attributes.
|
|
85 *
|
|
86 * @param pkt packet
|
|
87 * @param channel_id packet channel ID
|
|
88 * @param type packet type
|
|
89 * @param timestamp packet timestamp
|
|
90 * @param size packet size
|
|
91 * @return zero on success, negative value otherwise
|
|
92 */
|
|
93 int ff_rtmp_packet_create(RTMPPacket *pkt, int channel_id, RTMPPacketType type,
|
|
94 int timestamp, int size);
|
|
95
|
|
96 /**
|
|
97 * Frees RTMP packet.
|
|
98 *
|
|
99 * @param pkt packet
|
|
100 */
|
|
101 void ff_rtmp_packet_destroy(RTMPPacket *pkt);
|
|
102
|
|
103 /**
|
|
104 * Reads RTMP packet sent by the server.
|
|
105 *
|
|
106 * @param h reader context
|
|
107 * @param p packet
|
|
108 * @param chunk_size current chunk size
|
|
109 * @param prev_pkt previously read packet headers for all channels
|
|
110 * (may be needed for restoring incomplete packet header)
|
|
111 * @return zero on success, negative value otherwise
|
|
112 */
|
|
113 int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p,
|
|
114 int chunk_size, RTMPPacket *prev_pkt);
|
|
115
|
|
116 /**
|
|
117 * Sends RTMP packet to the server.
|
|
118 *
|
|
119 * @param h reader context
|
|
120 * @param p packet to send
|
|
121 * @param chunk_size current chunk size
|
|
122 * @param prev_pkt previously sent packet headers for all channels
|
|
123 * (may be used for packet header compressing)
|
|
124 * @return zero on success, negative value otherwise
|
|
125 */
|
|
126 int ff_rtmp_packet_write(URLContext *h, RTMPPacket *p,
|
|
127 int chunk_size, RTMPPacket *prev_pkt);
|
|
128
|
|
129 /**
|
|
130 * @defgroup amffuncs functions used to work with AMF format (which is also used in .flv)
|
|
131 * @see amf_* funcs in libavformat/flvdec.c
|
|
132 * @{
|
|
133 */
|
|
134
|
|
135 /**
|
|
136 * Calculates number of bytes taken by first AMF entry in data.
|
|
137 *
|
|
138 * @param data input data
|
|
139 * @param data_end input buffer end
|
|
140 * @return number of bytes used by first AMF entry
|
|
141 */
|
|
142 int ff_amf_tag_size(const uint8_t *data, const uint8_t *data_end);
|
|
143
|
|
144 /**
|
|
145 * Retrieves value of given AMF object field in string form.
|
|
146 *
|
|
147 * @param data AMF object data
|
|
148 * @param data_end input buffer end
|
|
149 * @param name name of field to retrieve
|
|
150 * @param dst buffer for storing result
|
|
151 * @param dst_size output buffer size
|
|
152 * @return 0 if search and retrieval succeeded, negative value otherwise
|
|
153 */
|
|
154 int ff_amf_get_field_value(const uint8_t *data, const uint8_t *data_end,
|
|
155 const uint8_t *name, uint8_t *dst, int dst_size);
|
|
156
|
|
157 /**
|
|
158 * Writes boolean value in AMF format to buffer.
|
|
159 *
|
|
160 * @param dst pointer to the input buffer (will be modified)
|
|
161 * @param val value to write
|
|
162 */
|
|
163 void ff_amf_write_bool(uint8_t **dst, int val);
|
|
164
|
|
165 /**
|
|
166 * Writes number in AMF format to buffer.
|
|
167 *
|
|
168 * @param dst pointer to the input buffer (will be modified)
|
|
169 * @param num value to write
|
|
170 */
|
|
171 void ff_amf_write_number(uint8_t **dst, double num);
|
|
172
|
|
173 /**
|
|
174 * Writes string in AMF format to buffer.
|
|
175 *
|
|
176 * @param dst pointer to the input buffer (will be modified)
|
|
177 * @param str string to write
|
|
178 */
|
|
179 void ff_amf_write_string(uint8_t **dst, const char *str);
|
|
180
|
|
181 /**
|
|
182 * Writes AMF NULL value to buffer.
|
|
183 *
|
|
184 * @param dst pointer to the input buffer (will be modified)
|
|
185 */
|
|
186 void ff_amf_write_null(uint8_t **dst);
|
|
187
|
|
188 /**
|
|
189 * Writes marker for AMF object to buffer.
|
|
190 *
|
|
191 * @param dst pointer to the input buffer (will be modified)
|
|
192 */
|
|
193 void ff_amf_write_object_start(uint8_t **dst);
|
|
194
|
|
195 /**
|
|
196 * Writes string used as field name in AMF object to buffer.
|
|
197 *
|
|
198 * @param dst pointer to the input buffer (will be modified)
|
|
199 * @param str string to write
|
|
200 */
|
|
201 void ff_amf_write_field_name(uint8_t **dst, const char *str);
|
|
202
|
|
203 /**
|
|
204 * Writes marker for end of AMF object to buffer.
|
|
205 *
|
|
206 * @param dst pointer to the input buffer (will be modified)
|
|
207 */
|
|
208 void ff_amf_write_object_end(uint8_t **dst);
|
|
209
|
|
210 /** @} */ // AMF funcs
|
|
211
|
|
212 #endif /* AVFORMAT_RTMPPKT_H */
|