]> git.sesse.net Git - ffmpeg/blob - libavcodec/libgsm.c
always print message when error, AV_LOG_DEBUG -> AV_LOG_ERROR
[ffmpeg] / libavcodec / libgsm.c
1 /*
2  * Interface to libgsm for gsm encoding/decoding
3  * Copyright (c) 2005 Alban Bedel <albeu@free.fr>
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 /**
23  * @file libgsm.c
24  * Interface to libgsm for gsm encoding/decoding
25  */
26
27 #include "avcodec.h"
28 #include <gsm.h>
29
30 // gsm.h miss some essential constants
31 #define GSM_BLOCK_SIZE 33
32 #define GSM_FRAME_SIZE 160
33
34 static int libgsm_init(AVCodecContext *avctx) {
35     if (avctx->channels > 1 || avctx->sample_rate != 8000)
36         return -1;
37
38     avctx->frame_size = GSM_FRAME_SIZE;
39     avctx->block_align = GSM_BLOCK_SIZE;
40
41     avctx->priv_data = gsm_create();
42
43     avctx->coded_frame= avcodec_alloc_frame();
44     avctx->coded_frame->key_frame= 1;
45
46     return 0;
47 }
48
49 static int libgsm_close(AVCodecContext *avctx) {
50     gsm_destroy(avctx->priv_data);
51     avctx->priv_data = NULL;
52     return 0;
53 }
54
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;
59
60     gsm_encode(avctx->priv_data,data,frame);
61
62     return GSM_BLOCK_SIZE;
63 }
64
65
66 AVCodec libgsm_encoder = {
67     "gsm",
68     CODEC_TYPE_AUDIO,
69     CODEC_ID_GSM,
70     0,
71     libgsm_init,
72     libgsm_encode_frame,
73     libgsm_close,
74 };
75
76 static int libgsm_decode_frame(AVCodecContext *avctx,
77                                void *data, int *data_size,
78                                uint8_t *buf, int buf_size) {
79
80     if(buf_size < GSM_BLOCK_SIZE) return 0;
81
82     if(gsm_decode(avctx->priv_data,buf,data)) return -1;
83
84     *data_size = GSM_FRAME_SIZE*2;
85     return GSM_BLOCK_SIZE;
86 }
87
88 AVCodec libgsm_decoder = {
89     "gsm",
90     CODEC_TYPE_AUDIO,
91     CODEC_ID_GSM,
92     0,
93     libgsm_init,
94     NULL,
95     libgsm_close,
96     libgsm_decode_frame,
97 };