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