2 * Interface to libgsm for gsm encoding/decoding
3 * Copyright (c) 2005 Alban Bedel <albeu@free.fr>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * Interface to libgsm for gsm encoding/decoding
28 // gsm.h miss some essential constants
29 #define GSM_BLOCK_SIZE 33
30 #define GSM_FRAME_SIZE 160
32 static int libgsm_init(AVCodecContext *avctx) {
33 if (avctx->channels > 1 || avctx->sample_rate != 8000)
36 avctx->frame_size = GSM_FRAME_SIZE;
37 avctx->block_align = GSM_BLOCK_SIZE;
39 avctx->priv_data = gsm_create();
41 avctx->coded_frame= avcodec_alloc_frame();
42 avctx->coded_frame->key_frame= 1;
47 static int libgsm_close(AVCodecContext *avctx) {
48 gsm_destroy(avctx->priv_data);
49 avctx->priv_data = NULL;
53 static int libgsm_encode_frame(AVCodecContext *avctx,
54 unsigned char *frame, int buf_size, void *data) {
55 // we need a full block
56 if(buf_size < GSM_BLOCK_SIZE) return 0;
58 gsm_encode(avctx->priv_data,data,frame);
60 return GSM_BLOCK_SIZE;
64 AVCodec libgsm_encoder = {
74 static int libgsm_decode_frame(AVCodecContext *avctx,
75 void *data, int *data_size,
76 uint8_t *buf, int buf_size) {
78 if(buf_size < GSM_BLOCK_SIZE) return 0;
80 if(gsm_decode(avctx->priv_data,buf,data)) return -1;
82 *data_size = GSM_FRAME_SIZE*2;
83 return GSM_BLOCK_SIZE;
86 AVCodec libgsm_decoder = {