1 /*
2 * codec2 encoder/decoder using libcodec2
3 * Copyright (c) 2017 Tomas Härdin
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 <codec2/codec2.h>
30
36
38 //not AV_OPT_FLAG_DECODING_PARAM since mode should come from the demuxer
39 //1300 (aka FreeDV 1600) is the most common mode on-the-air, default to it here as well
42 };
43
49 };
50
52 {
54 //Grab mode name from options, unless it's some weird number.
56
57 c2->codec = codec2_create(
mode);
59 //Out of memory or unsupported mode. The latter seems most likely,
60 //but we can't tell for sure with the current API.
61 goto libcodec2_init_common_error;
62 }
63
65 avctx->
block_align = (codec2_bits_per_frame(
c2->codec) + 7) / 8;
66
68 //codec2_create() may succeed for some modes but still fail at codec2_samples_per_frame()
69 //example is -mode 700C on libcodec2 0.4
70 codec2_destroy(
c2->codec);
72 goto libcodec2_init_common_error;
73 }
74
75 codec2_set_natural_or_gray(
c2->codec, 1);
76
77 return 0;
78
79 libcodec2_init_common_error:
81 "Mode %i (%s) not supported with the linked version of libcodec2\n",
84 }
85
87 {
92
97 }
98
100 }
101
103 {
105
106 //will need to be smarter once we get wideband support
111 }
112
116 }
117
120
122 }
123
125 {
127
128 codec2_destroy(
c2->codec);
129 return 0;
130 }
131
134 {
137 const uint8_t *
input;
139
142
146 }
147
150
151 for (
i = 0;
i < nframes;
i++) {
155 }
156
157 *got_frame_ptr = nframes > 0;
159 }
160
163 {
166
170 }
171
173 *got_packet_ptr = 1;
174
175 return 0;
176 }
177
179 .
p.
name =
"libcodec2",
184 .p.supported_samplerates = (const int[]){ 8000, 0 },
192 };
193
195 .
p.
name =
"libcodec2",
201 .p.supported_samplerates = (const int[]){ 8000, 0 },
210 };