yading@11
|
1 /*
|
yading@11
|
2 * RTP demuxer definitions
|
yading@11
|
3 * Copyright (c) 2002 Fabrice Bellard
|
yading@11
|
4 * Copyright (c) 2006 Ryan Martell <rdm4@martellventures.com>
|
yading@11
|
5 *
|
yading@11
|
6 * This file is part of FFmpeg.
|
yading@11
|
7 *
|
yading@11
|
8 * FFmpeg is free software; you can redistribute it and/or
|
yading@11
|
9 * modify it under the terms of the GNU Lesser General Public
|
yading@11
|
10 * License as published by the Free Software Foundation; either
|
yading@11
|
11 * version 2.1 of the License, or (at your option) any later version.
|
yading@11
|
12 *
|
yading@11
|
13 * FFmpeg is distributed in the hope that it will be useful,
|
yading@11
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
yading@11
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
yading@11
|
16 * Lesser General Public License for more details.
|
yading@11
|
17 *
|
yading@11
|
18 * You should have received a copy of the GNU Lesser General Public
|
yading@11
|
19 * License along with FFmpeg; if not, write to the Free Software
|
yading@11
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
yading@11
|
21 */
|
yading@11
|
22
|
yading@11
|
23 #ifndef AVFORMAT_RTPDEC_H
|
yading@11
|
24 #define AVFORMAT_RTPDEC_H
|
yading@11
|
25
|
yading@11
|
26 #include "libavcodec/avcodec.h"
|
yading@11
|
27 #include "avformat.h"
|
yading@11
|
28 #include "rtp.h"
|
yading@11
|
29 #include "url.h"
|
yading@11
|
30 #include "srtp.h"
|
yading@11
|
31
|
yading@11
|
32 typedef struct PayloadContext PayloadContext;
|
yading@11
|
33 typedef struct RTPDynamicProtocolHandler RTPDynamicProtocolHandler;
|
yading@11
|
34
|
yading@11
|
35 #define RTP_MIN_PACKET_LENGTH 12
|
yading@11
|
36 #define RTP_MAX_PACKET_LENGTH 8192
|
yading@11
|
37
|
yading@11
|
38 #define RTP_REORDER_QUEUE_DEFAULT_SIZE 10
|
yading@11
|
39
|
yading@11
|
40 #define RTP_NOTS_VALUE ((uint32_t)-1)
|
yading@11
|
41
|
yading@11
|
42 typedef struct RTPDemuxContext RTPDemuxContext;
|
yading@11
|
43 RTPDemuxContext *ff_rtp_parse_open(AVFormatContext *s1, AVStream *st,
|
yading@11
|
44 int payload_type, int queue_size);
|
yading@11
|
45 void ff_rtp_parse_set_dynamic_protocol(RTPDemuxContext *s, PayloadContext *ctx,
|
yading@11
|
46 RTPDynamicProtocolHandler *handler);
|
yading@11
|
47 void ff_rtp_parse_set_crypto(RTPDemuxContext *s, const char *suite,
|
yading@11
|
48 const char *params);
|
yading@11
|
49 int ff_rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt,
|
yading@11
|
50 uint8_t **buf, int len);
|
yading@11
|
51 void ff_rtp_parse_close(RTPDemuxContext *s);
|
yading@11
|
52 int64_t ff_rtp_queued_packet_time(RTPDemuxContext *s);
|
yading@11
|
53 void ff_rtp_reset_packet_queue(RTPDemuxContext *s);
|
yading@11
|
54 int ff_rtp_get_local_rtp_port(URLContext *h);
|
yading@11
|
55 int ff_rtp_get_local_rtcp_port(URLContext *h);
|
yading@11
|
56
|
yading@11
|
57 int ff_rtp_set_remote_url(URLContext *h, const char *uri);
|
yading@11
|
58
|
yading@11
|
59 /**
|
yading@11
|
60 * Send a dummy packet on both port pairs to set up the connection
|
yading@11
|
61 * state in potential NAT routers, so that we're able to receive
|
yading@11
|
62 * packets.
|
yading@11
|
63 *
|
yading@11
|
64 * Note, this only works if the NAT router doesn't remap ports. This
|
yading@11
|
65 * isn't a standardized procedure, but it works in many cases in practice.
|
yading@11
|
66 *
|
yading@11
|
67 * The same routine is used with RDT too, even if RDT doesn't use normal
|
yading@11
|
68 * RTP packets otherwise.
|
yading@11
|
69 */
|
yading@11
|
70 void ff_rtp_send_punch_packets(URLContext* rtp_handle);
|
yading@11
|
71
|
yading@11
|
72 /**
|
yading@11
|
73 * some rtp servers assume client is dead if they don't hear from them...
|
yading@11
|
74 * so we send a Receiver Report to the provided URLContext or AVIOContext
|
yading@11
|
75 * (we don't have access to the rtcp handle from here)
|
yading@11
|
76 */
|
yading@11
|
77 int ff_rtp_check_and_send_back_rr(RTPDemuxContext *s, URLContext *fd,
|
yading@11
|
78 AVIOContext *avio, int count);
|
yading@11
|
79 int ff_rtp_send_rtcp_feedback(RTPDemuxContext *s, URLContext *fd,
|
yading@11
|
80 AVIOContext *avio);
|
yading@11
|
81
|
yading@11
|
82 // these statistics are used for rtcp receiver reports...
|
yading@11
|
83 typedef struct RTPStatistics {
|
yading@11
|
84 uint16_t max_seq; ///< highest sequence number seen
|
yading@11
|
85 uint32_t cycles; ///< shifted count of sequence number cycles
|
yading@11
|
86 uint32_t base_seq; ///< base sequence number
|
yading@11
|
87 uint32_t bad_seq; ///< last bad sequence number + 1
|
yading@11
|
88 int probation; ///< sequence packets till source is valid
|
yading@11
|
89 uint32_t received; ///< packets received
|
yading@11
|
90 uint32_t expected_prior; ///< packets expected in last interval
|
yading@11
|
91 uint32_t received_prior; ///< packets received in last interval
|
yading@11
|
92 uint32_t transit; ///< relative transit time for previous packet
|
yading@11
|
93 uint32_t jitter; ///< estimated jitter.
|
yading@11
|
94 } RTPStatistics;
|
yading@11
|
95
|
yading@11
|
96 #define RTP_FLAG_KEY 0x1 ///< RTP packet contains a keyframe
|
yading@11
|
97 #define RTP_FLAG_MARKER 0x2 ///< RTP marker bit was set for this packet
|
yading@11
|
98 /**
|
yading@11
|
99 * Packet parsing for "private" payloads in the RTP specs.
|
yading@11
|
100 *
|
yading@11
|
101 * @param ctx RTSP demuxer context
|
yading@11
|
102 * @param s stream context
|
yading@11
|
103 * @param st stream that this packet belongs to
|
yading@11
|
104 * @param pkt packet in which to write the parsed data
|
yading@11
|
105 * @param timestamp pointer to the RTP timestamp of the input data, can be
|
yading@11
|
106 * updated by the function if returning older, buffered data
|
yading@11
|
107 * @param buf pointer to raw RTP packet data
|
yading@11
|
108 * @param len length of buf
|
yading@11
|
109 * @param seq RTP sequence number of the packet
|
yading@11
|
110 * @param flags flags from the RTP packet header (RTP_FLAG_*)
|
yading@11
|
111 */
|
yading@11
|
112 typedef int (*DynamicPayloadPacketHandlerProc)(AVFormatContext *ctx,
|
yading@11
|
113 PayloadContext *s,
|
yading@11
|
114 AVStream *st, AVPacket *pkt,
|
yading@11
|
115 uint32_t *timestamp,
|
yading@11
|
116 const uint8_t * buf,
|
yading@11
|
117 int len, uint16_t seq, int flags);
|
yading@11
|
118
|
yading@11
|
119 struct RTPDynamicProtocolHandler {
|
yading@11
|
120 const char enc_name[50];
|
yading@11
|
121 enum AVMediaType codec_type;
|
yading@11
|
122 enum AVCodecID codec_id;
|
yading@11
|
123 int static_payload_id; /* 0 means no payload id is set. 0 is a valid
|
yading@11
|
124 * payload ID (PCMU), too, but that format doesn't
|
yading@11
|
125 * require any custom depacketization code. */
|
yading@11
|
126
|
yading@11
|
127 /** Initialize dynamic protocol handler, called after the full rtpmap line is parsed, may be null */
|
yading@11
|
128 int (*init)(AVFormatContext *s, int st_index, PayloadContext *priv_data);
|
yading@11
|
129 /** Parse the a= line from the sdp field */
|
yading@11
|
130 int (*parse_sdp_a_line)(AVFormatContext *s, int st_index,
|
yading@11
|
131 PayloadContext *priv_data, const char *line);
|
yading@11
|
132 /** Allocate any data needed by the rtp parsing for this dynamic data. */
|
yading@11
|
133 PayloadContext *(*alloc)(void);
|
yading@11
|
134 /** Free any data needed by the rtp parsing for this dynamic data. */
|
yading@11
|
135 void (*free)(PayloadContext *protocol_data);
|
yading@11
|
136 /** Parse handler for this dynamic packet */
|
yading@11
|
137 DynamicPayloadPacketHandlerProc parse_packet;
|
yading@11
|
138 int (*need_keyframe)(PayloadContext *context);
|
yading@11
|
139
|
yading@11
|
140 struct RTPDynamicProtocolHandler *next;
|
yading@11
|
141 };
|
yading@11
|
142
|
yading@11
|
143 typedef struct RTPPacket {
|
yading@11
|
144 uint16_t seq;
|
yading@11
|
145 uint8_t *buf;
|
yading@11
|
146 int len;
|
yading@11
|
147 int64_t recvtime;
|
yading@11
|
148 struct RTPPacket *next;
|
yading@11
|
149 } RTPPacket;
|
yading@11
|
150
|
yading@11
|
151 struct RTPDemuxContext {
|
yading@11
|
152 AVFormatContext *ic;
|
yading@11
|
153 AVStream *st;
|
yading@11
|
154 int payload_type;
|
yading@11
|
155 uint32_t ssrc;
|
yading@11
|
156 uint16_t seq;
|
yading@11
|
157 uint32_t timestamp;
|
yading@11
|
158 uint32_t base_timestamp;
|
yading@11
|
159 uint32_t cur_timestamp;
|
yading@11
|
160 int64_t unwrapped_timestamp;
|
yading@11
|
161 int64_t range_start_offset;
|
yading@11
|
162 int max_payload_size;
|
yading@11
|
163 /* used to send back RTCP RR */
|
yading@11
|
164 char hostname[256];
|
yading@11
|
165
|
yading@11
|
166 int srtp_enabled;
|
yading@11
|
167 struct SRTPContext srtp;
|
yading@11
|
168
|
yading@11
|
169 /** Statistics for this stream (used by RTCP receiver reports) */
|
yading@11
|
170 RTPStatistics statistics;
|
yading@11
|
171
|
yading@11
|
172 /** Fields for packet reordering @{ */
|
yading@11
|
173 int prev_ret; ///< The return value of the actual parsing of the previous packet
|
yading@11
|
174 RTPPacket* queue; ///< A sorted queue of buffered packets not yet returned
|
yading@11
|
175 int queue_len; ///< The number of packets in queue
|
yading@11
|
176 int queue_size; ///< The size of queue, or 0 if reordering is disabled
|
yading@11
|
177 /*@}*/
|
yading@11
|
178
|
yading@11
|
179 /* rtcp sender statistics receive */
|
yading@11
|
180 int64_t last_rtcp_ntp_time;
|
yading@11
|
181 int64_t last_rtcp_reception_time;
|
yading@11
|
182 int64_t first_rtcp_ntp_time;
|
yading@11
|
183 uint32_t last_rtcp_timestamp;
|
yading@11
|
184 int64_t rtcp_ts_offset;
|
yading@11
|
185
|
yading@11
|
186 /* rtcp sender statistics */
|
yading@11
|
187 unsigned int packet_count;
|
yading@11
|
188 unsigned int octet_count;
|
yading@11
|
189 unsigned int last_octet_count;
|
yading@11
|
190 int64_t last_feedback_time;
|
yading@11
|
191
|
yading@11
|
192 /* dynamic payload stuff */
|
yading@11
|
193 const RTPDynamicProtocolHandler *handler;
|
yading@11
|
194 PayloadContext *dynamic_protocol_context;
|
yading@11
|
195 };
|
yading@11
|
196
|
yading@11
|
197 void ff_register_dynamic_payload_handler(RTPDynamicProtocolHandler *handler);
|
yading@11
|
198 RTPDynamicProtocolHandler *ff_rtp_handler_find_by_name(const char *name,
|
yading@11
|
199 enum AVMediaType codec_type);
|
yading@11
|
200 RTPDynamicProtocolHandler *ff_rtp_handler_find_by_id(int id,
|
yading@11
|
201 enum AVMediaType codec_type);
|
yading@11
|
202
|
yading@11
|
203 /* from rtsp.c, but used by rtp dynamic protocol handlers. */
|
yading@11
|
204 int ff_rtsp_next_attr_and_value(const char **p, char *attr, int attr_size,
|
yading@11
|
205 char *value, int value_size);
|
yading@11
|
206
|
yading@11
|
207 int ff_parse_fmtp(AVStream *stream, PayloadContext *data, const char *p,
|
yading@11
|
208 int (*parse_fmtp)(AVStream *stream,
|
yading@11
|
209 PayloadContext *data,
|
yading@11
|
210 char *attr, char *value));
|
yading@11
|
211
|
yading@11
|
212 void av_register_rtp_dynamic_payload_handlers(void);
|
yading@11
|
213
|
yading@11
|
214 /**
|
yading@11
|
215 * Close the dynamic buffer and make a packet from it.
|
yading@11
|
216 */
|
yading@11
|
217 int ff_rtp_finalize_packet(AVPacket *pkt, AVIOContext **dyn_buf, int stream_idx);
|
yading@11
|
218
|
yading@11
|
219 #endif /* AVFORMAT_RTPDEC_H */
|