Originally committed as revision 24790 to svn://svn.ffmpeg.org/ffmpeg/trunk
Martin Storsjö authored on 2010/08/13 06:07:17... | ... |
@@ -23,7 +23,7 @@ |
23 | 23 |
|
24 | 24 |
#define LIBAVFORMAT_VERSION_MAJOR 52 |
25 | 25 |
#define LIBAVFORMAT_VERSION_MINOR 78 |
26 |
-#define LIBAVFORMAT_VERSION_MICRO 1 |
|
26 |
+#define LIBAVFORMAT_VERSION_MICRO 2 |
|
27 | 27 |
|
28 | 28 |
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ |
29 | 29 |
LIBAVFORMAT_VERSION_MINOR, \ |
... | ... |
@@ -65,6 +65,7 @@ void av_register_rtp_dynamic_payload_handlers(void) |
65 | 65 |
ff_register_dynamic_payload_handler(&ff_theora_dynamic_handler); |
66 | 66 |
ff_register_dynamic_payload_handler(&ff_qdm2_dynamic_handler); |
67 | 67 |
ff_register_dynamic_payload_handler(&ff_svq3_dynamic_handler); |
68 |
+ ff_register_dynamic_payload_handler(&ff_mp4a_latm_dynamic_handler); |
|
68 | 69 |
|
69 | 70 |
ff_register_dynamic_payload_handler(&ff_ms_rtp_asf_pfv_handler); |
70 | 71 |
ff_register_dynamic_payload_handler(&ff_ms_rtp_asf_pfa_handler); |
... | ... |
@@ -36,6 +36,7 @@ extern RTPDynamicProtocolHandler ff_amr_wb_dynamic_handler; |
36 | 36 |
extern RTPDynamicProtocolHandler ff_h263_1998_dynamic_handler; |
37 | 37 |
extern RTPDynamicProtocolHandler ff_h263_2000_dynamic_handler; |
38 | 38 |
extern RTPDynamicProtocolHandler ff_h264_dynamic_handler; |
39 |
+extern RTPDynamicProtocolHandler ff_mp4a_latm_dynamic_handler; |
|
39 | 40 |
extern RTPDynamicProtocolHandler ff_mp4v_es_dynamic_handler; |
40 | 41 |
extern RTPDynamicProtocolHandler ff_mpeg4_generic_dynamic_handler; |
41 | 42 |
extern RTPDynamicProtocolHandler ff_ms_rtp_asf_pfa_handler; |
42 | 43 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,187 @@ |
0 |
+/** |
|
1 |
+ * RTP Depacketization of MP4A-LATM, RFC 3016 |
|
2 |
+ * Copyright (c) 2010 Martin Storsjo |
|
3 |
+ * |
|
4 |
+ * This file is part of FFmpeg. |
|
5 |
+ * |
|
6 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
7 |
+ * modify it under the terms of the GNU Lesser General Public |
|
8 |
+ * License as published by the Free Software Foundation; either |
|
9 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
10 |
+ * |
|
11 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
12 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 |
+ * Lesser General Public License for more details. |
|
15 |
+ * |
|
16 |
+ * You should have received a copy of the GNU Lesser General Public |
|
17 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
18 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
19 |
+ */ |
|
20 |
+ |
|
21 |
+#include "rtpdec_formats.h" |
|
22 |
+#include "internal.h" |
|
23 |
+#include "libavutil/avstring.h" |
|
24 |
+#include "libavcodec/get_bits.h" |
|
25 |
+#include <strings.h> |
|
26 |
+ |
|
27 |
+struct PayloadContext { |
|
28 |
+ ByteIOContext *dyn_buf; |
|
29 |
+ uint8_t *buf; |
|
30 |
+ int pos, len; |
|
31 |
+ uint32_t timestamp; |
|
32 |
+}; |
|
33 |
+ |
|
34 |
+static PayloadContext *latm_new_context(void) |
|
35 |
+{ |
|
36 |
+ return av_mallocz(sizeof(PayloadContext)); |
|
37 |
+} |
|
38 |
+ |
|
39 |
+static void latm_free_context(PayloadContext *data) |
|
40 |
+{ |
|
41 |
+ if (!data) |
|
42 |
+ return; |
|
43 |
+ if (data->dyn_buf) { |
|
44 |
+ uint8_t *p; |
|
45 |
+ url_close_dyn_buf(data->dyn_buf, &p); |
|
46 |
+ av_free(p); |
|
47 |
+ } |
|
48 |
+ av_free(data->buf); |
|
49 |
+ av_free(data); |
|
50 |
+} |
|
51 |
+ |
|
52 |
+static int latm_parse_packet(AVFormatContext *ctx, PayloadContext *data, |
|
53 |
+ AVStream *st, AVPacket *pkt, uint32_t *timestamp, |
|
54 |
+ const uint8_t *buf, int len, int flags) |
|
55 |
+{ |
|
56 |
+ int ret, cur_len; |
|
57 |
+ |
|
58 |
+ if (buf) { |
|
59 |
+ if (!data->dyn_buf || data->timestamp != *timestamp) { |
|
60 |
+ av_freep(&data->buf); |
|
61 |
+ if (data->dyn_buf) |
|
62 |
+ url_close_dyn_buf(data->dyn_buf, &data->buf); |
|
63 |
+ data->dyn_buf = NULL; |
|
64 |
+ av_freep(&data->buf); |
|
65 |
+ |
|
66 |
+ data->timestamp = *timestamp; |
|
67 |
+ if ((ret = url_open_dyn_buf(&data->dyn_buf)) < 0) |
|
68 |
+ return ret; |
|
69 |
+ } |
|
70 |
+ put_buffer(data->dyn_buf, buf, len); |
|
71 |
+ |
|
72 |
+ if (!(flags & RTP_FLAG_MARKER)) |
|
73 |
+ return AVERROR(EAGAIN); |
|
74 |
+ av_free(data->buf); |
|
75 |
+ data->len = url_close_dyn_buf(data->dyn_buf, &data->buf); |
|
76 |
+ data->dyn_buf = NULL; |
|
77 |
+ data->pos = 0; |
|
78 |
+ } |
|
79 |
+ |
|
80 |
+ if (!data->buf) { |
|
81 |
+ av_log(ctx, AV_LOG_ERROR, "No data available yet\n"); |
|
82 |
+ return AVERROR(EIO); |
|
83 |
+ } |
|
84 |
+ |
|
85 |
+ cur_len = 0; |
|
86 |
+ while (data->pos < data->len) { |
|
87 |
+ uint8_t val = data->buf[data->pos++]; |
|
88 |
+ cur_len += val; |
|
89 |
+ if (val != 0xff) |
|
90 |
+ break; |
|
91 |
+ } |
|
92 |
+ if (data->pos + cur_len > data->len) { |
|
93 |
+ av_log(ctx, AV_LOG_ERROR, "Malformed LATM packet\n"); |
|
94 |
+ return AVERROR(EIO); |
|
95 |
+ } |
|
96 |
+ |
|
97 |
+ if ((ret = av_new_packet(pkt, cur_len)) < 0) |
|
98 |
+ return ret; |
|
99 |
+ memcpy(pkt->data, data->buf + data->pos, cur_len); |
|
100 |
+ data->pos += cur_len; |
|
101 |
+ pkt->stream_index = st->index; |
|
102 |
+ return data->pos < data->len; |
|
103 |
+} |
|
104 |
+ |
|
105 |
+static int parse_fmtp_config(AVStream *st, char *value) |
|
106 |
+{ |
|
107 |
+ int len = ff_hex_to_data(NULL, value), i, ret = 0; |
|
108 |
+ GetBitContext gb; |
|
109 |
+ uint8_t *config; |
|
110 |
+ int audio_mux_version, same_time_framing, num_sub_frames, |
|
111 |
+ num_programs, num_layers; |
|
112 |
+ |
|
113 |
+ /* Pad this buffer, too, to avoid out of bounds reads with get_bits below */ |
|
114 |
+ config = av_mallocz(len + FF_INPUT_BUFFER_PADDING_SIZE); |
|
115 |
+ if (!config) |
|
116 |
+ return AVERROR(ENOMEM); |
|
117 |
+ ff_hex_to_data(config, value); |
|
118 |
+ init_get_bits(&gb, config, len*8); |
|
119 |
+ audio_mux_version = get_bits(&gb, 1); |
|
120 |
+ same_time_framing = get_bits(&gb, 1); |
|
121 |
+ num_sub_frames = get_bits(&gb, 6); |
|
122 |
+ num_programs = get_bits(&gb, 4); |
|
123 |
+ num_layers = get_bits(&gb, 3); |
|
124 |
+ if (audio_mux_version != 0 || same_time_framing != 1 || num_programs != 0 || |
|
125 |
+ num_layers != 0) { |
|
126 |
+ av_log(NULL, AV_LOG_WARNING, "Unsupported LATM config (%d,%d,%d,%d)\n", |
|
127 |
+ audio_mux_version, same_time_framing, |
|
128 |
+ num_programs, num_layers); |
|
129 |
+ ret = AVERROR_PATCHWELCOME; |
|
130 |
+ goto end; |
|
131 |
+ } |
|
132 |
+ av_freep(&st->codec->extradata); |
|
133 |
+ st->codec->extradata_size = (get_bits_left(&gb) + 7)/8; |
|
134 |
+ st->codec->extradata = av_mallocz(st->codec->extradata_size + |
|
135 |
+ FF_INPUT_BUFFER_PADDING_SIZE); |
|
136 |
+ if (!st->codec->extradata) { |
|
137 |
+ ret = AVERROR(ENOMEM); |
|
138 |
+ goto end; |
|
139 |
+ } |
|
140 |
+ for (i = 0; i < st->codec->extradata_size; i++) |
|
141 |
+ st->codec->extradata[i] = get_bits(&gb, 8); |
|
142 |
+ |
|
143 |
+end: |
|
144 |
+ av_free(config); |
|
145 |
+ return ret; |
|
146 |
+} |
|
147 |
+ |
|
148 |
+static int parse_fmtp(AVStream *stream, PayloadContext *data, |
|
149 |
+ char *attr, char *value) |
|
150 |
+{ |
|
151 |
+ int res; |
|
152 |
+ |
|
153 |
+ if (!strcmp(attr, "config")) { |
|
154 |
+ res = parse_fmtp_config(stream, value); |
|
155 |
+ if (res < 0) |
|
156 |
+ return res; |
|
157 |
+ } else if (!strcmp(attr, "cpresent")) { |
|
158 |
+ int cpresent = atoi(value); |
|
159 |
+ if (cpresent != 0) |
|
160 |
+ av_log_missing_feature(NULL, "RTP MP4A-LATM with in-band " |
|
161 |
+ "configuration", 1); |
|
162 |
+ } |
|
163 |
+ |
|
164 |
+ return 0; |
|
165 |
+} |
|
166 |
+ |
|
167 |
+static int latm_parse_sdp_line(AVFormatContext *s, int st_index, |
|
168 |
+ PayloadContext *data, const char *line) |
|
169 |
+{ |
|
170 |
+ const char *p; |
|
171 |
+ |
|
172 |
+ if (av_strstart(line, "fmtp:", &p)) |
|
173 |
+ return ff_parse_fmtp(s->streams[st_index], data, p, parse_fmtp); |
|
174 |
+ |
|
175 |
+ return 0; |
|
176 |
+} |
|
177 |
+ |
|
178 |
+RTPDynamicProtocolHandler ff_mp4a_latm_dynamic_handler = { |
|
179 |
+ .enc_name = "MP4A-LATM", |
|
180 |
+ .codec_type = AVMEDIA_TYPE_AUDIO, |
|
181 |
+ .codec_id = CODEC_ID_AAC, |
|
182 |
+ .parse_sdp_a_line = latm_parse_sdp_line, |
|
183 |
+ .open = latm_new_context, |
|
184 |
+ .close = latm_free_context, |
|
185 |
+ .parse_packet = latm_parse_packet |
|
186 |
+}; |