3 * Copyright (c) 2001 ffmpeg project
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 Write and read amr data according to RFC3267, http://www.ietf.org/rfc/rfc3267.txt?number=3267
23 Only amr narrowband (not amr-wb) is supported for now.
29 static const unsigned char AMR_header [] = "#!AMR\n";
32 static int put_amr_header(ByteIOContext *pb, AVCodecContext *enc)
34 put_tag(pb, AMR_header); /* magic number */
38 static int amr_write_header(AVFormatContext *s)
40 ByteIOContext *pb = &s->pb;
45 if (put_amr_header(pb, &s->streams[0]->codec) < 0) {
54 static int amr_write_packet(AVFormatContext *s, int stream_index_ptr,
55 uint8_t *buf, int size, int force_pts)
57 put_buffer(&s->pb, buf, size);
58 put_flush_packet(&s->pb);
62 static int amr_write_trailer(AVFormatContext *s)
67 static int amr_probe(AVProbeData *p)
69 /* check file header */
72 if(memcmp(p->buf,AMR_header,6)==0)
73 return AVPROBE_SCORE_MAX;
79 static int amr_read_header(AVFormatContext *s,
80 AVFormatParameters *ap)
82 ByteIOContext *pb = &s->pb;
86 get_buffer(pb, header, 6);
88 if(memcmp(header,AMR_header,6)!=0)
93 st = av_new_stream(s, 0);
97 st->codec.codec_type = CODEC_TYPE_AUDIO;
98 st->codec.codec_tag = CODEC_ID_AMR_NB;
99 st->codec.codec_id = CODEC_ID_AMR_NB;
100 st->codec.channels = 1;
101 st->codec.sample_rate = 8000;
107 static int amr_read_packet(AVFormatContext *s,
110 static uint16_t packed_size[16] = {12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0};
115 if (url_feof(&s->pb))
120 toc=get_byte(&s->pb);
122 q = (toc >> 2) & 0x01;
123 ft = (toc >> 3) & 0x0F;
125 size=packed_size[ft];
126 //printf("amr_read_packet size=%d\n",size);
128 if (av_new_packet(pkt, size+1))
130 pkt->stream_index = 0;
134 read = get_buffer(&s->pb, pkt->data+1, size);
145 static int amr_read_close(AVFormatContext *s)
150 static AVInputFormat amr_iformat = {
152 "3gpp amr file format",
160 static AVOutputFormat amr_oformat = {
162 "3gpp amr file format",
175 av_register_input_format(&amr_iformat);
176 av_register_output_format(&amr_oformat);