1 /*
2 * Xiph CELT decoder using libcelt
3 * Copyright (c) 2011 Nicolas George
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include <celt/celt.h>
23 #include <celt/celt_header.h>
28
33 };
34
36 {
37 switch (err) {
38 case CELT_BAD_ARG:
return AVERROR(EINVAL);
39 #ifdef CELT_BUFFER_TOO_SMALL
40 case CELT_BUFFER_TOO_SMALL:
return AVERROR(ENOBUFS);
41 #endif
42 case CELT_INTERNAL_ERROR:
return AVERROR(EFAULT);
44 case CELT_UNIMPLEMENTED:
return AVERROR(ENOSYS);
45 #ifdef ENOTRECOVERABLE
46 case CELT_INVALID_STATE:
return AVERROR(ENOTRECOVERABLE);
47 #endif
48 case CELT_ALLOC_FAIL:
return AVERROR(ENOMEM);
49 default:
return AVERROR(EINVAL);
50 }
51 }
52
54 {
55 CELTHeader
header = { .version_id = 0 };
58 }
59
61 {
63 int err;
64
65 if (!
c->ch_layout.nb_channels || !
c->frame_size ||
66 c->frame_size > INT_MAX /
sizeof(int16_t) /
c->ch_layout.nb_channels)
68 celt->
mode = celt_mode_create(
c->sample_rate,
c->frame_size, &err);
71 celt->
dec = celt_decoder_create_custom(celt->
mode,
c->ch_layout.nb_channels, &err);
73 celt_mode_destroy(celt->
mode);
75 }
76 if (
c->extradata_size >= 4) {
80 "Invalid overlap (%d), ignored.\n", celt->
discard);
82 }
83 }
84 if (
c->extradata_size >= 8) {
89 "CELT bitstream version 0x%x may be "
90 "improperly decoded by libcelt for version 0x%x.\n",
92 }
94 return 0;
95 }
96
98 {
100
101 celt_decoder_destroy(celt->
dec);
102 celt_mode_destroy(celt->
mode);
103 return 0;
104 }
105
108 {
110 int err;
111 int16_t *pcm;
112
113 frame->nb_samples =
c->frame_size;
115 return err;
116 pcm = (int16_t *)
frame->data[0];
118 if (err < 0)
122 memmove(pcm, pcm + celt->
discard *
c->ch_layout.nb_channels,
123 frame->nb_samples *
c->ch_layout.nb_channels *
sizeof(int16_t));
125 }
126 *got_frame_ptr = 1;
128 }
129
136 .p.wrapper_name = "libcelt",
142 };