| @@ -38,6 +38,13 @@ typedef struct { · 37 unmodified lines |
| 38 | static const char AMR_header[] = "#!AMR\n"; | 38 | static const char AMR_header[] = "#!AMR\n"; |
| 39 | static const char AMRWB_header[] = "#!AMR-WB\n"; | 39 | static const char AMRWB_header[] = "#!AMR-WB\n"; |
| 40 | | 40 | |
| | 41 | static const uint8_t amrnb_packed_size[16] = { |
| | 42 | 13, 14, 16, 18, 20, 21, 27, 32, 6, 1, 1, 1, 1, 1, 1, 1 |
| | 43 | }; |
| | 44 | static const uint8_t amrwb_packed_size[16] = { |
| | 45 | 18, 24, 33, 37, 41, 47, 51, 59, 61, 6, 1, 1, 1, 1, 1, 1 |
| | 46 | }; |
| | 47 | |
| 41 | #if CONFIG_AMR_MUXER | 48 | #if CONFIG_AMR_MUXER |
| 42 | static int amr_write_header(AVFormatContext *s) | 49 | static int amr_write_header(AVFormatContext *s) |
| 43 | { | 50 | { |
| @@ -126,17 +133,9 @@ static int amr_read_packet(AVFormatContext *s, AVPacket *pkt) · 82 unmodified lines |
| 126 | mode = (toc >> 3) & 0x0F; | 133 | mode = (toc >> 3) & 0x0F; |
| 127 | | 134 | |
| 128 | if (par->codec_id == AV_CODEC_ID_AMR_NB) { | 135 | if (par->codec_id == AV_CODEC_ID_AMR_NB) { |
| 129 | static const uint8_t packed_size[16] = { | 136 | size = amrnb_packed_size[mode]; |
| 130 | 12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0 | | |
| 131 | }; | | |
| 132 | | | |
| 133 | size = packed_size[mode] + 1; | | |
| 134 | } else if (par->codec_id == AV_CODEC_ID_AMR_WB) { | 137 | } else if (par->codec_id == AV_CODEC_ID_AMR_WB) { |
| 135 | static const uint8_t packed_size[16] = { | 138 | size = amrwb_packed_size[mode]; |
| 136 | 18, 24, 33, 37, 41, 47, 51, 59, 61, 6, 6, 0, 0, 0, 1, 1 | | |
| 137 | }; | | |
| 138 | | | |
| 139 | size = packed_size[mode]; | | |
| 140 | } | 139 | } |
| 141 | | 140 | |
| 142 | if (!size || av_new_packet(pkt, size)) | 141 | if (!size || av_new_packet(pkt, size)) |
| @@ -176,6 +175,120 @@ AVInputFormat ff_amr_demuxer = { · 33 unmodified lines |
| 176 | }; | 175 | }; |
| 177 | #endif | 176 | #endif |
| 178 | | 177 | |
| | 178 | #if CONFIG_AMRNB_DEMUXER |
| | 179 | static int amrnb_probe(AVProbeData *p) |
| | 180 | { |
| | 181 | int mode, i = 0, valid = 0; |
| | 182 | const uint8_t *b = p->buf; |
| | 183 | |
| | 184 | while (i < p->buf_size) { |
| | 185 | mode = b[i] >> 3 & 0x0F; |
| | 186 | if (mode < 9 && (b[i] & 0x4) == 0x4) { |
| | 187 | int last = mode; |
| | 188 | int size = amrnb_packed_size[mode]; |
| | 189 | while (size--) { |
| | 190 | if (b[++i] != last) |
| | 191 | break; |
| | 192 | last = b[i]; |
| | 193 | } |
| | 194 | if (size > 0) { |
| | 195 | valid++; |
| | 196 | i += size; |
| | 197 | } |
| | 198 | } else { |
| | 199 | valid = 0; |
| | 200 | i++; |
| | 201 | } |
| | 202 | } |
| | 203 | if (valid > 100) |
| | 204 | return AVPROBE_SCORE_EXTENSION / 2 + 1; |
| | 205 | return 0; |
| | 206 | } |
| | 207 | |
| | 208 | static int amrnb_read_header(AVFormatContext *s) |
| | 209 | { |
| | 210 | AVStream *st = avformat_new_stream(s, NULL); |
| | 211 | if (!st) |
| | 212 | return AVERROR(ENOMEM); |
| | 213 | st->codecpar->codec_tag = MKTAG('s', 'a', 'm', 'r'); |
| | 214 | st->codecpar->codec_id = AV_CODEC_ID_AMR_NB; |
| | 215 | st->codecpar->sample_rate = 8000; |
| | 216 | st->codecpar->channels = 1; |
| | 217 | st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; |
| | 218 | st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; |
| | 219 | avpriv_set_pts_info(st, 64, 1, 8000); |
| | 220 | |
| | 221 | return 0; |
| | 222 | } |
| | 223 | |
| | 224 | AVInputFormat ff_amrnb_demuxer = { |
| | 225 | .name = "amrnb", |
| | 226 | .long_name = NULL_IF_CONFIG_SMALL("raw AMR-NB"), |
| | 227 | .priv_data_size = sizeof(AMRContext), |
| | 228 | .read_probe = amrnb_probe, |
| | 229 | .read_header = amrnb_read_header, |
| | 230 | .read_packet = amr_read_packet, |
| | 231 | .flags = AVFMT_GENERIC_INDEX, |
| | 232 | }; |
| | 233 | #endif |
| | 234 | |
| | 235 | #if CONFIG_AMRWB_DEMUXER |
| | 236 | static int amrwb_probe(AVProbeData *p) |
| | 237 | { |
| | 238 | int mode, i = 0, valid = 0; |
| | 239 | const uint8_t *b = p->buf; |
| | 240 | |
| | 241 | while (i < p->buf_size) { |
| | 242 | mode = b[i] >> 3 & 0x0F; |
| | 243 | if (mode < 10 && (b[i] & 0x4) == 0x4) { |
| | 244 | int last = mode; |
| | 245 | int size = amrwb_packed_size[mode]; |
| | 246 | while (size--) { |
| | 247 | if (b[++i] != last) |
| | 248 | break; |
| | 249 | last = b[i]; |
| | 250 | } |
| | 251 | if (size > 0) { |
| | 252 | valid++; |
| | 253 | i += size; |
| | 254 | } |
| | 255 | } else { |
| | 256 | valid = 0; |
| | 257 | i++; |
| | 258 | } |
| | 259 | } |
| | 260 | if (valid > 100) |
| | 261 | return AVPROBE_SCORE_EXTENSION / 2 - 1; |
| | 262 | return 0; |
| | 263 | } |
| | 264 | |
| | 265 | static int amrwb_read_header(AVFormatContext *s) |
| | 266 | { |
| | 267 | AVStream *st = avformat_new_stream(s, NULL); |
| | 268 | if (!st) |
| | 269 | return AVERROR(ENOMEM); |
| | 270 | st->codecpar->codec_tag = MKTAG('s', 'a', 'w', 'b'); |
| | 271 | st->codecpar->codec_id = AV_CODEC_ID_AMR_WB; |
| | 272 | st->codecpar->sample_rate = 16000; |
| | 273 | st->codecpar->channels = 1; |
| | 274 | st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; |
| | 275 | st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; |
| | 276 | avpriv_set_pts_info(st, 64, 1, 16000); |
| | 277 | |
| | 278 | return 0; |
| | 279 | } |
| | 280 | |
| | 281 | AVInputFormat ff_amrwb_demuxer = { |
| | 282 | .name = "amrwb", |
| | 283 | .long_name = NULL_IF_CONFIG_SMALL("raw AMR-WB"), |
| | 284 | .priv_data_size = sizeof(AMRContext), |
| | 285 | .read_probe = amrwb_probe, |
| | 286 | .read_header = amrwb_read_header, |
| | 287 | .read_packet = amr_read_packet, |
| | 288 | .flags = AVFMT_GENERIC_INDEX, |
| | 289 | }; |
| | 290 | #endif |
| | 291 | |
| 179 | #if CONFIG_AMR_MUXER | 292 | #if CONFIG_AMR_MUXER |
| 180 | AVOutputFormat ff_amr_muxer = { | 293 | AVOutputFormat ff_amr_muxer = { |
| 181 | .name = "amr", | 294 | .name = "amr", |