annotate rtpdec_amr.c @ 6024:ee42a04b24f2 libavformat

Add a libavformat internal function ff_write_chained
author mstorsjo
date Fri, 21 May 2010 07:07:57 +0000
parents 08cd1179a20d
children 51ea3f882776
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");
5930
08cd1179a20d Replace all remaining occurrences of AVERROR_NOMEM with
stefano
parents: 5910
diff changeset
86 return AVERROR(ENOMEM);
5643
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))) {
5863
7d952a85947b Interpret valueless attributes in AMR ftmp lines as being 1
mstorsjo
parents: 5697
diff changeset
145 /* Some AMR SDP configurations contain "octet-align", without
7d952a85947b Interpret valueless attributes in AMR ftmp lines as being 1
mstorsjo
parents: 5697
diff changeset
146 * the trailing =1. Therefore, if the value is empty,
7d952a85947b Interpret valueless attributes in AMR ftmp lines as being 1
mstorsjo
parents: 5697
diff changeset
147 * interpret it as "1".
7d952a85947b Interpret valueless attributes in AMR ftmp lines as being 1
mstorsjo
parents: 5697
diff changeset
148 */
7d952a85947b Interpret valueless attributes in AMR ftmp lines as being 1
mstorsjo
parents: 5697
diff changeset
149 if (!strcmp(value, "")) {
7d952a85947b Interpret valueless attributes in AMR ftmp lines as being 1
mstorsjo
parents: 5697
diff changeset
150 av_log(s, AV_LOG_WARNING, "AMR fmtp attribute %s had "
7d952a85947b Interpret valueless attributes in AMR ftmp lines as being 1
mstorsjo
parents: 5697
diff changeset
151 "nonstandard empty value\n", attr);
7d952a85947b Interpret valueless attributes in AMR ftmp lines as being 1
mstorsjo
parents: 5697
diff changeset
152 strcpy(value, "1");
7d952a85947b Interpret valueless attributes in AMR ftmp lines as being 1
mstorsjo
parents: 5697
diff changeset
153 }
5643
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
154 if (!strcmp(attr, "octet-align"))
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
155 octet_align = atoi(value);
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
156 else if (!strcmp(attr, "crc"))
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
157 crc = atoi(value);
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
158 else if (!strcmp(attr, "interleaving"))
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
159 interleaving = atoi(value);
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
160 else if (!strcmp(attr, "channels"))
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
161 channels = atoi(value);
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
162 }
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
163 if (!octet_align || crc || interleaving || channels != 1) {
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
164 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
165 return -1;
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
166 }
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
167 }
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
168 return 0;
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
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
171 RTPDynamicProtocolHandler ff_amr_nb_dynamic_handler = {
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
172 .enc_name = "AMR",
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5863
diff changeset
173 .codec_type = AVMEDIA_TYPE_AUDIO,
5643
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
174 .codec_id = CODEC_ID_AMR_NB,
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
175 .parse_sdp_a_line = amr_parse_sdp_line,
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
176 .parse_packet = amr_handle_packet,
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
177 };
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
178
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
179 RTPDynamicProtocolHandler ff_amr_wb_dynamic_handler = {
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
180 .enc_name = "AMR-WB",
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5863
diff changeset
181 .codec_type = AVMEDIA_TYPE_AUDIO,
5643
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
182 .codec_id = CODEC_ID_AMR_WB,
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
183 .parse_sdp_a_line = amr_parse_sdp_line,
457efbf56d15 RTP/AMR depacketizer, by Martin Storsj <$firstname at $firstname dot st>.
rbultje
parents:
diff changeset
184 .parse_packet = amr_handle_packet,
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