VirtualBox

source: vbox/trunk/src/libs/ffmpeg-20060710/libavcodec/libgsm.c@ 5776

Last change on this file since 5776 was 5776, checked in by vboxsync, 17 years ago

ffmpeg: exported to OSE

File size: 2.4 KB
Line 
1/*
2 * Interface to libgsm for gsm encoding/decoding
3 * Copyright (c) 2005 Alban Bedel <[email protected]>
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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
32static 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
47static int libgsm_close(AVCodecContext *avctx) {
48 gsm_destroy(avctx->priv_data);
49 avctx->priv_data = NULL;
50 return 0;
51}
52
53static 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
64AVCodec 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
74static 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
86AVCodec 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};
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette