annotate src/alac/plugin.c @ 56:56c88eee9802 trunk

[svn] - experimental ALAC plugin -- don't use this, it crashes
author nenolod
date Sat, 30 Sep 2006 19:26:34 -0700
parents
children 96901271d2e2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
56
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
1 /*
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
2 * Copyright (c) 2005 David Hammerton
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
3 * All rights reserved.
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
4 *
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
5 * Adapted from example program by William Pitcock <nenolod@atheme.org>
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
6 *
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
7 * Permission is hereby granted, free of charge, to any person
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
8 * obtaining a copy of this software and associated documentation
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
9 * files (the "Software"), to deal in the Software without
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
10 * restriction, including without limitation the rights to use,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
11 * copy, modify, merge, publish, distribute, sublicense, and/or
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
12 * sell copies of the Software, and to permit persons to whom the
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
13 * Software is furnished to do so, subject to the following conditions:
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
14 *
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
15 * The above copyright notice and this permission notice shall be
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
16 * included in all copies or substantial portions of the Software.
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
17 *
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
20 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
22 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
25 * OTHER DEALINGS IN THE SOFTWARE.
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
26 */
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
27
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
28 #include <ctype.h>
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
29 #include <stdio.h>
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
30 #include <stdint.h>
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
31 #include <stdlib.h>
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
32 #include <errno.h>
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
33 #include <string.h>
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
34
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
35 #include <audacious/plugin.h>
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
36 #include <audacious/output.h>
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
37 #include <audacious/vfs.h>
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
38
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
39 #include "demux.h"
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
40 #include "decomp.h"
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
41 #include "stream.h"
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
42
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
43 alac_file *alac = NULL;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
44
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
45 static VFSFile *input_file = NULL;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
46 static int input_opened = 0;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
47 static stream_t *input_stream;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
48
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
49 static int write_wav_format = 0;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
50 static int verbose = 0;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
51
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
52 gpointer decode_thread(void *args);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
53 static GThread *playback_thread;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
54
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
55 static void alac_init(void)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
56 {
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
57 /* empty */
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
58 }
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
59
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
60 gboolean is_our_file(char *filename)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
61 {
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
62 demux_res_t demux_res;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
63 input_file = vfs_fopen(filename, "rb");
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
64 #ifdef WORDS_BIGENDIAN
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
65 input_stream = stream_create_file(input_file, 1);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
66 #else
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
67 input_stream = stream_create_file(input_file, 0);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
68 #endif
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
69 if (!input_stream)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
70 {
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
71 fprintf(stderr, "failed to create input stream from file\n");
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
72 vfs_fclose(input_file);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
73 return FALSE;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
74 }
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
75
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
76 /* if qtmovie_read returns successfully, the stream is up to
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
77 * the movie data, which can be used directly by the decoder */
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
78 if (!qtmovie_read(input_stream, &demux_res))
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
79 {
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
80 fprintf(stderr, "failed to load the QuickTime movie headers\n");
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
81 stream_destroy(input_stream);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
82 vfs_fclose(input_file);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
83 return FALSE;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
84 }
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
85
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
86 stream_destroy(input_stream);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
87 vfs_fclose(input_file);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
88
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
89 return TRUE;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
90 }
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
91
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
92 static void play_file(char *filename)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
93 {
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
94 playback_thread = g_thread_create(decode_thread, filename, TRUE, NULL);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
95 }
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
96
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
97 static void stop(void)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
98 {
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
99 g_thread_join(playback_thread);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
100 output_close_audio();
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
101 }
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
102
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
103 static void seek(gint time)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
104 {
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
105 /* unimplemented */
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
106 }
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
107
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
108 InputPlugin alac_ip = {
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
109 NULL,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
110 NULL,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
111 "Apple Lossless Plugin", /* Description */
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
112 alac_init,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
113 NULL,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
114 NULL,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
115 is_our_file,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
116 NULL,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
117 play_file,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
118 stop,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
119 output_pause,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
120 seek,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
121 NULL,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
122 get_output_time,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
123 NULL,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
124 NULL,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
125 NULL,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
126 NULL,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
127 NULL,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
128 NULL,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
129 NULL,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
130 NULL,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
131 NULL, /* file_info_box */
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
132 NULL
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
133 };
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
134
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
135 static int get_sample_info(demux_res_t *demux_res, uint32_t samplenum,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
136 uint32_t *sample_duration,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
137 uint32_t *sample_byte_size)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
138 {
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
139 unsigned int duration_index_accum = 0;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
140 unsigned int duration_cur_index = 0;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
141
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
142 if (samplenum >= demux_res->num_sample_byte_sizes)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
143 {
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
144 fprintf(stderr, "sample %i does not exist\n", samplenum);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
145 return 0;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
146 }
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
147
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
148 if (!demux_res->num_time_to_samples)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
149 {
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
150 fprintf(stderr, "no time to samples\n");
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
151 return 0;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
152 }
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
153 while ((demux_res->time_to_sample[duration_cur_index].sample_count + duration_index_accum)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
154 <= samplenum)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
155 {
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
156 duration_index_accum += demux_res->time_to_sample[duration_cur_index].sample_count;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
157 duration_cur_index++;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
158 if (duration_cur_index >= demux_res->num_time_to_samples)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
159 {
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
160 fprintf(stderr, "sample %i does not have a duration\n", samplenum);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
161 return 0;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
162 }
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
163 }
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
164
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
165 *sample_duration = demux_res->time_to_sample[duration_cur_index].sample_duration;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
166 *sample_byte_size = demux_res->sample_byte_size[samplenum];
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
167
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
168 return 1;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
169 }
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
170
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
171 static void GetBuffer(demux_res_t *demux_res)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
172 {
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
173 unsigned long destBufferSize = 1024*16; /* 16kb buffer = 4096 frames = 1 alac sample */
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
174 void *pDestBuffer = malloc(destBufferSize);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
175 int bytes_read = 0;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
176
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
177 unsigned int buffer_size = 1024*64;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
178 void *buffer;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
179
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
180 unsigned int i;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
181
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
182 buffer = malloc(buffer_size);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
183
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
184 for (i = 0; i < demux_res->num_sample_byte_sizes; i++)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
185 {
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
186 uint32_t sample_duration;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
187 uint32_t sample_byte_size;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
188
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
189 int outputBytes;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
190
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
191 /* just get one sample for now */
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
192 if (!get_sample_info(demux_res, i,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
193 &sample_duration, &sample_byte_size))
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
194 {
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
195 fprintf(stderr, "sample failed\n");
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
196 return;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
197 }
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
198
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
199 if (buffer_size < sample_byte_size)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
200 {
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
201 fprintf(stderr, "sorry buffer too small! (is %i want %i)\n",
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
202 buffer_size,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
203 sample_byte_size);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
204 return;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
205 }
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
206
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
207 stream_read(input_stream, sample_byte_size,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
208 buffer);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
209
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
210 /* now fetch */
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
211 outputBytes = destBufferSize;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
212 decode_frame(alac, buffer, pDestBuffer, &outputBytes);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
213
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
214 /* write */
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
215 bytes_read += outputBytes;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
216
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
217 if (verbose)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
218 fprintf(stderr, "read %i bytes. total: %i\n", outputBytes, bytes_read);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
219
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
220 produce_audio(get_written_time(), FMT_S16_LE, demux_res->num_channels, outputBytes, pDestBuffer, NULL);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
221 }
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
222 if (verbose)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
223 fprintf(stderr, "done reading, read %i frames\n", i);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
224 }
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
225
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
226 static void init_sound_converter(demux_res_t *demux_res)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
227 {
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
228 alac = create_alac(demux_res->sample_size, demux_res->num_channels);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
229
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
230 alac_set_info(alac, demux_res->codecdata);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
231 }
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
232
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
233 gpointer decode_thread(void *args)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
234 {
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
235 demux_res_t demux_res;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
236 unsigned int output_size, i;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
237
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
238 input_file = vfs_fopen((char *) args, "rb");
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
239 #ifdef WORDS_BIGENDIAN
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
240 input_stream = stream_create_file(input_file, 1);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
241 #else
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
242 input_stream = stream_create_file(input_file, 0);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
243 #endif
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
244 if (!input_stream)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
245 {
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
246 fprintf(stderr, "failed to create input stream from file\n");
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
247 return 0;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
248 }
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
249
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
250 /* if qtmovie_read returns successfully, the stream is up to
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
251 * the movie data, which can be used directly by the decoder */
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
252 if (!qtmovie_read(input_stream, &demux_res))
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
253 {
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
254 fprintf(stderr, "failed to load the QuickTime movie headers\n");
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
255 return 0;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
256 }
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
257
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
258 /* initialise the sound converter */
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
259 init_sound_converter(&demux_res);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
260
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
261 /* will convert the entire buffer */
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
262 GetBuffer(&demux_res);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
263
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
264 stream_destroy(input_stream);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
265
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
266 if (input_opened)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
267 vfs_fclose(input_file);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
268
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
269 return NULL;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
270 }
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
271
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
272 InputPlugin *get_iplugin_info(void)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
273 {
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
274 return &alac_ip;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
275 }