yading@11
|
1 /*
|
yading@11
|
2 * RTP iLBC Depacketizer, RFC 3952
|
yading@11
|
3 * Copyright (c) 2012 Martin Storsjo
|
yading@11
|
4 *
|
yading@11
|
5 * This file is part of FFmpeg.
|
yading@11
|
6 *
|
yading@11
|
7 * FFmpeg is free software; you can redistribute it and/or
|
yading@11
|
8 * modify it under the terms of the GNU Lesser General Public
|
yading@11
|
9 * License as published by the Free Software Foundation; either
|
yading@11
|
10 * version 2.1 of the License, or (at your option) any later version.
|
yading@11
|
11 *
|
yading@11
|
12 * FFmpeg is distributed in the hope that it will be useful,
|
yading@11
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
yading@11
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
yading@11
|
15 * Lesser General Public License for more details.
|
yading@11
|
16 *
|
yading@11
|
17 * You should have received a copy of the GNU Lesser General Public
|
yading@11
|
18 * License along with FFmpeg; if not, write to the Free Software
|
yading@11
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
yading@11
|
20 */
|
yading@11
|
21
|
yading@11
|
22 #include "avformat.h"
|
yading@11
|
23 #include "rtpdec_formats.h"
|
yading@11
|
24 #include "libavutil/avstring.h"
|
yading@11
|
25
|
yading@11
|
26 static int ilbc_parse_fmtp(AVStream *stream, PayloadContext *data,
|
yading@11
|
27 char *attr, char *value)
|
yading@11
|
28 {
|
yading@11
|
29 if (!strcmp(attr, "mode")) {
|
yading@11
|
30 int mode = atoi(value);
|
yading@11
|
31 switch (mode) {
|
yading@11
|
32 case 20:
|
yading@11
|
33 stream->codec->block_align = 38;
|
yading@11
|
34 break;
|
yading@11
|
35 case 30:
|
yading@11
|
36 stream->codec->block_align = 50;
|
yading@11
|
37 break;
|
yading@11
|
38 default:
|
yading@11
|
39 av_log(NULL, AV_LOG_ERROR, "Unsupported iLBC mode %d\n", mode);
|
yading@11
|
40 return AVERROR(EINVAL);
|
yading@11
|
41 }
|
yading@11
|
42 }
|
yading@11
|
43 return 0;
|
yading@11
|
44 }
|
yading@11
|
45
|
yading@11
|
46 static int ilbc_parse_sdp_line(AVFormatContext *s, int st_index,
|
yading@11
|
47 PayloadContext *data, const char *line)
|
yading@11
|
48 {
|
yading@11
|
49 const char *p;
|
yading@11
|
50 AVStream *st;
|
yading@11
|
51
|
yading@11
|
52 if (st_index < 0)
|
yading@11
|
53 return 0;
|
yading@11
|
54 st = s->streams[st_index];
|
yading@11
|
55
|
yading@11
|
56 if (av_strstart(line, "fmtp:", &p)) {
|
yading@11
|
57 int ret = ff_parse_fmtp(st, data, p, ilbc_parse_fmtp);
|
yading@11
|
58 if (ret < 0)
|
yading@11
|
59 return ret;
|
yading@11
|
60 if (!st->codec->block_align) {
|
yading@11
|
61 av_log(s, AV_LOG_ERROR, "No iLBC mode set\n");
|
yading@11
|
62 return AVERROR(EINVAL);
|
yading@11
|
63 }
|
yading@11
|
64 }
|
yading@11
|
65 return 0;
|
yading@11
|
66 }
|
yading@11
|
67
|
yading@11
|
68 RTPDynamicProtocolHandler ff_ilbc_dynamic_handler = {
|
yading@11
|
69 .enc_name = "iLBC",
|
yading@11
|
70 .codec_type = AVMEDIA_TYPE_AUDIO,
|
yading@11
|
71 .codec_id = AV_CODEC_ID_ILBC,
|
yading@11
|
72 .parse_sdp_a_line = ilbc_parse_sdp_line,
|
yading@11
|
73 };
|