Mercurial > mplayer.hg
annotate libmpcodecs/ad_speex.c @ 30788:ea3ba0e77acf
Fix return values of WaitForSingleObject when checking an event.
These were simply inverted compared to what they should be.
author | sesse |
---|---|
date | Thu, 04 Mar 2010 15:23:52 +0000 |
parents | 32725ca88fed |
children | a1bf34d75484 |
rev | line source |
---|---|
30421
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
20962
diff
changeset
|
1 /* |
16916 | 2 * Speex decoder by Reimar Döffinger <Reimar.Doeffinger@stud.uni-karlsruhe.de> |
30421
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
20962
diff
changeset
|
3 * |
16916 | 4 * This code may be be relicensed under the terms of the GNU LGPL when it |
5 * becomes part of the FFmpeg project (ffmpeg.org) | |
30421
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
20962
diff
changeset
|
6 * |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
20962
diff
changeset
|
7 * This file is part of MPlayer. |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
20962
diff
changeset
|
8 * |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
20962
diff
changeset
|
9 * MPlayer is free software; you can redistribute it and/or modify |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
20962
diff
changeset
|
10 * it under the terms of the GNU General Public License as published by |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
20962
diff
changeset
|
11 * the Free Software Foundation; either version 2 of the License, or |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
20962
diff
changeset
|
12 * (at your option) any later version. |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
20962
diff
changeset
|
13 * |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
20962
diff
changeset
|
14 * MPlayer is distributed in the hope that it will be useful, |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
20962
diff
changeset
|
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
20962
diff
changeset
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
20962
diff
changeset
|
17 * GNU General Public License for more details. |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
20962
diff
changeset
|
18 * |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
20962
diff
changeset
|
19 * You should have received a copy of the GNU General Public License along |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
20962
diff
changeset
|
20 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
20962
diff
changeset
|
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
16916 | 22 */ |
30421
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
20962
diff
changeset
|
23 |
16916 | 24 #include "config.h" |
18157
2c7219c38e56
bug fixes: left-over mode variable used uninitialized,
reimar
parents:
17429
diff
changeset
|
25 #include <stdlib.h> |
16916 | 26 #include <speex/speex.h> |
27 #include <speex/speex_stereo.h> | |
28 #include <speex/speex_header.h> | |
29 #include "ad_internal.h" | |
30 | |
30504
cc27da5d7286
Mark all ad_info_t/vd_info_t structure declarations as const.
diego
parents:
30421
diff
changeset
|
31 static const ad_info_t info = { |
16916 | 32 "Speex audio decoder", |
33 "speex", | |
34 "Reimar Döffinger", | |
35 "", | |
36 "" | |
37 }; | |
38 | |
39 LIBAD_EXTERN(speex) | |
40 | |
41 typedef struct { | |
42 SpeexBits bits; | |
43 void *dec_context; | |
44 SpeexStereoState stereo; | |
45 SpeexHeader *hdr; | |
46 } context_t; | |
47 | |
18157
2c7219c38e56
bug fixes: left-over mode variable used uninitialized,
reimar
parents:
17429
diff
changeset
|
48 #define MAX_FRAMES_PER_PACKET 100 |
2c7219c38e56
bug fixes: left-over mode variable used uninitialized,
reimar
parents:
17429
diff
changeset
|
49 |
16916 | 50 static int preinit(sh_audio_t *sh) { |
18157
2c7219c38e56
bug fixes: left-over mode variable used uninitialized,
reimar
parents:
17429
diff
changeset
|
51 sh->audio_out_minsize = 2 * 320 * MAX_FRAMES_PER_PACKET * 2 * sizeof(short); |
16916 | 52 return 1; |
53 } | |
54 | |
55 static int init(sh_audio_t *sh) { | |
18879 | 56 context_t *ctx = calloc(1, sizeof(context_t)); |
16916 | 57 const SpeexMode *spx_mode; |
58 const SpeexStereoState st_st = SPEEX_STEREO_STATE_INIT; // hack | |
59 if (!sh->wf || sh->wf->cbSize < 80) { | |
60 mp_msg(MSGT_DECAUDIO, MSGL_FATAL, "Missing extradata!\n"); | |
61 return 0; | |
62 } | |
63 ctx->hdr = speex_packet_to_header((char *)&sh->wf[1], sh->wf->cbSize); | |
64 if (ctx->hdr->nb_channels != 1 && ctx->hdr->nb_channels != 2) { | |
65 mp_msg(MSGT_DECAUDIO, MSGL_WARN, "Invalid number of channels (%i), " | |
66 "assuming mono\n", ctx->hdr->nb_channels); | |
67 ctx->hdr->nb_channels = 1; | |
68 } | |
18157
2c7219c38e56
bug fixes: left-over mode variable used uninitialized,
reimar
parents:
17429
diff
changeset
|
69 if (ctx->hdr->frames_per_packet > MAX_FRAMES_PER_PACKET) { |
2c7219c38e56
bug fixes: left-over mode variable used uninitialized,
reimar
parents:
17429
diff
changeset
|
70 mp_msg(MSGT_DECAUDIO, MSGL_WARN, "Invalid number of frames per packet (%i), " |
2c7219c38e56
bug fixes: left-over mode variable used uninitialized,
reimar
parents:
17429
diff
changeset
|
71 "assuming 1\n", ctx->hdr->frames_per_packet); |
2c7219c38e56
bug fixes: left-over mode variable used uninitialized,
reimar
parents:
17429
diff
changeset
|
72 ctx->hdr->frames_per_packet = 1; |
2c7219c38e56
bug fixes: left-over mode variable used uninitialized,
reimar
parents:
17429
diff
changeset
|
73 } |
16916 | 74 switch (ctx->hdr->mode) { |
75 case 0: | |
76 spx_mode = &speex_nb_mode; break; | |
77 case 1: | |
78 spx_mode = &speex_wb_mode; break; | |
79 case 2: | |
80 spx_mode = &speex_uwb_mode; break; | |
81 default: | |
18157
2c7219c38e56
bug fixes: left-over mode variable used uninitialized,
reimar
parents:
17429
diff
changeset
|
82 mp_msg(MSGT_DECAUDIO, MSGL_WARN, "Unknown speex mode (%i)\n", ctx->hdr->mode); |
16916 | 83 spx_mode = &speex_nb_mode; |
84 } | |
85 ctx->dec_context = speex_decoder_init(spx_mode); | |
86 speex_bits_init(&ctx->bits); | |
87 memcpy(&ctx->stereo, &st_st, sizeof(ctx->stereo)); // hack part 2 | |
88 sh->channels = ctx->hdr->nb_channels; | |
89 sh->samplerate = ctx->hdr->rate; | |
90 sh->samplesize = 2; | |
91 sh->sample_format = AF_FORMAT_S16_NE; | |
92 sh->context = ctx; | |
93 return 1; | |
94 } | |
95 | |
96 static void uninit(sh_audio_t *sh) { | |
97 context_t *ctx = sh->context; | |
98 if (ctx) { | |
99 speex_bits_destroy(&ctx->bits); | |
100 speex_decoder_destroy(ctx->dec_context); | |
101 if (ctx->hdr) | |
17429
7dac2afa70aa
Use free instead of speex_free - since speex_free does not appear in the
reimar
parents:
16916
diff
changeset
|
102 free(ctx->hdr); |
16916 | 103 free(ctx); |
104 } | |
105 ctx = NULL; | |
106 } | |
107 | |
108 static int decode_audio(sh_audio_t *sh, unsigned char *buf, | |
109 int minlen, int maxlen) { | |
110 context_t *ctx = sh->context; | |
111 int len, framelen, framesamples; | |
112 char *packet; | |
113 int i, err; | |
114 speex_decoder_ctl(ctx->dec_context, SPEEX_GET_FRAME_SIZE, &framesamples); | |
115 framelen = framesamples * ctx->hdr->nb_channels * sizeof(short); | |
116 if (maxlen < ctx->hdr->frames_per_packet * framelen) { | |
117 mp_msg(MSGT_DECAUDIO, MSGL_V, "maxlen too small in decode_audio\n"); | |
118 return -1; | |
119 } | |
120 len = ds_get_packet(sh->ds, (unsigned char **)&packet); | |
121 if (len <= 0) return -1; | |
122 speex_bits_read_from(&ctx->bits, packet, len); | |
123 i = ctx->hdr->frames_per_packet; | |
124 do { | |
125 err = speex_decode_int(ctx->dec_context, &ctx->bits, (short *)buf); | |
126 if (err == -2) | |
127 mp_msg(MSGT_DECAUDIO, MSGL_ERR, "Error decoding file.\n"); | |
128 if (ctx->hdr->nb_channels == 2) | |
129 speex_decode_stereo_int((short *)buf, framesamples, &ctx->stereo); | |
130 buf = &buf[framelen]; | |
131 } while (--i > 0); | |
132 return ctx->hdr->frames_per_packet * framelen; | |
133 } | |
134 | |
135 static int control(sh_audio_t *sh, int cmd, void *arg, ...) { | |
136 return CONTROL_UNKNOWN; | |
137 } |