ffmpeg / libavcodec / libvo-amrwbenc.c @ 900a129f
History | View | Annotate | Download (3.62 KB)
1 |
/*
|
---|---|
2 |
* AMR Audio encoder stub
|
3 |
* Copyright (c) 2003 the ffmpeg project
|
4 |
*
|
5 |
* This file is part of Libav.
|
6 |
*
|
7 |
* Libav 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 |
* Libav 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 Libav; if not, write to the Free Software
|
19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
20 |
*/
|
21 |
|
22 |
#include <vo-amrwbenc/enc_if.h> |
23 |
|
24 |
#include "avcodec.h" |
25 |
|
26 |
static const char wb_bitrate_unsupported[] = |
27 |
"bitrate not supported: use one of 6.6k, 8.85k, 12.65k, 14.25k, 15.85k, "
|
28 |
"18.25k, 19.85k, 23.05k, or 23.85k\n";
|
29 |
|
30 |
typedef struct AMRWB_bitrates { |
31 |
int rate;
|
32 |
int mode;
|
33 |
} AMRWB_bitrates; |
34 |
|
35 |
typedef struct AMRWBContext { |
36 |
void *state;
|
37 |
int mode;
|
38 |
int allow_dtx;
|
39 |
} AMRWBContext; |
40 |
|
41 |
static int getWBBitrateMode(int bitrate) |
42 |
{ |
43 |
/* make the correspondance between bitrate and mode */
|
44 |
AMRWB_bitrates rates[] = { { 6600, 0}, |
45 |
{ 8850, 1}, |
46 |
{12650, 2}, |
47 |
{14250, 3}, |
48 |
{15850, 4}, |
49 |
{18250, 5}, |
50 |
{19850, 6}, |
51 |
{23050, 7}, |
52 |
{23850, 8}, }; |
53 |
int i;
|
54 |
|
55 |
for (i = 0; i < 9; i++) |
56 |
if (rates[i].rate == bitrate)
|
57 |
return rates[i].mode;
|
58 |
/* no bitrate matching, return an error */
|
59 |
return -1; |
60 |
} |
61 |
|
62 |
static av_cold int amr_wb_encode_init(AVCodecContext *avctx) |
63 |
{ |
64 |
AMRWBContext *s = avctx->priv_data; |
65 |
|
66 |
if (avctx->sample_rate != 16000) { |
67 |
av_log(avctx, AV_LOG_ERROR, "Only 16000Hz sample rate supported\n");
|
68 |
return AVERROR(ENOSYS);
|
69 |
} |
70 |
|
71 |
if (avctx->channels != 1) { |
72 |
av_log(avctx, AV_LOG_ERROR, "Only mono supported\n");
|
73 |
return AVERROR(ENOSYS);
|
74 |
} |
75 |
|
76 |
if ((s->mode = getWBBitrateMode(avctx->bit_rate)) < 0) { |
77 |
av_log(avctx, AV_LOG_ERROR, wb_bitrate_unsupported); |
78 |
return AVERROR(ENOSYS);
|
79 |
} |
80 |
|
81 |
avctx->frame_size = 320;
|
82 |
avctx->coded_frame = avcodec_alloc_frame(); |
83 |
|
84 |
s->state = E_IF_init(); |
85 |
s->allow_dtx = 0;
|
86 |
|
87 |
return 0; |
88 |
} |
89 |
|
90 |
static int amr_wb_encode_close(AVCodecContext *avctx) |
91 |
{ |
92 |
AMRWBContext *s = avctx->priv_data; |
93 |
|
94 |
E_IF_exit(s->state); |
95 |
av_freep(&avctx->coded_frame); |
96 |
return 0; |
97 |
} |
98 |
|
99 |
static int amr_wb_encode_frame(AVCodecContext *avctx, |
100 |
unsigned char *frame/*out*/, |
101 |
int buf_size, void *data/*in*/) |
102 |
{ |
103 |
AMRWBContext *s = avctx->priv_data; |
104 |
int size;
|
105 |
|
106 |
if ((s->mode = getWBBitrateMode(avctx->bit_rate)) < 0) { |
107 |
av_log(avctx, AV_LOG_ERROR, wb_bitrate_unsupported); |
108 |
return AVERROR(ENOSYS);
|
109 |
} |
110 |
size = E_IF_encode(s->state, s->mode, data, frame, s->allow_dtx); |
111 |
return size;
|
112 |
} |
113 |
|
114 |
AVCodec ff_libvo_amrwbenc_encoder = { |
115 |
"libvo_amrwbenc",
|
116 |
CODEC_TYPE_AUDIO, |
117 |
CODEC_ID_AMR_WB, |
118 |
sizeof(AMRWBContext),
|
119 |
amr_wb_encode_init, |
120 |
amr_wb_encode_frame, |
121 |
amr_wb_encode_close, |
122 |
NULL,
|
123 |
.sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, |
124 |
.long_name = NULL_IF_CONFIG_SMALL("libvo-amrwbenc Adaptive Multi-Rate "
|
125 |
"(AMR) Wide-Band"),
|
126 |
}; |
127 |
|