Mercurial > libavformat.hg
annotate rtpdec_amr.c @ 6470:5d5fbab4d608 libavformat
adts demuxer: Set the time base to be the LCM of all ADTS sample rates.
author | alexc |
---|---|
date | Thu, 09 Sep 2010 23:15:17 +0000 |
parents | 491eea5c52d6 |
children |
rev | line source |
---|---|
5643
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
1 /* |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
2 * RTP AMR Depacketizer, RFC 3267 |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
3 * Copyright (c) 2010 Martin Storsjo |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
4 * |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
5 * This file is part of FFmpeg. |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
6 * |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
9 * License as published by the Free Software Foundation; either |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
11 * |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
15 * Lesser General Public License for more details. |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
16 * |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
20 */ |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
21 |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
22 #include "avformat.h" |
6339
491eea5c52d6
Remove mostly unnecessary rtpdec_*.h files, store the declarations in one file
mstorsjo
parents:
6196
diff
changeset
|
23 #include "rtpdec_formats.h" |
5643
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
24 #include "libavutil/avstring.h" |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
25 |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
26 static const uint8_t frame_sizes_nb[16] = { |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
27 12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0 |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
28 }; |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
29 static const uint8_t frame_sizes_wb[16] = { |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
30 17, 23, 32, 36, 40, 46, 50, 58, 60, 5, 5, 0, 0, 0, 0, 0 |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
31 }; |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
32 |
6195
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
33 struct PayloadContext { |
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
34 int octet_align; |
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
35 int crc; |
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
36 int interleaving; |
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
37 int channels; |
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
38 }; |
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
39 |
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
40 static PayloadContext *amr_new_context(void) |
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
41 { |
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
42 PayloadContext *data = av_mallocz(sizeof(PayloadContext)); |
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
43 if(!data) return data; |
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
44 data->channels = 1; |
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
45 return data; |
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
46 } |
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
47 |
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
48 static void amr_free_context(PayloadContext *data) |
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
49 { |
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
50 av_free(data); |
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
51 } |
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
52 |
5643
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
53 static int amr_handle_packet(AVFormatContext *ctx, |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
54 PayloadContext *data, |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
55 AVStream *st, |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
56 AVPacket * pkt, |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
57 uint32_t * timestamp, |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
58 const uint8_t * buf, |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
59 int len, int flags) |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
60 { |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
61 const uint8_t *frame_sizes = NULL; |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
62 int frames; |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
63 int i; |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
64 const uint8_t *speech_data; |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
65 uint8_t *ptr; |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
66 |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
67 if (st->codec->codec_id == CODEC_ID_AMR_NB) { |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
68 frame_sizes = frame_sizes_nb; |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
69 } else if (st->codec->codec_id == CODEC_ID_AMR_WB) { |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
70 frame_sizes = frame_sizes_wb; |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
71 } else { |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
72 av_log(ctx, AV_LOG_ERROR, "Bad codec ID\n"); |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
73 return AVERROR_INVALIDDATA; |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
74 } |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
75 |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
76 if (st->codec->channels != 1) { |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
77 av_log(ctx, AV_LOG_ERROR, "Only mono AMR is supported\n"); |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
78 return AVERROR_INVALIDDATA; |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
79 } |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
80 |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
81 /* The AMR RTP packet consists of one header byte, followed |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
82 * by one TOC byte for each AMR frame in the packet, followed |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
83 * by the speech data for all the AMR frames. |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
84 * |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
85 * The header byte contains only a codec mode request, for |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
86 * requesting what kind of AMR data the sender wants to |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
87 * receive. Not used at the moment. |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
88 */ |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
89 |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
90 /* Count the number of frames in the packet. The highest bit |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
91 * is set in a TOC byte if there are more frames following. |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
92 */ |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
93 for (frames = 1; frames < len && (buf[frames] & 0x80); frames++) ; |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
94 |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
95 if (1 + frames >= len) { |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
96 /* We hit the end of the packet while counting frames. */ |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
97 av_log(ctx, AV_LOG_ERROR, "No speech data found\n"); |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
98 return AVERROR_INVALIDDATA; |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
99 } |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
100 |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
101 speech_data = buf + 1 + frames; |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
102 |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
103 /* Everything except the codec mode request byte should be output. */ |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
104 if (av_new_packet(pkt, len - 1)) { |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
105 av_log(ctx, AV_LOG_ERROR, "Out of memory\n"); |
5930
08cd1179a20d
Replace all remaining occurrences of AVERROR_NOMEM with
stefano
parents:
5910
diff
changeset
|
106 return AVERROR(ENOMEM); |
5643
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
107 } |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
108 pkt->stream_index = st->index; |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
109 ptr = pkt->data; |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
110 |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
111 for (i = 0; i < frames; i++) { |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
112 uint8_t toc = buf[1 + i]; |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
113 int frame_size = frame_sizes[(toc >> 3) & 0x0f]; |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
114 |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
115 if (speech_data + frame_size > buf + len) { |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
116 /* Too little speech data */ |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
117 av_log(ctx, AV_LOG_WARNING, "Too little speech data in the RTP packet\n"); |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
118 /* Set the unwritten part of the packet to zero. */ |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
119 memset(ptr, 0, pkt->data + pkt->size - ptr); |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
120 pkt->size = ptr - pkt->data; |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
121 return 0; |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
122 } |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
123 |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
124 /* Extract the AMR frame mode from the TOC byte */ |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
125 *ptr++ = toc & 0x7C; |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
126 |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
127 /* Copy the speech data */ |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
128 memcpy(ptr, speech_data, frame_size); |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
129 speech_data += frame_size; |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
130 ptr += frame_size; |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
131 } |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
132 |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
133 if (speech_data < buf + len) { |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
134 av_log(ctx, AV_LOG_WARNING, "Too much speech data in the RTP packet?\n"); |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
135 /* Set the unwritten part of the packet to zero. */ |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
136 memset(ptr, 0, pkt->data + pkt->size - ptr); |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
137 pkt->size = ptr - pkt->data; |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
138 } |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
139 |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
140 return 0; |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
141 } |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
142 |
6195
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
143 static int amr_parse_fmtp(AVStream *stream, PayloadContext *data, |
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
144 char *attr, char *value) |
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
145 { |
6196 | 146 /* Some AMR SDP configurations contain "octet-align", without |
147 * the trailing =1. Therefore, if the value is empty, | |
148 * interpret it as "1". | |
149 */ | |
150 if (!strcmp(value, "")) { | |
151 av_log(NULL, AV_LOG_WARNING, "AMR fmtp attribute %s had " | |
152 "nonstandard empty value\n", attr); | |
153 strcpy(value, "1"); | |
154 } | |
155 if (!strcmp(attr, "octet-align")) | |
156 data->octet_align = atoi(value); | |
157 else if (!strcmp(attr, "crc")) | |
158 data->crc = atoi(value); | |
159 else if (!strcmp(attr, "interleaving")) | |
160 data->interleaving = atoi(value); | |
161 else if (!strcmp(attr, "channels")) | |
162 data->channels = atoi(value); | |
6195
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
163 return 0; |
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
164 } |
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
165 |
5643
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
166 static int amr_parse_sdp_line(AVFormatContext *s, int st_index, |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
167 PayloadContext *data, const char *line) |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
168 { |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
169 const char *p; |
6195
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
170 int ret; |
5643
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
171 |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
172 /* Parse an fmtp line this one: |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
173 * a=fmtp:97 octet-align=1; interleaving=0 |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
174 * That is, a normal fmtp: line followed by semicolon & space |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
175 * separated key/value pairs. |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
176 */ |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
177 if (av_strstart(line, "fmtp:", &p)) { |
6195
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
178 ret = ff_parse_fmtp(s->streams[st_index], data, p, amr_parse_fmtp); |
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
179 if (!data->octet_align || data->crc || |
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
180 data->interleaving || data->channels != 1) { |
5643
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
181 av_log(s, AV_LOG_ERROR, "Unsupported RTP/AMR configuration!\n"); |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
182 return -1; |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
183 } |
6195
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
184 return ret; |
5643
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
185 } |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
186 return 0; |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
187 } |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
188 |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
189 RTPDynamicProtocolHandler ff_amr_nb_dynamic_handler = { |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
190 .enc_name = "AMR", |
5910
536e5527c1e0
Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents:
5863
diff
changeset
|
191 .codec_type = AVMEDIA_TYPE_AUDIO, |
5643
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
192 .codec_id = CODEC_ID_AMR_NB, |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
193 .parse_sdp_a_line = amr_parse_sdp_line, |
6195
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
194 .open = amr_new_context, |
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
195 .close = amr_free_context, |
5643
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
196 .parse_packet = amr_handle_packet, |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
197 }; |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
198 |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
199 RTPDynamicProtocolHandler ff_amr_wb_dynamic_handler = { |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
200 .enc_name = "AMR-WB", |
5910
536e5527c1e0
Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents:
5863
diff
changeset
|
201 .codec_type = AVMEDIA_TYPE_AUDIO, |
5643
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
202 .codec_id = CODEC_ID_AMR_WB, |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
203 .parse_sdp_a_line = amr_parse_sdp_line, |
6195
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
204 .open = amr_new_context, |
51ea3f882776
rtpdec: Clean up FMTP parsing code in AMR RTP depacketizer
mstorsjo
parents:
5930
diff
changeset
|
205 .close = amr_free_context, |
5643
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
206 .parse_packet = amr_handle_packet, |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
207 }; |
457efbf56d15
RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff
changeset
|
208 |