2 * Interface to libgsm for gsm encoding/decoding
3 * Copyright (c) 2005 Alban Bedel <albeu@free.fr>
5 * This file is part of FFmpeg.
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.
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.
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
24 * Interface to libgsm for gsm encoding/decoding
30 // gsm.h miss some essential constants
31 #define GSM_BLOCK_SIZE 33
32 #define GSM_FRAME_SIZE 160
34 static int libgsm_init(AVCodecContext *avctx) {
35 if (avctx->channels > 1 || avctx->sample_rate != 8000)
38 avctx->frame_size = GSM_FRAME_SIZE;
39 avctx->block_align = GSM_BLOCK_SIZE;
41 avctx->priv_data = gsm_create();
43 avctx->coded_frame= avcodec_alloc_frame();
44 avctx->coded_frame->key_frame= 1;
49 static int libgsm_close(AVCodecContext *avctx) {
50 gsm_destroy(avctx->priv_data);
51 avctx->priv_data = NULL;
55 static int libgsm_encode_frame(AVCodecContext *avctx,
56 unsigned char *frame, int buf_size, void *data) {
57 // we need a full block
58 if(buf_size < GSM_BLOCK_SIZE) return 0;
60 gsm_encode(avctx->priv_data,data,frame);
62 return GSM_BLOCK_SIZE;
66 AVCodec libgsm_encoder = {
76 static int libgsm_decode_frame(AVCodecContext *avctx,
77 void *data, int *data_size,
78 uint8_t *buf, int buf_size) {
80 if(buf_size < GSM_BLOCK_SIZE) return 0;
82 if(gsm_decode(avctx->priv_data,buf,data)) return -1;
84 *data_size = GSM_FRAME_SIZE*2;
85 return GSM_BLOCK_SIZE;
88 AVCodec libgsm_decoder = {