Mercurial > audlegacy-plugins
annotate src/tta/aud-tta.c @ 851:712df386597e trunk
[svn] - add support for mseek.
- fix inaccurate seek position calculation. this bug prevented tta working with cuesheet.
- move to GThread API and make use of GCond signaling.
author | yaz |
---|---|
date | Wed, 14 Mar 2007 03:16:45 -0700 |
parents | 7b65072e2efb |
children | 421d5587b761 |
rev | line source |
---|---|
290 | 1 /* |
2 * aud--tta.c | |
3 * | |
4 * Description: TTA input plug-in for Audacious | |
5 * Developed by: Alexander Djourik <sasha@iszf.irk.ru> | |
6 * Pavel Zhilin <pzh@iszf.irk.ru> | |
7 * Audacious port: Yoshiki Yazawa <yaz@cc.rim.or.jp> | |
8 * | |
9 * Copyright (c) 2004 Alexander Djourik. All rights reserved. | |
10 * | |
11 */ | |
12 | |
13 /* | |
14 * This library is free software; you can redistribute it and/or | |
15 * modify it under the terms of the GNU Lesser General Public | |
16 * License as published by the Free Software Foundation; either | |
17 * version 2.1 of the License, or (at your option) any later version. | |
18 * | |
19 * This library is distributed in the hope that it will be useful, | |
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
22 * Lesser General Public License for more details. | |
23 * | |
24 * You should have received a copy of the GNU Lesser General Public | |
25 * License along with this library; if not, write to the Free Software | |
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
27 * | |
28 * Please see the file COPYING in this directory for full copyright | |
29 * information. | |
30 */ | |
528 | 31 |
32 #ifdef HAVE_CONFIG_H | |
33 # include "config.h" | |
34 #endif | |
35 | |
290 | 36 #include <stdio.h> |
37 #include <stdlib.h> | |
38 #include <string.h> | |
39 #include <time.h> | |
40 #include <sys/types.h> | |
41 #include <sys/stat.h> | |
42 #include <glib.h> | |
43 #include <string.h> | |
44 | |
45 #include <audacious/util.h> | |
46 #include <audacious/plugin.h> | |
47 #include <audacious/titlestring.h> | |
48 #include <audacious/vfs.h> | |
49 #include "aud-support.h" | |
520
8f1785471613
[svn] - add missing inclusion of audacious/strings.h where necessary
giacomo
parents:
443
diff
changeset
|
50 #include <audacious/output.h> |
8f1785471613
[svn] - add missing inclusion of audacious/strings.h where necessary
giacomo
parents:
443
diff
changeset
|
51 #include <audacious/strings.h> |
527
d124034ebea3
[svn] - glib/gi18n.h -> audacious/i18n.h for automatic dgettext support
nenolod
parents:
520
diff
changeset
|
52 #include <audacious/i18n.h> |
290 | 53 |
661 | 54 #include <audacious/id3tag.h> |
290 | 55 |
851 | 56 /* #define DEBUG 1 */ |
290 | 57 |
58 #define PLUGIN_VERSION "1.2" | |
59 #define PROJECT_URL "<http://www.true-audio.com>" | |
60 | |
61 #pragma pack (1) | |
62 #include "ttalib.h" | |
63 | |
64 #define OUTPUT_ERROR (MEMORY_ERROR+1) | |
65 #define MAX_BSIZE (MAX_BPS>>3) | |
66 | |
67 | |
68 static void init (); | |
69 static void cleanup (); | |
70 static int is_our_file (char *filename); | |
561
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
71 static void play_file (InputPlayback *playback); |
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
72 static void tta_pause (InputPlayback *playback, short paused); |
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
73 static void stop (InputPlayback *playback); |
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
74 static void seek (InputPlayback *playback, int time); |
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
75 static int get_time (InputPlayback *playback); |
290 | 76 static void get_song_info (char *filename, char **title, int *length); |
77 static void file_info (char *filename); | |
78 static void about (); | |
79 static TitleInput *get_song_tuple(char *filename); | |
80 static gchar *extname(const char *filename); | |
851 | 81 static void mseek (InputPlayback *data, gulong millisecond); |
82 | |
290 | 83 |
372
a157306caf03
[svn] - finalize the plugin-side of the extension-assist ABI
nenolod
parents:
368
diff
changeset
|
84 gchar *tta_fmts[] = { "tta", NULL }; |
a157306caf03
[svn] - finalize the plugin-side of the extension-assist ABI
nenolod
parents:
368
diff
changeset
|
85 |
290 | 86 InputPlugin tta_ip = |
87 { | |
88 NULL, | |
89 NULL, | |
90 NULL, | |
91 init, | |
92 about, | |
93 NULL, | |
94 is_our_file, | |
95 NULL, | |
96 play_file, | |
97 stop, | |
98 tta_pause, | |
99 seek, | |
100 NULL, | |
101 get_time, | |
102 NULL, | |
103 NULL, | |
104 cleanup, | |
105 NULL, | |
106 NULL, | |
107 NULL, | |
108 NULL, | |
109 get_song_info, | |
110 file_info, | |
111 NULL, | |
112 get_song_tuple, // get_song_tuple | |
113 NULL, // set_song_tuple | |
368
c812e846b84e
[svn] - add support for extension probing to many plugins.
nenolod
parents:
290
diff
changeset
|
114 NULL, // buffer |
372
a157306caf03
[svn] - finalize the plugin-side of the extension-assist ABI
nenolod
parents:
368
diff
changeset
|
115 NULL, // vfs |
a157306caf03
[svn] - finalize the plugin-side of the extension-assist ABI
nenolod
parents:
368
diff
changeset
|
116 tta_fmts, |
851 | 117 mseek, |
290 | 118 }; |
119 | |
120 InputPlugin * | |
121 get_iplugin_info (void) | |
122 { | |
123 tta_ip.description = g_strdup_printf ("True Audio Plugin %s", PLUGIN_VERSION); | |
124 return &tta_ip; | |
125 } | |
126 | |
851 | 127 static GThread *decode_thread; |
290 | 128 static char sample_buffer[PCM_BUFFER_LENGTH * MAX_BSIZE * MAX_NCH]; |
129 static tta_info info; // currently playing file info | |
130 static long seek_position = -1; | |
131 static int playing = FALSE; | |
132 static int read_samples = -1; | |
133 | |
851 | 134 static GMutex *play_mutex; |
135 static GCond *play_cond; | |
136 | |
290 | 137 static void |
138 tta_error (int error) | |
139 { | |
140 char *message; | |
141 static GtkWidget *errorbox; | |
142 if (errorbox != NULL) return; | |
143 | |
144 switch (error) | |
145 { | |
146 case OPEN_ERROR: | |
147 message = "Can't open file\n"; | |
148 break; | |
149 case FORMAT_ERROR: | |
150 message = "Not supported file format\n"; | |
151 break; | |
152 case FILE_ERROR: | |
153 message = "File is corrupted\n"; | |
154 break; | |
155 case READ_ERROR: | |
156 message = "Can't read from file\n"; | |
157 break; | |
158 case MEMORY_ERROR: | |
159 message = "Insufficient memory available\n"; | |
160 break; | |
161 case OUTPUT_ERROR: | |
162 message = "Output plugin error\n"; | |
163 break; | |
164 default: | |
165 message = "Unknown error\n"; | |
166 break; | |
167 } | |
168 | |
169 xmms_show_message ("TTA Decoder Error", message, | |
170 "Ok", FALSE, NULL, NULL); | |
171 | |
172 gtk_signal_connect(GTK_OBJECT(errorbox), "destroy", | |
173 G_CALLBACK(gtk_widget_destroyed), &errorbox); | |
174 } | |
175 | |
176 static gchar * | |
177 get_title (char *filename, tta_info *ttainfo) | |
178 { | |
179 char *name, *p; | |
180 | |
181 if (ttainfo->id3v2.id3has && | |
182 (*ttainfo->id3v2.artist || *ttainfo->id3v2.title)) { | |
183 if (*ttainfo->id3v2.artist && *ttainfo->id3v2.title) | |
184 return g_strdup_printf("%s - %s", ttainfo->id3v2.artist, ttainfo->id3v2.title); | |
185 else if (*ttainfo->id3v2.artist && *ttainfo->id3v2.album) | |
186 return g_strdup_printf("%s - %s", ttainfo->id3v2.artist, ttainfo->id3v2.album); | |
187 else if (*ttainfo->id3v2.artist) return g_strdup(ttainfo->id3v2.artist); | |
188 else if (*ttainfo->id3v2.title) return g_strdup(ttainfo->id3v2.title); | |
189 } else if (ttainfo->id3v1.id3has && | |
190 (*ttainfo->id3v1.artist || *ttainfo->id3v1.title)) { | |
191 if (*ttainfo->id3v1.artist && *ttainfo->id3v1.title) | |
192 return g_strdup_printf("%s - %s", ttainfo->id3v1.artist, ttainfo->id3v1.title); | |
193 else if (*ttainfo->id3v1.artist && *ttainfo->id3v1.album) | |
194 return g_strdup_printf("%s - %s", ttainfo->id3v1.artist, ttainfo->id3v1.album); | |
195 else if (*ttainfo->id3v1.artist) return g_strdup(ttainfo->id3v1.artist); | |
196 else if (*ttainfo->id3v1.title) return g_strdup(ttainfo->id3v1.title); | |
197 } | |
198 name = g_strdup (g_basename(filename)); | |
199 p = name + strlen(name); | |
200 while (*p != '.' && p >= name) p--; | |
201 if (*p == '.') *p = '\0'; | |
202 p = g_strdup (name); | |
203 g_free (name); | |
204 return p; | |
205 } | |
206 | |
207 static void * | |
851 | 208 play_loop (gpointer arg) |
290 | 209 { |
851 | 210 InputPlayback *playback = (InputPlayback *)arg; |
290 | 211 int bufsize = PCM_BUFFER_LENGTH * info.BSIZE * info.NCH; |
851 | 212 GTimeVal sleep_time; |
290 | 213 |
214 //////////////////////////////////////// | |
215 // decode PCM_BUFFER_LENGTH samples | |
216 // into the current PCM buffer position | |
217 | |
851 | 218 while (playing) { |
219 while ((read_samples = get_samples (sample_buffer)) > 0) { | |
220 // wait for buffer becomes available | |
221 while ((playback->output->buffer_free () < bufsize) && seek_position == -1) { | |
222 g_get_current_time(&sleep_time); | |
223 g_time_val_add(&sleep_time, 10000); | |
224 g_mutex_lock(play_mutex); | |
225 g_cond_timed_wait(play_cond, play_mutex, &sleep_time); | |
226 g_mutex_unlock(play_mutex); | |
227 if (!playing) | |
228 goto DONE; | |
229 } | |
230 | |
231 if (seek_position == -1) { | |
232 produce_audio(playback->output->written_time(), | |
233 ((info.BPS == 8) ? FMT_U8 : FMT_S16_LE), | |
234 info.NCH, | |
235 read_samples * info.NCH * info.BSIZE, | |
236 sample_buffer, | |
237 NULL); | |
238 } | |
239 else { | |
240 set_position (seek_position / SEEK_STEP); //now seek_postion is in millisecond. | |
241 playback->output->flush (seek_position); | |
242 seek_position = -1; | |
243 } | |
290 | 244 |
851 | 245 // sleep for a while |
246 g_get_current_time(&sleep_time); | |
247 g_time_val_add(&sleep_time, 10000); | |
248 g_mutex_lock(play_mutex); | |
249 g_cond_timed_wait(play_cond, play_mutex, &sleep_time); | |
250 g_mutex_unlock(play_mutex); | |
251 if (!playing) | |
252 goto DONE; | |
253 } | |
254 | |
255 // process remaining data | |
256 playback->output->buffer_free (); | |
257 playback->output->buffer_free (); | |
258 | |
259 while(playback->output->buffer_playing()) { | |
260 g_get_current_time(&sleep_time); | |
261 g_time_val_add(&sleep_time, 10000); | |
262 g_mutex_lock(play_mutex); | |
263 g_cond_timed_wait(play_cond, play_mutex, &sleep_time); | |
264 g_mutex_unlock(play_mutex); | |
265 if(!playing) | |
266 goto DONE; | |
267 } | |
290 | 268 } |
269 | |
851 | 270 DONE: |
271 g_thread_exit(NULL); | |
290 | 272 } |
273 | |
274 static void | |
275 init () | |
276 { | |
277 memset (&info, 0, sizeof (tta_info)); | |
851 | 278 play_mutex = g_mutex_new(); |
279 play_cond = g_cond_new(); | |
290 | 280 } |
281 | |
282 static void | |
283 cleanup () | |
284 { | |
851 | 285 g_cond_free(play_cond); |
286 g_mutex_free(play_mutex); | |
290 | 287 } |
288 | |
289 static void | |
290 about () | |
291 { | |
292 static GtkWidget *aboutbox; | |
293 if (aboutbox != NULL) return; | |
294 | |
295 aboutbox = xmms_show_message( | |
296 "About True Audio Plugin", | |
297 "TTA input plugin" PLUGIN_VERSION "for BMP\n" | |
298 "Copyright (c) 2004 True Audio Software\n" | |
299 PROJECT_URL, "Ok", FALSE, NULL, NULL); | |
300 | |
301 gtk_signal_connect(GTK_OBJECT(aboutbox), "destroy", | |
302 G_CALLBACK(gtk_widget_destroyed), &aboutbox); | |
303 } | |
304 | |
305 static GtkWidget *window = NULL; | |
306 static GtkWidget *filename_entry, *title_entry, | |
307 *artist_entry, *album_entry, | |
308 *year_entry, *tracknum_entry, | |
309 *comment_entry, *genre_entry, | |
310 *info_frame; | |
311 | |
312 extern char *genre[]; | |
313 | |
314 static void | |
315 file_info (char *filename) | |
316 { | |
317 tta_info ttainfo; | |
318 char *title; | |
319 gchar *utf_filename = NULL; | |
320 | |
321 if (!window) { | |
322 GtkWidget *vbox, *hbox, *left_vbox, *table; | |
323 GtkWidget *label, *filename_hbox, *button_ok; | |
324 | |
325 window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
326 gtk_window_set_policy(GTK_WINDOW(window), FALSE, FALSE, FALSE); | |
327 gtk_signal_connect(GTK_OBJECT(window), "destroy", | |
328 G_CALLBACK(gtk_widget_destroyed), &window); | |
329 gtk_container_set_border_width(GTK_CONTAINER(window), 10); | |
330 | |
331 vbox = gtk_vbox_new(FALSE, 10); | |
332 gtk_container_add(GTK_CONTAINER(window), vbox); | |
333 | |
334 filename_hbox = gtk_hbox_new(FALSE, 5); | |
335 gtk_box_pack_start(GTK_BOX(vbox), filename_hbox, FALSE, TRUE, 0); | |
336 label = gtk_label_new("Filename:"); | |
337 gtk_box_pack_start(GTK_BOX(filename_hbox), label, FALSE, TRUE, 0); | |
338 | |
339 filename_entry = gtk_entry_new_with_max_length(1024); | |
340 gtk_editable_set_editable(GTK_EDITABLE(filename_entry), FALSE); | |
341 gtk_box_pack_start(GTK_BOX(filename_hbox), filename_entry, TRUE, TRUE, 0); | |
342 | |
343 hbox = gtk_hbox_new(FALSE, 10); | |
344 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0); | |
345 left_vbox = gtk_vbox_new(FALSE, 10); | |
346 gtk_box_pack_start(GTK_BOX(hbox), left_vbox, FALSE, FALSE, 0); | |
347 | |
348 info_frame = gtk_frame_new("ID3 Tag:"); | |
349 gtk_box_pack_start(GTK_BOX(left_vbox), info_frame, FALSE, FALSE, 0); | |
350 | |
351 table = gtk_table_new(5, 5, FALSE); | |
352 gtk_container_set_border_width(GTK_CONTAINER(table), 5); | |
353 gtk_container_add(GTK_CONTAINER(info_frame), table); | |
354 | |
355 label = gtk_label_new("Title:"); | |
356 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); | |
357 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 5, 5); | |
358 | |
359 title_entry = gtk_entry_new_with_max_length(1024); | |
360 gtk_editable_set_editable(GTK_EDITABLE(title_entry), FALSE); | |
361 gtk_table_attach(GTK_TABLE(table), title_entry, 1, 4, 0, 1, | |
362 GTK_FILL | GTK_EXPAND | GTK_SHRINK, | |
363 GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 5); | |
364 | |
365 label = gtk_label_new("Artist:"); | |
366 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); | |
367 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, | |
368 GTK_FILL, GTK_FILL, 5, 5); | |
369 | |
370 artist_entry = gtk_entry_new_with_max_length(1024); | |
371 gtk_editable_set_editable(GTK_EDITABLE(artist_entry), FALSE); | |
372 gtk_table_attach(GTK_TABLE(table), artist_entry, 1, 4, 1, 2, | |
373 GTK_FILL | GTK_EXPAND | GTK_SHRINK, | |
374 GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 5); | |
375 | |
376 label = gtk_label_new("Album:"); | |
377 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); | |
378 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2, 3, | |
379 GTK_FILL, GTK_FILL, 5, 5); | |
380 | |
381 album_entry = gtk_entry_new_with_max_length(1024); | |
382 gtk_editable_set_editable(GTK_EDITABLE(album_entry), FALSE); | |
383 gtk_table_attach(GTK_TABLE(table), album_entry, 1, 4, 2, 3, | |
384 GTK_FILL | GTK_EXPAND | GTK_SHRINK, | |
385 GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 5); | |
386 | |
387 label = gtk_label_new("Comment:"); | |
388 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); | |
389 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 3, 4, | |
390 GTK_FILL, GTK_FILL, 5, 5); | |
391 | |
392 comment_entry = gtk_entry_new_with_max_length(1024); | |
393 gtk_editable_set_editable(GTK_EDITABLE(comment_entry), FALSE); | |
394 gtk_table_attach(GTK_TABLE(table), comment_entry, 1, 4, 3, 4, | |
395 GTK_FILL | GTK_EXPAND | GTK_SHRINK, | |
396 GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 5); | |
397 | |
398 label = gtk_label_new("Year:"); | |
399 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); | |
400 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 4, 5, | |
401 GTK_FILL, GTK_FILL, 5, 5); | |
402 | |
403 year_entry = gtk_entry_new_with_max_length(4); | |
404 gtk_editable_set_editable(GTK_EDITABLE(year_entry), FALSE); | |
405 gtk_widget_set_usize(year_entry, 40, -1); | |
406 gtk_table_attach(GTK_TABLE(table), year_entry, 1, 2, 4, 5, | |
407 GTK_FILL | GTK_EXPAND | GTK_SHRINK, | |
408 GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 5); | |
409 | |
410 label = gtk_label_new("Track number:"); | |
411 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); | |
412 gtk_table_attach(GTK_TABLE(table), label, 2, 3, 4, 5, | |
413 GTK_FILL, GTK_FILL, 5, 5); | |
414 | |
415 tracknum_entry = gtk_entry_new_with_max_length(3); | |
416 gtk_editable_set_editable(GTK_EDITABLE(tracknum_entry), FALSE); | |
417 gtk_widget_set_usize(tracknum_entry, 40, -1); | |
418 gtk_table_attach(GTK_TABLE(table), tracknum_entry, 3, 4, 4, 5, | |
419 GTK_FILL | GTK_EXPAND | GTK_SHRINK, | |
420 GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 5); | |
421 | |
422 label = gtk_label_new("Genre:"); | |
423 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); | |
424 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 5, 6, | |
425 GTK_FILL, GTK_FILL, 5, 5); | |
426 | |
427 genre_entry = gtk_entry_new_with_max_length(1024); | |
428 gtk_editable_set_editable(GTK_EDITABLE(genre_entry), FALSE); | |
429 gtk_widget_set_usize(genre_entry, 40, -1); | |
430 gtk_table_attach(GTK_TABLE(table), genre_entry, 1, 4, 5, 6, | |
431 GTK_FILL | GTK_EXPAND | GTK_SHRINK, | |
432 GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 5); | |
433 | |
434 button_ok = gtk_button_new_with_label("Ok"); | |
435 gtk_signal_connect_object(GTK_OBJECT(button_ok), "clicked", | |
436 G_CALLBACK(gtk_widget_destroy), G_OBJECT(window)); | |
437 GTK_WIDGET_SET_FLAGS(button_ok, GTK_CAN_DEFAULT); | |
438 gtk_box_pack_start(GTK_BOX(vbox), button_ok, TRUE, TRUE, 0); | |
439 | |
440 gtk_widget_show_all (window); | |
441 } | |
442 | |
443 utf_filename = str_to_utf8(filename); | |
444 title = g_strdup_printf(_("File Info - %s"), g_basename(utf_filename)); | |
445 gtk_window_set_title(GTK_WINDOW(window), title); | |
446 g_free(title); | |
447 | |
448 gtk_entry_set_text(GTK_ENTRY(filename_entry), utf_filename); | |
449 gtk_editable_set_position(GTK_EDITABLE(filename_entry), -1); | |
450 | |
451 #if 1 | |
452 title = g_strdup(g_basename(utf_filename)); | |
453 // if ((tmp = strrchr(title, '.')) != NULL) *tmp = '\0'; | |
454 gtk_entry_set_text(GTK_ENTRY(title_entry), title); | |
455 g_free(title); | |
456 #endif | |
457 g_free(utf_filename); | |
458 | |
459 if (open_tta_file (filename, &ttainfo, 0) >= 0) | |
460 { | |
461 gtk_entry_set_text(GTK_ENTRY(title_entry), ""); | |
462 gtk_entry_set_text(GTK_ENTRY(artist_entry), ""); | |
463 gtk_entry_set_text(GTK_ENTRY(album_entry), ""); | |
464 gtk_entry_set_text(GTK_ENTRY(year_entry), ""); | |
465 gtk_entry_set_text(GTK_ENTRY(tracknum_entry), ""); | |
466 gtk_entry_set_text(GTK_ENTRY(comment_entry), ""); | |
467 gtk_entry_set_text(GTK_ENTRY(genre_entry), ""); | |
468 | |
469 if (ttainfo.id3v2.id3has) | |
470 { | |
471 gtk_entry_set_text(GTK_ENTRY(title_entry), ttainfo.id3v2.title); | |
472 gtk_entry_set_text(GTK_ENTRY(artist_entry), ttainfo.id3v2.artist); | |
473 gtk_entry_set_text(GTK_ENTRY(album_entry), ttainfo.id3v2.album); | |
474 gtk_entry_set_text(GTK_ENTRY(year_entry), ttainfo.id3v2.year); | |
475 gtk_entry_set_text(GTK_ENTRY(tracknum_entry), ttainfo.id3v2.track); | |
476 gtk_entry_set_text(GTK_ENTRY(comment_entry), ttainfo.id3v2.comment); | |
477 gtk_entry_set_text(GTK_ENTRY(genre_entry), ttainfo.id3v2.genre); | |
478 } | |
479 else if (ttainfo.id3v1.id3has) | |
480 { | |
481 gchar *track = g_strdup_printf ("%2d", ttainfo.id3v1.track); | |
482 gtk_entry_set_text(GTK_ENTRY(title_entry), ttainfo.id3v1.title); | |
483 gtk_entry_set_text(GTK_ENTRY(artist_entry), ttainfo.id3v1.artist); | |
484 gtk_entry_set_text(GTK_ENTRY(album_entry), ttainfo.id3v1.album); | |
485 gtk_entry_set_text(GTK_ENTRY(year_entry), ttainfo.id3v1.year); | |
486 gtk_entry_set_text(GTK_ENTRY(tracknum_entry), track); | |
487 gtk_entry_set_text(GTK_ENTRY(comment_entry), ttainfo.id3v1.comment); | |
488 gtk_entry_set_text(GTK_ENTRY(genre_entry), | |
489 genre[ttainfo.id3v1.genre <= GENRES ? ttainfo.id3v1.genre : 12]); | |
490 g_free (track); | |
491 } | |
492 } | |
493 close_tta_file (&ttainfo); | |
494 | |
495 gtk_widget_set_sensitive(info_frame, TRUE); | |
496 } | |
497 | |
498 static int | |
499 is_our_file (char *filename) | |
500 { | |
501 if (!strcasecmp (filename + strlen (filename) - 4, ".tta")) | |
502 { | |
503 return TRUE; | |
504 } | |
505 return FALSE; | |
506 } | |
507 | |
508 static void | |
561
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
509 play_file (InputPlayback *playback) |
290 | 510 { |
561
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
511 char *filename = playback->filename; |
290 | 512 char *title; |
513 long datasize, origsize, bitrate; | |
514 | |
851 | 515 g_mutex_lock(play_mutex); |
290 | 516 playing = FALSE; |
851 | 517 g_mutex_unlock(play_mutex); |
518 g_cond_signal(play_cond); | |
290 | 519 |
520 //////////////////////////////////////// | |
521 // open TTA file | |
522 if (open_tta_file (filename, &info, 0) < 0) | |
523 { | |
851 | 524 tta_error (info.STATE); |
525 close_tta_file (&info); | |
526 return; | |
290 | 527 } |
528 | |
529 //////////////////////////////////////// | |
530 // initialize TTA player | |
531 if (player_init (&info) < 0) | |
532 { | |
851 | 533 tta_error (info.STATE); |
534 close_tta_file (&info); | |
535 return; | |
290 | 536 } |
537 | |
538 | |
561
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
539 if (playback->output->open_audio ((info.BPS == 8) ? FMT_U8 : FMT_S16_LE, |
851 | 540 info.SAMPLERATE, info.NCH) == 0) |
290 | 541 { |
851 | 542 tta_error (OUTPUT_ERROR); |
543 close_tta_file (&info); | |
544 return; | |
290 | 545 } |
546 title = get_title (filename, &info); | |
851 | 547 #ifdef DEBUG |
290 | 548 printf("title @1 = %s\n", title); |
851 | 549 #endif |
290 | 550 { |
551 TitleInput *tuple; | |
552 | |
553 tuple = get_song_tuple(filename); | |
554 if(tuple->track_name) { | |
555 g_free(title); | |
556 title = g_strdup(tuple->track_name); | |
851 | 557 #ifdef DEBUG |
290 | 558 printf("title @2 = %s\n", title); |
851 | 559 #endif |
290 | 560 } |
561 | |
562 bmp_title_input_free(tuple); | |
563 } | |
564 | |
565 datasize = file_size(filename) - info.DATAPOS; | |
566 origsize = info.DATALENGTH * info.BSIZE * info.NCH; | |
567 | |
568 bitrate = (long) ((float) datasize / origsize * | |
851 | 569 (info.SAMPLERATE * info.NCH * info.BPS)); |
290 | 570 |
571 tta_ip.set_info (title, 1000 * info.LENGTH, bitrate, info.SAMPLERATE, info.NCH); | |
572 | |
573 if (title) | |
851 | 574 g_free (title); |
290 | 575 |
851 | 576 g_mutex_lock(play_mutex); |
290 | 577 playing = TRUE; |
578 seek_position = -1; | |
579 read_samples = -1; | |
851 | 580 g_mutex_unlock(play_mutex); |
581 g_cond_signal(play_cond); | |
290 | 582 |
851 | 583 decode_thread = g_thread_create(play_loop, (gpointer)playback, TRUE, NULL); |
584 printf("decode_thread = %p\n", decode_thread); | |
290 | 585 } |
586 | |
587 static void | |
561
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
588 tta_pause (InputPlayback *playback, short paused) |
290 | 589 { |
561
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
590 playback->output->pause (paused); |
290 | 591 } |
851 | 592 |
290 | 593 static void |
561
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
594 stop (InputPlayback *playback) |
290 | 595 { |
851 | 596 printf("tta: f: stop:\n"); |
597 | |
598 g_mutex_lock(play_mutex); | |
599 playing = FALSE; | |
600 g_mutex_unlock(play_mutex); | |
601 g_cond_signal(play_cond); | |
602 printf("tta: i: stop: stop signaled\n"); | |
603 | |
604 if (decode_thread) { | |
605 g_thread_join(decode_thread); | |
606 } | |
607 | |
608 #ifdef DEBUG | |
609 printf("tta: stop: decode_thread joined\n"); | |
610 #endif | |
611 playback->output->close_audio (); | |
612 player_stop(); | |
613 close_tta_file (&info); | |
614 read_samples = 0; | |
615 } | |
616 | |
617 static void | |
618 mseek (InputPlayback *data, gulong millisecond) | |
619 { | |
620 if (playing) { | |
621 seek_position = millisecond; | |
290 | 622 } |
623 } | |
624 | |
625 static void | |
568 | 626 seek (InputPlayback *data, int time) |
290 | 627 { |
851 | 628 mseek(data, 1000 * time); |
290 | 629 } |
630 | |
631 static int | |
561
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
632 get_time (InputPlayback *playback) |
290 | 633 { |
561
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
634 if (playing && (read_samples || playback->output->buffer_playing())) |
914c96de3244
[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents:
528
diff
changeset
|
635 return playback->output->output_time(); |
290 | 636 |
637 return -1; | |
638 } | |
639 | |
640 static void | |
641 get_song_info (char *filename, char **title, int *length) | |
642 { | |
643 tta_info ttainfo; | |
644 | |
645 if (open_tta_file (filename, &ttainfo, 0) >= 0) | |
646 { | |
647 *title = get_title (filename, &ttainfo); | |
648 *length = ttainfo.LENGTH * 1000; | |
649 } | |
650 close_tta_file (&ttainfo); | |
651 } | |
652 | |
653 | |
654 | |
655 static TitleInput * | |
656 get_song_tuple(char *filename) | |
657 { | |
658 TitleInput *tuple = NULL; | |
659 tta_info *ttainfo; | |
660 VFSFile *file; | |
661 | |
662 ttainfo = g_malloc0(sizeof(tta_info)); | |
663 | |
664 if((file = vfs_fopen(filename, "rb")) != NULL) { | |
665 | |
666 #ifdef DEBUG | |
667 printf("about to open_tta_file\n"); | |
668 #endif | |
669 if(open_tta_file(filename, ttainfo, 0) >= 0) { | |
670 tuple = bmp_title_input_new(); | |
671 #ifdef DEBUG | |
672 printf("open_tta_file succeed\n"); | |
673 #endif | |
674 tuple->file_name = g_path_get_basename(filename); | |
675 tuple->file_path = g_path_get_dirname(filename); | |
676 tuple->file_ext = extname(filename); | |
677 tuple->length = ttainfo->LENGTH * 1000; | |
678 | |
679 if (ttainfo->id3v2.id3has) { | |
680 if(ttainfo->id3v2.artist) | |
681 tuple->performer = g_strdup(ttainfo->id3v2.artist); | |
682 | |
683 if(ttainfo->id3v2.album) | |
684 tuple->album_name = g_strdup(ttainfo->id3v2.album); | |
685 | |
686 if(ttainfo->id3v2.title) | |
687 tuple->track_name = g_strdup(ttainfo->id3v2.title); | |
688 | |
689 tuple->year = atoi(ttainfo->id3v2.year); | |
690 | |
691 tuple->track_number = atoi(ttainfo->id3v2.track); | |
692 | |
693 if(ttainfo->id3v2.genre){ | |
694 // printf("genre = %s\n",ttainfo->id3v2.genre); | |
695 tuple->genre = g_strdup(ttainfo->id3v2.genre); | |
696 } | |
697 if(ttainfo->id3v2.comment) | |
698 tuple->comment = g_strdup(ttainfo->id3v2.comment); | |
699 } else if (ttainfo->id3v1.id3has) { | |
700 if(ttainfo->id3v1.artist) | |
701 tuple->performer = g_strdup(ttainfo->id3v1.artist); | |
702 | |
703 if(ttainfo->id3v1.album) | |
704 tuple->album_name = g_strdup(ttainfo->id3v1.album); | |
705 | |
706 if(ttainfo->id3v1.title) | |
707 tuple->track_name = g_strdup(ttainfo->id3v1.title); | |
708 | |
709 tuple->year = atoi(ttainfo->id3v1.year); | |
710 | |
711 tuple->track_number = (int)ttainfo->id3v1.track; | |
712 | |
713 if(ttainfo->id3v1.genre) | |
714 tuple->genre = g_strdup(genre[ttainfo->id3v1.genre <= GENRES ? ttainfo->id3v1.genre : 12]); | |
715 if(ttainfo->id3v1.comment) | |
716 tuple->comment = g_strdup(ttainfo->id3v1.comment); | |
717 } | |
718 | |
719 close_tta_file (ttainfo); | |
720 } | |
721 | |
722 vfs_fclose(file); | |
723 } | |
724 return tuple; | |
725 } | |
726 | |
727 static gchar * | |
728 extname(const char *filename) | |
729 { | |
730 gchar *ext = strrchr(filename, '.'); | |
731 | |
732 if (ext != NULL) | |
733 ++ext; | |
734 | |
735 return ext; | |
736 } | |
737 | |
738 /* return length in letters */ | |
739 size_t tta_ucs4len(id3_ucs4_t *ucs) | |
740 { | |
741 id3_ucs4_t *ptr = ucs; | |
742 size_t len = 0; | |
743 | |
744 while(*ptr++ != 0) | |
745 len++; | |
746 | |
747 return len; | |
748 } | |
749 | |
750 /* duplicate id3_ucs4_t string. new string will be terminated with 0. */ | |
751 id3_ucs4_t *tta_ucs4dup(id3_ucs4_t *org) | |
752 { | |
753 id3_ucs4_t *new = NULL; | |
754 size_t len = tta_ucs4len(org); | |
755 | |
756 new = g_malloc0((len + 1) * sizeof(id3_ucs4_t)); | |
757 memcpy(new, org, len * sizeof(id3_ucs4_t)); | |
758 *(new + len) = 0; //terminate | |
759 | |
760 return new; | |
761 } | |
762 | |
763 #define BYTES(x) ((x) * sizeof(id3_ucs4_t)) | |
764 | |
765 id3_ucs4_t *tta_parse_genre(const id3_ucs4_t *string) | |
766 { | |
767 id3_ucs4_t *ret = NULL; | |
768 id3_ucs4_t *tmp = NULL; | |
769 id3_ucs4_t *genre = NULL; | |
770 id3_ucs4_t *ptr, *end, *tail, *tp; | |
771 size_t ret_len = 0; //num of ucs4 char! | |
772 size_t tmp_len = 0; | |
773 gboolean is_num = TRUE; | |
774 | |
775 tail = (id3_ucs4_t *)string + tta_ucs4len((id3_ucs4_t *)string); | |
776 | |
777 ret = g_malloc0(1024); | |
778 | |
779 for(ptr = (id3_ucs4_t *)string; *ptr != 0 && ptr <= tail; ptr++) { | |
780 if(*ptr == '(') { | |
781 if(*(++ptr) == '(') { // escaped text like: ((something) | |
782 for(end = ptr; *end != ')' && *end != 0;) { // copy "(something)" | |
783 end++; | |
784 } | |
785 end++; //include trailing ')' | |
786 memcpy(ret, ptr, BYTES(end - ptr)); | |
787 ret_len += (end - ptr); | |
788 *(ret + ret_len) = 0; //terminate | |
789 ptr = end + 1; | |
790 } | |
791 else { | |
792 // reference to an id3v1 genre code | |
793 for(end = ptr; *end != ')' && *end != 0;) { | |
794 end++; | |
795 } | |
796 | |
797 tmp = g_malloc0(BYTES(end - ptr + 1)); | |
798 memcpy(tmp, ptr, BYTES(end - ptr)); | |
799 *(tmp + (end - ptr)) = 0; //terminate | |
800 ptr += end - ptr; | |
801 | |
802 genre = (id3_ucs4_t *)id3_genre_name((const id3_ucs4_t *)tmp); | |
803 | |
804 g_free(tmp); | |
805 tmp = NULL; | |
806 | |
807 tmp_len = tta_ucs4len(genre); | |
808 | |
809 memcpy(ret + BYTES(ret_len), genre, BYTES(tmp_len)); | |
810 | |
811 ret_len += tmp_len; | |
812 *(ret + ret_len) = 0; //terminate | |
813 } | |
814 } | |
815 else { | |
816 for(end = ptr; *end != '(' && *end != 0; ) { | |
817 end++; | |
818 } | |
819 // scan string to determine whether a genre code number or not | |
820 tp = ptr; | |
821 is_num = TRUE; | |
822 while(tp < end) { | |
823 if(*tp < '0' || *tp > '9') { // anything else than number appears. | |
824 is_num = FALSE; | |
825 break; | |
826 } | |
827 tp++; | |
828 } | |
829 if(is_num) { | |
830 #ifdef DEBUG | |
831 printf("is_num!\n"); | |
832 #endif | |
833 tmp = g_malloc0(BYTES(end - ptr + 1)); | |
834 memcpy(tmp, ptr, BYTES(end - ptr)); | |
835 *(tmp + (end - ptr)) = 0; //terminate | |
836 ptr += end - ptr; | |
837 | |
838 genre = (id3_ucs4_t *)id3_genre_name((const id3_ucs4_t *)tmp); | |
839 #ifdef DEBUG | |
840 printf("genre length = %d\n", tta_ucs4len(genre)); | |
841 #endif | |
842 g_free(tmp); | |
843 tmp = NULL; | |
844 | |
845 tmp_len = tta_ucs4len(genre); | |
846 | |
847 memcpy(ret + BYTES(ret_len), genre, BYTES(tmp_len)); | |
848 | |
849 ret_len += tmp_len; | |
850 *(ret + ret_len) = 0; //terminate | |
851 } | |
852 else { // plain text | |
853 #ifdef DEBUG | |
854 printf("plain!\n"); | |
855 printf("ret_len = %d\n", ret_len); | |
856 #endif | |
857 memcpy(ret + BYTES(ret_len), ptr, BYTES(end - ptr)); | |
858 ret_len = ret_len + (end - ptr); | |
859 *(ret + ret_len) = 0; //terminate | |
860 ptr += (end - ptr); | |
861 } | |
862 } | |
863 } | |
864 return ret; | |
865 } | |
866 | |
867 gchar *tta_input_id3_get_string(struct id3_tag * tag, char *frame_name) | |
868 { | |
869 gchar *rtn; | |
870 gchar *rtn2; | |
871 const id3_ucs4_t *string_const; | |
872 id3_ucs4_t *string; | |
873 id3_ucs4_t *ucsptr; | |
874 struct id3_frame *frame; | |
875 union id3_field *field; | |
876 gboolean flagutf = FALSE; | |
877 | |
878 frame = id3_tag_findframe(tag, frame_name, 0); | |
879 if (!frame) | |
880 return NULL; | |
881 | |
882 if (frame_name == ID3_FRAME_COMMENT) | |
883 field = id3_frame_field(frame, 3); | |
884 else | |
885 field = id3_frame_field(frame, 1); | |
886 | |
887 if (!field) | |
888 return NULL; | |
889 | |
890 if (frame_name == ID3_FRAME_COMMENT) | |
891 string_const = id3_field_getfullstring(field); | |
892 else | |
893 string_const = id3_field_getstrings(field, 0); | |
894 | |
895 if (!string_const) | |
896 return NULL; | |
897 | |
898 string = tta_ucs4dup((id3_ucs4_t *)string_const); | |
899 | |
900 if (frame_name == ID3_FRAME_GENRE) { | |
901 id3_ucs4_t *string2 = NULL; | |
902 string2 = tta_parse_genre(string); | |
903 g_free((void *)string); | |
904 string = string2; | |
905 } | |
906 | |
907 ucsptr = (id3_ucs4_t *)string; | |
908 while (*ucsptr) { | |
909 if (*ucsptr > 0x000000ffL) { | |
910 flagutf = TRUE; | |
911 break; | |
912 } | |
913 ucsptr++; | |
914 } | |
915 | |
916 if (flagutf) { | |
917 #ifdef DEBUG | |
918 g_message("aud-tta: flagutf!\n"); | |
919 #endif | |
920 rtn = id3_ucs4_utf8duplicate(string); | |
921 } | |
922 else { | |
923 rtn = id3_ucs4_latin1duplicate(string); | |
924 rtn2 = str_to_utf8(rtn); | |
925 free(rtn); | |
926 rtn = rtn2; | |
927 } | |
928 g_free(string); | |
929 string = NULL; | |
930 #ifdef DEBUG | |
931 g_print("string = %s\n", rtn); | |
932 #endif | |
933 return rtn; | |
934 } | |
935 | |
936 int get_id3_tags (const char *filename, tta_info *ttainfo) { | |
937 int id3v2_size; | |
938 gchar *str = NULL; | |
939 | |
940 struct id3_file *id3file = NULL; | |
941 struct id3_tag *tag = NULL; | |
942 | |
943 ttainfo->id3v2.id3has = 0; | |
944 ttainfo->id3v1.id3has = 0; | |
945 | |
946 id3file = id3_file_open (filename, ID3_FILE_MODE_READONLY); | |
947 | |
948 if (id3file) { | |
949 tag = id3_file_tag (id3file); | |
950 | |
951 if (tag) { | |
952 str = tta_input_id3_get_string (tag, ID3_FRAME_ARTIST); | |
953 if(str) { | |
441 | 954 strncpy(ttainfo->id3v2.artist, str, MAX_LINE); |
290 | 955 strncpy(ttainfo->id3v1.artist, str, 30); |
956 } | |
957 free(str); | |
958 str = NULL; | |
959 | |
960 str = tta_input_id3_get_string (tag, ID3_FRAME_ALBUM); | |
961 if(str){ | |
442 | 962 strncpy(ttainfo->id3v2.album, str, MAX_LINE); |
290 | 963 strncpy(ttainfo->id3v1.album, str, 30); |
964 } | |
965 free(str); | |
966 str = NULL; | |
967 | |
968 str = tta_input_id3_get_string (tag, ID3_FRAME_TITLE); | |
969 if(str) { | |
442 | 970 strncpy(ttainfo->id3v2.title, str, MAX_LINE); |
290 | 971 strncpy(ttainfo->id3v1.title, str, 30); |
972 } | |
973 free(str); | |
974 str = NULL; | |
975 | |
976 // year | |
977 str = tta_input_id3_get_string (tag, ID3_FRAME_YEAR); //TDRC | |
978 if(!str) { | |
979 str = tta_input_id3_get_string (tag, "TYER"); | |
980 } | |
981 | |
982 if(str){ | |
983 strncpy(ttainfo->id3v2.year, str, 5); | |
984 strncpy(ttainfo->id3v1.year, str, 5); | |
985 } | |
986 free(str); | |
987 str = NULL; | |
988 | |
989 // track number | |
990 str = tta_input_id3_get_string (tag, ID3_FRAME_TRACK); | |
991 if(str) | |
442 | 992 strncpy(ttainfo->id3v2.track, str, MAX_TRACK); |
290 | 993 free(str); |
994 str = NULL; | |
995 | |
996 // genre | |
997 str = tta_input_id3_get_string (tag, ID3_FRAME_GENRE); | |
998 if(str) { | |
999 id3_ucs4_t *tmp = NULL; | |
442 | 1000 strncpy(ttainfo->id3v2.genre, str, MAX_GENRE); |
290 | 1001 tmp = id3_latin1_ucs4duplicate((id3_latin1_t *)str); |
1002 ttainfo->id3v1.genre = id3_genre_number(tmp); | |
1003 g_free(tmp); | |
1004 } | |
1005 free(str); | |
1006 str = NULL; | |
1007 | |
1008 // comment | |
1009 str = tta_input_id3_get_string (tag, ID3_FRAME_COMMENT); | |
443
9e76e87c857e
[svn] One more. Seems like one meant id3v1, not id3v2 for the 30 char limit.
js
parents:
442
diff
changeset
|
1010 if(str) { |
9e76e87c857e
[svn] One more. Seems like one meant id3v1, not id3v2 for the 30 char limit.
js
parents:
442
diff
changeset
|
1011 strncpy(ttainfo->id3v2.comment, str, MAX_LINE); |
9e76e87c857e
[svn] One more. Seems like one meant id3v1, not id3v2 for the 30 char limit.
js
parents:
442
diff
changeset
|
1012 strncpy(ttainfo->id3v1.comment, str, 30); |
9e76e87c857e
[svn] One more. Seems like one meant id3v1, not id3v2 for the 30 char limit.
js
parents:
442
diff
changeset
|
1013 } |
290 | 1014 free(str); |
1015 str = NULL; | |
1016 | |
1017 if(*(ttainfo->id3v2.title) && *(ttainfo->id3v2.artist)) { | |
1018 ttainfo->id3v2.id3has = 1; | |
1019 ttainfo->id3v2.id3has = 1; | |
1020 } | |
1021 } | |
1022 id3_file_close(id3file); | |
1023 } | |
1024 return id3v2_size; // not used | |
1025 } |