annotate rtp.c @ 251:300c94a708f7 libavformat

remove unused AMREXTRALIBS
author bellard
date Tue, 16 Sep 2003 20:29:19 +0000
parents 3d92f793fd67
children 6091b76cfc2a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1 /*
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
2 * RTP input/output format
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
3 * Copyright (c) 2002 Fabrice Bellard.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
4 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
9 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
13 * Lesser General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
18 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
19 #include "avformat.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
20
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
21 #include <unistd.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
22 #include <sys/types.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
23 #include <sys/socket.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
24 #include <netinet/in.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
25 #ifndef __BEOS__
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
26 # include <arpa/inet.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
27 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
28 # include "barpainet.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
29 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
30 #include <netdb.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
31
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
32 //#define DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
33
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
34
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
35 /* TODO: - add RTCP statistics reporting (should be optional).
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
36
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
37 - add support for h263/mpeg4 packetized output : IDEA: send a
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
38 buffer to 'rtp_write_packet' contains all the packets for ONE
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
39 frame. Each packet should have a four byte header containing
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
40 the length in big endian format (same trick as
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
41 'url_open_dyn_packet_buf')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
42 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
43
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
44 #define RTP_VERSION 2
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
45
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
46 #define RTP_MAX_SDES 256 /* maximum text length for SDES */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
47
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
48 /* RTCP paquets use 0.5 % of the bandwidth */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
49 #define RTCP_TX_RATIO_NUM 5
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50 #define RTCP_TX_RATIO_DEN 1000
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
51
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
52 typedef enum {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
53 RTCP_SR = 200,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
54 RTCP_RR = 201,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
55 RTCP_SDES = 202,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
56 RTCP_BYE = 203,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
57 RTCP_APP = 204
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
58 } rtcp_type_t;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
59
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
60 typedef enum {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
61 RTCP_SDES_END = 0,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
62 RTCP_SDES_CNAME = 1,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
63 RTCP_SDES_NAME = 2,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
64 RTCP_SDES_EMAIL = 3,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
65 RTCP_SDES_PHONE = 4,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
66 RTCP_SDES_LOC = 5,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
67 RTCP_SDES_TOOL = 6,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
68 RTCP_SDES_NOTE = 7,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
69 RTCP_SDES_PRIV = 8,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
70 RTCP_SDES_IMG = 9,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
71 RTCP_SDES_DOOR = 10,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
72 RTCP_SDES_SOURCE = 11
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
73 } rtcp_sdes_type_t;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
74
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
75 enum RTPPayloadType {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
76 RTP_PT_ULAW = 0,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
77 RTP_PT_GSM = 3,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
78 RTP_PT_G723 = 4,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
79 RTP_PT_ALAW = 8,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80 RTP_PT_S16BE_STEREO = 10,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81 RTP_PT_S16BE_MONO = 11,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82 RTP_PT_MPEGAUDIO = 14,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83 RTP_PT_JPEG = 26,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84 RTP_PT_H261 = 31,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85 RTP_PT_MPEGVIDEO = 32,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
86 RTP_PT_MPEG2TS = 33,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
87 RTP_PT_H263 = 34, /* old H263 encapsulation */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
88 RTP_PT_PRIVATE = 96,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
89 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
90
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
91 typedef struct RTPContext {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
92 int payload_type;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
93 uint32_t ssrc;
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
94 uint16_t seq;
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
95 uint32_t timestamp;
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
96 uint32_t base_timestamp;
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
97 uint32_t cur_timestamp;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
98 int max_payload_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
99 /* rtcp sender statistics receive */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
100 int64_t last_rtcp_ntp_time;
173
38f64fabb24b fixed NTP generation for mpeg
bellard
parents: 85
diff changeset
101 int64_t first_rtcp_ntp_time;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
102 uint32_t last_rtcp_timestamp;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
103 /* rtcp sender statistics */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
104 unsigned int packet_count;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
105 unsigned int octet_count;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
106 unsigned int last_octet_count;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
107 int first_packet;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
108 /* buffer for output */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
109 uint8_t buf[RTP_MAX_PACKET_LENGTH];
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
110 uint8_t *buf_ptr;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
111 } RTPContext;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
112
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
113 int rtp_get_codec_info(AVCodecContext *codec, int payload_type)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
114 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
115 switch(payload_type) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
116 case RTP_PT_ULAW:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
117 codec->codec_id = CODEC_ID_PCM_MULAW;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
118 codec->channels = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
119 codec->sample_rate = 8000;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
120 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
121 case RTP_PT_ALAW:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
122 codec->codec_id = CODEC_ID_PCM_ALAW;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
123 codec->channels = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
124 codec->sample_rate = 8000;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
125 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
126 case RTP_PT_S16BE_STEREO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
127 codec->codec_id = CODEC_ID_PCM_S16BE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
128 codec->channels = 2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
129 codec->sample_rate = 44100;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
130 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
131 case RTP_PT_S16BE_MONO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
132 codec->codec_id = CODEC_ID_PCM_S16BE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
133 codec->channels = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
134 codec->sample_rate = 44100;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
135 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
136 case RTP_PT_MPEGAUDIO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
137 codec->codec_id = CODEC_ID_MP2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
138 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
139 case RTP_PT_JPEG:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
140 codec->codec_id = CODEC_ID_MJPEG;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
141 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
142 case RTP_PT_MPEGVIDEO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
143 codec->codec_id = CODEC_ID_MPEG1VIDEO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
144 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
145 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
146 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
147 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
148 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
149 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
150
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
151 /* return < 0 if unknown payload type */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
152 int rtp_get_payload_type(AVCodecContext *codec)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
153 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
154 int payload_type;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
155
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
156 /* compute the payload type */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
157 payload_type = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
158 switch(codec->codec_id) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
159 case CODEC_ID_PCM_MULAW:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
160 payload_type = RTP_PT_ULAW;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
161 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
162 case CODEC_ID_PCM_ALAW:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
163 payload_type = RTP_PT_ALAW;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
164 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
165 case CODEC_ID_PCM_S16BE:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
166 if (codec->channels == 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
167 payload_type = RTP_PT_S16BE_MONO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
168 } else if (codec->channels == 2) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
169 payload_type = RTP_PT_S16BE_STEREO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
170 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
171 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
172 case CODEC_ID_MP2:
232
eb90c0a5a1ba CODEC_ID_MP3LAME is obsolete
bellard
parents: 173
diff changeset
173 case CODEC_ID_MP3:
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
174 payload_type = RTP_PT_MPEGAUDIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
175 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
176 case CODEC_ID_MJPEG:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
177 payload_type = RTP_PT_JPEG;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
178 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
179 case CODEC_ID_MPEG1VIDEO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
180 payload_type = RTP_PT_MPEGVIDEO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
181 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
182 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
183 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
184 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
185 return payload_type;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
186 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
187
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
188 static inline uint32_t decode_be32(const uint8_t *p)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
189 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
190 return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
191 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
192
173
38f64fabb24b fixed NTP generation for mpeg
bellard
parents: 85
diff changeset
193 static inline uint64_t decode_be64(const uint8_t *p)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
194 {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
195 return ((uint64_t)decode_be32(p) << 32) | decode_be32(p + 4);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
196 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
197
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
198 static int rtcp_parse_packet(AVFormatContext *s1, const unsigned char *buf, int len)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
199 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
200 RTPContext *s = s1->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
201
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
202 if (buf[1] != 200)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
203 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
204 s->last_rtcp_ntp_time = decode_be64(buf + 8);
173
38f64fabb24b fixed NTP generation for mpeg
bellard
parents: 85
diff changeset
205 if (s->first_rtcp_ntp_time == AV_NOPTS_VALUE)
38f64fabb24b fixed NTP generation for mpeg
bellard
parents: 85
diff changeset
206 s->first_rtcp_ntp_time = s->last_rtcp_ntp_time;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
207 s->last_rtcp_timestamp = decode_be32(buf + 16);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
208 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
209 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
210
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
211 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
212 * Parse an RTP packet directly sent as raw data. Can only be used if
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
213 * 'raw' is given as input file
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
214 * @param s1 media file context
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
215 * @param pkt returned packet
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
216 * @param buf input buffer
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
217 * @param len buffer len
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
218 * @return zero if no error.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
219 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
220 int rtp_parse_packet(AVFormatContext *s1, AVPacket *pkt,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
221 const unsigned char *buf, int len)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
222 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
223 RTPContext *s = s1->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
224 unsigned int ssrc, h;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
225 int payload_type, seq, delta_timestamp;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
226 AVStream *st;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
227 uint32_t timestamp;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
228
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
229 if (len < 12)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
230 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
231
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
232 if ((buf[0] & 0xc0) != (RTP_VERSION << 6))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
233 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
234 if (buf[1] >= 200 && buf[1] <= 204) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
235 rtcp_parse_packet(s1, buf, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
236 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
237 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
238 payload_type = buf[1] & 0x7f;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
239 seq = (buf[2] << 8) | buf[3];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
240 timestamp = decode_be32(buf + 4);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
241 ssrc = decode_be32(buf + 8);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
242
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
243 if (s->payload_type < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
244 s->payload_type = payload_type;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
245
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
246 if (payload_type == RTP_PT_MPEG2TS) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
247 /* XXX: special case : not a single codec but a whole stream */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
248 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
249 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
250 st = av_new_stream(s1, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
251 if (!st)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
252 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
253 rtp_get_codec_info(&st->codec, payload_type);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
254 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
255 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
256
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
257 /* NOTE: we can handle only one payload type */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
258 if (s->payload_type != payload_type)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
259 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
260 #if defined(DEBUG) || 1
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
261 if (seq != ((s->seq + 1) & 0xffff)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
262 printf("RTP: PT=%02x: bad cseq %04x expected=%04x\n",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
263 payload_type, seq, ((s->seq + 1) & 0xffff));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
264 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
265 s->seq = seq;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
266 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
267 len -= 12;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
268 buf += 12;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
269 st = s1->streams[0];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
270 switch(st->codec.codec_id) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
271 case CODEC_ID_MP2:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
272 /* better than nothing: skip mpeg audio RTP header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
273 if (len <= 4)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
274 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
275 h = decode_be32(buf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
276 len -= 4;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
277 buf += 4;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
278 av_new_packet(pkt, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
279 memcpy(pkt->data, buf, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
280 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
281 case CODEC_ID_MPEG1VIDEO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
282 /* better than nothing: skip mpeg audio RTP header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
283 if (len <= 4)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
284 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
285 h = decode_be32(buf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
286 buf += 4;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
287 len -= 4;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
288 if (h & (1 << 26)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
289 /* mpeg2 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
290 if (len <= 4)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
291 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
292 buf += 4;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
293 len -= 4;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
294 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
295 av_new_packet(pkt, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
296 memcpy(pkt->data, buf, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
297 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
298 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
299 av_new_packet(pkt, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
300 memcpy(pkt->data, buf, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
301 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
302 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
303
173
38f64fabb24b fixed NTP generation for mpeg
bellard
parents: 85
diff changeset
304 switch(st->codec.codec_id) {
38f64fabb24b fixed NTP generation for mpeg
bellard
parents: 85
diff changeset
305 case CODEC_ID_MP2:
38f64fabb24b fixed NTP generation for mpeg
bellard
parents: 85
diff changeset
306 case CODEC_ID_MPEG1VIDEO:
38f64fabb24b fixed NTP generation for mpeg
bellard
parents: 85
diff changeset
307 if (s->last_rtcp_ntp_time != AV_NOPTS_VALUE) {
38f64fabb24b fixed NTP generation for mpeg
bellard
parents: 85
diff changeset
308 int64_t addend;
38f64fabb24b fixed NTP generation for mpeg
bellard
parents: 85
diff changeset
309 /* XXX: is it really necessary to unify the timestamp base ? */
38f64fabb24b fixed NTP generation for mpeg
bellard
parents: 85
diff changeset
310 /* compute pts from timestamp with received ntp_time */
38f64fabb24b fixed NTP generation for mpeg
bellard
parents: 85
diff changeset
311 delta_timestamp = timestamp - s->last_rtcp_timestamp;
38f64fabb24b fixed NTP generation for mpeg
bellard
parents: 85
diff changeset
312 /* convert to 90 kHz without overflow */
38f64fabb24b fixed NTP generation for mpeg
bellard
parents: 85
diff changeset
313 addend = (s->last_rtcp_ntp_time - s->first_rtcp_ntp_time) >> 14;
38f64fabb24b fixed NTP generation for mpeg
bellard
parents: 85
diff changeset
314 addend = (addend * 5625) >> 14;
38f64fabb24b fixed NTP generation for mpeg
bellard
parents: 85
diff changeset
315 pkt->pts = addend + delta_timestamp;
38f64fabb24b fixed NTP generation for mpeg
bellard
parents: 85
diff changeset
316 }
38f64fabb24b fixed NTP generation for mpeg
bellard
parents: 85
diff changeset
317 break;
38f64fabb24b fixed NTP generation for mpeg
bellard
parents: 85
diff changeset
318 default:
38f64fabb24b fixed NTP generation for mpeg
bellard
parents: 85
diff changeset
319 /* no timestamp info yet */
38f64fabb24b fixed NTP generation for mpeg
bellard
parents: 85
diff changeset
320 break;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
321 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
322 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
323 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
324
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
325 static int rtp_read_header(AVFormatContext *s1,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
326 AVFormatParameters *ap)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
327 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
328 RTPContext *s = s1->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
329 s->payload_type = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
330 s->last_rtcp_ntp_time = AV_NOPTS_VALUE;
173
38f64fabb24b fixed NTP generation for mpeg
bellard
parents: 85
diff changeset
331 s->first_rtcp_ntp_time = AV_NOPTS_VALUE;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
332 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
333 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
334
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
335 static int rtp_read_packet(AVFormatContext *s1, AVPacket *pkt)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
336 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
337 char buf[RTP_MAX_PACKET_LENGTH];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
338 int ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
339
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
340 /* XXX: needs a better API for packet handling ? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
341 for(;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
342 ret = url_read(url_fileno(&s1->pb), buf, sizeof(buf));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
343 if (ret < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
344 return AVERROR_IO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
345 if (rtp_parse_packet(s1, pkt, buf, ret) == 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
346 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
347 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
348 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
349 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
350
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
351 static int rtp_read_close(AVFormatContext *s1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
352 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
353 // RTPContext *s = s1->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
354 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
355 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
356
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
357 static int rtp_probe(AVProbeData *p)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
358 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
359 if (strstart(p->filename, "rtp://", NULL))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
360 return AVPROBE_SCORE_MAX;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
361 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
362 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
363
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
364 /* rtp output */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
365
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
366 static int rtp_write_header(AVFormatContext *s1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
367 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
368 RTPContext *s = s1->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
369 int payload_type, max_packet_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
370 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
371
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
372 if (s1->nb_streams != 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
373 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
374 st = s1->streams[0];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
375
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
376 payload_type = rtp_get_payload_type(&st->codec);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
377 if (payload_type < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
378 payload_type = RTP_PT_PRIVATE; /* private payload type */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
379 s->payload_type = payload_type;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
380
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
381 s->base_timestamp = random();
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
382 s->timestamp = s->base_timestamp;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
383 s->ssrc = random();
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
384 s->first_packet = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
385
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
386 max_packet_size = url_fget_max_packet_size(&s1->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
387 if (max_packet_size <= 12)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
388 return AVERROR_IO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
389 s->max_payload_size = max_packet_size - 12;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
390
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
391 switch(st->codec.codec_id) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
392 case CODEC_ID_MP2:
232
eb90c0a5a1ba CODEC_ID_MP3LAME is obsolete
bellard
parents: 173
diff changeset
393 case CODEC_ID_MP3:
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
394 s->buf_ptr = s->buf + 4;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
395 s->cur_timestamp = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
396 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
397 case CODEC_ID_MPEG1VIDEO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
398 s->cur_timestamp = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
399 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
400 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
401 s->buf_ptr = s->buf;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
402 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
403 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
404
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
405 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
406 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
407
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
408 /* send an rtcp sender report packet */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
409 static void rtcp_send_sr(AVFormatContext *s1, int64_t ntp_time)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
410 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
411 RTPContext *s = s1->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
412 #if defined(DEBUG)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
413 printf("RTCP: %02x %Lx %x\n", s->payload_type, ntp_time, s->timestamp);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
414 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
415 put_byte(&s1->pb, (RTP_VERSION << 6));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
416 put_byte(&s1->pb, 200);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
417 put_be16(&s1->pb, 6); /* length in words - 1 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
418 put_be32(&s1->pb, s->ssrc);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
419 put_be64(&s1->pb, ntp_time);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
420 put_be32(&s1->pb, s->timestamp);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
421 put_be32(&s1->pb, s->packet_count);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
422 put_be32(&s1->pb, s->octet_count);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
423 put_flush_packet(&s1->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
424 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
425
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
426 /* send an rtp packet. sequence number is incremented, but the caller
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
427 must update the timestamp itself */
241
3d92f793fd67 64 bit pts for writing - more const usage
bellard
parents: 232
diff changeset
428 static void rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
429 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
430 RTPContext *s = s1->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
431
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
432 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
433 printf("rtp_send_data size=%d\n", len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
434 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
435
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
436 /* build the RTP header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
437 put_byte(&s1->pb, (RTP_VERSION << 6));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
438 put_byte(&s1->pb, s->payload_type & 0x7f);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
439 put_be16(&s1->pb, s->seq);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
440 put_be32(&s1->pb, s->timestamp);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
441 put_be32(&s1->pb, s->ssrc);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
442
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
443 put_buffer(&s1->pb, buf1, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
444 put_flush_packet(&s1->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
445
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
446 s->seq++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
447 s->octet_count += len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
448 s->packet_count++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
449 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
450
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
451 /* send an integer number of samples and compute time stamp and fill
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
452 the rtp send buffer before sending. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
453 static void rtp_send_samples(AVFormatContext *s1,
241
3d92f793fd67 64 bit pts for writing - more const usage
bellard
parents: 232
diff changeset
454 const uint8_t *buf1, int size, int sample_size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
455 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
456 RTPContext *s = s1->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
457 int len, max_packet_size, n;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
458
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
459 max_packet_size = (s->max_payload_size / sample_size) * sample_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
460 /* not needed, but who nows */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
461 if ((size % sample_size) != 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
462 av_abort();
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
463 while (size > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
464 len = (max_packet_size - (s->buf_ptr - s->buf));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
465 if (len > size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
466 len = size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
467
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
468 /* copy data */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
469 memcpy(s->buf_ptr, buf1, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
470 s->buf_ptr += len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
471 buf1 += len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
472 size -= len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
473 n = (s->buf_ptr - s->buf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
474 /* if buffer full, then send it */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
475 if (n >= max_packet_size) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
476 rtp_send_data(s1, s->buf, n);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
477 s->buf_ptr = s->buf;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
478 /* update timestamp */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
479 s->timestamp += n / sample_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
480 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
481 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
482 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
483
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
484 /* NOTE: we suppose that exactly one frame is given as argument here */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
485 /* XXX: test it */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
486 static void rtp_send_mpegaudio(AVFormatContext *s1,
241
3d92f793fd67 64 bit pts for writing - more const usage
bellard
parents: 232
diff changeset
487 const uint8_t *buf1, int size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
488 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
489 RTPContext *s = s1->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
490 AVStream *st = s1->streams[0];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
491 int len, count, max_packet_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
492
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
493 max_packet_size = s->max_payload_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
494
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
495 /* test if we must flush because not enough space */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
496 len = (s->buf_ptr - s->buf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
497 if ((len + size) > max_packet_size) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
498 if (len > 4) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
499 rtp_send_data(s1, s->buf, s->buf_ptr - s->buf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
500 s->buf_ptr = s->buf + 4;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
501 /* 90 KHz time stamp */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
502 s->timestamp = s->base_timestamp +
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
503 (s->cur_timestamp * 90000LL) / st->codec.sample_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
504 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
505 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
506
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
507 /* add the packet */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
508 if (size > max_packet_size) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
509 /* big packet: fragment */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
510 count = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
511 while (size > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
512 len = max_packet_size - 4;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
513 if (len > size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
514 len = size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
515 /* build fragmented packet */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
516 s->buf[0] = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
517 s->buf[1] = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
518 s->buf[2] = count >> 8;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
519 s->buf[3] = count;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
520 memcpy(s->buf + 4, buf1, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
521 rtp_send_data(s1, s->buf, len + 4);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
522 size -= len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
523 buf1 += len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
524 count += len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
525 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
526 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
527 if (s->buf_ptr == s->buf + 4) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
528 /* no fragmentation possible */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
529 s->buf[0] = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
530 s->buf[1] = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
531 s->buf[2] = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
532 s->buf[3] = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
533 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
534 memcpy(s->buf_ptr, buf1, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
535 s->buf_ptr += size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
536 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
537 s->cur_timestamp += st->codec.frame_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
538 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
539
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
540 /* NOTE: a single frame must be passed with sequence header if
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
541 needed. XXX: use slices. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
542 static void rtp_send_mpegvideo(AVFormatContext *s1,
241
3d92f793fd67 64 bit pts for writing - more const usage
bellard
parents: 232
diff changeset
543 const uint8_t *buf1, int size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
544 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
545 RTPContext *s = s1->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
546 AVStream *st = s1->streams[0];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
547 int len, h, max_packet_size;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
548 uint8_t *q;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
549
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
550 max_packet_size = s->max_payload_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
551
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
552 while (size > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
553 /* XXX: more correct headers */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
554 h = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
555 if (st->codec.sub_id == 2)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
556 h |= 1 << 26; /* mpeg 2 indicator */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
557 q = s->buf;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
558 *q++ = h >> 24;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
559 *q++ = h >> 16;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
560 *q++ = h >> 8;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
561 *q++ = h;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
562
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
563 if (st->codec.sub_id == 2) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
564 h = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
565 *q++ = h >> 24;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
566 *q++ = h >> 16;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
567 *q++ = h >> 8;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
568 *q++ = h;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
569 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
570
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
571 len = max_packet_size - (q - s->buf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
572 if (len > size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
573 len = size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
574
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
575 memcpy(q, buf1, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
576 q += len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
577
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
578 /* 90 KHz time stamp */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
579 s->timestamp = s->base_timestamp +
85
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 65
diff changeset
580 av_rescale((int64_t)s->cur_timestamp * st->codec.frame_rate_base, 90000, st->codec.frame_rate);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
581 rtp_send_data(s1, s->buf, q - s->buf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
582
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
583 buf1 += len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
584 size -= len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
585 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
586 s->cur_timestamp++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
587 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
588
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
589 static void rtp_send_raw(AVFormatContext *s1,
241
3d92f793fd67 64 bit pts for writing - more const usage
bellard
parents: 232
diff changeset
590 const uint8_t *buf1, int size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
591 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
592 RTPContext *s = s1->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
593 AVStream *st = s1->streams[0];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
594 int len, max_packet_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
595
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
596 max_packet_size = s->max_payload_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
597
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
598 while (size > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
599 len = max_packet_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
600 if (len > size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
601 len = size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
602
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
603 /* 90 KHz time stamp */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
604 s->timestamp = s->base_timestamp +
85
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 65
diff changeset
605 av_rescale((int64_t)s->cur_timestamp * st->codec.frame_rate_base, 90000, st->codec.frame_rate);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
606 rtp_send_data(s1, buf1, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
607
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
608 buf1 += len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
609 size -= len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
610 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
611 s->cur_timestamp++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
612 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
613
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
614 /* write an RTP packet. 'buf1' must contain a single specific frame. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
615 static int rtp_write_packet(AVFormatContext *s1, int stream_index,
241
3d92f793fd67 64 bit pts for writing - more const usage
bellard
parents: 232
diff changeset
616 const uint8_t *buf1, int size, int64_t pts)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
617 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
618 RTPContext *s = s1->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
619 AVStream *st = s1->streams[0];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
620 int rtcp_bytes;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
621 int64_t ntp_time;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
622
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
623 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
624 printf("%d: write len=%d\n", stream_index, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
625 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
626
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
627 /* XXX: mpeg pts hardcoded. RTCP send every 0.5 seconds */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
628 rtcp_bytes = ((s->octet_count - s->last_octet_count) * RTCP_TX_RATIO_NUM) /
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
629 RTCP_TX_RATIO_DEN;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
630 if (s->first_packet || rtcp_bytes >= 28) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
631 /* compute NTP time */
173
38f64fabb24b fixed NTP generation for mpeg
bellard
parents: 85
diff changeset
632 /* XXX: 90 kHz timestamp hardcoded */
241
3d92f793fd67 64 bit pts for writing - more const usage
bellard
parents: 232
diff changeset
633 ntp_time = (pts << 28) / 5625;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
634 rtcp_send_sr(s1, ntp_time);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
635 s->last_octet_count = s->octet_count;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
636 s->first_packet = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
637 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
638
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
639 switch(st->codec.codec_id) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
640 case CODEC_ID_PCM_MULAW:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
641 case CODEC_ID_PCM_ALAW:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
642 case CODEC_ID_PCM_U8:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
643 case CODEC_ID_PCM_S8:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
644 rtp_send_samples(s1, buf1, size, 1 * st->codec.channels);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
645 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
646 case CODEC_ID_PCM_U16BE:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
647 case CODEC_ID_PCM_U16LE:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
648 case CODEC_ID_PCM_S16BE:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
649 case CODEC_ID_PCM_S16LE:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
650 rtp_send_samples(s1, buf1, size, 2 * st->codec.channels);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
651 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
652 case CODEC_ID_MP2:
232
eb90c0a5a1ba CODEC_ID_MP3LAME is obsolete
bellard
parents: 173
diff changeset
653 case CODEC_ID_MP3:
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
654 rtp_send_mpegaudio(s1, buf1, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
655 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
656 case CODEC_ID_MPEG1VIDEO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
657 rtp_send_mpegvideo(s1, buf1, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
658 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
659 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
660 /* better than nothing : send the codec raw data */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
661 rtp_send_raw(s1, buf1, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
662 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
663 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
664 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
665 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
666
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
667 static int rtp_write_trailer(AVFormatContext *s1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
668 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
669 // RTPContext *s = s1->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
670 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
671 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
672
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
673 AVInputFormat rtp_demux = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
674 "rtp",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
675 "RTP input format",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
676 sizeof(RTPContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
677 rtp_probe,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
678 rtp_read_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
679 rtp_read_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
680 rtp_read_close,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
681 .flags = AVFMT_NOHEADER,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
682 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
683
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
684 AVOutputFormat rtp_mux = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
685 "rtp",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
686 "RTP output format",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
687 NULL,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
688 NULL,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
689 sizeof(RTPContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
690 CODEC_ID_PCM_MULAW,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
691 CODEC_ID_NONE,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
692 rtp_write_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
693 rtp_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
694 rtp_write_trailer,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
695 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
696
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
697 int rtp_init(void)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
698 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
699 av_register_output_format(&rtp_mux);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
700 av_register_input_format(&rtp_demux);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
701 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
702 }