Statistics
| Branch: | Revision:

ffmpeg / libavformat / rtmppkt.h @ 2912e87a

History | View | Annotate | Download (7.07 KB)

1 9fd6b843 Kostya Shishkov
/*
2
 * RTMP packet utilities
3
 * Copyright (c) 2009 Kostya Shishkov
4
 *
5 2912e87a Mans Rullgard
 * This file is part of Libav.
6 9fd6b843 Kostya Shishkov
 *
7 2912e87a Mans Rullgard
 * Libav is free software; you can redistribute it and/or
8 9fd6b843 Kostya Shishkov
 * 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 2912e87a Mans Rullgard
 * Libav is distributed in the hope that it will be useful,
13 9fd6b843 Kostya Shishkov
 * 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 2912e87a Mans Rullgard
 * License along with Libav; if not, write to the Free Software
19 9fd6b843 Kostya Shishkov
 * 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 */
28 5d660598 Kostya Shishkov
#define RTMP_CHANNELS 65599
29 9fd6b843 Kostya Shishkov
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 9e69ab18 Sergiy
    RTMP_SOURCE_CHANNEL,        ///< channel for sending a/v to server
38 9fd6b843 Kostya Shishkov
    RTMP_VIDEO_CHANNEL = 8,     ///< channel for video data
39
    RTMP_AUDIO_CHANNEL,         ///< channel for audio data
40
};
41
42
/**
43
 * known RTMP packet types
44
 */
45
typedef enum RTMPPacketType {
46
    RTMP_PT_CHUNK_SIZE   =  1,  ///< chunk size change
47
    RTMP_PT_BYTES_READ   =  3,  ///< number of bytes read
48
    RTMP_PT_PING,               ///< ping
49
    RTMP_PT_SERVER_BW,          ///< server bandwidth
50
    RTMP_PT_CLIENT_BW,          ///< client bandwidth
51
    RTMP_PT_AUDIO        =  8,  ///< audio packet
52
    RTMP_PT_VIDEO,              ///< video packet
53
    RTMP_PT_FLEX_STREAM  = 15,  ///< Flex shared stream
54
    RTMP_PT_FLEX_OBJECT,        ///< Flex shared object
55
    RTMP_PT_FLEX_MESSAGE,       ///< Flex shared message
56
    RTMP_PT_NOTIFY,             ///< some notification
57
    RTMP_PT_SHARED_OBJ,         ///< shared object
58
    RTMP_PT_INVOKE,             ///< invoke some stream action
59
    RTMP_PT_METADATA     = 22,  ///< FLV metadata
60
} RTMPPacketType;
61
62
/**
63
 * possible RTMP packet header sizes
64
 */
65
enum RTMPPacketSize {
66
    RTMP_PS_TWELVEBYTES = 0, ///< packet has 12-byte header
67
    RTMP_PS_EIGHTBYTES,      ///< packet has 8-byte header
68
    RTMP_PS_FOURBYTES,       ///< packet has 4-byte header
69
    RTMP_PS_ONEBYTE          ///< packet is really a next chunk of a packet
70
};
71
72
/**
73
 * structure for holding RTMP packets
74
 */
75
typedef struct RTMPPacket {
76 6a63e83a Kostya Shishkov
    int            channel_id; ///< RTMP channel ID (nothing to do with audio/video channels though)
77 9fd6b843 Kostya Shishkov
    RTMPPacketType type;       ///< packet payload type
78 a352b605 Sergiy
    uint32_t       timestamp;  ///< packet full timestamp
79
    uint32_t       ts_delta;   ///< timestamp increment to the previous one in milliseconds (latter only for media packets)
80 9fd6b843 Kostya Shishkov
    uint32_t       extra;      ///< probably an additional channel ID used during streaming data
81
    uint8_t        *data;      ///< packet payload
82
    int            data_size;  ///< packet payload size
83
} RTMPPacket;
84
85
/**
86 49bd8e4b Måns Rullgård
 * Create new RTMP packet with given attributes.
87 9fd6b843 Kostya Shishkov
 *
88
 * @param pkt        packet
89
 * @param channel_id packet channel ID
90
 * @param type       packet type
91
 * @param timestamp  packet timestamp
92
 * @param size       packet size
93
 * @return zero on success, negative value otherwise
94
 */
95
int ff_rtmp_packet_create(RTMPPacket *pkt, int channel_id, RTMPPacketType type,
96
                          int timestamp, int size);
97
98
/**
99 49bd8e4b Måns Rullgård
 * Free RTMP packet.
100 9fd6b843 Kostya Shishkov
 *
101
 * @param pkt packet
102
 */
103
void ff_rtmp_packet_destroy(RTMPPacket *pkt);
104
105
/**
106 49bd8e4b Måns Rullgård
 * Read RTMP packet sent by the server.
107 9fd6b843 Kostya Shishkov
 *
108
 * @param h          reader context
109
 * @param p          packet
110
 * @param chunk_size current chunk size
111
 * @param prev_pkt   previously read packet headers for all channels
112
 *                   (may be needed for restoring incomplete packet header)
113 0b6b10d9 Kostya Shishkov
 * @return number of bytes read on success, negative value otherwise
114 9fd6b843 Kostya Shishkov
 */
115
int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p,
116
                        int chunk_size, RTMPPacket *prev_pkt);
117
118
/**
119 49bd8e4b Måns Rullgård
 * Send RTMP packet to the server.
120 9fd6b843 Kostya Shishkov
 *
121
 * @param h          reader context
122
 * @param p          packet to send
123
 * @param chunk_size current chunk size
124
 * @param prev_pkt   previously sent packet headers for all channels
125
 *                   (may be used for packet header compressing)
126 0b6b10d9 Kostya Shishkov
 * @return number of bytes written on success, negative value otherwise
127 9fd6b843 Kostya Shishkov
 */
128
int ff_rtmp_packet_write(URLContext *h, RTMPPacket *p,
129
                         int chunk_size, RTMPPacket *prev_pkt);
130
131
/**
132 49bd8e4b Måns Rullgård
 * Print information and contents of RTMP packet.
133 cfac91fe Kostya Shishkov
 *
134 9a58234f Diego Biurrun
 * @param ctx        output context
135 cfac91fe Kostya Shishkov
 * @param p          packet to dump
136
 */
137
void ff_rtmp_packet_dump(void *ctx, RTMPPacket *p);
138
139
/**
140 9fd6b843 Kostya Shishkov
 * @defgroup amffuncs functions used to work with AMF format (which is also used in .flv)
141
 * @see amf_* funcs in libavformat/flvdec.c
142
 * @{
143
 */
144
145
/**
146 49bd8e4b Måns Rullgård
 * Calculate number of bytes taken by first AMF entry in data.
147 9fd6b843 Kostya Shishkov
 *
148
 * @param data input data
149
 * @param data_end input buffer end
150
 * @return number of bytes used by first AMF entry
151
 */
152
int ff_amf_tag_size(const uint8_t *data, const uint8_t *data_end);
153
154
/**
155 49bd8e4b Måns Rullgård
 * Retrieve value of given AMF object field in string form.
156 9fd6b843 Kostya Shishkov
 *
157
 * @param data     AMF object data
158
 * @param data_end input buffer end
159
 * @param name     name of field to retrieve
160
 * @param dst      buffer for storing result
161
 * @param dst_size output buffer size
162
 * @return 0 if search and retrieval succeeded, negative value otherwise
163
 */
164
int ff_amf_get_field_value(const uint8_t *data, const uint8_t *data_end,
165
                           const uint8_t *name, uint8_t *dst, int dst_size);
166
167
/**
168 49bd8e4b Måns Rullgård
 * Write boolean value in AMF format to buffer.
169 9fd6b843 Kostya Shishkov
 *
170
 * @param dst pointer to the input buffer (will be modified)
171
 * @param val value to write
172
 */
173
void ff_amf_write_bool(uint8_t **dst, int val);
174
175
/**
176 49bd8e4b Måns Rullgård
 * Write number in AMF format to buffer.
177 9fd6b843 Kostya Shishkov
 *
178
 * @param dst pointer to the input buffer (will be modified)
179
 * @param num value to write
180
 */
181
void ff_amf_write_number(uint8_t **dst, double num);
182
183
/**
184 49bd8e4b Måns Rullgård
 * Write string in AMF format to buffer.
185 9fd6b843 Kostya Shishkov
 *
186
 * @param dst pointer to the input buffer (will be modified)
187
 * @param str string to write
188
 */
189
void ff_amf_write_string(uint8_t **dst, const char *str);
190
191
/**
192 49bd8e4b Måns Rullgård
 * Write AMF NULL value to buffer.
193 9fd6b843 Kostya Shishkov
 *
194
 * @param dst pointer to the input buffer (will be modified)
195
 */
196
void ff_amf_write_null(uint8_t **dst);
197
198
/**
199 49bd8e4b Måns Rullgård
 * Write marker for AMF object to buffer.
200 9fd6b843 Kostya Shishkov
 *
201
 * @param dst pointer to the input buffer (will be modified)
202
 */
203
void ff_amf_write_object_start(uint8_t **dst);
204
205
/**
206 49bd8e4b Måns Rullgård
 * Write string used as field name in AMF object to buffer.
207 9fd6b843 Kostya Shishkov
 *
208
 * @param dst pointer to the input buffer (will be modified)
209
 * @param str string to write
210
 */
211
void ff_amf_write_field_name(uint8_t **dst, const char *str);
212
213
/**
214 49bd8e4b Måns Rullgård
 * Write marker for end of AMF object to buffer.
215 9fd6b843 Kostya Shishkov
 *
216
 * @param dst pointer to the input buffer (will be modified)
217
 */
218
void ff_amf_write_object_end(uint8_t **dst);
219
220
/** @} */ // AMF funcs
221
222
#endif /* AVFORMAT_RTMPPKT_H */