summaryrefslogtreecommitdiff
path: root/audio/squash/files/patch-src_play__flac.c
blob: b9925d280e15a16f1473380617915cb6f6ff6f89 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
--- src/play_flac.c.orig	2003-12-18 17:08:57 UTC
+++ src/play_flac.c
@@ -24,7 +24,7 @@
 #include "database.h" /* for insert_meta_data */
 #include "play_flac.h"
 
-void flac_error_callback(const FLAC__FileDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data) {
+void flac_error_callback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data) {
     /* errors?  we don't need no stinking errors */
     return;
 }
@@ -36,47 +36,26 @@ void flac_error_callback(const FLAC__Fil
  */
 void *flac_open( char *filename, sound_format_t *sound_format ) {
     flac_data_t *flac_data;
-    FLAC__FileDecoderState state;
+    FLAC__StreamDecoderInitStatus state;
 
     /* Allocate space for data */
     squash_malloc( flac_data, sizeof(flac_data_t) );
 
-    if( (flac_data->decoder = FLAC__file_decoder_new()) == NULL ) {
+    if( (flac_data->decoder = FLAC__stream_decoder_new()) == NULL ) {
         squash_free( flac_data );
         return (void *)NULL;
         // squash_error( "Unable to create flac decoder" );
     }
 
-    if( !FLAC__file_decoder_set_filename( flac_data->decoder, filename ) ) {
-        squash_free( flac_data );
-        return (void *)NULL;
-        // squash_error( "Unable to set filename in decoder" );
-    }
-
-    FLAC__file_decoder_set_metadata_callback( flac_data->decoder, flac_metadata_callback_decode_frame );
-
-    FLAC__file_decoder_set_write_callback( flac_data->decoder, flac_write_callback_decode_frame );
-
-    FLAC__file_decoder_set_error_callback( flac_data->decoder, flac_error_callback );
-
-    FLAC__file_decoder_set_client_data( flac_data->decoder, flac_data );
-
-    state = FLAC__file_decoder_init( flac_data->decoder );
+    state = FLAC__stream_decoder_init_file( flac_data->decoder, filename, flac_write_callback_decode_frame, flac_metadata_callback_decode_frame, flac_error_callback, flac_data );
     switch( state ) {
-        case FLAC__FILE_DECODER_OK:
+        case FLAC__STREAM_DECODER_INIT_STATUS_OK:
             /* no problem */
             break;
-        case FLAC__FILE_DECODER_END_OF_FILE:
-        case FLAC__FILE_DECODER_ERROR_OPENING_FILE:
-        case FLAC__FILE_DECODER_MEMORY_ALLOCATION_ERROR:
-        case FLAC__FILE_DECODER_SEEK_ERROR:
-        case FLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR:
-        case FLAC__FILE_DECODER_ALREADY_INITIALIZED:
-        case FLAC__FILE_DECODER_INVALID_CALLBACK:
-        case FLAC__FILE_DECODER_UNINITIALIZED:
+        default:
             squash_free( flac_data );
             return (void *)NULL;
-            // squash_error( "Unable to initialize decoder: %s", FLAC__FileDecoderStateString[ state ] );
+            // squash_error( "Unable to initialize decoder: %s", FLAC__StreamDecoderInitStatusString[ state ] );
             break;
     }
 
@@ -86,7 +65,7 @@ void *flac_open( char *filename, sound_f
     flac_data->sample_rate = -1;
     flac_data->duration = -1;
 
-    FLAC__file_decoder_process_until_end_of_metadata( flac_data->decoder );
+    FLAC__stream_decoder_process_until_end_of_metadata( flac_data->decoder );
 
     sound_format->rate = flac_data->sample_rate;
     sound_format->channels = flac_data->channels;
@@ -97,12 +76,12 @@ void *flac_open( char *filename, sound_f
     return (void *)flac_data;
 }
 
-FLAC__StreamDecoderWriteStatus flac_write_callback_load_meta( const FLAC__FileDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data ) {
+FLAC__StreamDecoderWriteStatus flac_write_callback_load_meta( const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data ) {
     /* do nothing ignore any decoded frames (when just loading meta data)*/
     return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
 }
 
-void flac_metadata_callback_load_meta( const FLAC__FileDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data ) {
+void flac_metadata_callback_load_meta( const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data ) {
     FLAC__StreamMetadata_VorbisComment comment = metadata->data.vorbis_comment;
     int i;
     char *start, *end, *key, *value;
@@ -128,7 +107,7 @@ void flac_metadata_callback_load_meta( c
     }
 }
 
-FLAC__StreamDecoderWriteStatus flac_write_callback_decode_frame( const FLAC__FileDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data ) {
+FLAC__StreamDecoderWriteStatus flac_write_callback_decode_frame( const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data ) {
     flac_data_t *flac_data = (flac_data_t *)client_data;
     int i, j, k;
 
@@ -158,7 +137,7 @@ FLAC__StreamDecoderWriteStatus flac_writ
     return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
 }
 
-void flac_metadata_callback_decode_frame( const FLAC__FileDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data ) {
+void flac_metadata_callback_decode_frame( const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data ) {
     flac_data_t *flac_data = (flac_data_t *)client_data;
 
     if( metadata->type != FLAC__METADATA_TYPE_STREAMINFO ) {
@@ -172,47 +151,29 @@ void flac_metadata_callback_decode_frame
 }
 
 void flac_load_meta( void *data, char *filename ) {
-    FLAC__FileDecoder *decoder;
-    FLAC__FileDecoderState state;
+    FLAC__StreamDecoder *decoder;
+    FLAC__StreamDecoderInitStatus state;
 
-    if( (decoder = FLAC__file_decoder_new()) == NULL ) {
+    if( (decoder = FLAC__stream_decoder_new()) == NULL ) {
         squash_error( "Unable to create flac decoder" );
     }
 
-    if( !FLAC__file_decoder_set_filename( decoder, filename ) ) {
-        squash_error( "Unable to set filename in decoder" );
-    }
-
-    FLAC__file_decoder_set_metadata_callback( decoder, flac_metadata_callback_load_meta );
-    FLAC__file_decoder_set_metadata_respond_all( decoder );
-
-    FLAC__file_decoder_set_write_callback( decoder, flac_write_callback_load_meta );
-
-    FLAC__file_decoder_set_error_callback( decoder, flac_error_callback );
-
-    FLAC__file_decoder_set_client_data( decoder, data );
+    FLAC__stream_decoder_set_metadata_respond_all( decoder );
 
-    state = FLAC__file_decoder_init( decoder );
+    state = FLAC__stream_decoder_init_file( decoder, filename,  flac_write_callback_load_meta, flac_metadata_callback_load_meta, flac_error_callback, data );
     switch( state ) {
-        case FLAC__FILE_DECODER_OK:
+        case FLAC__STREAM_DECODER_INIT_STATUS_OK:
             /* no problem */
             break;
-        case FLAC__FILE_DECODER_END_OF_FILE:
-        case FLAC__FILE_DECODER_ERROR_OPENING_FILE:
-        case FLAC__FILE_DECODER_MEMORY_ALLOCATION_ERROR:
-        case FLAC__FILE_DECODER_SEEK_ERROR:
-        case FLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR:
-        case FLAC__FILE_DECODER_ALREADY_INITIALIZED:
-        case FLAC__FILE_DECODER_INVALID_CALLBACK:
-        case FLAC__FILE_DECODER_UNINITIALIZED:
-            squash_error( "Unable to initialize decoder: %s", FLAC__FileDecoderStateString[ state ] );
+        default:
+            squash_error( "Unable to initialize decoder: %s", FLAC__StreamDecoderInitStatusString[ state ] );
             break;
     }
 
-    FLAC__file_decoder_process_until_end_of_metadata( decoder );
+    FLAC__stream_decoder_process_until_end_of_metadata( decoder );
 
-    FLAC__file_decoder_finish( decoder );
-    FLAC__file_decoder_delete( decoder );
+    FLAC__stream_decoder_finish( decoder );
+    FLAC__stream_decoder_delete( decoder );
 
     return;
 }
@@ -223,29 +184,27 @@ void flac_load_meta( void *data, char *f
 frame_data_t flac_decode_frame( void *data ) {
     flac_data_t *flac_data = (flac_data_t *)data;
     frame_data_t frame_data;
-    FLAC__FileDecoderState state;
+    FLAC__StreamDecoderState state;
 
-    FLAC__file_decoder_process_single( flac_data->decoder );
+    FLAC__stream_decoder_process_single( flac_data->decoder );
     frame_data.position = flac_data->position;
 
-    state = FLAC__file_decoder_get_state( flac_data->decoder );
+    state = FLAC__stream_decoder_get_state( flac_data->decoder );
     switch( state ) {
-        case FLAC__FILE_DECODER_OK:
+        case FLAC__STREAM_DECODER_READ_FRAME:
             frame_data.pcm_data = flac_data->buffer;
             frame_data.pcm_size = flac_data->buffer_size;
             break;
-        case FLAC__FILE_DECODER_END_OF_FILE:
+        case FLAC__STREAM_DECODER_END_OF_STREAM:
             frame_data.pcm_data = NULL;
             frame_data.pcm_size = 0;
             break;
-        case FLAC__FILE_DECODER_ERROR_OPENING_FILE:
-        case FLAC__FILE_DECODER_MEMORY_ALLOCATION_ERROR:
-        case FLAC__FILE_DECODER_SEEK_ERROR:
-        case FLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR:
-        case FLAC__FILE_DECODER_ALREADY_INITIALIZED:
-        case FLAC__FILE_DECODER_INVALID_CALLBACK:
-        case FLAC__FILE_DECODER_UNINITIALIZED:
-            squash_error("Error while decoding: %s", FLAC__FileDecoderStateString[ state ] );
+        case FLAC__STREAM_DECODER_OGG_ERROR:
+        case FLAC__STREAM_DECODER_SEEK_ERROR:
+        case FLAC__STREAM_DECODER_ABORTED:
+        case FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR:
+        case FLAC__STREAM_DECODER_UNINITIALIZED:
+            squash_error("Error while decoding: %s", FLAC__StreamDecoderStateString[ state ] );
             break;
     }
 
@@ -267,7 +226,7 @@ long flac_calc_duration( void *data ) {
 void flac_seek( void *data, long seek_time, long duration ) {
     flac_data_t *flac_data = (flac_data_t *)data;
 
-    FLAC__file_decoder_seek_absolute( flac_data->decoder, seek_time * (flac_data->sample_rate / 1000) );
+    FLAC__stream_decoder_seek_absolute( flac_data->decoder, seek_time * (flac_data->sample_rate / 1000) );
     return;
 }
 
@@ -277,9 +236,9 @@ void flac_seek( void *data, long seek_ti
 void flac_close( void *data ) {
     flac_data_t *flac_data = (flac_data_t *)data;
 
-    FLAC__file_decoder_finish( flac_data->decoder );
+    FLAC__stream_decoder_finish( flac_data->decoder );
 
-    FLAC__file_decoder_delete( flac_data->decoder );
+    FLAC__stream_decoder_delete( flac_data->decoder );
 
     /* Free allocated storage */
     squash_free( flac_data->buffer );