Mercurial > SDL_sound_CoreAudio
comparison decoders/flac.c @ 516:46d5f399cb35
Patch from stable-1.0 branch r528:529.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sat, 28 Oct 2006 00:57:10 +0000 |
parents | 3e705c9180e5 |
children | 8a814bbbedfa |
comparison
equal
deleted
inserted
replaced
514:6c4f29fc3d87 | 516:46d5f399cb35 |
---|---|
42 #include "SDL_sound.h" | 42 #include "SDL_sound.h" |
43 | 43 |
44 #define __SDL_SOUND_INTERNAL__ | 44 #define __SDL_SOUND_INTERNAL__ |
45 #include "SDL_sound_internal.h" | 45 #include "SDL_sound_internal.h" |
46 | 46 |
47 #include <FLAC/export.h> | |
48 | |
49 /* FLAC 1.1.3 has FLAC_API_VERSION_CURRENT == 8 */ | |
50 #if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT < 8 | |
51 #define LEGACY_FLAC | |
52 #else | |
53 #undef LEGACY_FLAC | |
54 #endif | |
55 | |
56 #ifdef LEGACY_FLAC | |
47 #include <FLAC/seekable_stream_decoder.h> | 57 #include <FLAC/seekable_stream_decoder.h> |
48 | 58 |
49 #define D_END_OF_STREAM FLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM | 59 #define D_END_OF_STREAM FLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM |
50 | 60 |
51 #define d_new() FLAC__seekable_stream_decoder_new() | 61 #define d_new() FLAC__seekable_stream_decoder_new() |
78 #define d_seek_absolute(x, y) FLAC__seekable_stream_decoder_seek_absolute(x, y) | 88 #define d_seek_absolute(x, y) FLAC__seekable_stream_decoder_seek_absolute(x, y) |
79 | 89 |
80 typedef FLAC__SeekableStreamDecoderSeekStatus d_seek_status_t; | 90 typedef FLAC__SeekableStreamDecoderSeekStatus d_seek_status_t; |
81 typedef FLAC__SeekableStreamDecoderTellStatus d_tell_status_t; | 91 typedef FLAC__SeekableStreamDecoderTellStatus d_tell_status_t; |
82 typedef FLAC__SeekableStreamDecoderLengthStatus d_length_status_t; | 92 typedef FLAC__SeekableStreamDecoderLengthStatus d_length_status_t; |
93 #else | |
94 #include <FLAC/stream_decoder.h> | |
95 | |
96 #define D_END_OF_STREAM FLAC__STREAM_DECODER_END_OF_STREAM | |
97 | |
98 #define d_new() FLAC__stream_decoder_new() | |
99 #define d_process_metadata(x) FLAC__stream_decoder_process_until_end_of_metadata(x) | |
100 #define d_process_one_frame(x) FLAC__stream_decoder_process_single(x) | |
101 #define d_get_state(x) FLAC__stream_decoder_get_state(x) | |
102 #define d_finish(x) FLAC__stream_decoder_finish(x) | |
103 #define d_delete(x) FLAC__stream_decoder_delete(x) | |
104 | |
105 typedef FLAC__StreamDecoder decoder_t; | |
106 typedef FLAC__StreamDecoderReadStatus d_read_status_t; | |
107 | |
108 #define D_SEEK_STATUS_OK FLAC__STREAM_DECODER_SEEK_STATUS_OK | |
109 #define D_SEEK_STATUS_ERROR FLAC__STREAM_DECODER_SEEK_STATUS_ERROR | |
110 #define D_TELL_STATUS_OK FLAC__STREAM_DECODER_TELL_STATUS_OK | |
111 #define D_TELL_STATUS_ERROR FLAC__STREAM_DECODER_TELL_STATUS_ERROR | |
112 #define D_LENGTH_STATUS_OK FLAC__STREAM_DECODER_LENGTH_STATUS_OK | |
113 #define D_LENGTH_STATUS_ERROR FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR | |
114 | |
115 #define d_seek_absolute(x, y) FLAC__stream_decoder_seek_absolute(x, y) | |
116 | |
117 typedef FLAC__StreamDecoderSeekStatus d_seek_status_t; | |
118 typedef FLAC__StreamDecoderTellStatus d_tell_status_t; | |
119 typedef FLAC__StreamDecoderLengthStatus d_length_status_t; | |
120 #endif | |
83 | 121 |
84 #define D_WRITE_CONTINUE FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE | 122 #define D_WRITE_CONTINUE FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE |
85 #define D_READ_END_OF_STREAM FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM | 123 #define D_READ_END_OF_STREAM FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM |
86 #define D_READ_ABORT FLAC__STREAM_DECODER_READ_STATUS_ABORT | 124 #define D_READ_ABORT FLAC__STREAM_DECODER_READ_STATUS_ABORT |
87 #define D_READ_CONTINUE FLAC__STREAM_DECODER_READ_STATUS_CONTINUE | 125 #define D_READ_CONTINUE FLAC__STREAM_DECODER_READ_STATUS_CONTINUE |
139 d_delete(f->decoder); | 177 d_delete(f->decoder); |
140 free(f); | 178 free(f); |
141 } /* free_flac */ | 179 } /* free_flac */ |
142 | 180 |
143 | 181 |
182 #ifdef LEGACY_FLAC | |
144 static d_read_status_t read_callback( | 183 static d_read_status_t read_callback( |
145 const decoder_t *decoder, FLAC__byte buffer[], | 184 const decoder_t *decoder, FLAC__byte buffer[], |
146 unsigned int *bytes, void *client_data) | 185 unsigned int *bytes, void *client_data) |
186 #else | |
187 static d_read_status_t read_callback( | |
188 const decoder_t *decoder, FLAC__byte buffer[], | |
189 size_t *bytes, void *client_data) | |
190 #endif | |
147 { | 191 { |
148 flac_t *f = (flac_t *) client_data; | 192 flac_t *f = (flac_t *) client_data; |
149 Uint32 retval; | 193 Uint32 retval; |
150 | 194 |
151 retval = SDL_RWread(f->rw, (Uint8 *) buffer, 1, *bytes); | 195 retval = SDL_RWread(f->rw, (Uint8 *) buffer, 1, *bytes); |
414 { | 458 { |
415 free(f); | 459 free(f); |
416 BAIL_MACRO(ERR_OUT_OF_MEMORY, 0); | 460 BAIL_MACRO(ERR_OUT_OF_MEMORY, 0); |
417 } /* if */ | 461 } /* if */ |
418 | 462 |
463 #ifdef LEGACY_FLAC | |
419 d_set_read_callback(decoder, read_callback); | 464 d_set_read_callback(decoder, read_callback); |
420 d_set_write_callback(decoder, write_callback); | 465 d_set_write_callback(decoder, write_callback); |
421 d_set_metadata_callback(decoder, metadata_callback); | 466 d_set_metadata_callback(decoder, metadata_callback); |
422 d_set_error_callback(decoder, error_callback); | 467 d_set_error_callback(decoder, error_callback); |
423 d_set_seek_callback(decoder, seek_callback); | 468 d_set_seek_callback(decoder, seek_callback); |
424 d_set_tell_callback(decoder, tell_callback); | 469 d_set_tell_callback(decoder, tell_callback); |
425 d_set_length_callback(decoder, length_callback); | 470 d_set_length_callback(decoder, length_callback); |
426 d_set_eof_callback(decoder, eof_callback); | 471 d_set_eof_callback(decoder, eof_callback); |
427 | 472 |
428 d_set_client_data(decoder, f); | 473 d_set_client_data(decoder, f); |
474 #endif | |
429 | 475 |
430 f->rw = internal->rw; | 476 f->rw = internal->rw; |
431 f->sample = sample; | 477 f->sample = sample; |
432 f->decoder = decoder; | 478 f->decoder = decoder; |
433 f->sample->actual.format = 0; | 479 f->sample->actual.format = 0; |
434 f->is_flac = 0 /* !!! FIXME: should be "has_extension", not "0". */; | 480 f->is_flac = 0 /* !!! FIXME: should be "has_extension", not "0". */; |
435 | 481 |
436 internal->decoder_private = f; | 482 internal->decoder_private = f; |
483 /* really should check the init return value here: */ | |
484 #ifdef LEGACY_FLAC | |
437 d_init(decoder); | 485 d_init(decoder); |
486 #else | |
487 FLAC__stream_decoder_init_stream(decoder, read_callback, seek_callback, | |
488 tell_callback, length_callback, | |
489 eof_callback, write_callback, | |
490 metadata_callback, error_callback, f); | |
491 #endif | |
438 | 492 |
439 sample->flags = SOUND_SAMPLEFLAG_NONE; | 493 sample->flags = SOUND_SAMPLEFLAG_NONE; |
440 | 494 |
441 pos = SDL_RWtell(f->rw); | 495 pos = SDL_RWtell(f->rw); |
442 if (SDL_RWseek(f->rw, 0, SEEK_END) > 0) | 496 if (SDL_RWseek(f->rw, 0, SEEK_END) > 0) |