Mercurial > libavcodec.hg
annotate libamr.c @ 9896:bbefbca72722 libavcodec
Drop code that attempts to decode frames that are prefixed by junk.
Too often it ends up decoding random data into noise without detecting
it (for example after seeking of some MP3 data with oddly often occurring
startcode emulation).
Fixes issue1154.
| author | michael |
|---|---|
| date | Tue, 30 Jun 2009 03:57:27 +0000 |
| parents | 336d3c384066 |
| children |
| rev | line source |
|---|---|
|
1258
802614404398
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
diff
changeset
|
1 /* |
|
802614404398
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
diff
changeset
|
2 * AMR Audio decoder stub |
|
802614404398
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
diff
changeset
|
3 * Copyright (c) 2003 the ffmpeg project |
|
802614404398
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
diff
changeset
|
4 * |
|
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3463
diff
changeset
|
5 * This file is part of FFmpeg. |
|
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3463
diff
changeset
|
6 * |
|
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3463
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
|
1258
802614404398
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public |
|
802614404398
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
diff
changeset
|
9 * License as published by the Free Software Foundation; either |
|
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3463
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
|
1258
802614404398
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
diff
changeset
|
11 * |
|
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3463
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
|
1258
802614404398
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
802614404398
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
802614404398
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
diff
changeset
|
15 * Lesser General Public License for more details. |
|
802614404398
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
diff
changeset
|
16 * |
|
802614404398
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
|
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3463
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
|
3036
0b546eab515d
Update licensing information: The FSF changed postal address.
diego
parents:
2979
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
1258
802614404398
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
diff
changeset
|
20 */ |
| 2967 | 21 |
| 4575 | 22 /** @file |
| 23 * Adaptive Multi-Rate (AMR) Audio decoder stub. | |
| 24 * | |
| 25 * This code implements both an AMR-NarrowBand (AMR-NB) and an AMR-WideBand | |
| 26 * (AMR-WB) audio encoder/decoder through external reference code from | |
| 27 * http://www.3gpp.org/. The license of the code from 3gpp is unclear so you | |
|
9826
336d3c384066
Remove comments that refer to fixed-point AMR implementations.
diego
parents:
9677
diff
changeset
|
28 * have to download the code separately. |
| 4575 | 29 * |
| 30 * \section AMR-NB | |
| 31 * | |
| 32 * The float version (default) can be downloaded from: | |
|
4746
4aedb3b6fa4e
Update specification and reference implementation links.
diego
parents:
4744
diff
changeset
|
33 * http://www.3gpp.org/ftp/Specs/archive/26_series/26.104/26104-610.zip |
| 4575 | 34 * |
| 35 * \subsection Specification | |
| 36 * The specification for AMR-NB can be found in TS 26.071 | |
| 37 * (http://www.3gpp.org/ftp/Specs/html-info/26071.htm) and some other | |
| 38 * info at http://www.3gpp.org/ftp/Specs/html-info/26-series.htm. | |
| 39 * | |
| 40 * \section AMR-WB | |
|
4858
3e38885a28bc
Remove the build instructions from the doxygen comments, they are duplicated
diego
parents:
4857
diff
changeset
|
41 * |
| 4575 | 42 * The reference code can be downloaded from: |
|
4746
4aedb3b6fa4e
Update specification and reference implementation links.
diego
parents:
4744
diff
changeset
|
43 * http://www.3gpp.org/ftp/Specs/archive/26_series/26.204/26204-600.zip |
| 4575 | 44 * |
| 45 * \subsection Specification | |
|
4746
4aedb3b6fa4e
Update specification and reference implementation links.
diego
parents:
4744
diff
changeset
|
46 * The specification for AMR-WB can be found in TS 26.171 |
|
4aedb3b6fa4e
Update specification and reference implementation links.
diego
parents:
4744
diff
changeset
|
47 * (http://www.3gpp.org/ftp/Specs/html-info/26171.htm) and some other |
|
4aedb3b6fa4e
Update specification and reference implementation links.
diego
parents:
4744
diff
changeset
|
48 * info at http://www.3gpp.org/ftp/Specs/html-info/26-series.htm. |
| 4575 | 49 * |
| 1297 | 50 */ |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
51 |
| 1297 | 52 #include "avcodec.h" |
| 53 | |
|
9670
5c929c37e1a0
Move AMR-WB-specific code to the AMR-WB section of the file.
diego
parents:
9669
diff
changeset
|
54 static void amr_decode_fix_avctx(AVCodecContext *avctx) |
|
5c929c37e1a0
Move AMR-WB-specific code to the AMR-WB section of the file.
diego
parents:
9669
diff
changeset
|
55 { |
|
5c929c37e1a0
Move AMR-WB-specific code to the AMR-WB section of the file.
diego
parents:
9669
diff
changeset
|
56 const int is_amr_wb = 1 + (avctx->codec_id == CODEC_ID_AMR_WB); |
|
5c929c37e1a0
Move AMR-WB-specific code to the AMR-WB section of the file.
diego
parents:
9669
diff
changeset
|
57 |
|
5c929c37e1a0
Move AMR-WB-specific code to the AMR-WB section of the file.
diego
parents:
9669
diff
changeset
|
58 if (!avctx->sample_rate) |
|
5c929c37e1a0
Move AMR-WB-specific code to the AMR-WB section of the file.
diego
parents:
9669
diff
changeset
|
59 avctx->sample_rate = 8000 * is_amr_wb; |
|
5c929c37e1a0
Move AMR-WB-specific code to the AMR-WB section of the file.
diego
parents:
9669
diff
changeset
|
60 |
|
5c929c37e1a0
Move AMR-WB-specific code to the AMR-WB section of the file.
diego
parents:
9669
diff
changeset
|
61 if (!avctx->channels) |
|
5c929c37e1a0
Move AMR-WB-specific code to the AMR-WB section of the file.
diego
parents:
9669
diff
changeset
|
62 avctx->channels = 1; |
|
5c929c37e1a0
Move AMR-WB-specific code to the AMR-WB section of the file.
diego
parents:
9669
diff
changeset
|
63 |
|
5c929c37e1a0
Move AMR-WB-specific code to the AMR-WB section of the file.
diego
parents:
9669
diff
changeset
|
64 avctx->frame_size = 160 * is_amr_wb; |
|
5c929c37e1a0
Move AMR-WB-specific code to the AMR-WB section of the file.
diego
parents:
9669
diff
changeset
|
65 avctx->sample_fmt = SAMPLE_FMT_S16; |
|
5c929c37e1a0
Move AMR-WB-specific code to the AMR-WB section of the file.
diego
parents:
9669
diff
changeset
|
66 } |
|
5c929c37e1a0
Move AMR-WB-specific code to the AMR-WB section of the file.
diego
parents:
9669
diff
changeset
|
67 |
|
5c929c37e1a0
Move AMR-WB-specific code to the AMR-WB section of the file.
diego
parents:
9669
diff
changeset
|
68 #if CONFIG_LIBAMR_NB |
|
5c929c37e1a0
Move AMR-WB-specific code to the AMR-WB section of the file.
diego
parents:
9669
diff
changeset
|
69 |
|
4843
0e11f292482f
Replace hackish support for amr-nb and amr-wb. Instead of including the source
diego
parents:
4842
diff
changeset
|
70 #include <amrnb/interf_dec.h> |
|
0e11f292482f
Replace hackish support for amr-nb and amr-wb. Instead of including the source
diego
parents:
4842
diff
changeset
|
71 #include <amrnb/interf_enc.h> |
| 1297 | 72 |
|
8347
81238f0bea66
Fix warning "format not a string literal and no format arguments".
benoit
parents:
7451
diff
changeset
|
73 static const char nb_bitrate_unsupported[] = |
|
4793
e69d9ecaaf84
Print a list of valid AMR bitrates if a wrong one is used.
diego
parents:
4789
diff
changeset
|
74 "bitrate not supported: use one of 4.75k, 5.15k, 5.9k, 6.7k, 7.4k, 7.95k, 10.2k or 12.2k\n"; |
|
e69d9ecaaf84
Print a list of valid AMR bitrates if a wrong one is used.
diego
parents:
4789
diff
changeset
|
75 |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
76 typedef struct AMR_bitrates { |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
77 int rate; |
| 1297 | 78 enum Mode mode; |
| 79 } AMR_bitrates; | |
| 80 | |
| 4744 | 81 /* Match desired bitrate */ |
| 82 static int getBitrateMode(int bitrate) | |
| 1297 | 83 { |
| 4744 | 84 /* make the correspondance between bitrate and mode */ |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
85 AMR_bitrates rates[] = { { 4750, MR475}, |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
86 { 5150, MR515}, |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
87 { 5900, MR59}, |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
88 { 6700, MR67}, |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
89 { 7400, MR74}, |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
90 { 7950, MR795}, |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
91 {10200, MR102}, |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
92 {12200, MR122}, }; |
| 1297 | 93 int i; |
| 4633 | 94 |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
95 for (i = 0; i < 8; i++) |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
96 if (rates[i].rate == bitrate) |
| 6750 | 97 return rates[i].mode; |
| 4744 | 98 /* no bitrate matching, return an error */ |
| 99 return -1; | |
| 1297 | 100 } |
| 101 | |
| 102 typedef struct AMRContext { | |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
103 int frameCount; |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
104 void *decState; |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
105 int *enstate; |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
106 int enc_bitrate; |
| 1297 | 107 } AMRContext; |
| 108 | |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
109 static av_cold int amr_nb_decode_init(AVCodecContext *avctx) |
| 1297 | 110 { |
| 111 AMRContext *s = avctx->priv_data; | |
| 4633 | 112 |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
113 s->frameCount = 0; |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
114 s->decState = Decoder_Interface_init(); |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
115 if (!s->decState) { |
| 1825 | 116 av_log(avctx, AV_LOG_ERROR, "Decoder_Interface_init error\r\n"); |
| 1297 | 117 return -1; |
| 118 } | |
| 4094 | 119 |
| 120 amr_decode_fix_avctx(avctx); | |
| 121 | |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
122 if (avctx->channels > 1) { |
| 4094 | 123 av_log(avctx, AV_LOG_ERROR, "amr_nb: multichannel decoding not supported\n"); |
| 124 return -1; | |
| 125 } | |
| 126 | |
| 1297 | 127 return 0; |
| 128 } | |
| 129 | |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
130 static av_cold int amr_nb_decode_close(AVCodecContext *avctx) |
|
9651
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
131 { |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
132 AMRContext *s = avctx->priv_data; |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
133 |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
134 Decoder_Interface_exit(s->decState); |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
135 return 0; |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
136 } |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
137 |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
138 static int amr_nb_decode_frame(AVCodecContext *avctx, void *data, |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
139 int *data_size, AVPacket *avpkt) |
|
9651
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
140 { |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
141 const uint8_t *buf = avpkt->data; |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
142 int buf_size = avpkt->size; |
|
9651
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
143 AMRContext *s = avctx->priv_data; |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
144 const uint8_t *amrData = buf; |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
145 static const uint8_t block_size[16] = { 12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0 }; |
|
9651
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
146 enum Mode dec_mode; |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
147 int packet_size; |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
148 |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
149 /* av_log(NULL, AV_LOG_DEBUG, "amr_decode_frame buf=%p buf_size=%d frameCount=%d!!\n", |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
150 buf, buf_size, s->frameCount); */ |
|
9651
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
151 |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
152 dec_mode = (buf[0] >> 3) & 0x000F; |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
153 packet_size = block_size[dec_mode] + 1; |
|
9651
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
154 |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
155 if (packet_size > buf_size) { |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
156 av_log(avctx, AV_LOG_ERROR, "amr frame too short (%u, should be %u)\n", |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
157 buf_size, packet_size); |
|
9651
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
158 return -1; |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
159 } |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
160 |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
161 s->frameCount++; |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
162 /* av_log(NULL, AV_LOG_DEBUG, "packet_size=%d amrData= 0x%X %X %X %X\n", |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
163 packet_size, amrData[0], amrData[1], amrData[2], amrData[3]); */ |
|
9651
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
164 /* call decoder */ |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
165 Decoder_Interface_Decode(s->decState, amrData, data, 0); |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
166 *data_size = 160 * 2; |
|
9651
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
167 |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
168 return packet_size; |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
169 } |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
170 |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
171 AVCodec libamr_nb_decoder = { |
|
9651
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
172 "libamr_nb", |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
173 CODEC_TYPE_AUDIO, |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
174 CODEC_ID_AMR_NB, |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
175 sizeof(AMRContext), |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
176 amr_nb_decode_init, |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
177 NULL, |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
178 amr_nb_decode_close, |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
179 amr_nb_decode_frame, |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
180 .long_name = NULL_IF_CONFIG_SMALL("libamr-nb Adaptive Multi-Rate (AMR) Narrow-Band"), |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
181 }; |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
182 |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
183 static av_cold int amr_nb_encode_init(AVCodecContext *avctx) |
| 1297 | 184 { |
| 185 AMRContext *s = avctx->priv_data; | |
| 4633 | 186 |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
187 s->frameCount = 0; |
| 2967 | 188 |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
189 if (avctx->sample_rate != 8000) { |
|
4309
1f95aa362562
always print message when error, AV_LOG_DEBUG -> AV_LOG_ERROR
bcoudurier
parents:
4221
diff
changeset
|
190 av_log(avctx, AV_LOG_ERROR, "Only 8000Hz sample rate supported\n"); |
| 1297 | 191 return -1; |
| 192 } | |
| 193 | |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
194 if (avctx->channels != 1) { |
|
4309
1f95aa362562
always print message when error, AV_LOG_DEBUG -> AV_LOG_ERROR
bcoudurier
parents:
4221
diff
changeset
|
195 av_log(avctx, AV_LOG_ERROR, "Only mono supported\n"); |
| 1297 | 196 return -1; |
| 197 } | |
| 198 | |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
199 avctx->frame_size = 160; |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
200 avctx->coded_frame = avcodec_alloc_frame(); |
| 1297 | 201 |
| 202 s->enstate=Encoder_Interface_init(0); | |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
203 if (!s->enstate) { |
|
4309
1f95aa362562
always print message when error, AV_LOG_DEBUG -> AV_LOG_ERROR
bcoudurier
parents:
4221
diff
changeset
|
204 av_log(avctx, AV_LOG_ERROR, "Encoder_Interface_init error\n"); |
| 1297 | 205 return -1; |
| 206 } | |
| 207 | |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
208 if ((s->enc_bitrate = getBitrateMode(avctx->bit_rate)) < 0) { |
|
4793
e69d9ecaaf84
Print a list of valid AMR bitrates if a wrong one is used.
diego
parents:
4789
diff
changeset
|
209 av_log(avctx, AV_LOG_ERROR, nb_bitrate_unsupported); |
| 4744 | 210 return -1; |
| 211 } | |
| 1297 | 212 |
| 213 return 0; | |
| 214 } | |
| 215 | |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
216 static av_cold int amr_nb_encode_close(AVCodecContext *avctx) |
| 1297 | 217 { |
| 218 AMRContext *s = avctx->priv_data; | |
| 4633 | 219 |
| 1297 | 220 Encoder_Interface_exit(s->enstate); |
| 221 av_freep(&avctx->coded_frame); | |
| 222 return 0; | |
| 223 } | |
| 224 | |
| 225 static int amr_nb_encode_frame(AVCodecContext *avctx, | |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
226 unsigned char *frame/*out*/, |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
227 int buf_size, void *data/*in*/) |
| 1297 | 228 { |
|
4634
8b96c50c6723
Remove useless casts as recommended by M?ns Rullg?rd.
takis
parents:
4633
diff
changeset
|
229 AMRContext *s = avctx->priv_data; |
| 1297 | 230 int written; |
| 231 | |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
232 if ((s->enc_bitrate = getBitrateMode(avctx->bit_rate)) < 0) { |
|
4793
e69d9ecaaf84
Print a list of valid AMR bitrates if a wrong one is used.
diego
parents:
4789
diff
changeset
|
233 av_log(avctx, AV_LOG_ERROR, nb_bitrate_unsupported); |
| 4744 | 234 return -1; |
| 235 } | |
|
4220
4115a044e31d
allow amr bitrate to be changed "on the fly" through avctx->bitrate.
gpoirier
parents:
4094
diff
changeset
|
236 |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
237 written = Encoder_Interface_Encode(s->enstate, s->enc_bitrate, data, |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
238 frame, 0); |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
239 /* av_log(NULL, AV_LOG_DEBUG, "amr_nb_encode_frame encoded %u bytes, bitrate %u, first byte was %#02x\n", |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
240 written, s->enc_bitrate, frame[0] ); */ |
| 1297 | 241 |
| 242 return written; | |
| 243 } | |
| 244 | |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
245 AVCodec libamr_nb_encoder = { |
|
4898
3df69e140c33
Give libamr decoders/encoders a lib prefix in the name.
diego
parents:
4858
diff
changeset
|
246 "libamr_nb", |
| 1297 | 247 CODEC_TYPE_AUDIO, |
| 248 CODEC_ID_AMR_NB, | |
| 249 sizeof(AMRContext), | |
| 250 amr_nb_encode_init, | |
| 251 amr_nb_encode_frame, | |
| 252 amr_nb_encode_close, | |
| 253 NULL, | |
|
7451
85ab7655ad4d
Modify all codecs to report their supported input and output sample format(s).
pross
parents:
7040
diff
changeset
|
254 .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, |
|
7040
e943e1409077
Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents:
6750
diff
changeset
|
255 .long_name = NULL_IF_CONFIG_SMALL("libamr-nb Adaptive Multi-Rate (AMR) Narrow-Band"), |
| 1297 | 256 }; |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
257 |
| 2895 | 258 #endif |
| 259 | |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
260 /* -----------AMR wideband ------------*/ |
| 8590 | 261 #if CONFIG_LIBAMR_WB |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
262 |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
263 #ifdef _TYPEDEF_H |
| 6186 | 264 //To avoid duplicate typedefs from typedef in amr-nb |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
265 #define typedef_h |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
266 #endif |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
267 |
|
4843
0e11f292482f
Replace hackish support for amr-nb and amr-wb. Instead of including the source
diego
parents:
4842
diff
changeset
|
268 #include <amrwb/dec_if.h> |
|
0e11f292482f
Replace hackish support for amr-nb and amr-wb. Instead of including the source
diego
parents:
4842
diff
changeset
|
269 #include <amrwb/if_rom.h> |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
270 |
|
9669
09b3564c17e5
cosmetics: Move AMR-WB-specific code to the AMR-WB part of the file.
diego
parents:
9656
diff
changeset
|
271 static const char wb_bitrate_unsupported[] = |
|
09b3564c17e5
cosmetics: Move AMR-WB-specific code to the AMR-WB part of the file.
diego
parents:
9656
diff
changeset
|
272 "bitrate not supported: use one of 6.6k, 8.85k, 12.65k, 14.25k, 15.85k, 18.25k, 19.85k, 23.05k, or 23.85k\n"; |
|
09b3564c17e5
cosmetics: Move AMR-WB-specific code to the AMR-WB part of the file.
diego
parents:
9656
diff
changeset
|
273 |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
274 typedef struct AMRWB_bitrates { |
| 4744 | 275 int rate; |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
276 int mode; |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
277 } AMRWB_bitrates; |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
278 |
|
9652
356079de3642
cosmetics: Move some more code around to avoid #ifdeffery.
diego
parents:
9651
diff
changeset
|
279 typedef struct AMRWBContext { |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
280 int frameCount; |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
281 void *state; |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
282 int mode; |
|
9652
356079de3642
cosmetics: Move some more code around to avoid #ifdeffery.
diego
parents:
9651
diff
changeset
|
283 Word16 allow_dtx; |
|
356079de3642
cosmetics: Move some more code around to avoid #ifdeffery.
diego
parents:
9651
diff
changeset
|
284 } AMRWBContext; |
|
356079de3642
cosmetics: Move some more code around to avoid #ifdeffery.
diego
parents:
9651
diff
changeset
|
285 |
|
9653
a572a4628a5a
Surround AMR_WB encoding code by appropriate #ifdefs.
diego
parents:
9652
diff
changeset
|
286 #if CONFIG_LIBAMR_WB_ENCODER |
|
a572a4628a5a
Surround AMR_WB encoding code by appropriate #ifdefs.
diego
parents:
9652
diff
changeset
|
287 |
|
9652
356079de3642
cosmetics: Move some more code around to avoid #ifdeffery.
diego
parents:
9651
diff
changeset
|
288 #include <amrwb/enc_if.h> |
|
356079de3642
cosmetics: Move some more code around to avoid #ifdeffery.
diego
parents:
9651
diff
changeset
|
289 |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
290 static int getWBBitrateMode(int bitrate) |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
291 { |
| 4744 | 292 /* make the correspondance between bitrate and mode */ |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
293 AMRWB_bitrates rates[] = { { 6600, 0}, |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
294 { 8850, 1}, |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
295 {12650, 2}, |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
296 {14250, 3}, |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
297 {15850, 4}, |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
298 {18250, 5}, |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
299 {19850, 6}, |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
300 {23050, 7}, |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
301 {23850, 8}, }; |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
302 int i; |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
303 |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
304 for (i = 0; i < 9; i++) |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
305 if (rates[i].rate == bitrate) |
| 6750 | 306 return rates[i].mode; |
| 4744 | 307 /* no bitrate matching, return an error */ |
| 308 return -1; | |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
309 } |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
310 |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
311 static av_cold int amr_wb_encode_init(AVCodecContext *avctx) |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
312 { |
|
4634
8b96c50c6723
Remove useless casts as recommended by M?ns Rullg?rd.
takis
parents:
4633
diff
changeset
|
313 AMRWBContext *s = avctx->priv_data; |
| 4633 | 314 |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
315 s->frameCount = 0; |
| 2967 | 316 |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
317 if (avctx->sample_rate != 16000) { |
|
4309
1f95aa362562
always print message when error, AV_LOG_DEBUG -> AV_LOG_ERROR
bcoudurier
parents:
4221
diff
changeset
|
318 av_log(avctx, AV_LOG_ERROR, "Only 16000Hz sample rate supported\n"); |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
319 return -1; |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
320 } |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
321 |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
322 if (avctx->channels != 1) { |
|
4309
1f95aa362562
always print message when error, AV_LOG_DEBUG -> AV_LOG_ERROR
bcoudurier
parents:
4221
diff
changeset
|
323 av_log(avctx, AV_LOG_ERROR, "Only mono supported\n"); |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
324 return -1; |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
325 } |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
326 |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
327 if ((s->mode = getWBBitrateMode(avctx->bit_rate)) < 0) { |
|
4793
e69d9ecaaf84
Print a list of valid AMR bitrates if a wrong one is used.
diego
parents:
4789
diff
changeset
|
328 av_log(avctx, AV_LOG_ERROR, wb_bitrate_unsupported); |
| 4744 | 329 return -1; |
| 330 } | |
| 331 | |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
332 avctx->frame_size = 320; |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
333 avctx->coded_frame = avcodec_alloc_frame(); |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
334 |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
335 s->state = E_IF_init(); |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
336 s->allow_dtx = 0; |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
337 |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
338 return 0; |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
339 } |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
340 |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
341 static int amr_wb_encode_close(AVCodecContext *avctx) |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
342 { |
|
4634
8b96c50c6723
Remove useless casts as recommended by M?ns Rullg?rd.
takis
parents:
4633
diff
changeset
|
343 AMRWBContext *s = avctx->priv_data; |
| 4633 | 344 |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
345 E_IF_exit(s->state); |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
346 av_freep(&avctx->coded_frame); |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
347 s->frameCount++; |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
348 return 0; |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
349 } |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
350 |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
351 static int amr_wb_encode_frame(AVCodecContext *avctx, |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
352 unsigned char *frame/*out*/, |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
353 int buf_size, void *data/*in*/) |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
354 { |
|
4634
8b96c50c6723
Remove useless casts as recommended by M?ns Rullg?rd.
takis
parents:
4633
diff
changeset
|
355 AMRWBContext *s = avctx->priv_data; |
|
4220
4115a044e31d
allow amr bitrate to be changed "on the fly" through avctx->bitrate.
gpoirier
parents:
4094
diff
changeset
|
356 int size; |
|
4632
260b5f667458
Move the initialization on context definition. In amr.c, only the
takis
parents:
4575
diff
changeset
|
357 |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
358 if ((s->mode = getWBBitrateMode(avctx->bit_rate)) < 0) { |
|
4793
e69d9ecaaf84
Print a list of valid AMR bitrates if a wrong one is used.
diego
parents:
4789
diff
changeset
|
359 av_log(avctx, AV_LOG_ERROR, wb_bitrate_unsupported); |
| 4744 | 360 return -1; |
| 361 } | |
|
4220
4115a044e31d
allow amr bitrate to be changed "on the fly" through avctx->bitrate.
gpoirier
parents:
4094
diff
changeset
|
362 size = E_IF_encode(s->state, s->mode, data, frame, s->allow_dtx); |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
363 return size; |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
364 } |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
365 |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
366 AVCodec libamr_wb_encoder = { |
|
9651
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
367 "libamr_wb", |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
368 CODEC_TYPE_AUDIO, |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
369 CODEC_ID_AMR_WB, |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
370 sizeof(AMRWBContext), |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
371 amr_wb_encode_init, |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
372 amr_wb_encode_frame, |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
373 amr_wb_encode_close, |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
374 NULL, |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
375 .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
376 .long_name = NULL_IF_CONFIG_SMALL("libamr-wb Adaptive Multi-Rate (AMR) Wide-Band"), |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
377 }; |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
378 |
|
9653
a572a4628a5a
Surround AMR_WB encoding code by appropriate #ifdefs.
diego
parents:
9652
diff
changeset
|
379 #endif |
|
a572a4628a5a
Surround AMR_WB encoding code by appropriate #ifdefs.
diego
parents:
9652
diff
changeset
|
380 |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
381 static av_cold int amr_wb_decode_init(AVCodecContext *avctx) |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
382 { |
|
4634
8b96c50c6723
Remove useless casts as recommended by M?ns Rullg?rd.
takis
parents:
4633
diff
changeset
|
383 AMRWBContext *s = avctx->priv_data; |
| 4633 | 384 |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
385 s->frameCount = 0; |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
386 s->state = D_IF_init(); |
| 4094 | 387 |
| 388 amr_decode_fix_avctx(avctx); | |
| 389 | |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
390 if (avctx->channels > 1) { |
| 4094 | 391 av_log(avctx, AV_LOG_ERROR, "amr_wb: multichannel decoding not supported\n"); |
| 392 return -1; | |
| 393 } | |
| 394 | |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
395 return 0; |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
396 } |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
397 |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
398 static int amr_wb_decode_frame(AVCodecContext *avctx, void *data, |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
399 int *data_size, AVPacket *avpkt) |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
400 { |
|
9355
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
9007
diff
changeset
|
401 const uint8_t *buf = avpkt->data; |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
402 int buf_size = avpkt->size; |
|
4634
8b96c50c6723
Remove useless casts as recommended by M?ns Rullg?rd.
takis
parents:
4633
diff
changeset
|
403 AMRWBContext *s = avctx->priv_data; |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
404 const uint8_t *amrData = buf; |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
405 int mode; |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
406 int packet_size; |
| 9677 | 407 static const uint8_t block_size[16] = {18, 24, 33, 37, 41, 47, 51, 59, 61, 6, 6, 0, 0, 0, 1, 1}; |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
408 |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
409 if (!buf_size) |
|
2287
679642dc54cf
segfault in amr decoder fix patch by (Richard van der Hoff - richvdh0)
michael
parents:
2028
diff
changeset
|
410 /* nothing to do */ |
|
679642dc54cf
segfault in amr decoder fix patch by (Richard van der Hoff - richvdh0)
michael
parents:
2028
diff
changeset
|
411 return 0; |
|
679642dc54cf
segfault in amr decoder fix patch by (Richard van der Hoff - richvdh0)
michael
parents:
2028
diff
changeset
|
412 |
|
679642dc54cf
segfault in amr decoder fix patch by (Richard van der Hoff - richvdh0)
michael
parents:
2028
diff
changeset
|
413 mode = (amrData[0] >> 3) & 0x000F; |
|
679642dc54cf
segfault in amr decoder fix patch by (Richard van der Hoff - richvdh0)
michael
parents:
2028
diff
changeset
|
414 packet_size = block_size[mode]; |
|
679642dc54cf
segfault in amr decoder fix patch by (Richard van der Hoff - richvdh0)
michael
parents:
2028
diff
changeset
|
415 |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
416 if (packet_size > buf_size) { |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
417 av_log(avctx, AV_LOG_ERROR, "amr frame too short (%u, should be %u)\n", |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
418 buf_size, packet_size + 1); |
|
2287
679642dc54cf
segfault in amr decoder fix patch by (Richard van der Hoff - richvdh0)
michael
parents:
2028
diff
changeset
|
419 return -1; |
|
679642dc54cf
segfault in amr decoder fix patch by (Richard van der Hoff - richvdh0)
michael
parents:
2028
diff
changeset
|
420 } |
| 2967 | 421 |
|
2287
679642dc54cf
segfault in amr decoder fix patch by (Richard van der Hoff - richvdh0)
michael
parents:
2028
diff
changeset
|
422 s->frameCount++; |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
423 D_IF_decode(s->state, amrData, data, _good_frame); |
|
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
424 *data_size = 320 * 2; |
|
2287
679642dc54cf
segfault in amr decoder fix patch by (Richard van der Hoff - richvdh0)
michael
parents:
2028
diff
changeset
|
425 return packet_size; |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
426 } |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
427 |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
428 static int amr_wb_decode_close(AVCodecContext *avctx) |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
429 { |
|
4634
8b96c50c6723
Remove useless casts as recommended by M?ns Rullg?rd.
takis
parents:
4633
diff
changeset
|
430 AMRWBContext *s = avctx->priv_data; |
| 4633 | 431 |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
432 D_IF_exit(s->state); |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
433 return 0; |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
434 } |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
435 |
|
9656
03361db4df10
cosmetics: K&R coding style, indent correctly, break overly long lines
diego
parents:
9655
diff
changeset
|
436 AVCodec libamr_wb_decoder = { |
|
4898
3df69e140c33
Give libamr decoders/encoders a lib prefix in the name.
diego
parents:
4858
diff
changeset
|
437 "libamr_wb", |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
438 CODEC_TYPE_AUDIO, |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
439 CODEC_ID_AMR_WB, |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
440 sizeof(AMRWBContext), |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
441 amr_wb_decode_init, |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
442 NULL, |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
443 amr_wb_decode_close, |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
444 amr_wb_decode_frame, |
|
7040
e943e1409077
Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents:
6750
diff
changeset
|
445 .long_name = NULL_IF_CONFIG_SMALL("libamr-wb Adaptive Multi-Rate (AMR) Wide-Band"), |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
446 }; |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
447 |
|
4898
3df69e140c33
Give libamr decoders/encoders a lib prefix in the name.
diego
parents:
4858
diff
changeset
|
448 #endif //CONFIG_LIBAMR_WB |
