00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00025 #include "avcodec.h"
00026 #include <gsm.h>
00027
00028
00029 #define GSM_BLOCK_SIZE 33
00030 #define GSM_FRAME_SIZE 160
00031
00032 static int libgsm_init(AVCodecContext *avctx) {
00033 if (avctx->channels > 1 || avctx->sample_rate != 8000)
00034 return -1;
00035
00036 avctx->frame_size = GSM_FRAME_SIZE;
00037 avctx->block_align = GSM_BLOCK_SIZE;
00038
00039 avctx->priv_data = gsm_create();
00040
00041 avctx->coded_frame= avcodec_alloc_frame();
00042 avctx->coded_frame->key_frame= 1;
00043
00044 return 0;
00045 }
00046
00047 static int libgsm_close(AVCodecContext *avctx) {
00048 gsm_destroy(avctx->priv_data);
00049 avctx->priv_data = NULL;
00050 return 0;
00051 }
00052
00053 static int libgsm_encode_frame(AVCodecContext *avctx,
00054 unsigned char *frame, int buf_size, void *data) {
00055
00056 if(buf_size < GSM_BLOCK_SIZE) return 0;
00057
00058 gsm_encode(avctx->priv_data,data,frame);
00059
00060 return GSM_BLOCK_SIZE;
00061 }
00062
00063
00064 AVCodec libgsm_encoder = {
00065 "gsm",
00066 CODEC_TYPE_AUDIO,
00067 CODEC_ID_GSM,
00068 0,
00069 libgsm_init,
00070 libgsm_encode_frame,
00071 libgsm_close,
00072 };
00073
00074 static int libgsm_decode_frame(AVCodecContext *avctx,
00075 void *data, int *data_size,
00076 uint8_t *buf, int buf_size) {
00077
00078 if(buf_size < GSM_BLOCK_SIZE) return 0;
00079
00080 if(gsm_decode(avctx->priv_data,buf,data)) return -1;
00081
00082 *data_size = GSM_FRAME_SIZE*2;
00083 return GSM_BLOCK_SIZE;
00084 }
00085
00086 AVCodec libgsm_decoder = {
00087 "gsm",
00088 CODEC_TYPE_AUDIO,
00089 CODEC_ID_GSM,
00090 0,
00091 libgsm_init,
00092 NULL,
00093 libgsm_close,
00094 libgsm_decode_frame,
00095 };