comparison src/alac/plugin.c @ 57:96901271d2e2 trunk

[svn] - fix crashing. works on my x64 box, static on bigendian (tested: x64-be, mips, ppc64)
author nenolod
date Sat, 30 Sep 2006 20:58:51 -0700
parents 56c88eee9802
children d42917f142b5
comparison
equal deleted inserted replaced
56:56c88eee9802 57:96901271d2e2
45 static VFSFile *input_file = NULL; 45 static VFSFile *input_file = NULL;
46 static int input_opened = 0; 46 static int input_opened = 0;
47 static stream_t *input_stream; 47 static stream_t *input_stream;
48 48
49 static int write_wav_format = 0; 49 static int write_wav_format = 0;
50 static int verbose = 0; 50 static int verbose = 1;
51 51
52 gpointer decode_thread(void *args); 52 gpointer decode_thread(void *args);
53 static GThread *playback_thread; 53 static GThread *playback_thread;
54 54
55 extern void set_endian();
56
55 static void alac_init(void) 57 static void alac_init(void)
56 { 58 {
57 /* empty */ 59 /* empty */
58 } 60 }
59 61
60 gboolean is_our_file(char *filename) 62 gboolean is_our_file(char *filename)
61 { 63 {
62 demux_res_t demux_res; 64 demux_res_t demux_res;
63 input_file = vfs_fopen(filename, "rb"); 65 input_file = vfs_fopen(filename, "rb");
64 #ifdef WORDS_BIGENDIAN
65 input_stream = stream_create_file(input_file, 1); 66 input_stream = stream_create_file(input_file, 1);
66 #else 67
67 input_stream = stream_create_file(input_file, 0); 68 set_endian();
68 #endif 69
69 if (!input_stream) 70 if (!input_stream)
70 { 71 {
71 fprintf(stderr, "failed to create input stream from file\n"); 72 fprintf(stderr, "failed to create input stream from file\n");
72 vfs_fclose(input_file); 73 vfs_fclose(input_file);
73 return FALSE; 74 return FALSE;
166 *sample_byte_size = demux_res->sample_byte_size[samplenum]; 167 *sample_byte_size = demux_res->sample_byte_size[samplenum];
167 168
168 return 1; 169 return 1;
169 } 170 }
170 171
171 static void GetBuffer(demux_res_t *demux_res) 172 void GetBuffer(demux_res_t *demux_res)
172 { 173 {
173 unsigned long destBufferSize = 1024*16; /* 16kb buffer = 4096 frames = 1 alac sample */ 174 unsigned long destBufferSize = 1024*16; /* 16kb buffer = 4096 frames = 1 alac sample */
174 void *pDestBuffer = malloc(destBufferSize); 175 void *pDestBuffer = malloc(destBufferSize);
175 int bytes_read = 0; 176 int bytes_read = 0;
176 177 int going = 1;
177 unsigned int buffer_size = 1024*64; 178
179 unsigned int buffer_size = 1024*128;
178 void *buffer; 180 void *buffer;
179 181
180 unsigned int i; 182 unsigned int i;
181 183
182 buffer = malloc(buffer_size); 184 buffer = malloc(buffer_size);
215 bytes_read += outputBytes; 217 bytes_read += outputBytes;
216 218
217 if (verbose) 219 if (verbose)
218 fprintf(stderr, "read %i bytes. total: %i\n", outputBytes, bytes_read); 220 fprintf(stderr, "read %i bytes. total: %i\n", outputBytes, bytes_read);
219 221
220 produce_audio(get_written_time(), FMT_S16_LE, demux_res->num_channels, outputBytes, pDestBuffer, NULL); 222 produce_audio(alac_ip.output->written_time(), FMT_S16_LE, demux_res->num_channels, outputBytes, pDestBuffer, &going);
221 } 223 }
222 if (verbose) 224 if (verbose)
223 fprintf(stderr, "done reading, read %i frames\n", i); 225 fprintf(stderr, "done reading, read %i frames\n", i);
224 } 226 }
225 227
233 gpointer decode_thread(void *args) 235 gpointer decode_thread(void *args)
234 { 236 {
235 demux_res_t demux_res; 237 demux_res_t demux_res;
236 unsigned int output_size, i; 238 unsigned int output_size, i;
237 239
240 set_endian();
241
238 input_file = vfs_fopen((char *) args, "rb"); 242 input_file = vfs_fopen((char *) args, "rb");
239 #ifdef WORDS_BIGENDIAN
240 input_stream = stream_create_file(input_file, 1); 243 input_stream = stream_create_file(input_file, 1);
241 #else 244
242 input_stream = stream_create_file(input_file, 0); 245 printf("filename: %s\n", (char *) args);
243 #endif 246
244 if (!input_stream) 247 if (!input_stream)
245 { 248 {
246 fprintf(stderr, "failed to create input stream from file\n"); 249 fprintf(stderr, "failed to create input stream from file\n");
247 return 0; 250 return 0;
248 } 251 }
256 } 259 }
257 260
258 /* initialise the sound converter */ 261 /* initialise the sound converter */
259 init_sound_converter(&demux_res); 262 init_sound_converter(&demux_res);
260 263
264 alac_ip.output->open_audio(FMT_S16_LE, demux_res.sample_rate, demux_res.num_channels);
265
261 /* will convert the entire buffer */ 266 /* will convert the entire buffer */
262 GetBuffer(&demux_res); 267 GetBuffer(&demux_res);
263 268
264 stream_destroy(input_stream); 269 stream_destroy(input_stream);
265 270
266 if (input_opened) 271 if (input_opened)
267 vfs_fclose(input_file); 272 vfs_fclose(input_file);
268 273
274 alac_ip.output->close_audio();
275
269 return NULL; 276 return NULL;
270 } 277 }
271 278
272 InputPlugin *get_iplugin_info(void) 279 InputPlugin *get_iplugin_info(void)
273 { 280 {