Mercurial > libavformat.hg
annotate rtp.c @ 1427:f1614c754d5b libavformat
move up (in the file) AAC audio handling moved from below
This is because upper section handles packets, and the lower switch handles timestamps
Patch by Ryan Martell % rdm4 A martellventures P com %
Original thread:
Date: Oct 27, 2006 11:40 PM
Subject: Re: [Ffmpeg-devel] RTP patches & RFC
author | gpoirier |
---|---|
date | Sat, 28 Oct 2006 00:29:59 +0000 |
parents | 00d9393a126f |
children | 2d8a17631520 |
rev | line source |
---|---|
0 | 1 /* |
2 * RTP input/output format | |
3 * Copyright (c) 2002 Fabrice Bellard. | |
4 * | |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1332
diff
changeset
|
5 * This file is part of FFmpeg. |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1332
diff
changeset
|
6 * |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1332
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
0 | 8 * modify it under the terms of the GNU Lesser General Public |
9 * License as published by the Free Software Foundation; either | |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1332
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
0 | 11 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1332
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
0 | 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 | |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1332
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
896
edbe5c3717f9
Update licensing information: The FSF changed postal address.
diego
parents:
885
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 20 */ |
21 #include "avformat.h" | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
22 #include "mpegts.h" |
774 | 23 #include "bitstream.h" |
0 | 24 |
25 #include <unistd.h> | |
26 #include <sys/types.h> | |
27 #include <sys/socket.h> | |
28 #include <netinet/in.h> | |
29 #ifndef __BEOS__ | |
30 # include <arpa/inet.h> | |
31 #else | |
32 # include "barpainet.h" | |
33 #endif | |
34 #include <netdb.h> | |
35 | |
1419 | 36 #include "rtp_internal.h" |
37 | |
38 //#define RTP_H264 | |
39 #ifdef RTP_H264 | |
40 #include "rtp_h264.h" | |
41 #endif | |
42 | |
0 | 43 //#define DEBUG |
44 | |
45 | |
46 /* TODO: - add RTCP statistics reporting (should be optional). | |
47 | |
48 - add support for h263/mpeg4 packetized output : IDEA: send a | |
49 buffer to 'rtp_write_packet' contains all the packets for ONE | |
50 frame. Each packet should have a four byte header containing | |
51 the length in big endian format (same trick as | |
885 | 52 'url_open_dyn_packet_buf') |
0 | 53 */ |
54 | |
774 | 55 /* from http://www.iana.org/assignments/rtp-parameters last updated 05 January 2005 */ |
56 AVRtpPayloadType_t AVRtpPayloadTypes[]= | |
57 { | |
58 {0, "PCMU", CODEC_TYPE_AUDIO, CODEC_ID_PCM_MULAW, 8000, 1}, | |
59 {1, "Reserved", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
60 {2, "Reserved", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
61 {3, "GSM", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1}, | |
62 {4, "G723", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1}, | |
63 {5, "DVI4", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1}, | |
64 {6, "DVI4", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 16000, 1}, | |
65 {7, "LPC", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1}, | |
66 {8, "PCMA", CODEC_TYPE_AUDIO, CODEC_ID_PCM_ALAW, 8000, 1}, | |
67 {9, "G722", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1}, | |
68 {10, "L16", CODEC_TYPE_AUDIO, CODEC_ID_PCM_S16BE, 44100, 2}, | |
69 {11, "L16", CODEC_TYPE_AUDIO, CODEC_ID_PCM_S16BE, 44100, 1}, | |
1259 | 70 {12, "QCELP", CODEC_TYPE_AUDIO, CODEC_ID_QCELP, 8000, 1}, |
774 | 71 {13, "CN", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1}, |
72 {14, "MPA", CODEC_TYPE_AUDIO, CODEC_ID_MP2, 90000, -1}, | |
73 {15, "G728", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1}, | |
74 {16, "DVI4", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 11025, 1}, | |
75 {17, "DVI4", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 22050, 1}, | |
76 {18, "G729", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1}, | |
77 {19, "reserved", CODEC_TYPE_AUDIO, CODEC_ID_NONE, -1, -1}, | |
78 {20, "unassigned", CODEC_TYPE_AUDIO, CODEC_ID_NONE, -1, -1}, | |
79 {21, "unassigned", CODEC_TYPE_AUDIO, CODEC_ID_NONE, -1, -1}, | |
80 {22, "unassigned", CODEC_TYPE_AUDIO, CODEC_ID_NONE, -1, -1}, | |
81 {23, "unassigned", CODEC_TYPE_AUDIO, CODEC_ID_NONE, -1, -1}, | |
82 {24, "unassigned", CODEC_TYPE_VIDEO, CODEC_ID_NONE, -1, -1}, | |
83 {25, "CelB", CODEC_TYPE_VIDEO, CODEC_ID_NONE, 90000, -1}, | |
84 {26, "JPEG", CODEC_TYPE_VIDEO, CODEC_ID_MJPEG, 90000, -1}, | |
85 {27, "unassigned", CODEC_TYPE_VIDEO, CODEC_ID_NONE, -1, -1}, | |
86 {28, "nv", CODEC_TYPE_VIDEO, CODEC_ID_NONE, 90000, -1}, | |
87 {29, "unassigned", CODEC_TYPE_VIDEO, CODEC_ID_NONE, -1, -1}, | |
88 {30, "unassigned", CODEC_TYPE_VIDEO, CODEC_ID_NONE, -1, -1}, | |
89 {31, "H261", CODEC_TYPE_VIDEO, CODEC_ID_H261, 90000, -1}, | |
90 {32, "MPV", CODEC_TYPE_VIDEO, CODEC_ID_MPEG1VIDEO, 90000, -1}, | |
91 {33, "MP2T", CODEC_TYPE_DATA, CODEC_ID_MPEG2TS, 90000, -1}, | |
92 {34, "H263", CODEC_TYPE_VIDEO, CODEC_ID_H263, 90000, -1}, | |
93 {35, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
94 {36, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
95 {37, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
96 {38, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
97 {39, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
98 {40, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
99 {41, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
100 {42, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
101 {43, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
102 {44, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
103 {45, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
104 {46, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
105 {47, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
106 {48, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
107 {49, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
108 {50, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
109 {51, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
110 {52, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
111 {53, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
112 {54, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
113 {55, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
114 {56, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
115 {57, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
116 {58, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
117 {59, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
118 {60, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
119 {61, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
120 {62, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
121 {63, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
122 {64, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
123 {65, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
124 {66, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
125 {67, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
126 {68, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
127 {69, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
128 {70, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
129 {71, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
130 {72, "reserved for RTCP conflict avoidance", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
131 {73, "reserved for RTCP conflict avoidance", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
132 {74, "reserved for RTCP conflict avoidance", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
133 {75, "reserved for RTCP conflict avoidance", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
134 {76, "reserved for RTCP conflict avoidance", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
135 {77, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
136 {78, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
137 {79, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
138 {80, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
139 {81, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
140 {82, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
141 {83, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
142 {84, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
143 {85, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
144 {86, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
145 {87, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
146 {88, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
147 {89, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
148 {90, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
149 {91, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
150 {92, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
151 {93, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
152 {94, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
153 {95, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
154 {96, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
155 {97, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
156 {98, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
157 {99, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
158 {100, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
159 {101, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
160 {102, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
161 {103, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
162 {104, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
163 {105, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
164 {106, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
165 {107, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
166 {108, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
167 {109, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
168 {110, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
169 {111, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
170 {112, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
171 {113, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
172 {114, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
173 {115, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
174 {116, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
175 {117, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
176 {118, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
177 {119, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
178 {120, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
179 {121, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
180 {122, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
181 {123, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
182 {124, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
183 {125, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
184 {126, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
185 {127, "dynamic", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, | |
186 {-1, "", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1} | |
187 }; | |
0 | 188 |
1419 | 189 /* statistics functions */ |
190 RTPDynamicProtocolHandler *RTPFirstDynamicPayloadHandler= NULL; | |
191 | |
192 static RTPDynamicProtocolHandler mp4v_es_handler= {"MP4V-ES", CODEC_TYPE_VIDEO, CODEC_ID_MPEG4}; | |
193 static RTPDynamicProtocolHandler mpeg4_generic_handler= {"mpeg4-generic", CODEC_TYPE_AUDIO, CODEC_ID_MPEG4AAC}; | |
0 | 194 |
1419 | 195 static void register_dynamic_payload_handler(RTPDynamicProtocolHandler *handler) |
196 { | |
197 handler->next= RTPFirstDynamicPayloadHandler; | |
198 RTPFirstDynamicPayloadHandler= handler; | |
199 } | |
885 | 200 |
1419 | 201 void av_register_rtp_dynamic_payload_handlers() |
202 { | |
203 register_dynamic_payload_handler(&mp4v_es_handler); | |
204 register_dynamic_payload_handler(&mpeg4_generic_handler); | |
205 #ifdef RTP_H264 | |
206 register_dynamic_payload_handler(&ff_h264_dynamic_handler); | |
207 #endif | |
208 } | |
0 | 209 |
210 int rtp_get_codec_info(AVCodecContext *codec, int payload_type) | |
211 { | |
774 | 212 if (AVRtpPayloadTypes[payload_type].codec_id != CODEC_ID_NONE) { |
213 codec->codec_type = AVRtpPayloadTypes[payload_type].codec_type; | |
1116 | 214 codec->codec_id = AVRtpPayloadTypes[payload_type].codec_id; |
774 | 215 if (AVRtpPayloadTypes[payload_type].audio_channels > 0) |
216 codec->channels = AVRtpPayloadTypes[payload_type].audio_channels; | |
217 if (AVRtpPayloadTypes[payload_type].clock_rate > 0) | |
218 codec->sample_rate = AVRtpPayloadTypes[payload_type].clock_rate; | |
219 return 0; | |
0 | 220 } |
774 | 221 return -1; |
0 | 222 } |
223 | |
224 /* return < 0 if unknown payload type */ | |
225 int rtp_get_payload_type(AVCodecContext *codec) | |
226 { | |
774 | 227 int i, payload_type; |
0 | 228 |
229 /* compute the payload type */ | |
774 | 230 for (payload_type = -1, i = 0; AVRtpPayloadTypes[i].pt >= 0; ++i) |
231 if (AVRtpPayloadTypes[i].codec_id == codec->codec_id) { | |
232 if (codec->codec_id == CODEC_ID_PCM_S16BE) | |
233 if (codec->channels != AVRtpPayloadTypes[i].audio_channels) | |
234 continue; | |
235 payload_type = AVRtpPayloadTypes[i].pt; | |
0 | 236 } |
237 return payload_type; | |
238 } | |
239 | |
65 | 240 static inline uint32_t decode_be32(const uint8_t *p) |
0 | 241 { |
242 return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; | |
243 } | |
244 | |
173 | 245 static inline uint64_t decode_be64(const uint8_t *p) |
0 | 246 { |
65 | 247 return ((uint64_t)decode_be32(p) << 32) | decode_be32(p + 4); |
0 | 248 } |
249 | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
250 static int rtcp_parse_packet(RTPDemuxContext *s, const unsigned char *buf, int len) |
0 | 251 { |
252 if (buf[1] != 200) | |
253 return -1; | |
254 s->last_rtcp_ntp_time = decode_be64(buf + 8); | |
173 | 255 if (s->first_rtcp_ntp_time == AV_NOPTS_VALUE) |
256 s->first_rtcp_ntp_time = s->last_rtcp_ntp_time; | |
0 | 257 s->last_rtcp_timestamp = decode_be32(buf + 16); |
258 return 0; | |
259 } | |
260 | |
261 /** | |
1425
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
262 * some rtp servers assume client is dead if they don't hear from them... |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
263 * so we send a Receiver Report to the provided ByteIO context |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
264 * (we don't have access to the rtcp handle from here) |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
265 */ |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
266 int rtp_check_and_send_back_rr(RTPDemuxContext *s, int count) |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
267 { |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
268 ByteIOContext pb; |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
269 uint8_t *buf; |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
270 int len; |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
271 int rtcp_bytes; |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
272 |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
273 if (!s->rtp_ctx || (count < 1)) |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
274 return -1; |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
275 |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
276 /* XXX: mpeg pts hardcoded. RTCP send every 0.5 seconds */ |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
277 s->octet_count += count; |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
278 rtcp_bytes = ((s->octet_count - s->last_octet_count) * RTCP_TX_RATIO_NUM) / |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
279 RTCP_TX_RATIO_DEN; |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
280 rtcp_bytes /= 50; // mmu_man: that's enough for me... VLC sends much less btw !? |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
281 if (rtcp_bytes < 28) |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
282 return -1; |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
283 s->last_octet_count = s->octet_count; |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
284 |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
285 if (url_open_dyn_buf(&pb) < 0) |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
286 return -1; |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
287 |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
288 // Receiver Report |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
289 put_byte(&pb, (RTP_VERSION << 6) + 1); /* 1 report block */ |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
290 put_byte(&pb, 201); |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
291 put_be16(&pb, 7); /* length in words - 1 */ |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
292 put_be32(&pb, s->ssrc); // our own SSRC |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
293 put_be32(&pb, s->ssrc); // XXX: should be the server's here! |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
294 // some placeholders we should really fill... |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
295 put_be32(&pb, ((0 << 24) | (0 & 0x0ffffff))); /* 0% lost, total 0 lost */ |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
296 put_be32(&pb, (0 << 16) | s->seq); |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
297 put_be32(&pb, 0x68); /* jitter */ |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
298 put_be32(&pb, -1); /* last SR timestamp */ |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
299 put_be32(&pb, 1); /* delay since last SR */ |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
300 |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
301 // CNAME |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
302 put_byte(&pb, (RTP_VERSION << 6) + 1); /* 1 report block */ |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
303 put_byte(&pb, 202); |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
304 len = strlen(s->hostname); |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
305 put_be16(&pb, (6 + len + 3) / 4); /* length in words - 1 */ |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
306 put_be32(&pb, s->ssrc); |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
307 put_byte(&pb, 0x01); |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
308 put_byte(&pb, len); |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
309 put_buffer(&pb, s->hostname, len); |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
310 // padding |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
311 for (len = (6 + len) % 4; len % 4; len++) { |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
312 put_byte(&pb, 0); |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
313 } |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
314 |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
315 put_flush_packet(&pb); |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
316 len = url_close_dyn_buf(&pb, &buf); |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
317 if ((len > 0) && buf) { |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
318 #if defined(DEBUG) |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
319 printf("sending %d bytes of RR\n", len); |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
320 #endif |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
321 url_write(s->rtp_ctx, buf, len); |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
322 av_free(buf); |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
323 } |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
324 return 0; |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
325 } |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
326 |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
327 /** |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
328 * open a new RTP parse context for stream 'st'. 'st' can be NULL for |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
329 * MPEG2TS streams to indicate that they should be demuxed inside the |
885 | 330 * rtp demux (otherwise CODEC_ID_MPEG2TS packets are returned) |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
331 */ |
1425
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
332 RTPDemuxContext *rtp_parse_open(AVFormatContext *s1, AVStream *st, URLContext *rtpc, int payload_type, rtp_payload_data_t *rtp_payload_data) |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
333 { |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
334 RTPDemuxContext *s; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
335 |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
336 s = av_mallocz(sizeof(RTPDemuxContext)); |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
337 if (!s) |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
338 return NULL; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
339 s->payload_type = payload_type; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
340 s->last_rtcp_ntp_time = AV_NOPTS_VALUE; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
341 s->first_rtcp_ntp_time = AV_NOPTS_VALUE; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
342 s->ic = s1; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
343 s->st = st; |
774 | 344 s->rtp_payload_data = rtp_payload_data; |
345 if (!strcmp(AVRtpPayloadTypes[payload_type].enc_name, "MP2T")) { | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
346 s->ts = mpegts_parse_open(s->ic); |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
347 if (s->ts == NULL) { |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
348 av_free(s); |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
349 return NULL; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
350 } |
305 | 351 } else { |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
777
diff
changeset
|
352 switch(st->codec->codec_id) { |
305 | 353 case CODEC_ID_MPEG1VIDEO: |
354 case CODEC_ID_MPEG2VIDEO: | |
355 case CODEC_ID_MP2: | |
356 case CODEC_ID_MP3: | |
357 case CODEC_ID_MPEG4: | |
1419 | 358 #ifdef RTP_H264 |
359 case CODEC_ID_H264: | |
360 #endif | |
305 | 361 st->need_parsing = 1; |
362 break; | |
363 default: | |
364 break; | |
365 } | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
366 } |
1425
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
367 // needed to send back RTCP RR in RTSP sessions |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
368 s->rtp_ctx = rtpc; |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
369 gethostname(s->hostname, sizeof(s->hostname)); |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
370 return s; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
371 } |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
372 |
774 | 373 static int rtp_parse_mp4_au(RTPDemuxContext *s, const uint8_t *buf) |
374 { | |
375 int au_headers_length, au_header_size, i; | |
376 GetBitContext getbitcontext; | |
377 rtp_payload_data_t *infos; | |
378 | |
379 infos = s->rtp_payload_data; | |
380 | |
381 if (infos == NULL) | |
382 return -1; | |
383 | |
384 /* decode the first 2 bytes where are stored the AUHeader sections | |
385 length in bits */ | |
386 au_headers_length = BE_16(buf); | |
387 | |
388 if (au_headers_length > RTP_MAX_PACKET_LENGTH) | |
389 return -1; | |
390 | |
391 infos->au_headers_length_bytes = (au_headers_length + 7) / 8; | |
392 | |
393 /* skip AU headers length section (2 bytes) */ | |
394 buf += 2; | |
395 | |
396 init_get_bits(&getbitcontext, buf, infos->au_headers_length_bytes * 8); | |
397 | |
398 /* XXX: Wrong if optionnal additional sections are present (cts, dts etc...) */ | |
399 au_header_size = infos->sizelength + infos->indexlength; | |
400 if (au_header_size <= 0 || (au_headers_length % au_header_size != 0)) | |
401 return -1; | |
402 | |
403 infos->nb_au_headers = au_headers_length / au_header_size; | |
404 infos->au_headers = av_malloc(sizeof(struct AUHeaders) * infos->nb_au_headers); | |
405 | |
406 /* XXX: We handle multiple AU Section as only one (need to fix this for interleaving) | |
407 In my test, the faad decoder doesnt behave correctly when sending each AU one by one | |
408 but does when sending the whole as one big packet... */ | |
409 infos->au_headers[0].size = 0; | |
410 infos->au_headers[0].index = 0; | |
411 for (i = 0; i < infos->nb_au_headers; ++i) { | |
412 infos->au_headers[0].size += get_bits_long(&getbitcontext, infos->sizelength); | |
413 infos->au_headers[0].index = get_bits_long(&getbitcontext, infos->indexlength); | |
414 } | |
415 | |
416 infos->nb_au_headers = 1; | |
417 | |
418 return 0; | |
419 } | |
420 | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
421 /** |
885 | 422 * Parse an RTP or RTCP packet directly sent as a buffer. |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
423 * @param s RTP parse context. |
0 | 424 * @param pkt returned packet |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
425 * @param buf input buffer or NULL to read the next packets |
0 | 426 * @param len buffer len |
885 | 427 * @return 0 if a packet is returned, 1 if a packet is returned and more can follow |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
428 * (use buf as NULL to read the next). -1 if no packet (error or no more packet). |
0 | 429 */ |
885 | 430 int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt, |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
431 const uint8_t *buf, int len) |
0 | 432 { |
433 unsigned int ssrc, h; | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
434 int payload_type, seq, delta_timestamp, ret; |
0 | 435 AVStream *st; |
65 | 436 uint32_t timestamp; |
885 | 437 |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
438 if (!buf) { |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
439 /* return the next packets, if any */ |
1419 | 440 if(s->st && s->parse_packet) { |
441 return s->parse_packet(s, pkt, 0, NULL, 0); | |
442 } else { | |
1424
1c39ce5c6a5d
indentation fix, patch by Ryan Martell % rdm4 A martellventures P com %
gpoirier
parents:
1419
diff
changeset
|
443 if (s->read_buf_index >= s->read_buf_size) |
1c39ce5c6a5d
indentation fix, patch by Ryan Martell % rdm4 A martellventures P com %
gpoirier
parents:
1419
diff
changeset
|
444 return -1; |
1c39ce5c6a5d
indentation fix, patch by Ryan Martell % rdm4 A martellventures P com %
gpoirier
parents:
1419
diff
changeset
|
445 ret = mpegts_parse_packet(s->ts, pkt, s->buf + s->read_buf_index, |
1c39ce5c6a5d
indentation fix, patch by Ryan Martell % rdm4 A martellventures P com %
gpoirier
parents:
1419
diff
changeset
|
446 s->read_buf_size - s->read_buf_index); |
1c39ce5c6a5d
indentation fix, patch by Ryan Martell % rdm4 A martellventures P com %
gpoirier
parents:
1419
diff
changeset
|
447 if (ret < 0) |
1c39ce5c6a5d
indentation fix, patch by Ryan Martell % rdm4 A martellventures P com %
gpoirier
parents:
1419
diff
changeset
|
448 return -1; |
1c39ce5c6a5d
indentation fix, patch by Ryan Martell % rdm4 A martellventures P com %
gpoirier
parents:
1419
diff
changeset
|
449 s->read_buf_index += ret; |
1c39ce5c6a5d
indentation fix, patch by Ryan Martell % rdm4 A martellventures P com %
gpoirier
parents:
1419
diff
changeset
|
450 if (s->read_buf_index < s->read_buf_size) |
1c39ce5c6a5d
indentation fix, patch by Ryan Martell % rdm4 A martellventures P com %
gpoirier
parents:
1419
diff
changeset
|
451 return 1; |
1c39ce5c6a5d
indentation fix, patch by Ryan Martell % rdm4 A martellventures P com %
gpoirier
parents:
1419
diff
changeset
|
452 else |
1c39ce5c6a5d
indentation fix, patch by Ryan Martell % rdm4 A martellventures P com %
gpoirier
parents:
1419
diff
changeset
|
453 return 0; |
1419 | 454 } |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
455 } |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
456 |
0 | 457 if (len < 12) |
458 return -1; | |
459 | |
460 if ((buf[0] & 0xc0) != (RTP_VERSION << 6)) | |
461 return -1; | |
462 if (buf[1] >= 200 && buf[1] <= 204) { | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
463 rtcp_parse_packet(s, buf, len); |
0 | 464 return -1; |
465 } | |
466 payload_type = buf[1] & 0x7f; | |
467 seq = (buf[2] << 8) | buf[3]; | |
468 timestamp = decode_be32(buf + 4); | |
469 ssrc = decode_be32(buf + 8); | |
1425
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
470 /* store the ssrc in the RTPDemuxContext */ |
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
471 s->ssrc = ssrc; |
885 | 472 |
0 | 473 /* NOTE: we can handle only one payload type */ |
474 if (s->payload_type != payload_type) | |
475 return -1; | |
986
f5194ed612b5
fix debug code: do not try to take st->codec if st is NULL. This makes ffplay give me pics from FreeBoxTV \o/
mmu_man
parents:
896
diff
changeset
|
476 |
f5194ed612b5
fix debug code: do not try to take st->codec if st is NULL. This makes ffplay give me pics from FreeBoxTV \o/
mmu_man
parents:
896
diff
changeset
|
477 st = s->st; |
0 | 478 #if defined(DEBUG) || 1 |
479 if (seq != ((s->seq + 1) & 0xffff)) { | |
986
f5194ed612b5
fix debug code: do not try to take st->codec if st is NULL. This makes ffplay give me pics from FreeBoxTV \o/
mmu_man
parents:
896
diff
changeset
|
480 av_log(st?st->codec:NULL, AV_LOG_ERROR, "RTP: PT=%02x: bad cseq %04x expected=%04x\n", |
0 | 481 payload_type, seq, ((s->seq + 1) & 0xffff)); |
482 } | |
774 | 483 #endif |
0 | 484 s->seq = seq; |
485 len -= 12; | |
486 buf += 12; | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
487 |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
488 if (!st) { |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
489 /* specific MPEG2TS demux support */ |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
490 ret = mpegts_parse_packet(s->ts, pkt, buf, len); |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
491 if (ret < 0) |
0 | 492 return -1; |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
493 if (ret < len) { |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
494 s->read_buf_size = len - ret; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
495 memcpy(s->buf, buf + ret, s->read_buf_size); |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
496 s->read_buf_index = 0; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
497 return 1; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
498 } |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
499 } else { |
1419 | 500 // at this point, the RTP header has been stripped; This is ASSUMING that there is only 1 CSRC, which in't wise. |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
777
diff
changeset
|
501 switch(st->codec->codec_id) { |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
502 case CODEC_ID_MP2: |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
503 /* better than nothing: skip mpeg audio RTP header */ |
0 | 504 if (len <= 4) |
505 return -1; | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
506 h = decode_be32(buf); |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
507 len -= 4; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
508 buf += 4; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
509 av_new_packet(pkt, len); |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
510 memcpy(pkt->data, buf, len); |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
511 break; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
512 case CODEC_ID_MPEG1VIDEO: |
305 | 513 /* better than nothing: skip mpeg video RTP header */ |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
514 if (len <= 4) |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
515 return -1; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
516 h = decode_be32(buf); |
0 | 517 buf += 4; |
518 len -= 4; | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
519 if (h & (1 << 26)) { |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
520 /* mpeg2 */ |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
521 if (len <= 4) |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
522 return -1; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
523 buf += 4; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
524 len -= 4; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
525 } |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
526 av_new_packet(pkt, len); |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
527 memcpy(pkt->data, buf, len); |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
528 break; |
1427
f1614c754d5b
move up (in the file) AAC audio handling moved from below
gpoirier
parents:
1425
diff
changeset
|
529 // moved from below, verbatim. this is because this section handles packets, and the lower switch handles |
f1614c754d5b
move up (in the file) AAC audio handling moved from below
gpoirier
parents:
1425
diff
changeset
|
530 // timestamps. |
f1614c754d5b
move up (in the file) AAC audio handling moved from below
gpoirier
parents:
1425
diff
changeset
|
531 // TODO: Put this into a dynamic packet handler... |
f1614c754d5b
move up (in the file) AAC audio handling moved from below
gpoirier
parents:
1425
diff
changeset
|
532 case CODEC_ID_MPEG4AAC: |
f1614c754d5b
move up (in the file) AAC audio handling moved from below
gpoirier
parents:
1425
diff
changeset
|
533 if (rtp_parse_mp4_au(s, buf)) |
f1614c754d5b
move up (in the file) AAC audio handling moved from below
gpoirier
parents:
1425
diff
changeset
|
534 return -1; |
f1614c754d5b
move up (in the file) AAC audio handling moved from below
gpoirier
parents:
1425
diff
changeset
|
535 { |
f1614c754d5b
move up (in the file) AAC audio handling moved from below
gpoirier
parents:
1425
diff
changeset
|
536 rtp_payload_data_t *infos = s->rtp_payload_data; |
f1614c754d5b
move up (in the file) AAC audio handling moved from below
gpoirier
parents:
1425
diff
changeset
|
537 if (infos == NULL) |
f1614c754d5b
move up (in the file) AAC audio handling moved from below
gpoirier
parents:
1425
diff
changeset
|
538 return -1; |
f1614c754d5b
move up (in the file) AAC audio handling moved from below
gpoirier
parents:
1425
diff
changeset
|
539 buf += infos->au_headers_length_bytes + 2; |
f1614c754d5b
move up (in the file) AAC audio handling moved from below
gpoirier
parents:
1425
diff
changeset
|
540 len -= infos->au_headers_length_bytes + 2; |
f1614c754d5b
move up (in the file) AAC audio handling moved from below
gpoirier
parents:
1425
diff
changeset
|
541 |
f1614c754d5b
move up (in the file) AAC audio handling moved from below
gpoirier
parents:
1425
diff
changeset
|
542 /* XXX: Fixme we only handle the case where rtp_parse_mp4_au define |
f1614c754d5b
move up (in the file) AAC audio handling moved from below
gpoirier
parents:
1425
diff
changeset
|
543 one au_header */ |
f1614c754d5b
move up (in the file) AAC audio handling moved from below
gpoirier
parents:
1425
diff
changeset
|
544 av_new_packet(pkt, infos->au_headers[0].size); |
f1614c754d5b
move up (in the file) AAC audio handling moved from below
gpoirier
parents:
1425
diff
changeset
|
545 memcpy(pkt->data, buf, infos->au_headers[0].size); |
f1614c754d5b
move up (in the file) AAC audio handling moved from below
gpoirier
parents:
1425
diff
changeset
|
546 buf += infos->au_headers[0].size; |
f1614c754d5b
move up (in the file) AAC audio handling moved from below
gpoirier
parents:
1425
diff
changeset
|
547 len -= infos->au_headers[0].size; |
f1614c754d5b
move up (in the file) AAC audio handling moved from below
gpoirier
parents:
1425
diff
changeset
|
548 } |
f1614c754d5b
move up (in the file) AAC audio handling moved from below
gpoirier
parents:
1425
diff
changeset
|
549 s->read_buf_size = len; |
f1614c754d5b
move up (in the file) AAC audio handling moved from below
gpoirier
parents:
1425
diff
changeset
|
550 s->buf_ptr = buf; |
f1614c754d5b
move up (in the file) AAC audio handling moved from below
gpoirier
parents:
1425
diff
changeset
|
551 pkt->stream_index = s->st->index; |
f1614c754d5b
move up (in the file) AAC audio handling moved from below
gpoirier
parents:
1425
diff
changeset
|
552 return 0; ///< Temporary return. |
f1614c754d5b
move up (in the file) AAC audio handling moved from below
gpoirier
parents:
1425
diff
changeset
|
553 break; |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
554 default: |
1419 | 555 if(s->parse_packet) { |
556 return s->parse_packet(s, pkt, timestamp, buf, len); | |
557 } else { | |
1424
1c39ce5c6a5d
indentation fix, patch by Ryan Martell % rdm4 A martellventures P com %
gpoirier
parents:
1419
diff
changeset
|
558 av_new_packet(pkt, len); |
1c39ce5c6a5d
indentation fix, patch by Ryan Martell % rdm4 A martellventures P com %
gpoirier
parents:
1419
diff
changeset
|
559 memcpy(pkt->data, buf, len); |
1419 | 560 } |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
561 break; |
0 | 562 } |
885 | 563 |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
777
diff
changeset
|
564 switch(st->codec->codec_id) { |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
565 case CODEC_ID_MP2: |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
566 case CODEC_ID_MPEG1VIDEO: |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
567 if (s->last_rtcp_ntp_time != AV_NOPTS_VALUE) { |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
568 int64_t addend; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
569 /* XXX: is it really necessary to unify the timestamp base ? */ |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
570 /* compute pts from timestamp with received ntp_time */ |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
571 delta_timestamp = timestamp - s->last_rtcp_timestamp; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
572 /* convert to 90 kHz without overflow */ |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
573 addend = (s->last_rtcp_ntp_time - s->first_rtcp_ntp_time) >> 14; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
574 addend = (addend * 5625) >> 14; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
575 pkt->pts = addend + delta_timestamp; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
576 } |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
577 break; |
1427
f1614c754d5b
move up (in the file) AAC audio handling moved from below
gpoirier
parents:
1425
diff
changeset
|
578 case CODEC_ID_MPEG4AAC: |
f1614c754d5b
move up (in the file) AAC audio handling moved from below
gpoirier
parents:
1425
diff
changeset
|
579 case CODEC_ID_H264: |
774 | 580 case CODEC_ID_MPEG4: |
581 pkt->pts = timestamp; | |
582 break; | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
583 default: |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
584 /* no timestamp info yet */ |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
585 break; |
173 | 586 } |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
587 pkt->stream_index = s->st->index; |
0 | 588 } |
589 return 0; | |
590 } | |
591 | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
592 void rtp_parse_close(RTPDemuxContext *s) |
0 | 593 { |
1419 | 594 // TODO: fold this into the protocol specific data fields. |
774 | 595 if (!strcmp(AVRtpPayloadTypes[s->payload_type].enc_name, "MP2T")) { |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
596 mpegts_parse_close(s->ts); |
0 | 597 } |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
598 av_free(s); |
0 | 599 } |
600 | |
601 /* rtp output */ | |
602 | |
603 static int rtp_write_header(AVFormatContext *s1) | |
604 { | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
605 RTPDemuxContext *s = s1->priv_data; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
606 int payload_type, max_packet_size, n; |
0 | 607 AVStream *st; |
608 | |
609 if (s1->nb_streams != 1) | |
610 return -1; | |
611 st = s1->streams[0]; | |
612 | |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
777
diff
changeset
|
613 payload_type = rtp_get_payload_type(st->codec); |
0 | 614 if (payload_type < 0) |
615 payload_type = RTP_PT_PRIVATE; /* private payload type */ | |
616 s->payload_type = payload_type; | |
617 | |
1099 | 618 // following 2 FIXMies could be set based on the current time, theres normaly no info leak, as rtp will likely be transmitted immedeatly |
1045
7f1b7f811f01
fix constraint violation: libavformat is not allowed to modify state of caller, including rng state
rfelker
parents:
986
diff
changeset
|
619 s->base_timestamp = 0; /* FIXME: was random(), what should this be? */ |
0 | 620 s->timestamp = s->base_timestamp; |
1045
7f1b7f811f01
fix constraint violation: libavformat is not allowed to modify state of caller, including rng state
rfelker
parents:
986
diff
changeset
|
621 s->ssrc = 0; /* FIXME: was random(), what should this be? */ |
0 | 622 s->first_packet = 1; |
623 | |
624 max_packet_size = url_fget_max_packet_size(&s1->pb); | |
625 if (max_packet_size <= 12) | |
626 return AVERROR_IO; | |
627 s->max_payload_size = max_packet_size - 12; | |
628 | |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
777
diff
changeset
|
629 switch(st->codec->codec_id) { |
0 | 630 case CODEC_ID_MP2: |
232 | 631 case CODEC_ID_MP3: |
0 | 632 s->buf_ptr = s->buf + 4; |
633 s->cur_timestamp = 0; | |
634 break; | |
635 case CODEC_ID_MPEG1VIDEO: | |
636 s->cur_timestamp = 0; | |
637 break; | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
638 case CODEC_ID_MPEG2TS: |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
639 n = s->max_payload_size / TS_PACKET_SIZE; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
640 if (n < 1) |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
641 n = 1; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
642 s->max_payload_size = n * TS_PACKET_SIZE; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
643 s->buf_ptr = s->buf; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
644 break; |
0 | 645 default: |
646 s->buf_ptr = s->buf; | |
647 break; | |
648 } | |
649 | |
650 return 0; | |
651 } | |
652 | |
653 /* send an rtcp sender report packet */ | |
65 | 654 static void rtcp_send_sr(AVFormatContext *s1, int64_t ntp_time) |
0 | 655 { |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
656 RTPDemuxContext *s = s1->priv_data; |
0 | 657 #if defined(DEBUG) |
658 printf("RTCP: %02x %Lx %x\n", s->payload_type, ntp_time, s->timestamp); | |
659 #endif | |
660 put_byte(&s1->pb, (RTP_VERSION << 6)); | |
661 put_byte(&s1->pb, 200); | |
662 put_be16(&s1->pb, 6); /* length in words - 1 */ | |
663 put_be32(&s1->pb, s->ssrc); | |
664 put_be64(&s1->pb, ntp_time); | |
665 put_be32(&s1->pb, s->timestamp); | |
666 put_be32(&s1->pb, s->packet_count); | |
667 put_be32(&s1->pb, s->octet_count); | |
668 put_flush_packet(&s1->pb); | |
669 } | |
670 | |
671 /* send an rtp packet. sequence number is incremented, but the caller | |
672 must update the timestamp itself */ | |
826
ee7ba4017c8d
MPEG4 streaming over RTP patch by (Luca Abeni: lucabe72, email it)
michael
parents:
820
diff
changeset
|
673 static void rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len, int m) |
0 | 674 { |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
675 RTPDemuxContext *s = s1->priv_data; |
0 | 676 |
677 #ifdef DEBUG | |
678 printf("rtp_send_data size=%d\n", len); | |
679 #endif | |
680 | |
681 /* build the RTP header */ | |
682 put_byte(&s1->pb, (RTP_VERSION << 6)); | |
826
ee7ba4017c8d
MPEG4 streaming over RTP patch by (Luca Abeni: lucabe72, email it)
michael
parents:
820
diff
changeset
|
683 put_byte(&s1->pb, (s->payload_type & 0x7f) | ((m & 0x01) << 7)); |
0 | 684 put_be16(&s1->pb, s->seq); |
685 put_be32(&s1->pb, s->timestamp); | |
686 put_be32(&s1->pb, s->ssrc); | |
885 | 687 |
0 | 688 put_buffer(&s1->pb, buf1, len); |
689 put_flush_packet(&s1->pb); | |
885 | 690 |
0 | 691 s->seq++; |
692 s->octet_count += len; | |
693 s->packet_count++; | |
694 } | |
695 | |
696 /* send an integer number of samples and compute time stamp and fill | |
697 the rtp send buffer before sending. */ | |
698 static void rtp_send_samples(AVFormatContext *s1, | |
241 | 699 const uint8_t *buf1, int size, int sample_size) |
0 | 700 { |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
701 RTPDemuxContext *s = s1->priv_data; |
0 | 702 int len, max_packet_size, n; |
703 | |
704 max_packet_size = (s->max_payload_size / sample_size) * sample_size; | |
705 /* not needed, but who nows */ | |
706 if ((size % sample_size) != 0) | |
707 av_abort(); | |
708 while (size > 0) { | |
709 len = (max_packet_size - (s->buf_ptr - s->buf)); | |
710 if (len > size) | |
711 len = size; | |
712 | |
713 /* copy data */ | |
714 memcpy(s->buf_ptr, buf1, len); | |
715 s->buf_ptr += len; | |
716 buf1 += len; | |
717 size -= len; | |
718 n = (s->buf_ptr - s->buf); | |
719 /* if buffer full, then send it */ | |
720 if (n >= max_packet_size) { | |
826
ee7ba4017c8d
MPEG4 streaming over RTP patch by (Luca Abeni: lucabe72, email it)
michael
parents:
820
diff
changeset
|
721 rtp_send_data(s1, s->buf, n, 0); |
0 | 722 s->buf_ptr = s->buf; |
723 /* update timestamp */ | |
724 s->timestamp += n / sample_size; | |
725 } | |
726 } | |
885 | 727 } |
0 | 728 |
729 /* NOTE: we suppose that exactly one frame is given as argument here */ | |
730 /* XXX: test it */ | |
731 static void rtp_send_mpegaudio(AVFormatContext *s1, | |
241 | 732 const uint8_t *buf1, int size) |
0 | 733 { |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
734 RTPDemuxContext *s = s1->priv_data; |
0 | 735 AVStream *st = s1->streams[0]; |
736 int len, count, max_packet_size; | |
737 | |
738 max_packet_size = s->max_payload_size; | |
739 | |
740 /* test if we must flush because not enough space */ | |
741 len = (s->buf_ptr - s->buf); | |
742 if ((len + size) > max_packet_size) { | |
743 if (len > 4) { | |
826
ee7ba4017c8d
MPEG4 streaming over RTP patch by (Luca Abeni: lucabe72, email it)
michael
parents:
820
diff
changeset
|
744 rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0); |
0 | 745 s->buf_ptr = s->buf + 4; |
746 /* 90 KHz time stamp */ | |
885 | 747 s->timestamp = s->base_timestamp + |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
777
diff
changeset
|
748 (s->cur_timestamp * 90000LL) / st->codec->sample_rate; |
0 | 749 } |
750 } | |
751 | |
752 /* add the packet */ | |
753 if (size > max_packet_size) { | |
754 /* big packet: fragment */ | |
755 count = 0; | |
756 while (size > 0) { | |
757 len = max_packet_size - 4; | |
758 if (len > size) | |
759 len = size; | |
760 /* build fragmented packet */ | |
761 s->buf[0] = 0; | |
762 s->buf[1] = 0; | |
763 s->buf[2] = count >> 8; | |
764 s->buf[3] = count; | |
765 memcpy(s->buf + 4, buf1, len); | |
826
ee7ba4017c8d
MPEG4 streaming over RTP patch by (Luca Abeni: lucabe72, email it)
michael
parents:
820
diff
changeset
|
766 rtp_send_data(s1, s->buf, len + 4, 0); |
0 | 767 size -= len; |
768 buf1 += len; | |
769 count += len; | |
770 } | |
771 } else { | |
772 if (s->buf_ptr == s->buf + 4) { | |
773 /* no fragmentation possible */ | |
774 s->buf[0] = 0; | |
775 s->buf[1] = 0; | |
776 s->buf[2] = 0; | |
777 s->buf[3] = 0; | |
778 } | |
779 memcpy(s->buf_ptr, buf1, size); | |
780 s->buf_ptr += size; | |
781 } | |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
777
diff
changeset
|
782 s->cur_timestamp += st->codec->frame_size; |
0 | 783 } |
784 | |
785 /* NOTE: a single frame must be passed with sequence header if | |
786 needed. XXX: use slices. */ | |
787 static void rtp_send_mpegvideo(AVFormatContext *s1, | |
241 | 788 const uint8_t *buf1, int size) |
0 | 789 { |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
790 RTPDemuxContext *s = s1->priv_data; |
0 | 791 AVStream *st = s1->streams[0]; |
792 int len, h, max_packet_size; | |
65 | 793 uint8_t *q; |
0 | 794 |
795 max_packet_size = s->max_payload_size; | |
796 | |
797 while (size > 0) { | |
798 /* XXX: more correct headers */ | |
799 h = 0; | |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
777
diff
changeset
|
800 if (st->codec->sub_id == 2) |
0 | 801 h |= 1 << 26; /* mpeg 2 indicator */ |
802 q = s->buf; | |
803 *q++ = h >> 24; | |
804 *q++ = h >> 16; | |
805 *q++ = h >> 8; | |
806 *q++ = h; | |
807 | |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
777
diff
changeset
|
808 if (st->codec->sub_id == 2) { |
0 | 809 h = 0; |
810 *q++ = h >> 24; | |
811 *q++ = h >> 16; | |
812 *q++ = h >> 8; | |
813 *q++ = h; | |
814 } | |
885 | 815 |
0 | 816 len = max_packet_size - (q - s->buf); |
817 if (len > size) | |
818 len = size; | |
819 | |
820 memcpy(q, buf1, len); | |
821 q += len; | |
822 | |
823 /* 90 KHz time stamp */ | |
885 | 824 s->timestamp = s->base_timestamp + |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
777
diff
changeset
|
825 av_rescale((int64_t)s->cur_timestamp * st->codec->time_base.num, 90000, st->codec->time_base.den); //FIXME pass timestamps |
827
d064b7d0899d
mpeg1video m bit fix by (Luca Abeni: lucabe72, email it)
michael
parents:
826
diff
changeset
|
826 rtp_send_data(s1, s->buf, q - s->buf, (len == size)); |
0 | 827 |
828 buf1 += len; | |
829 size -= len; | |
830 } | |
831 s->cur_timestamp++; | |
832 } | |
833 | |
834 static void rtp_send_raw(AVFormatContext *s1, | |
241 | 835 const uint8_t *buf1, int size) |
0 | 836 { |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
837 RTPDemuxContext *s = s1->priv_data; |
0 | 838 AVStream *st = s1->streams[0]; |
839 int len, max_packet_size; | |
840 | |
841 max_packet_size = s->max_payload_size; | |
842 | |
843 while (size > 0) { | |
844 len = max_packet_size; | |
845 if (len > size) | |
846 len = size; | |
847 | |
848 /* 90 KHz time stamp */ | |
885 | 849 s->timestamp = s->base_timestamp + |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
777
diff
changeset
|
850 av_rescale((int64_t)s->cur_timestamp * st->codec->time_base.num, 90000, st->codec->time_base.den); //FIXME pass timestamps |
826
ee7ba4017c8d
MPEG4 streaming over RTP patch by (Luca Abeni: lucabe72, email it)
michael
parents:
820
diff
changeset
|
851 rtp_send_data(s1, buf1, len, (len == size)); |
0 | 852 |
853 buf1 += len; | |
854 size -= len; | |
855 } | |
856 s->cur_timestamp++; | |
857 } | |
858 | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
859 /* NOTE: size is assumed to be an integer multiple of TS_PACKET_SIZE */ |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
860 static void rtp_send_mpegts_raw(AVFormatContext *s1, |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
861 const uint8_t *buf1, int size) |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
862 { |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
863 RTPDemuxContext *s = s1->priv_data; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
864 int len, out_len; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
865 |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
866 while (size >= TS_PACKET_SIZE) { |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
867 len = s->max_payload_size - (s->buf_ptr - s->buf); |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
868 if (len > size) |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
869 len = size; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
870 memcpy(s->buf_ptr, buf1, len); |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
871 buf1 += len; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
872 size -= len; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
873 s->buf_ptr += len; |
885 | 874 |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
875 out_len = s->buf_ptr - s->buf; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
876 if (out_len >= s->max_payload_size) { |
826
ee7ba4017c8d
MPEG4 streaming over RTP patch by (Luca Abeni: lucabe72, email it)
michael
parents:
820
diff
changeset
|
877 rtp_send_data(s1, s->buf, out_len, 0); |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
878 s->buf_ptr = s->buf; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
879 } |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
880 } |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
881 } |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
882 |
0 | 883 /* write an RTP packet. 'buf1' must contain a single specific frame. */ |
468 | 884 static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt) |
0 | 885 { |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
886 RTPDemuxContext *s = s1->priv_data; |
0 | 887 AVStream *st = s1->streams[0]; |
888 int rtcp_bytes; | |
65 | 889 int64_t ntp_time; |
468 | 890 int size= pkt->size; |
891 uint8_t *buf1= pkt->data; | |
885 | 892 |
0 | 893 #ifdef DEBUG |
468 | 894 printf("%d: write len=%d\n", pkt->stream_index, size); |
0 | 895 #endif |
896 | |
897 /* XXX: mpeg pts hardcoded. RTCP send every 0.5 seconds */ | |
885 | 898 rtcp_bytes = ((s->octet_count - s->last_octet_count) * RTCP_TX_RATIO_NUM) / |
0 | 899 RTCP_TX_RATIO_DEN; |
900 if (s->first_packet || rtcp_bytes >= 28) { | |
901 /* compute NTP time */ | |
173 | 902 /* XXX: 90 kHz timestamp hardcoded */ |
468 | 903 ntp_time = (pkt->pts << 28) / 5625; |
885 | 904 rtcp_send_sr(s1, ntp_time); |
0 | 905 s->last_octet_count = s->octet_count; |
906 s->first_packet = 0; | |
907 } | |
908 | |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
777
diff
changeset
|
909 switch(st->codec->codec_id) { |
0 | 910 case CODEC_ID_PCM_MULAW: |
911 case CODEC_ID_PCM_ALAW: | |
912 case CODEC_ID_PCM_U8: | |
913 case CODEC_ID_PCM_S8: | |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
777
diff
changeset
|
914 rtp_send_samples(s1, buf1, size, 1 * st->codec->channels); |
0 | 915 break; |
916 case CODEC_ID_PCM_U16BE: | |
917 case CODEC_ID_PCM_U16LE: | |
918 case CODEC_ID_PCM_S16BE: | |
919 case CODEC_ID_PCM_S16LE: | |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
777
diff
changeset
|
920 rtp_send_samples(s1, buf1, size, 2 * st->codec->channels); |
0 | 921 break; |
922 case CODEC_ID_MP2: | |
232 | 923 case CODEC_ID_MP3: |
0 | 924 rtp_send_mpegaudio(s1, buf1, size); |
925 break; | |
926 case CODEC_ID_MPEG1VIDEO: | |
927 rtp_send_mpegvideo(s1, buf1, size); | |
928 break; | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
929 case CODEC_ID_MPEG2TS: |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
930 rtp_send_mpegts_raw(s1, buf1, size); |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
931 break; |
0 | 932 default: |
933 /* better than nothing : send the codec raw data */ | |
934 rtp_send_raw(s1, buf1, size); | |
935 break; | |
936 } | |
937 return 0; | |
938 } | |
939 | |
940 static int rtp_write_trailer(AVFormatContext *s1) | |
941 { | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
942 // RTPDemuxContext *s = s1->priv_data; |
0 | 943 return 0; |
944 } | |
945 | |
1167 | 946 AVOutputFormat rtp_muxer = { |
0 | 947 "rtp", |
948 "RTP output format", | |
949 NULL, | |
950 NULL, | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
241
diff
changeset
|
951 sizeof(RTPDemuxContext), |
0 | 952 CODEC_ID_PCM_MULAW, |
953 CODEC_ID_NONE, | |
954 rtp_write_header, | |
955 rtp_write_packet, | |
956 rtp_write_trailer, | |
957 }; |