Mercurial > libavcodec.hg
annotate libamr.c @ 9651:e5ea408f6e2a libavcodec
cosmetics: Move functions around so that encoding and decoding functions are
grouped together. This will save some #ifdefs.
| author | diego |
|---|---|
| date | Fri, 15 May 2009 17:34:26 +0000 |
| parents | 531474d55492 |
| children | 356079de3642 |
| 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 | |
| 28 * have to download the code separately. Two versions exists: One fixed-point | |
| 4857 | 29 * and one floating-point. For some reason the float encoder is significantly |
| 30 * faster at least on a P4 1.5GHz (0.9s instead of 9.9s on a 30s audio clip | |
| 31 * at MR102). Both float and fixed point are supported for AMR-NB, but only | |
| 32 * float for AMR-WB. | |
| 4575 | 33 * |
| 34 * \section AMR-NB | |
| 35 * | |
| 36 * \subsection Float | |
| 37 * The float version (default) can be downloaded from: | |
|
4746
4aedb3b6fa4e
Update specification and reference implementation links.
diego
parents:
4744
diff
changeset
|
38 * http://www.3gpp.org/ftp/Specs/archive/26_series/26.104/26104-610.zip |
| 4575 | 39 * |
| 40 * \subsection Specification | |
| 41 * The specification for AMR-NB can be found in TS 26.071 | |
| 42 * (http://www.3gpp.org/ftp/Specs/html-info/26071.htm) and some other | |
| 43 * info at http://www.3gpp.org/ftp/Specs/html-info/26-series.htm. | |
| 44 * | |
| 45 * \section AMR-WB | |
|
4858
3e38885a28bc
Remove the build instructions from the doxygen comments, they are duplicated
diego
parents:
4857
diff
changeset
|
46 * |
| 4575 | 47 * \subsection Float |
| 48 * The reference code can be downloaded from: | |
|
4746
4aedb3b6fa4e
Update specification and reference implementation links.
diego
parents:
4744
diff
changeset
|
49 * http://www.3gpp.org/ftp/Specs/archive/26_series/26.204/26204-600.zip |
| 4575 | 50 * |
| 51 * \subsection Specification | |
|
4746
4aedb3b6fa4e
Update specification and reference implementation links.
diego
parents:
4744
diff
changeset
|
52 * The specification for AMR-WB can be found in TS 26.171 |
|
4aedb3b6fa4e
Update specification and reference implementation links.
diego
parents:
4744
diff
changeset
|
53 * (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
|
54 * info at http://www.3gpp.org/ftp/Specs/html-info/26-series.htm. |
| 4575 | 55 * |
| 1297 | 56 */ |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
57 |
| 1297 | 58 #include "avcodec.h" |
| 59 | |
|
4843
0e11f292482f
Replace hackish support for amr-nb and amr-wb. Instead of including the source
diego
parents:
4842
diff
changeset
|
60 #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
|
61 #include <amrnb/interf_enc.h> |
| 1297 | 62 |
|
8347
81238f0bea66
Fix warning "format not a string literal and no format arguments".
benoit
parents:
7451
diff
changeset
|
63 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
|
64 "bitrate not supported: use one of 4.75k, 5.15k, 5.9k, 6.7k, 7.4k, 7.95k, 10.2k or 12.2k\n"; |
|
8347
81238f0bea66
Fix warning "format not a string literal and no format arguments".
benoit
parents:
7451
diff
changeset
|
65 static const char wb_bitrate_unsupported[] = |
|
4793
e69d9ecaaf84
Print a list of valid AMR bitrates if a wrong one is used.
diego
parents:
4789
diff
changeset
|
66 "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"; |
|
e69d9ecaaf84
Print a list of valid AMR bitrates if a wrong one is used.
diego
parents:
4789
diff
changeset
|
67 |
| 1297 | 68 /* Common code for fixed and float version*/ |
| 69 typedef struct AMR_bitrates | |
| 70 { | |
| 4744 | 71 int rate; |
| 1297 | 72 enum Mode mode; |
| 73 } AMR_bitrates; | |
| 74 | |
| 4744 | 75 /* Match desired bitrate */ |
| 76 static int getBitrateMode(int bitrate) | |
| 1297 | 77 { |
| 4744 | 78 /* make the correspondance between bitrate and mode */ |
| 79 AMR_bitrates rates[]={ {4750,MR475}, | |
| 80 {5150,MR515}, | |
| 81 {5900,MR59}, | |
| 82 {6700,MR67}, | |
| 83 {7400,MR74}, | |
| 84 {7950,MR795}, | |
| 85 {10200,MR102}, | |
| 86 {12200,MR122}, | |
| 1297 | 87 }; |
| 88 int i; | |
| 4633 | 89 |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
90 for(i=0;i<8;i++) |
| 1297 | 91 { |
| 4744 | 92 if(rates[i].rate==bitrate) |
| 1297 | 93 { |
| 6750 | 94 return rates[i].mode; |
| 1297 | 95 } |
| 96 } | |
| 4744 | 97 /* no bitrate matching, return an error */ |
| 98 return -1; | |
| 1297 | 99 } |
| 100 | |
| 4094 | 101 static void amr_decode_fix_avctx(AVCodecContext * avctx) |
| 102 { | |
| 103 const int is_amr_wb = 1 + (avctx->codec_id == CODEC_ID_AMR_WB); | |
| 104 | |
| 105 if(avctx->sample_rate == 0) | |
| 106 { | |
| 107 avctx->sample_rate = 8000 * is_amr_wb; | |
| 108 } | |
| 109 | |
| 110 if(avctx->channels == 0) | |
| 111 { | |
| 112 avctx->channels = 1; | |
| 113 } | |
| 114 | |
| 115 avctx->frame_size = 160 * is_amr_wb; | |
|
7451
85ab7655ad4d
Modify all codecs to report their supported input and output sample format(s).
pross
parents:
7040
diff
changeset
|
116 avctx->sample_fmt = SAMPLE_FMT_S16; |
| 4094 | 117 } |
| 118 | |
| 9582 | 119 #if CONFIG_LIBAMR_NB |
| 1297 | 120 |
| 121 typedef struct AMRContext { | |
| 122 int frameCount; | |
| 123 void * decState; | |
| 124 int *enstate; | |
| 4744 | 125 int enc_bitrate; |
| 1297 | 126 } AMRContext; |
| 127 | |
|
9007
043574c5c153
Add missing av_cold in static init/close functions.
stefano
parents:
8590
diff
changeset
|
128 static av_cold int amr_nb_decode_init(AVCodecContext * avctx) |
| 1297 | 129 { |
| 130 AMRContext *s = avctx->priv_data; | |
| 4633 | 131 |
| 1297 | 132 s->frameCount=0; |
| 133 s->decState=Decoder_Interface_init(); | |
| 134 if(!s->decState) | |
| 135 { | |
| 1825 | 136 av_log(avctx, AV_LOG_ERROR, "Decoder_Interface_init error\r\n"); |
| 1297 | 137 return -1; |
| 138 } | |
| 4094 | 139 |
| 140 amr_decode_fix_avctx(avctx); | |
| 141 | |
| 142 if(avctx->channels > 1) | |
| 143 { | |
| 144 av_log(avctx, AV_LOG_ERROR, "amr_nb: multichannel decoding not supported\n"); | |
| 145 return -1; | |
| 146 } | |
| 147 | |
| 1297 | 148 return 0; |
| 149 } | |
| 150 | |
|
9651
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
151 static av_cold int amr_nb_decode_close(AVCodecContext * avctx) |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
152 { |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
153 AMRContext *s = avctx->priv_data; |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
154 |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
155 Decoder_Interface_exit(s->decState); |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
156 return 0; |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
157 } |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
158 |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
159 static int amr_nb_decode_frame(AVCodecContext * avctx, |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
160 void *data, int *data_size, |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
161 AVPacket *avpkt) |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
162 { |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
163 const uint8_t *buf = avpkt->data; |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
164 int buf_size = avpkt->size; |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
165 AMRContext *s = avctx->priv_data; |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
166 const uint8_t*amrData=buf; |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
167 static const uint8_t block_size[16]={ 12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0 }; |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
168 enum Mode dec_mode; |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
169 int packet_size; |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
170 |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
171 /* av_log(NULL,AV_LOG_DEBUG,"amr_decode_frame buf=%p buf_size=%d frameCount=%d!!\n",buf,buf_size,s->frameCount); */ |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
172 |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
173 dec_mode = (buf[0] >> 3) & 0x000F; |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
174 packet_size = block_size[dec_mode]+1; |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
175 |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
176 if(packet_size > buf_size) { |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
177 av_log(avctx, AV_LOG_ERROR, "amr frame too short (%u, should be %u)\n", buf_size, packet_size); |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
178 return -1; |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
179 } |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
180 |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
181 s->frameCount++; |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
182 /* av_log(NULL,AV_LOG_DEBUG,"packet_size=%d amrData= 0x%X %X %X %X\n",packet_size,amrData[0],amrData[1],amrData[2],amrData[3]); */ |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
183 /* call decoder */ |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
184 Decoder_Interface_Decode(s->decState, amrData, data, 0); |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
185 *data_size=160*2; |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
186 |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
187 return packet_size; |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
188 } |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
189 |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
190 AVCodec libamr_nb_decoder = |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
191 { |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
192 "libamr_nb", |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
193 CODEC_TYPE_AUDIO, |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
194 CODEC_ID_AMR_NB, |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
195 sizeof(AMRContext), |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
196 amr_nb_decode_init, |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
197 NULL, |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
198 amr_nb_decode_close, |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
199 amr_nb_decode_frame, |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
200 .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
|
201 }; |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
202 |
|
9007
043574c5c153
Add missing av_cold in static init/close functions.
stefano
parents:
8590
diff
changeset
|
203 static av_cold int amr_nb_encode_init(AVCodecContext * avctx) |
| 1297 | 204 { |
| 205 AMRContext *s = avctx->priv_data; | |
| 4633 | 206 |
| 1297 | 207 s->frameCount=0; |
| 2967 | 208 |
| 1297 | 209 if(avctx->sample_rate!=8000) |
| 210 { | |
|
4309
1f95aa362562
always print message when error, AV_LOG_DEBUG -> AV_LOG_ERROR
bcoudurier
parents:
4221
diff
changeset
|
211 av_log(avctx, AV_LOG_ERROR, "Only 8000Hz sample rate supported\n"); |
| 1297 | 212 return -1; |
| 213 } | |
| 214 | |
| 215 if(avctx->channels!=1) | |
| 216 { | |
|
4309
1f95aa362562
always print message when error, AV_LOG_DEBUG -> AV_LOG_ERROR
bcoudurier
parents:
4221
diff
changeset
|
217 av_log(avctx, AV_LOG_ERROR, "Only mono supported\n"); |
| 1297 | 218 return -1; |
| 219 } | |
| 220 | |
| 221 avctx->frame_size=160; | |
| 222 avctx->coded_frame= avcodec_alloc_frame(); | |
| 223 | |
| 224 s->enstate=Encoder_Interface_init(0); | |
| 225 if(!s->enstate) | |
| 226 { | |
|
4309
1f95aa362562
always print message when error, AV_LOG_DEBUG -> AV_LOG_ERROR
bcoudurier
parents:
4221
diff
changeset
|
227 av_log(avctx, AV_LOG_ERROR, "Encoder_Interface_init error\n"); |
| 1297 | 228 return -1; |
| 229 } | |
| 230 | |
| 4744 | 231 if((s->enc_bitrate=getBitrateMode(avctx->bit_rate))<0) |
| 232 { | |
|
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 } | |
| 1297 | 236 |
| 237 return 0; | |
| 238 } | |
| 239 | |
|
9007
043574c5c153
Add missing av_cold in static init/close functions.
stefano
parents:
8590
diff
changeset
|
240 static av_cold int amr_nb_encode_close(AVCodecContext * avctx) |
| 1297 | 241 { |
| 242 AMRContext *s = avctx->priv_data; | |
| 4633 | 243 |
| 1297 | 244 Encoder_Interface_exit(s->enstate); |
| 245 av_freep(&avctx->coded_frame); | |
| 246 return 0; | |
| 247 } | |
| 248 | |
| 249 static int amr_nb_encode_frame(AVCodecContext *avctx, | |
| 2979 | 250 unsigned char *frame/*out*/, int buf_size, void *data/*in*/) |
| 1297 | 251 { |
|
4634
8b96c50c6723
Remove useless casts as recommended by M?ns Rullg?rd.
takis
parents:
4633
diff
changeset
|
252 AMRContext *s = avctx->priv_data; |
| 1297 | 253 int written; |
| 254 | |
| 4744 | 255 if((s->enc_bitrate=getBitrateMode(avctx->bit_rate))<0) |
| 256 { | |
|
4793
e69d9ecaaf84
Print a list of valid AMR bitrates if a wrong one is used.
diego
parents:
4789
diff
changeset
|
257 av_log(avctx, AV_LOG_ERROR, nb_bitrate_unsupported); |
| 4744 | 258 return -1; |
| 259 } | |
|
4220
4115a044e31d
allow amr bitrate to be changed "on the fly" through avctx->bitrate.
gpoirier
parents:
4094
diff
changeset
|
260 |
| 2967 | 261 written = Encoder_Interface_Encode(s->enstate, |
| 262 s->enc_bitrate, | |
| 263 data, | |
| 264 frame, | |
| 1297 | 265 0); |
|
2571
b17d868a8f39
04_AMR_no_debug_output.patch by (Calcium | calcium nurs or jp)
michael
parents:
2287
diff
changeset
|
266 /* av_log(NULL,AV_LOG_DEBUG,"amr_nb_encode_frame encoded %u bytes, bitrate %u, first byte was %#02x\n",written, s->enc_bitrate, frame[0] ); */ |
| 1297 | 267 |
| 268 return written; | |
| 269 } | |
| 270 | |
|
4898
3df69e140c33
Give libamr decoders/encoders a lib prefix in the name.
diego
parents:
4858
diff
changeset
|
271 AVCodec libamr_nb_encoder = |
| 1297 | 272 { |
|
4898
3df69e140c33
Give libamr decoders/encoders a lib prefix in the name.
diego
parents:
4858
diff
changeset
|
273 "libamr_nb", |
| 1297 | 274 CODEC_TYPE_AUDIO, |
| 275 CODEC_ID_AMR_NB, | |
| 276 sizeof(AMRContext), | |
| 277 amr_nb_encode_init, | |
| 278 amr_nb_encode_frame, | |
| 279 amr_nb_encode_close, | |
| 280 NULL, | |
|
7451
85ab7655ad4d
Modify all codecs to report their supported input and output sample format(s).
pross
parents:
7040
diff
changeset
|
281 .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
|
282 .long_name = NULL_IF_CONFIG_SMALL("libamr-nb Adaptive Multi-Rate (AMR) Narrow-Band"), |
| 1297 | 283 }; |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
284 |
| 2895 | 285 #endif |
| 286 | |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
287 /* -----------AMR wideband ------------*/ |
| 8590 | 288 #if CONFIG_LIBAMR_WB |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
289 |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
290 #ifdef _TYPEDEF_H |
| 6186 | 291 //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
|
292 #define typedef_h |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
293 #endif |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
294 |
|
4843
0e11f292482f
Replace hackish support for amr-nb and amr-wb. Instead of including the source
diego
parents:
4842
diff
changeset
|
295 #include <amrwb/enc_if.h> |
|
0e11f292482f
Replace hackish support for amr-nb and amr-wb. Instead of including the source
diego
parents:
4842
diff
changeset
|
296 #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
|
297 #include <amrwb/if_rom.h> |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
298 |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
299 /* Common code for fixed and float version*/ |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
300 typedef struct AMRWB_bitrates |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
301 { |
| 4744 | 302 int rate; |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
303 int mode; |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
304 } AMRWB_bitrates; |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
305 |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
306 static int getWBBitrateMode(int bitrate) |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
307 { |
| 4744 | 308 /* make the correspondance between bitrate and mode */ |
| 309 AMRWB_bitrates rates[]={ {6600,0}, | |
| 310 {8850,1}, | |
| 311 {12650,2}, | |
| 312 {14250,3}, | |
| 313 {15850,4}, | |
| 314 {18250,5}, | |
| 315 {19850,6}, | |
| 316 {23050,7}, | |
| 317 {23850,8}, | |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
318 }; |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
319 int i; |
|
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 for(i=0;i<9;i++) |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
322 { |
| 4744 | 323 if(rates[i].rate==bitrate) |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
324 { |
| 6750 | 325 return rates[i].mode; |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
326 } |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
327 } |
| 4744 | 328 /* no bitrate matching, return an error */ |
| 329 return -1; | |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
330 } |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
331 |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
332 |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
333 typedef struct AMRWBContext { |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
334 int frameCount; |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
335 void *state; |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
336 int mode; |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
337 Word16 allow_dtx; |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
338 } AMRWBContext; |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
339 |
|
9649
2d4718adf588
Add av_cold attribute to amr_nb decoding/encoding initialization functions.
diego
parents:
9582
diff
changeset
|
340 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
|
341 { |
|
4634
8b96c50c6723
Remove useless casts as recommended by M?ns Rullg?rd.
takis
parents:
4633
diff
changeset
|
342 AMRWBContext *s = avctx->priv_data; |
| 4633 | 343 |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
344 s->frameCount=0; |
| 2967 | 345 |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
346 if(avctx->sample_rate!=16000) |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
347 { |
|
4309
1f95aa362562
always print message when error, AV_LOG_DEBUG -> AV_LOG_ERROR
bcoudurier
parents:
4221
diff
changeset
|
348 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
|
349 return -1; |
|
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 |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
352 if(avctx->channels!=1) |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
353 { |
|
4309
1f95aa362562
always print message when error, AV_LOG_DEBUG -> AV_LOG_ERROR
bcoudurier
parents:
4221
diff
changeset
|
354 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
|
355 return -1; |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
356 } |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
357 |
| 4744 | 358 if((s->mode=getWBBitrateMode(avctx->bit_rate))<0) |
| 359 { | |
|
4793
e69d9ecaaf84
Print a list of valid AMR bitrates if a wrong one is used.
diego
parents:
4789
diff
changeset
|
360 av_log(avctx, AV_LOG_ERROR, wb_bitrate_unsupported); |
| 4744 | 361 return -1; |
| 362 } | |
| 363 | |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
364 avctx->frame_size=320; |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
365 avctx->coded_frame= avcodec_alloc_frame(); |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
366 |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
367 s->state = E_IF_init(); |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
368 s->allow_dtx=0; |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
369 |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
370 return 0; |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
371 } |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
372 |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
373 static int amr_wb_encode_close(AVCodecContext * avctx) |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
374 { |
|
4634
8b96c50c6723
Remove useless casts as recommended by M?ns Rullg?rd.
takis
parents:
4633
diff
changeset
|
375 AMRWBContext *s = avctx->priv_data; |
| 4633 | 376 |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
377 E_IF_exit(s->state); |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
378 av_freep(&avctx->coded_frame); |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
379 s->frameCount++; |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
380 return 0; |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
381 } |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
382 |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
383 static int amr_wb_encode_frame(AVCodecContext *avctx, |
| 2979 | 384 unsigned char *frame/*out*/, int buf_size, void *data/*in*/) |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
385 { |
|
4634
8b96c50c6723
Remove useless casts as recommended by M?ns Rullg?rd.
takis
parents:
4633
diff
changeset
|
386 AMRWBContext *s = avctx->priv_data; |
|
4220
4115a044e31d
allow amr bitrate to be changed "on the fly" through avctx->bitrate.
gpoirier
parents:
4094
diff
changeset
|
387 int size; |
|
4632
260b5f667458
Move the initialization on context definition. In amr.c, only the
takis
parents:
4575
diff
changeset
|
388 |
| 4744 | 389 if((s->mode=getWBBitrateMode(avctx->bit_rate))<0) |
| 390 { | |
|
4793
e69d9ecaaf84
Print a list of valid AMR bitrates if a wrong one is used.
diego
parents:
4789
diff
changeset
|
391 av_log(avctx, AV_LOG_ERROR, wb_bitrate_unsupported); |
| 4744 | 392 return -1; |
| 393 } | |
|
4220
4115a044e31d
allow amr bitrate to be changed "on the fly" through avctx->bitrate.
gpoirier
parents:
4094
diff
changeset
|
394 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
|
395 return size; |
|
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 |
|
9651
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
398 AVCodec libamr_wb_encoder = |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
399 { |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
400 "libamr_wb", |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
401 CODEC_TYPE_AUDIO, |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
402 CODEC_ID_AMR_WB, |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
403 sizeof(AMRWBContext), |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
404 amr_wb_encode_init, |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
405 amr_wb_encode_frame, |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
406 amr_wb_encode_close, |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
407 NULL, |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
408 .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
|
409 .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
|
410 }; |
|
e5ea408f6e2a
cosmetics: Move functions around so that encoding and decoding functions are
diego
parents:
9650
diff
changeset
|
411 |
|
9649
2d4718adf588
Add av_cold attribute to amr_nb decoding/encoding initialization functions.
diego
parents:
9582
diff
changeset
|
412 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
|
413 { |
|
4634
8b96c50c6723
Remove useless casts as recommended by M?ns Rullg?rd.
takis
parents:
4633
diff
changeset
|
414 AMRWBContext *s = avctx->priv_data; |
| 4633 | 415 |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
416 s->frameCount=0; |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
417 s->state = D_IF_init(); |
| 4094 | 418 |
| 419 amr_decode_fix_avctx(avctx); | |
| 420 | |
| 421 if(avctx->channels > 1) | |
| 422 { | |
| 423 av_log(avctx, AV_LOG_ERROR, "amr_wb: multichannel decoding not supported\n"); | |
| 424 return -1; | |
| 425 } | |
| 426 | |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
427 return 0; |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
428 } |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
429 |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
430 static int amr_wb_decode_frame(AVCodecContext * avctx, |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
431 void *data, int *data_size, |
|
9355
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
9007
diff
changeset
|
432 AVPacket *avpkt) |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
433 { |
|
9355
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
9007
diff
changeset
|
434 const uint8_t *buf = avpkt->data; |
|
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
9007
diff
changeset
|
435 int buf_size = avpkt->size; |
|
4634
8b96c50c6723
Remove useless casts as recommended by M?ns Rullg?rd.
takis
parents:
4633
diff
changeset
|
436 AMRWBContext *s = avctx->priv_data; |
| 8348 | 437 const uint8_t*amrData=buf; |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
438 int mode; |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
439 int packet_size; |
| 6427 | 440 static const uint8_t block_size[16] = {18, 23, 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
|
441 |
|
2287
679642dc54cf
segfault in amr decoder fix patch by (Richard van der Hoff - richvdh0)
michael
parents:
2028
diff
changeset
|
442 if(buf_size==0) { |
|
679642dc54cf
segfault in amr decoder fix patch by (Richard van der Hoff - richvdh0)
michael
parents:
2028
diff
changeset
|
443 /* nothing to do */ |
|
679642dc54cf
segfault in amr decoder fix patch by (Richard van der Hoff - richvdh0)
michael
parents:
2028
diff
changeset
|
444 return 0; |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
445 } |
|
2287
679642dc54cf
segfault in amr decoder fix patch by (Richard van der Hoff - richvdh0)
michael
parents:
2028
diff
changeset
|
446 |
|
679642dc54cf
segfault in amr decoder fix patch by (Richard van der Hoff - richvdh0)
michael
parents:
2028
diff
changeset
|
447 mode = (amrData[0] >> 3) & 0x000F; |
|
679642dc54cf
segfault in amr decoder fix patch by (Richard van der Hoff - richvdh0)
michael
parents:
2028
diff
changeset
|
448 packet_size = block_size[mode]; |
|
679642dc54cf
segfault in amr decoder fix patch by (Richard van der Hoff - richvdh0)
michael
parents:
2028
diff
changeset
|
449 |
|
679642dc54cf
segfault in amr decoder fix patch by (Richard van der Hoff - richvdh0)
michael
parents:
2028
diff
changeset
|
450 if(packet_size > buf_size) { |
|
679642dc54cf
segfault in amr decoder fix patch by (Richard van der Hoff - richvdh0)
michael
parents:
2028
diff
changeset
|
451 av_log(avctx, AV_LOG_ERROR, "amr frame too short (%u, should be %u)\n", buf_size, packet_size+1); |
|
679642dc54cf
segfault in amr decoder fix patch by (Richard van der Hoff - richvdh0)
michael
parents:
2028
diff
changeset
|
452 return -1; |
|
679642dc54cf
segfault in amr decoder fix patch by (Richard van der Hoff - richvdh0)
michael
parents:
2028
diff
changeset
|
453 } |
| 2967 | 454 |
|
2287
679642dc54cf
segfault in amr decoder fix patch by (Richard van der Hoff - richvdh0)
michael
parents:
2028
diff
changeset
|
455 s->frameCount++; |
|
679642dc54cf
segfault in amr decoder fix patch by (Richard van der Hoff - richvdh0)
michael
parents:
2028
diff
changeset
|
456 D_IF_decode( s->state, amrData, data, _good_frame); |
|
679642dc54cf
segfault in amr decoder fix patch by (Richard van der Hoff - richvdh0)
michael
parents:
2028
diff
changeset
|
457 *data_size=320*2; |
|
679642dc54cf
segfault in amr decoder fix patch by (Richard van der Hoff - richvdh0)
michael
parents:
2028
diff
changeset
|
458 return packet_size; |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
459 } |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
460 |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
461 static int amr_wb_decode_close(AVCodecContext * avctx) |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
462 { |
|
4634
8b96c50c6723
Remove useless casts as recommended by M?ns Rullg?rd.
takis
parents:
4633
diff
changeset
|
463 AMRWBContext *s = avctx->priv_data; |
| 4633 | 464 |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
465 D_IF_exit(s->state); |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
466 return 0; |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
467 } |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
468 |
|
4898
3df69e140c33
Give libamr decoders/encoders a lib prefix in the name.
diego
parents:
4858
diff
changeset
|
469 AVCodec libamr_wb_decoder = |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
470 { |
|
4898
3df69e140c33
Give libamr decoders/encoders a lib prefix in the name.
diego
parents:
4858
diff
changeset
|
471 "libamr_wb", |
|
1486
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
472 CODEC_TYPE_AUDIO, |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
473 CODEC_ID_AMR_WB, |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
474 sizeof(AMRWBContext), |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
475 amr_wb_decode_init, |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
476 NULL, |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
477 amr_wb_decode_close, |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
478 amr_wb_decode_frame, |
|
7040
e943e1409077
Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents:
6750
diff
changeset
|
479 .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
|
480 }; |
|
f22010affdce
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
1297
diff
changeset
|
481 |
|
4898
3df69e140c33
Give libamr decoders/encoders a lib prefix in the name.
diego
parents:
4858
diff
changeset
|
482 #endif //CONFIG_LIBAMR_WB |
