Mercurial > libavcodec.hg
annotate libgsm.c @ 3798:6e7b9a44800c libavcodec
vorbis.h -> vorbis_data.c
move tables from vorbis.h to a C file so they can be used later in
vorbis_enc.c
author | ods15 |
---|---|
date | Sat, 30 Sep 2006 18:47:15 +0000 |
parents | 0b546eab515d |
children | c8c591fe26f8 |
rev | line source |
---|---|
2729 | 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 | |
3036
0b546eab515d
Update licensing information: The FSF changed postal address.
diego
parents:
2967
diff
changeset
|
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
2729 | 18 */ |
2967 | 19 |
2729 | 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(); | |
2967 | 40 |
2729 | 41 avctx->coded_frame= avcodec_alloc_frame(); |
42 avctx->coded_frame->key_frame= 1; | |
2967 | 43 |
2729 | 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 }; |