annotate rtpdec_amr.c @ 5699:2ace2ee84929 libavformat

Bink audio pts starts at 0, not reported_size
author pross
date Tue, 23 Feb 2010 11:01:51 +0000
parents 484fceabfad2
children 7d952a85947b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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"
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
23 #include "rtpdec_amr.h"
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
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
33 static int amr_handle_packet(AVFormatContext *ctx,
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
34 PayloadContext *data,
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
35 AVStream *st,
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
36 AVPacket * pkt,
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
37 uint32_t * timestamp,
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
38 const uint8_t * buf,
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
39 int len, int flags)
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
40 {
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
41 const uint8_t *frame_sizes = NULL;
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
42 int frames;
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
43 int i;
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
44 const uint8_t *speech_data;
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
45 uint8_t *ptr;
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
46
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
47 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
48 frame_sizes = frame_sizes_nb;
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
49 } 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
50 frame_sizes = frame_sizes_wb;
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
51 } else {
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
52 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
53 return AVERROR_INVALIDDATA;
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
54 }
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
55
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
56 if (st->codec->channels != 1) {
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
57 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
58 return AVERROR_INVALIDDATA;
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
59 }
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 /* 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
62 * 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
63 * 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
64 *
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
65 * 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
66 * 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
67 * receive. Not used at the moment.
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
68 */
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
69
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
70 /* 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
71 * 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
72 */
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
73 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
74
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
75 if (1 + frames >= len) {
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
76 /* 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
77 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
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 speech_data = buf + 1 + frames;
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
82
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
83 /* 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
84 if (av_new_packet(pkt, len - 1)) {
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
85 av_log(ctx, AV_LOG_ERROR, "Out of memory\n");
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
86 return AVERROR_NOMEM;
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
87 }
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
88 pkt->stream_index = st->index;
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
89 ptr = pkt->data;
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
90
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
91 for (i = 0; i < frames; i++) {
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
92 uint8_t toc = buf[1 + i];
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
93 int frame_size = frame_sizes[(toc >> 3) & 0x0f];
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 (speech_data + frame_size > buf + len) {
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
96 /* Too little speech data */
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
97 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
98 /* 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
99 memset(ptr, 0, pkt->data + pkt->size - ptr);
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
100 pkt->size = ptr - pkt->data;
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
101 return 0;
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
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
104 /* 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
105 *ptr++ = toc & 0x7C;
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
106
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
107 /* Copy the speech data */
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
108 memcpy(ptr, speech_data, frame_size);
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
109 speech_data += frame_size;
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
110 ptr += frame_size;
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
111 }
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
112
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
113 if (speech_data < buf + len) {
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
114 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
115 /* 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
116 memset(ptr, 0, pkt->data + pkt->size - ptr);
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
117 pkt->size = ptr - pkt->data;
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
118 }
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
119
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
120 return 0;
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
121 }
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 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
124 PayloadContext *data, const char *line)
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
125 {
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
126 const char *p;
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
127 char attr[25], value[25];
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
128
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
129 /* Parse an fmtp line this one:
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
130 * a=fmtp:97 octet-align=1; interleaving=0
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
131 * 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
132 * separated key/value pairs.
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
133 */
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
134 if (av_strstart(line, "fmtp:", &p)) {
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
135 int octet_align = 0;
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
136 int crc = 0;
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
137 int interleaving = 0;
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
138 int channels = 1;
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 while (*p && *p == ' ') p++; /* strip spaces */
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
141 while (*p && *p != ' ') p++; /* eat protocol identifier */
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
142 while (*p && *p == ' ') p++; /* strip trailing spaces */
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
143
5697
484fceabfad2 Prefix non-static RTSP functions with ff_.
rbultje
parents: 5643
diff changeset
144 while (ff_rtsp_next_attr_and_value(&p, attr, sizeof(attr), value, sizeof(value))) {
5643
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
145 if (!strcmp(attr, "octet-align"))
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
146 octet_align = atoi(value);
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
147 else if (!strcmp(attr, "crc"))
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
148 crc = atoi(value);
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
149 else if (!strcmp(attr, "interleaving"))
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
150 interleaving = atoi(value);
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
151 else if (!strcmp(attr, "channels"))
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
152 channels = atoi(value);
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
153 }
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
154 if (!octet_align || crc || interleaving || channels != 1) {
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
155 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
156 return -1;
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
157 }
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
158 }
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
159 return 0;
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
160 }
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
161
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
162 RTPDynamicProtocolHandler ff_amr_nb_dynamic_handler = {
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
163 .enc_name = "AMR",
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
164 .codec_type = CODEC_TYPE_AUDIO,
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
165 .codec_id = CODEC_ID_AMR_NB,
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
166 .parse_sdp_a_line = amr_parse_sdp_line,
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
167 .parse_packet = amr_handle_packet,
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
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
170 RTPDynamicProtocolHandler ff_amr_wb_dynamic_handler = {
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
171 .enc_name = "AMR-WB",
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
172 .codec_type = CODEC_TYPE_AUDIO,
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
173 .codec_id = CODEC_ID_AMR_WB,
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
174 .parse_sdp_a_line = amr_parse_sdp_line,
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
175 .parse_packet = amr_handle_packet,
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