annotate libgsm.c @ 4122:daae66c03857 libavcodec

Replace most of the %lld and %llx by their (cleaner) PRI*64 counterparts. patch by Steve Lhomme, slhomme divxcorp com
author diego
date Wed, 01 Nov 2006 22:39:58 +0000
parents c8c591fe26f8
children c0bf618fbe7e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2729
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
1 /*
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
2 * Interface to libgsm for gsm encoding/decoding
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
3 * Copyright (c) 2005 Alban Bedel <albeu@free.fr>
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
4 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
5 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
6 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
2729
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
2729
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
11 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
2729
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
15 * Lesser General Public License for more details.
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
16 *
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
3036
0b546eab515d Update licensing information: The FSF changed postal address.
diego
parents: 2967
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2729
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
20 */
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2729
diff changeset
21
2729
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
22 /**
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
23 * @file libgsm.c
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
24 * Interface to libgsm for gsm encoding/decoding
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
25 */
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
26
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
27 #include "avcodec.h"
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
28 #include <gsm.h>
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
29
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
30 // gsm.h miss some essential constants
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
31 #define GSM_BLOCK_SIZE 33
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
32 #define GSM_FRAME_SIZE 160
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
33
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
34 static int libgsm_init(AVCodecContext *avctx) {
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
35 if (avctx->channels > 1 || avctx->sample_rate != 8000)
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
36 return -1;
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
37
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
38 avctx->frame_size = GSM_FRAME_SIZE;
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
39 avctx->block_align = GSM_BLOCK_SIZE;
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
40
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
41 avctx->priv_data = gsm_create();
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2729
diff changeset
42
2729
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
43 avctx->coded_frame= avcodec_alloc_frame();
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
44 avctx->coded_frame->key_frame= 1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2729
diff changeset
45
2729
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
46 return 0;
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
47 }
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
48
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
49 static int libgsm_close(AVCodecContext *avctx) {
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
50 gsm_destroy(avctx->priv_data);
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
51 avctx->priv_data = NULL;
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
52 return 0;
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
53 }
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
54
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
55 static int libgsm_encode_frame(AVCodecContext *avctx,
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
56 unsigned char *frame, int buf_size, void *data) {
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
57 // we need a full block
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
58 if(buf_size < GSM_BLOCK_SIZE) return 0;
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
59
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
60 gsm_encode(avctx->priv_data,data,frame);
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
61
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
62 return GSM_BLOCK_SIZE;
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
63 }
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
64
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
65
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
66 AVCodec libgsm_encoder = {
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
67 "gsm",
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
68 CODEC_TYPE_AUDIO,
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
69 CODEC_ID_GSM,
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
70 0,
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
71 libgsm_init,
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
72 libgsm_encode_frame,
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
73 libgsm_close,
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
74 };
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
75
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
76 static int libgsm_decode_frame(AVCodecContext *avctx,
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
77 void *data, int *data_size,
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
78 uint8_t *buf, int buf_size) {
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
79
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
80 if(buf_size < GSM_BLOCK_SIZE) return 0;
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
81
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
82 if(gsm_decode(avctx->priv_data,buf,data)) return -1;
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
83
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
84 *data_size = GSM_FRAME_SIZE*2;
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
85 return GSM_BLOCK_SIZE;
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
86 }
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
87
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
88 AVCodec libgsm_decoder = {
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
89 "gsm",
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
90 CODEC_TYPE_AUDIO,
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
91 CODEC_ID_GSM,
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
92 0,
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
93 libgsm_init,
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
94 NULL,
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
95 libgsm_close,
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
96 libgsm_decode_frame,
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
97 };