~ubuntu-branches/ubuntu/lucid/warzone2100/lucid

« back to all changes in this revision

Viewing changes to lib/sound/oggvorbis.c

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Egger, Paul Wise, Christoph Egger
  • Date: 2009-06-29 17:12:52 UTC
  • mfrom: (1.1.11 upstream) (2.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090629171252-5ddnlfg3zfchrega
Tags: 2.2.1+dfsg1-1
[ Paul Wise ]
* New upstream release (Closes: #534962)
* Adjust the flex build-depends to take account of the conflict
  with all the versions of flex 2.5.34 (LP: #372872)
* Make the -music Recommends more strict, 2.1 music doesn't work
  with 2.2.
* Upstream moved the downloads to sourceforge, update the watch file
* Bump Standards-Version, no changes needed
* Drop use of dh_desktop since it no longer does anything
* Recommend the new warzone2100-video package, version 2.2 or similar
* Mention the warzone2100 crash reports in the -dbg package description

[ Christoph Egger ]
* Replace CC-2.0 graphic from cybersphinx, create a new tarball
* Add myself to uploaders

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
        This file is part of Warzone 2100.
3
 
        Copyright (C) 2005-2007  Warzone Resurrection Project
 
3
        Copyright (C) 2005-2009  Warzone Resurrection Project
4
4
 
5
5
        Warzone 2100 is free software; you can redistribute it and/or modify
6
6
        it under the terms of the GNU General Public License as published by
62
62
#ifndef WZ_NOSOUND
63
63
static size_t wz_oggVorbis_read(void *ptr, size_t size, size_t nmemb, void *datasource)
64
64
{
65
 
        PHYSFS_file* fileHandle = ((struct OggVorbisDecoderState*)datasource)->fileHandle;
 
65
        PHYSFS_file* fileHandle;
 
66
 
 
67
        ASSERT(datasource != NULL, "NULL decoder passed!");
 
68
 
 
69
        fileHandle = ((struct OggVorbisDecoderState*)datasource)->fileHandle;
 
70
        ASSERT(fileHandle != NULL, "Bad PhysicsFS file handle passed in");
 
71
 
66
72
        return PHYSFS_read(fileHandle, ptr, 1, size*nmemb);
67
73
}
68
74
 
69
75
static int wz_oggVorbis_seek(void *datasource, ogg_int64_t offset, int whence)
70
76
{
71
 
        PHYSFS_file* fileHandle = ((struct OggVorbisDecoderState*)datasource)->fileHandle;
72
 
        BOOL allowSeeking = ((struct OggVorbisDecoderState*)datasource)->allowSeeking;
73
 
 
 
77
        PHYSFS_file* fileHandle;
 
78
        BOOL allowSeeking;
74
79
        int newPos;
75
80
 
 
81
        ASSERT(datasource != NULL, "NULL decoder passed!");
 
82
 
 
83
        fileHandle = ((struct OggVorbisDecoderState*)datasource)->fileHandle;
 
84
        ASSERT(fileHandle != NULL, "Bad PhysicsFS file handle passed in");
 
85
 
 
86
        allowSeeking = ((struct OggVorbisDecoderState*)datasource)->allowSeeking;
 
87
 
76
88
        if (!allowSeeking)
77
89
                return -1;
78
90
 
125
137
 
126
138
static long wz_oggVorbis_tell(void *datasource)
127
139
{
128
 
        PHYSFS_file* fileHandle = ((struct OggVorbisDecoderState*)datasource)->fileHandle;
 
140
        PHYSFS_file* fileHandle;
 
141
 
 
142
        ASSERT(datasource != NULL, "NULL decoder passed!");
 
143
 
 
144
        fileHandle = ((struct OggVorbisDecoderState*)datasource)->fileHandle;
 
145
        ASSERT(fileHandle != NULL, "Bad PhysicsFS file handle passed in");
 
146
 
129
147
        return PHYSFS_tell(fileHandle);
130
148
}
131
149
 
147
165
        struct OggVorbisDecoderState* decoder = malloc(sizeof(struct OggVorbisDecoderState));
148
166
        if (decoder == NULL)
149
167
        {
150
 
                debug(LOG_ERROR, "sound_CreateOggVorbisDecoder: Out of memory");
 
168
                debug(LOG_ERROR, "Out of memory");
151
169
                abort();
152
170
                return NULL;
153
171
        }
154
172
 
 
173
        ASSERT(PHYSFS_fileHandle != NULL, "Bad PhysicsFS file handle passed in");
 
174
 
155
175
        decoder->fileHandle = PHYSFS_fileHandle;
156
176
        decoder->allowSeeking = allowSeeking;
157
177
 
159
179
        error = ov_open_callbacks(decoder, &decoder->oggVorbis_stream, NULL, 0, wz_oggVorbis_callbacks);
160
180
        if (error < 0)
161
181
        {
162
 
                debug(LOG_ERROR, "sound_CreateOggVorbisDecoder: ov_open_callbacks failed with errorcode %d", error);
 
182
                debug(LOG_ERROR, "ov_open_callbacks failed with errorcode %d", error);
163
183
                free(decoder);
164
184
                return NULL;
165
185
        }
173
193
 
174
194
void sound_DestroyOggVorbisDecoder(struct OggVorbisDecoderState* decoder)
175
195
{
 
196
        ASSERT(decoder != NULL, "NULL decoder passed!");
 
197
 
176
198
#ifndef WZ_NOSOUND
177
199
        // Close the OggVorbis decoding stream
178
200
        ov_clear(&decoder->oggVorbis_stream);
184
206
static inline unsigned int getSampleCount(struct OggVorbisDecoderState* decoder)
185
207
{
186
208
#ifndef WZ_NOSOUND
187
 
        int numSamples = ov_pcm_total(&decoder->oggVorbis_stream, -1);
 
209
        int numSamples;
 
210
 
 
211
        ASSERT(decoder != NULL, "NULL decoder passed!");
 
212
 
 
213
        numSamples = ov_pcm_total(&decoder->oggVorbis_stream, -1);
188
214
 
189
215
        if (numSamples == OV_EINVAL)
190
216
                return 0;
198
224
static inline unsigned int getCurrentSample(struct OggVorbisDecoderState* decoder)
199
225
{
200
226
#ifndef WZ_NOSOUND
201
 
        int samplePos = ov_pcm_tell(&decoder->oggVorbis_stream);
 
227
        int samplePos;
 
228
 
 
229
        ASSERT(decoder != NULL, "NULL decoder passed!");
 
230
 
 
231
        samplePos = ov_pcm_tell(&decoder->oggVorbis_stream);
202
232
 
203
233
        if (samplePos == OV_EINVAL)
204
234
                return 0;
218
248
 
219
249
        soundDataBuffer* buffer;
220
250
 
 
251
        ASSERT(decoder != NULL, "NULL decoder passed!");
 
252
 
221
253
#ifndef WZ_NOSOUND
222
254
        if (decoder->allowSeeking)
223
255
        {
234
266
        // If we can't seek nor receive any suggested size for our buffer, just quit
235
267
        if (bufferSize == 0)
236
268
        {
237
 
                debug(LOG_ERROR, "sound_DecodeOggVorbis: can't find a proper buffer size\n");
 
269
                debug(LOG_ERROR, "can't find a proper buffer size");
238
270
                return NULL;
239
271
        }
240
272
#else
244
276
        buffer = malloc(bufferSize + sizeof(soundDataBuffer));
245
277
        if (buffer == NULL)
246
278
        {
247
 
                debug(LOG_ERROR, "sound_DecodeOggVorbis: couldn't allocate memory (%zu bytes requested)\n", bufferSize + sizeof(soundDataBuffer));
 
279
                debug(LOG_ERROR, "couldn't allocate memory (%lu bytes requested)", (unsigned long) bufferSize + sizeof(soundDataBuffer));
248
280
                return NULL;
249
281
        }
250
282
 
265
297
 
266
298
                if (result < 0)
267
299
                {
268
 
                        debug(LOG_ERROR, "sound_DecodeOggVorbis: error decoding from OggVorbis file; errorcode from ov_read: %d\n", result);
 
300
                        debug(LOG_ERROR, "error decoding from OggVorbis file; errorcode from ov_read: %d", result);
269
301
                        free(buffer);
270
302
                        return NULL;
271
303
                }