annotate src/alac/plugin.c @ 71:5b0619b09745 trunk

[svn] Detect duration: - this took a lot of brute forcing - oh, and apparently apple has a sense of humour about their format, it uses a samplesize multiple of 251.
author nenolod
date Sun, 01 Oct 2006 00:05:37 -0700
parents 31799ddaf2e9
children c2981235af26
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
69
08c9353a9bb3 [svn] - about box
nenolod
parents: 68
diff changeset
35 #include <glib.h>
08c9353a9bb3 [svn] - about box
nenolod
parents: 68
diff changeset
36 #include <glib/gi18n.h>
08c9353a9bb3 [svn] - about box
nenolod
parents: 68
diff changeset
37
56
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
38 #include <audacious/plugin.h>
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
39 #include <audacious/output.h>
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
40 #include <audacious/vfs.h>
69
08c9353a9bb3 [svn] - about box
nenolod
parents: 68
diff changeset
41 #include <audacious/util.h>
56
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 #include "demux.h"
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
44 #include "decomp.h"
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
45 #include "stream.h"
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
46
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
47 alac_file *alac = NULL;
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 VFSFile *input_file = NULL;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
50 static int input_opened = 0;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
51 static stream_t *input_stream;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
52
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
53 gpointer decode_thread(void *args);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
54 static GThread *playback_thread;
66
f04b33512c3d [svn] - get_time() implementation
nenolod
parents: 59
diff changeset
55 static int going = 0;
56
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
56
57
96901271d2e2 [svn] - fix crashing. works on my x64 box, static on bigendian (tested: x64-be, mips, ppc64)
nenolod
parents: 56
diff changeset
57 extern void set_endian();
96901271d2e2 [svn] - fix crashing. works on my x64 box, static on bigendian (tested: x64-be, mips, ppc64)
nenolod
parents: 56
diff changeset
58
69
08c9353a9bb3 [svn] - about box
nenolod
parents: 68
diff changeset
59 static void alac_about(void)
08c9353a9bb3 [svn] - about box
nenolod
parents: 68
diff changeset
60 {
08c9353a9bb3 [svn] - about box
nenolod
parents: 68
diff changeset
61 static GtkWidget *aboutbox;
08c9353a9bb3 [svn] - about box
nenolod
parents: 68
diff changeset
62
08c9353a9bb3 [svn] - about box
nenolod
parents: 68
diff changeset
63 if(aboutbox != NULL)
08c9353a9bb3 [svn] - about box
nenolod
parents: 68
diff changeset
64 return;
08c9353a9bb3 [svn] - about box
nenolod
parents: 68
diff changeset
65
08c9353a9bb3 [svn] - about box
nenolod
parents: 68
diff changeset
66 aboutbox = xmms_show_message("About Apple Lossless Audio Plugin",
08c9353a9bb3 [svn] - about box
nenolod
parents: 68
diff changeset
67 "Copyright (c) 2006 Audacious team\n"
08c9353a9bb3 [svn] - about box
nenolod
parents: 68
diff changeset
68 "Portions (c) 2005-2006 David Hammerton <crazney -at- crazney.net>",
08c9353a9bb3 [svn] - about box
nenolod
parents: 68
diff changeset
69 _("Ok"), FALSE, NULL, NULL);
08c9353a9bb3 [svn] - about box
nenolod
parents: 68
diff changeset
70
08c9353a9bb3 [svn] - about box
nenolod
parents: 68
diff changeset
71 g_signal_connect(G_OBJECT(aboutbox), "destroy",
08c9353a9bb3 [svn] - about box
nenolod
parents: 68
diff changeset
72 G_CALLBACK(gtk_widget_destroyed),
08c9353a9bb3 [svn] - about box
nenolod
parents: 68
diff changeset
73 &aboutbox);
08c9353a9bb3 [svn] - about box
nenolod
parents: 68
diff changeset
74 }
08c9353a9bb3 [svn] - about box
nenolod
parents: 68
diff changeset
75
56
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
76 static void alac_init(void)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
77 {
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
78 /* empty */
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
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
81 gboolean is_our_file(char *filename)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
82 {
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
83 demux_res_t demux_res;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
84 input_file = vfs_fopen(filename, "rb");
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
85 input_stream = stream_create_file(input_file, 1);
57
96901271d2e2 [svn] - fix crashing. works on my x64 box, static on bigendian (tested: x64-be, mips, ppc64)
nenolod
parents: 56
diff changeset
86
96901271d2e2 [svn] - fix crashing. works on my x64 box, static on bigendian (tested: x64-be, mips, ppc64)
nenolod
parents: 56
diff changeset
87 set_endian();
96901271d2e2 [svn] - fix crashing. works on my x64 box, static on bigendian (tested: x64-be, mips, ppc64)
nenolod
parents: 56
diff changeset
88
56
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
89 if (!input_stream)
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 vfs_fclose(input_file);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
92 return FALSE;
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
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
95 /* 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
96 * 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
97 if (!qtmovie_read(input_stream, &demux_res))
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 stream_destroy(input_stream);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
100 vfs_fclose(input_file);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
101 return FALSE;
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
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
104 stream_destroy(input_stream);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
105 vfs_fclose(input_file);
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 return TRUE;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
108 }
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
109
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
110 static void play_file(char *filename)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
111 {
68
d435a3abc035 [svn] - set alac::going before we fork the decoder thread off, this stops the core from getting confused
nenolod
parents: 67
diff changeset
112 going = 1;
56
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
113 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
114 }
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
115
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
116 static void stop(void)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
117 {
68
d435a3abc035 [svn] - set alac::going before we fork the decoder thread off, this stops the core from getting confused
nenolod
parents: 67
diff changeset
118 going = 0;
56
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
119 g_thread_join(playback_thread);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
120 output_close_audio();
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
121 }
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
122
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
123 static void seek(gint time)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
124 {
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
125 /* unimplemented */
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
126 }
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
127
66
f04b33512c3d [svn] - get_time() implementation
nenolod
parents: 59
diff changeset
128 static gint get_time(void)
f04b33512c3d [svn] - get_time() implementation
nenolod
parents: 59
diff changeset
129 {
f04b33512c3d [svn] - get_time() implementation
nenolod
parents: 59
diff changeset
130 if (going)
f04b33512c3d [svn] - get_time() implementation
nenolod
parents: 59
diff changeset
131 return get_output_time();
f04b33512c3d [svn] - get_time() implementation
nenolod
parents: 59
diff changeset
132 else
f04b33512c3d [svn] - get_time() implementation
nenolod
parents: 59
diff changeset
133 return -1;
f04b33512c3d [svn] - get_time() implementation
nenolod
parents: 59
diff changeset
134 }
f04b33512c3d [svn] - get_time() implementation
nenolod
parents: 59
diff changeset
135
56
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
136 InputPlugin alac_ip = {
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
137 NULL,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
138 NULL,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
139 "Apple Lossless Plugin", /* Description */
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
140 alac_init,
69
08c9353a9bb3 [svn] - about box
nenolod
parents: 68
diff changeset
141 alac_about,
56
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
142 NULL,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
143 is_our_file,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
144 NULL,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
145 play_file,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
146 stop,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
147 output_pause,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
148 seek,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
149 NULL,
66
f04b33512c3d [svn] - get_time() implementation
nenolod
parents: 59
diff changeset
150 get_time,
56
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
151 NULL,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
152 NULL,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
153 NULL,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
154 NULL,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
155 NULL,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
156 NULL,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
157 NULL,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
158 NULL,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
159 NULL, /* file_info_box */
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
160 NULL
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
161 };
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 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
164 uint32_t *sample_duration,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
165 uint32_t *sample_byte_size)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
166 {
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
167 unsigned int duration_index_accum = 0;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
168 unsigned int duration_cur_index = 0;
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 if (samplenum >= demux_res->num_sample_byte_sizes)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
171 return 0;
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 if (!demux_res->num_time_to_samples)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
174 return 0;
67
41e2dc106f4e [svn] - remove spurious debugging notices
nenolod
parents: 66
diff changeset
175
56
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
176 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
177 <= samplenum)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
178 {
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
179 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
180 duration_cur_index++;
67
41e2dc106f4e [svn] - remove spurious debugging notices
nenolod
parents: 66
diff changeset
181
56
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
182 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
183 return 0;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
184 }
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 *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
187 *sample_byte_size = demux_res->sample_byte_size[samplenum];
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 return 1;
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
57
96901271d2e2 [svn] - fix crashing. works on my x64 box, static on bigendian (tested: x64-be, mips, ppc64)
nenolod
parents: 56
diff changeset
192 void GetBuffer(demux_res_t *demux_res)
56
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
193 {
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
194 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
195 void *pDestBuffer = malloc(destBufferSize);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
196 int bytes_read = 0;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
197
57
96901271d2e2 [svn] - fix crashing. works on my x64 box, static on bigendian (tested: x64-be, mips, ppc64)
nenolod
parents: 56
diff changeset
198 unsigned int buffer_size = 1024*128;
56
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
199 void *buffer;
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 unsigned int i;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
202
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
203 buffer = malloc(buffer_size);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
204
68
d435a3abc035 [svn] - set alac::going before we fork the decoder thread off, this stops the core from getting confused
nenolod
parents: 67
diff changeset
205 for (i = 0; i < demux_res->num_sample_byte_sizes && going == 1; i++)
56
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 uint32_t sample_duration;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
208 uint32_t sample_byte_size;
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 int outputBytes;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
211
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
212 /* just get one sample for now */
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
213 if (!get_sample_info(demux_res, i,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
214 &sample_duration, &sample_byte_size))
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
215 return;
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 (buffer_size < sample_byte_size)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
218 return;
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 stream_read(input_stream, sample_byte_size,
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
221 buffer);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
222
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
223 /* now fetch */
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
224 outputBytes = destBufferSize;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
225 decode_frame(alac, buffer, pDestBuffer, &outputBytes);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
226
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
227 /* write */
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
228 bytes_read += outputBytes;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
229
57
96901271d2e2 [svn] - fix crashing. works on my x64 box, static on bigendian (tested: x64-be, mips, ppc64)
nenolod
parents: 56
diff changeset
230 produce_audio(alac_ip.output->written_time(), FMT_S16_LE, demux_res->num_channels, outputBytes, pDestBuffer, &going);
56
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
231 }
70
31799ddaf2e9 [svn] - fix memory leaks
nenolod
parents: 69
diff changeset
232
31799ddaf2e9 [svn] - fix memory leaks
nenolod
parents: 69
diff changeset
233 free(buffer);
31799ddaf2e9 [svn] - fix memory leaks
nenolod
parents: 69
diff changeset
234 free(pDestBuffer);
56
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
235 }
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
236
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
237 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
238 {
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
239 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
240
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
241 alac_set_info(alac, demux_res->codecdata);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
242 }
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
243
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
244 gpointer decode_thread(void *args)
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 demux_res_t demux_res;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
247 unsigned int output_size, i;
71
5b0619b09745 [svn] Detect duration:
nenolod
parents: 70
diff changeset
248 gulong duration = 0; /* samples added up */
5b0619b09745 [svn] Detect duration:
nenolod
parents: 70
diff changeset
249 gint framesize;
56
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
250
57
96901271d2e2 [svn] - fix crashing. works on my x64 box, static on bigendian (tested: x64-be, mips, ppc64)
nenolod
parents: 56
diff changeset
251 set_endian();
96901271d2e2 [svn] - fix crashing. works on my x64 box, static on bigendian (tested: x64-be, mips, ppc64)
nenolod
parents: 56
diff changeset
252
56
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
253 input_file = vfs_fopen((char *) args, "rb");
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
254 input_stream = stream_create_file(input_file, 1);
57
96901271d2e2 [svn] - fix crashing. works on my x64 box, static on bigendian (tested: x64-be, mips, ppc64)
nenolod
parents: 56
diff changeset
255
56
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
256 if (!input_stream)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
257 return 0;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
258
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
259 /* 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
260 * 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
261 if (!qtmovie_read(input_stream, &demux_res))
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
262 return 0;
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 /* initialise the sound converter */
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
265 init_sound_converter(&demux_res);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
266
71
5b0619b09745 [svn] Detect duration:
nenolod
parents: 70
diff changeset
267 /* Sample rates are multiples of 251?! Apple is *fucking* *insane*! -nenolod */
5b0619b09745 [svn] Detect duration:
nenolod
parents: 70
diff changeset
268 duration = (demux_res.num_sample_byte_sizes * (float)((1024 * demux_res.sample_size) - 1.0) /
5b0619b09745 [svn] Detect duration:
nenolod
parents: 70
diff changeset
269 (float)(demux_res.sample_rate / 251));
5b0619b09745 [svn] Detect duration:
nenolod
parents: 70
diff changeset
270
57
96901271d2e2 [svn] - fix crashing. works on my x64 box, static on bigendian (tested: x64-be, mips, ppc64)
nenolod
parents: 56
diff changeset
271 alac_ip.output->open_audio(FMT_S16_LE, demux_res.sample_rate, demux_res.num_channels);
71
5b0619b09745 [svn] Detect duration:
nenolod
parents: 70
diff changeset
272 alac_ip.set_info((char *) args, duration, -1, demux_res.sample_rate, demux_res.num_channels);
57
96901271d2e2 [svn] - fix crashing. works on my x64 box, static on bigendian (tested: x64-be, mips, ppc64)
nenolod
parents: 56
diff changeset
273
56
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
274 /* will convert the entire buffer */
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
275 GetBuffer(&demux_res);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
276
66
f04b33512c3d [svn] - get_time() implementation
nenolod
parents: 59
diff changeset
277 going = 0;
f04b33512c3d [svn] - get_time() implementation
nenolod
parents: 59
diff changeset
278
56
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
279 stream_destroy(input_stream);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
280
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
281 if (input_opened)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
282 vfs_fclose(input_file);
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
283
57
96901271d2e2 [svn] - fix crashing. works on my x64 box, static on bigendian (tested: x64-be, mips, ppc64)
nenolod
parents: 56
diff changeset
284 alac_ip.output->close_audio();
96901271d2e2 [svn] - fix crashing. works on my x64 box, static on bigendian (tested: x64-be, mips, ppc64)
nenolod
parents: 56
diff changeset
285
56
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
286 return NULL;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
287 }
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
288
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
289 InputPlugin *get_iplugin_info(void)
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
290 {
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
291 return &alac_ip;
56c88eee9802 [svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff changeset
292 }