Mercurial > audlegacy-plugins
annotate src/alac/plugin.c @ 3196:0f7180e3b163
alsa-ng: Enforce a minimum buffer size of 500ms.
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Sun, 12 Jul 2009 08:30:13 -0500 |
parents | d7eea4d29d4a |
children |
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 |
330 | 28 #include "config.h" |
29 | |
56
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
30 #include <ctype.h> |
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
31 #include <stdio.h> |
330 | 32 |
33 #if HAVE_STDINT_H | |
34 # include <stdint.h> | |
35 #else | |
36 # if HAVE_INTTYPES_H | |
37 # include <inttypes.h> | |
38 # endif | |
39 #endif | |
40 | |
56
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
41 #include <stdlib.h> |
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
42 #include <errno.h> |
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
43 #include <string.h> |
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
44 |
69 | 45 #include <glib.h> |
2971
3134a0987162
- changed include path from audacious to audlegacy.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
2576
diff
changeset
|
46 #include <audlegacy/i18n.h> |
69 | 47 |
2971
3134a0987162
- changed include path from audacious to audlegacy.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
2576
diff
changeset
|
48 #include <audlegacy/plugin.h> |
3134a0987162
- changed include path from audacious to audlegacy.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
2576
diff
changeset
|
49 #include <audlegacy/output.h> |
56
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
50 |
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
51 #include "demux.h" |
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
52 #include "decomp.h" |
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
53 #include "stream.h" |
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
54 |
3154
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
55 static void decode_thread(InputPlayback *playback); |
56
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
56 static GThread *playback_thread; |
3154
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
57 static guint64 seek_to = -1; |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
58 static guint64 packet0_offset; |
56
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
59 |
57
96901271d2e2
[svn] - fix crashing. works on my x64 box, static on bigendian (tested: x64-be, mips, ppc64)
nenolod
parents:
56
diff
changeset
|
60 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
|
61 |
69 | 62 static void alac_about(void) |
63 { | |
64 static GtkWidget *aboutbox; | |
1284
190a447e5229
"About" window is now translatable.
Stany HENRY <StrassBoy@gmail.com>
parents:
1190
diff
changeset
|
65 |
69 | 66 if(aboutbox != NULL) |
67 return; | |
68 | |
1677
f6f5603a0954
xmms_show_message() changed to audacious_info_dialog()
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
69 aboutbox = audacious_info_dialog(_("About Apple Lossless Audio Plugin"), |
1284
190a447e5229
"About" window is now translatable.
Stany HENRY <StrassBoy@gmail.com>
parents:
1190
diff
changeset
|
70 _("Copyright (c) 2006 Audacious team\n" |
190a447e5229
"About" window is now translatable.
Stany HENRY <StrassBoy@gmail.com>
parents:
1190
diff
changeset
|
71 "Portions (c) 2005-2006 David Hammerton <crazney -at- crazney.net>"), |
69 | 72 _("Ok"), FALSE, NULL, NULL); |
73 | |
74 g_signal_connect(G_OBJECT(aboutbox), "destroy", | |
75 G_CALLBACK(gtk_widget_destroyed), | |
76 &aboutbox); | |
77 } | |
78 | |
256 | 79 gboolean is_our_fd(char *filename, VFSFile* input_file) |
56
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 demux_res_t demux_res; |
77 | 82 stream_t *input_stream; |
83 | |
56
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
84 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
|
85 |
96901271d2e2
[svn] - fix crashing. works on my x64 box, static on bigendian (tested: x64-be, mips, ppc64)
nenolod
parents:
56
diff
changeset
|
86 set_endian(); |
96901271d2e2
[svn] - fix crashing. works on my x64 box, static on bigendian (tested: x64-be, mips, ppc64)
nenolod
parents:
56
diff
changeset
|
87 |
56
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
88 if (!input_stream) |
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
89 return FALSE; |
1284
190a447e5229
"About" window is now translatable.
Stany HENRY <StrassBoy@gmail.com>
parents:
1190
diff
changeset
|
90 |
56
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
91 /* 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
|
92 * 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
|
93 if (!qtmovie_read(input_stream, &demux_res)) |
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 stream_destroy(input_stream); |
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
96 return FALSE; |
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
97 } |
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 |
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
101 return TRUE; |
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 |
3146
87b0c47089e5
alac: Various patches from Hans de Goede. (Closes #61)
William Pitcock <nenolod@atheme.org>
parents:
2971
diff
changeset
|
104 static int get_duration(demux_res_t *demux_res) |
87b0c47089e5
alac: Various patches from Hans de Goede. (Closes #61)
William Pitcock <nenolod@atheme.org>
parents:
2971
diff
changeset
|
105 { |
87b0c47089e5
alac: Various patches from Hans de Goede. (Closes #61)
William Pitcock <nenolod@atheme.org>
parents:
2971
diff
changeset
|
106 int i; |
87b0c47089e5
alac: Various patches from Hans de Goede. (Closes #61)
William Pitcock <nenolod@atheme.org>
parents:
2971
diff
changeset
|
107 long long samples = 0; |
87b0c47089e5
alac: Various patches from Hans de Goede. (Closes #61)
William Pitcock <nenolod@atheme.org>
parents:
2971
diff
changeset
|
108 |
87b0c47089e5
alac: Various patches from Hans de Goede. (Closes #61)
William Pitcock <nenolod@atheme.org>
parents:
2971
diff
changeset
|
109 for (i = 0; i < demux_res->num_time_to_samples; i++) |
87b0c47089e5
alac: Various patches from Hans de Goede. (Closes #61)
William Pitcock <nenolod@atheme.org>
parents:
2971
diff
changeset
|
110 samples += demux_res->time_to_sample[i].sample_count * |
87b0c47089e5
alac: Various patches from Hans de Goede. (Closes #61)
William Pitcock <nenolod@atheme.org>
parents:
2971
diff
changeset
|
111 demux_res->time_to_sample[i].sample_duration; |
87b0c47089e5
alac: Various patches from Hans de Goede. (Closes #61)
William Pitcock <nenolod@atheme.org>
parents:
2971
diff
changeset
|
112 |
87b0c47089e5
alac: Various patches from Hans de Goede. (Closes #61)
William Pitcock <nenolod@atheme.org>
parents:
2971
diff
changeset
|
113 return (samples * 1000) / demux_res->sample_rate; |
87b0c47089e5
alac: Various patches from Hans de Goede. (Closes #61)
William Pitcock <nenolod@atheme.org>
parents:
2971
diff
changeset
|
114 } |
87b0c47089e5
alac: Various patches from Hans de Goede. (Closes #61)
William Pitcock <nenolod@atheme.org>
parents:
2971
diff
changeset
|
115 |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1973
diff
changeset
|
116 Tuple *build_aud_tuple_from_demux(demux_res_t *demux_res, char *path) |
79
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
117 { |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1973
diff
changeset
|
118 Tuple *ti = aud_tuple_new_from_filename(path); |
79
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
119 |
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
120 if (demux_res->tuple.art != NULL) |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1973
diff
changeset
|
121 aud_tuple_associate_string(ti, FIELD_ARTIST, NULL, demux_res->tuple.art); |
79
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
122 if (demux_res->tuple.nam != NULL) |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1973
diff
changeset
|
123 aud_tuple_associate_string(ti, FIELD_TITLE, NULL, demux_res->tuple.nam); |
79
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
124 if (demux_res->tuple.alb != NULL) |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1973
diff
changeset
|
125 aud_tuple_associate_string(ti, FIELD_ALBUM, NULL, demux_res->tuple.alb); |
79
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
126 if (demux_res->tuple.gen != NULL) |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1973
diff
changeset
|
127 aud_tuple_associate_string(ti, FIELD_GENRE, NULL, demux_res->tuple.gen); |
79
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
128 if (demux_res->tuple.cmt != NULL) |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1973
diff
changeset
|
129 aud_tuple_associate_string(ti, FIELD_COMMENT, NULL, demux_res->tuple.cmt); |
79
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
130 if (demux_res->tuple.day != NULL) |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1973
diff
changeset
|
131 aud_tuple_associate_int(ti, FIELD_YEAR, NULL, atoi(demux_res->tuple.day)); |
1423
c5bbf2c90ba3
alac: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
132 |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1973
diff
changeset
|
133 aud_tuple_associate_string(ti, FIELD_CODEC, NULL, "Apple Lossless (ALAC)"); |
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1973
diff
changeset
|
134 aud_tuple_associate_string(ti, FIELD_QUALITY, NULL, "lossless"); |
3146
87b0c47089e5
alac: Various patches from Hans de Goede. (Closes #61)
William Pitcock <nenolod@atheme.org>
parents:
2971
diff
changeset
|
135 aud_tuple_associate_int(ti, FIELD_LENGTH, NULL, get_duration(demux_res)); |
79
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
136 |
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
137 return ti; |
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
138 } |
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
139 |
1423
c5bbf2c90ba3
alac: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
140 Tuple *build_tuple(char *filename) |
79
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
141 { |
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
142 demux_res_t demux_res; |
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
143 VFSFile *input_file; |
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
144 stream_t *input_stream; |
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
145 |
1978 | 146 input_file = aud_vfs_fopen(filename, "rb"); |
79
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
147 input_stream = stream_create_file(input_file, 1); |
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
148 |
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
149 set_endian(); |
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
150 |
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
151 if (!input_stream) |
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
152 { |
1978 | 153 aud_vfs_fclose(input_file); |
79
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
154 return NULL; |
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
155 } |
1284
190a447e5229
"About" window is now translatable.
Stany HENRY <StrassBoy@gmail.com>
parents:
1190
diff
changeset
|
156 |
79
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
157 /* if qtmovie_read returns successfully, the stream is up to |
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
158 * the movie data, which can be used directly by the decoder */ |
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
159 if (!qtmovie_read(input_stream, &demux_res)) |
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
160 { |
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
161 stream_destroy(input_stream); |
1978 | 162 aud_vfs_fclose(input_file); |
79
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
163 return NULL; |
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
164 } |
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
165 |
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
166 stream_destroy(input_stream); |
1978 | 167 aud_vfs_fclose(input_file); |
79
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
168 |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1973
diff
changeset
|
169 return build_aud_tuple_from_demux(&demux_res, filename); |
79
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
170 } |
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
171 |
3154
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
172 static void play_file(InputPlayback *playback) |
56
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
173 { |
3146
87b0c47089e5
alac: Various patches from Hans de Goede. (Closes #61)
William Pitcock <nenolod@atheme.org>
parents:
2971
diff
changeset
|
174 playback->playing = TRUE; |
1347
76eee61ed25a
alac: new threading model
William Pitcock <nenolod@atheme-project.org>
parents:
1284
diff
changeset
|
175 playback_thread = g_thread_self(); |
1447
195b5657303e
updated input plugins to use set_pb_ready to signal to the core that they're ready for playback
Giacomo Lozito <james@develia.org>
parents:
1431
diff
changeset
|
176 playback->set_pb_ready(playback); |
3154
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
177 decode_thread(playback); |
56
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 |
3154
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
180 static void stop(InputPlayback *playback) |
56
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
181 { |
3146
87b0c47089e5
alac: Various patches from Hans de Goede. (Closes #61)
William Pitcock <nenolod@atheme.org>
parents:
2971
diff
changeset
|
182 playback->playing = FALSE; |
56
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
183 g_thread_join(playback_thread); |
3154
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
184 playback->output->close_audio(); |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
185 } |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
186 |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
187 static void do_pause(InputPlayback *playback, short paused) |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
188 { |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
189 playback->output->pause(paused); |
56
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 |
3154
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
192 static void mseek(InputPlayback* playback, gulong millisecond) |
559 | 193 { |
3154
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
194 if (!playback->playing) |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
195 return; |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
196 |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
197 seek_to = millisecond; |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
198 |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
199 while (seek_to != -1) |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
200 g_usleep(10000); |
559 | 201 } |
202 | |
3154
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
203 static void seek(InputPlayback *playback, gint time) |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
204 { |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
205 mseek(playback, time * 1000); |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
206 } |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
207 |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
208 static guint64 get_packet_offset(demux_res_t *demux_res, guint packet) |
56
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
209 { |
3154
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
210 guint i; |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
211 guint64 offset = 0; |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
212 |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
213 for (i = 0; i < packet; i++) |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
214 offset += demux_res->sample_byte_size[i]; |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
215 |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
216 return offset; |
56
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
217 } |
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
218 |
3154
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
219 static guint handle_seek(InputPlayback *playback, |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
220 demux_res_t *demux_res, guint current_packet) |
56
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
221 { |
3154
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
222 guint i, packet; |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
223 guint64 offset, begin, end; |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
224 guint64 target = (seek_to * demux_res->sample_rate) / 1000; |
56
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
225 |
3154
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
226 begin = 0; |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
227 packet = 0; |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
228 for (i = 0; i < demux_res->num_time_to_samples; i++) |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
229 { |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
230 end = begin + demux_res->time_to_sample[i].sample_count * |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
231 demux_res->time_to_sample[i].sample_duration; |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
232 if (target >= begin && target < end) |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
233 { |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
234 offset = (target - begin) / |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
235 demux_res->time_to_sample[i].sample_duration; |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
236 /* Calculate packet to seek to */ |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
237 packet += offset; |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
238 /* Calculate resulting seek time */ |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
239 seek_to = (begin + offset * |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
240 demux_res->time_to_sample[i].sample_duration) * 1000 / |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
241 demux_res->sample_rate; |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
242 /* Do the actual seek and flush */ |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
243 offset = get_packet_offset(demux_res, packet) + packet0_offset; |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
244 stream_setpos(demux_res->stream, offset); |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
245 playback->output->flush(seek_to); |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
246 return packet; |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
247 } |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
248 begin = end; |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
249 packet += demux_res->time_to_sample[i].sample_count; |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
250 } |
56
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
251 |
3154
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
252 /* If we get here we somehow failed to find the target sample */ |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
253 return current_packet; |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
254 } |
56
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
255 |
3154
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
256 static guint get_max_packet_size(demux_res_t *demux_res) |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
257 { |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
258 guint i; |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
259 guint max = 0; |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
260 |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
261 for (i = 0; i < demux_res->num_sample_byte_sizes; i++) |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
262 if (demux_res->sample_byte_size[i] > max) |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
263 max = demux_res->sample_byte_size[i]; |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
264 |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
265 return max; |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
266 } |
56
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
267 |
3154
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
268 static guint get_max_packet_duration(demux_res_t *demux_res) |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
269 { |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
270 guint i; |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
271 guint max = 0; |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
272 |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
273 for (i = 0; i < demux_res->num_time_to_samples; i++) |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
274 if (demux_res->time_to_sample[i].sample_duration > max) |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
275 max = demux_res->time_to_sample[i].sample_duration; |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
276 |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
277 return max; |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
278 } |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
279 |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
280 void GetBuffer(InputPlayback *playback, demux_res_t *demux_res) |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
281 { |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
282 void *pDestBuffer = malloc(get_max_packet_duration(demux_res) * 4); |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
283 void *buffer = malloc(get_max_packet_size(demux_res)); |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
284 guint i = 0; |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
285 |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
286 while (playback->playing) |
56
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 int outputBytes; |
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
289 |
3154
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
290 if (seek_to != -1) |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
291 { |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
292 i = handle_seek(playback, demux_res, i); |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
293 seek_to = -1; |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
294 } |
91
6e1002ea4ded
[svn] - some seek code (can't be implemented right now though)
nenolod
parents:
85
diff
changeset
|
295 |
3154
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
296 if (i < demux_res->num_sample_byte_sizes) |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
297 { |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
298 /* just get one sample for now */ |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
299 stream_read(demux_res->stream, demux_res->sample_byte_size[i], buffer); |
91
6e1002ea4ded
[svn] - some seek code (can't be implemented right now though)
nenolod
parents:
85
diff
changeset
|
300 |
3154
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
301 /* now fetch */ |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
302 decode_frame(demux_res->alac, buffer, pDestBuffer, &outputBytes); |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
303 |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
304 /* write */ |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
305 playback->pass_audio(playback, FMT_S16_LE, demux_res->num_channels, outputBytes, pDestBuffer, &playback->playing); |
91
6e1002ea4ded
[svn] - some seek code (can't be implemented right now though)
nenolod
parents:
85
diff
changeset
|
306 |
3154
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
307 i++; |
56
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
308 |
3154
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
309 /* When we are at the end stop pre-buffering */ |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
310 if (i == demux_res->num_sample_byte_sizes) |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
311 { |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
312 playback->output->buffer_free(); |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
313 playback->output->buffer_free(); |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
314 } |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
315 } |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
316 else |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
317 { |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
318 /* Wait for output buffer to drain */ |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
319 if (!playback->output->buffer_playing()) |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
320 playback->playing = FALSE; |
56
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
321 |
3154
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
322 if (playback->playing) |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
323 g_usleep(40000); |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
324 } |
56
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
325 } |
70 | 326 |
327 free(buffer); | |
328 free(pDestBuffer); | |
56
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
329 } |
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
330 |
1074 | 331 static gchar *fmts[] = { "m4a", "alac", NULL }; |
332 | |
333 InputPlugin alac_ip = { | |
334 .description = "Apple Lossless Plugin", | |
335 .about = alac_about, | |
336 .play_file = play_file, | |
337 .stop = stop, | |
338 .pause = do_pause, | |
339 .seek = seek, | |
3154
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
340 .mseek = mseek, |
1074 | 341 .get_song_tuple = build_tuple, |
342 .is_our_file_from_vfs = is_our_fd, | |
1979
839804c3b3a4
aud_vfs_extensions -> vfs_extensions, some vtable fixes
William Pitcock <nenolod@atheme.org>
parents:
1978
diff
changeset
|
343 .vfs_extensions = fmts, |
1074 | 344 }; |
345 | |
346 InputPlugin *alac_iplist[] = { &alac_ip, NULL }; | |
347 | |
1395
761e17b23e0c
added Discovery plugin type
Cristi Magherusan <majeru@atheme-project.org>
parents:
1347
diff
changeset
|
348 DECLARE_PLUGIN(alac, NULL, NULL, alac_iplist, NULL, NULL, NULL, NULL, NULL); |
1074 | 349 |
3154
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
350 static void decode_thread(InputPlayback *playback) |
56
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
351 { |
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
352 demux_res_t demux_res; |
77 | 353 VFSFile *input_file; |
354 stream_t *input_stream; | |
1423
c5bbf2c90ba3
alac: new tuple API
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
355 Tuple *ti; |
79
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
356 gchar *title; |
56
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
357 |
85 | 358 memset(&demux_res, 0, sizeof(demux_res)); |
78 | 359 |
57
96901271d2e2
[svn] - fix crashing. works on my x64 box, static on bigendian (tested: x64-be, mips, ppc64)
nenolod
parents:
56
diff
changeset
|
360 set_endian(); |
96901271d2e2
[svn] - fix crashing. works on my x64 box, static on bigendian (tested: x64-be, mips, ppc64)
nenolod
parents:
56
diff
changeset
|
361 |
3154
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
362 input_file = aud_vfs_fopen(playback->filename, "rb"); |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
363 if (!input_file) |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
364 goto exit; |
57
96901271d2e2
[svn] - fix crashing. works on my x64 box, static on bigendian (tested: x64-be, mips, ppc64)
nenolod
parents:
56
diff
changeset
|
365 |
3154
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
366 input_stream = stream_create_file(input_file, 1); |
56
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
367 |
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
368 /* 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
|
369 * 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
|
370 if (!qtmovie_read(input_stream, &demux_res)) |
3154
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
371 goto exit_free_stream; |
56
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
372 |
78 | 373 demux_res.stream = input_stream; |
3154
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
374 packet0_offset = stream_tell(input_stream); |
78 | 375 |
79
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
376 /* Get the titlestring ready. */ |
3154
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
377 ti = build_aud_tuple_from_demux(&demux_res, playback->filename); |
2055 | 378 title = aud_tuple_formatter_make_title_string(ti, aud_get_gentitle_format()); |
79
722fd456ae1a
[svn] - parse metadata on ALAC files... seems to work, but the method is inefficient
nenolod
parents:
78
diff
changeset
|
379 |
56
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
380 /* initialise the sound converter */ |
77 | 381 demux_res.alac = create_alac(demux_res.sample_size, demux_res.num_channels); |
382 alac_set_info(demux_res.alac, demux_res.codecdata); | |
56
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
383 |
3154
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
384 if (!playback->output->open_audio(FMT_S16_LE, demux_res.sample_rate, demux_res.num_channels)) |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
385 goto exit_free_alac; |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
386 |
3146
87b0c47089e5
alac: Various patches from Hans de Goede. (Closes #61)
William Pitcock <nenolod@atheme.org>
parents:
2971
diff
changeset
|
387 playback->set_params(playback, title, get_duration(&demux_res), -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
|
388 |
56
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
389 /* will convert the entire buffer */ |
3154
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
390 GetBuffer(playback, &demux_res); |
56
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
391 |
561
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
559
diff
changeset
|
392 playback->output->close_audio(); |
3154
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
393 exit_free_alac: |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
394 free(demux_res.alac); |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
395 exit_free_stream: |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
396 stream_destroy(input_stream); |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
397 aud_vfs_fclose(input_file); |
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
398 exit: |
3146
87b0c47089e5
alac: Various patches from Hans de Goede. (Closes #61)
William Pitcock <nenolod@atheme.org>
parents:
2971
diff
changeset
|
399 playback->playing = FALSE; |
3154
d7eea4d29d4a
alac: Restructuring from Hans de Goede. (Closes #69)
William Pitcock <nenolod@atheme.org>
parents:
3146
diff
changeset
|
400 return; |
56
56c88eee9802
[svn] - experimental ALAC plugin -- don't use this, it crashes
nenolod
parents:
diff
changeset
|
401 } |