comparison libgsm.c @ 2729:26bf6f4e9945 libavcodec

libgsm warper by (Alban Bedel: albeu, free fr)
author michael
date Sun, 22 May 2005 23:39:11 +0000
parents
children ef2149182f1c
comparison
equal deleted inserted replaced
2728:9994e07cd45f 2729:26bf6f4e9945
1 /*
2 * Interface to libgsm for gsm encoding/decoding
3 * Copyright (c) 2005 Alban Bedel <albeu@free.fr>
4 *
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.
9 *
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.
14 *
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
18 */
19
20 /**
21 * @file libgsm.c
22 * Interface to libgsm for gsm encoding/decoding
23 */
24
25 #include "avcodec.h"
26 #include <gsm.h>
27
28 // gsm.h miss some essential constants
29 #define GSM_BLOCK_SIZE 33
30 #define GSM_FRAME_SIZE 160
31
32 static int libgsm_init(AVCodecContext *avctx) {
33 if (avctx->channels > 1 || avctx->sample_rate != 8000)
34 return -1;
35
36 avctx->frame_size = GSM_FRAME_SIZE;
37 avctx->block_align = GSM_BLOCK_SIZE;
38
39 avctx->priv_data = gsm_create();
40
41 avctx->coded_frame= avcodec_alloc_frame();
42 avctx->coded_frame->key_frame= 1;
43
44 return 0;
45 }
46
47 static int libgsm_close(AVCodecContext *avctx) {
48 gsm_destroy(avctx->priv_data);
49 avctx->priv_data = NULL;
50 return 0;
51 }
52
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;
57
58 gsm_encode(avctx->priv_data,data,frame);
59
60 return GSM_BLOCK_SIZE;
61 }
62
63
64 AVCodec libgsm_encoder = {
65 "gsm",
66 CODEC_TYPE_AUDIO,
67 CODEC_ID_GSM,
68 0,
69 libgsm_init,
70 libgsm_encode_frame,
71 libgsm_close,
72 };
73
74 static int libgsm_decode_frame(AVCodecContext *avctx,
75 void *data, int *data_size,
76 uint8_t *buf, int buf_size) {
77
78 if(buf_size < GSM_BLOCK_SIZE) return 0;
79
80 if(gsm_decode(avctx->priv_data,buf,data)) return -1;
81
82 *data_size = GSM_FRAME_SIZE*2;
83 return GSM_BLOCK_SIZE;
84 }
85
86 AVCodec libgsm_decoder = {
87 "gsm",
88 CODEC_TYPE_AUDIO,
89 CODEC_ID_GSM,
90 0,
91 libgsm_init,
92 NULL,
93 libgsm_close,
94 libgsm_decode_frame,
95 };