annotate libgsm.c @ 3158:5b2a0e54dfa7 libavcodec

fix infinite loop
author michael
date Thu, 02 Mar 2006 21:47:53 +0000
parents 0b546eab515d
children c8c591fe26f8
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 *
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
9 *
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
13 * Lesser General Public License for more details.
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
14 *
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
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
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
18 */
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2729
diff changeset
19
2729
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
20 /**
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
21 * @file libgsm.c
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
22 * Interface to libgsm for gsm encoding/decoding
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
23 */
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
24
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
25 #include "avcodec.h"
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
26 #include <gsm.h>
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
27
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
28 // gsm.h miss some essential constants
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
29 #define GSM_BLOCK_SIZE 33
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
30 #define GSM_FRAME_SIZE 160
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
31
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
32 static int libgsm_init(AVCodecContext *avctx) {
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
33 if (avctx->channels > 1 || avctx->sample_rate != 8000)
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
34 return -1;
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
35
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
36 avctx->frame_size = GSM_FRAME_SIZE;
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
37 avctx->block_align = GSM_BLOCK_SIZE;
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
38
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
39 avctx->priv_data = gsm_create();
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2729
diff changeset
40
2729
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
41 avctx->coded_frame= avcodec_alloc_frame();
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
42 avctx->coded_frame->key_frame= 1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2729
diff changeset
43
2729
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
44 return 0;
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
45 }
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
46
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
47 static int libgsm_close(AVCodecContext *avctx) {
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
48 gsm_destroy(avctx->priv_data);
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
49 avctx->priv_data = NULL;
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
50 return 0;
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
51 }
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
52
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
53 static int libgsm_encode_frame(AVCodecContext *avctx,
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
54 unsigned char *frame, int buf_size, void *data) {
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
55 // we need a full block
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
56 if(buf_size < GSM_BLOCK_SIZE) return 0;
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
57
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
58 gsm_encode(avctx->priv_data,data,frame);
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 return GSM_BLOCK_SIZE;
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
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 AVCodec libgsm_encoder = {
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
65 "gsm",
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
66 CODEC_TYPE_AUDIO,
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
67 CODEC_ID_GSM,
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
68 0,
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
69 libgsm_init,
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
70 libgsm_encode_frame,
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
71 libgsm_close,
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
72 };
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
73
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
74 static int libgsm_decode_frame(AVCodecContext *avctx,
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
75 void *data, int *data_size,
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
76 uint8_t *buf, int buf_size) {
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
77
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
78 if(buf_size < GSM_BLOCK_SIZE) return 0;
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(gsm_decode(avctx->priv_data,buf,data)) return -1;
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 *data_size = GSM_FRAME_SIZE*2;
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
83 return GSM_BLOCK_SIZE;
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
84 }
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
85
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
86 AVCodec libgsm_decoder = {
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
87 "gsm",
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
88 CODEC_TYPE_AUDIO,
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
89 CODEC_ID_GSM,
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
90 0,
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
91 libgsm_init,
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
92 NULL,
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
93 libgsm_close,
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
94 libgsm_decode_frame,
26bf6f4e9945 libgsm warper by (Alban Bedel: albeu, free fr)
michael
parents:
diff changeset
95 };