annotate Plugins/Input/mpg123/mpg123.c @ 352:f13ab2d8e9cf trunk

[svn] various fixes :(
author nenolod
date Mon, 26 Dec 2005 14:12:35 -0800
parents e7e9a86c0c01
children 18f881216679
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1 #include "mpg123.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
2
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
3 #include <glib.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
4 #include <glib/gi18n.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
5 #include <gtk/gtk.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
6 #include <stdlib.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
7 #include <string.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
8
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
9 #include <libaudacious/util.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
10 #include <libaudacious/configdb.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
11 #include <libaudacious/vfs.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
12 #include <libaudacious/titlestring.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
13
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
14 #include "audacious/util.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
15
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
16 static const long outscale = 32768;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
17
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
18 static struct frame fr, temp_fr;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
19
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
20 PlayerInfo *mpg123_info = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
21 static GThread *decode_thread;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
22
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
23 static gboolean audio_error = FALSE, output_opened = FALSE, dopause = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
24 gint mpg123_bitrate, mpg123_frequency, mpg123_length, mpg123_layer,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
25 mpg123_lsf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
26 gchar *mpg123_title = NULL, *mpg123_filename = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
27 static int disp_bitrate, skip_frames = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
28 static int cpu_fflags, cpu_efflags;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
29 gboolean mpg123_stereo, mpg123_mpeg25;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
30 int mpg123_mode;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
31
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
32 gchar **mpg123_id3_encoding_list = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
33
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
34 const char *mpg123_id3_genres[GENRE_MAX] = {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
35 N_("Blues"), N_("Classic Rock"), N_("Country"), N_("Dance"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
36 N_("Disco"), N_("Funk"), N_("Grunge"), N_("Hip-Hop"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
37 N_("Jazz"), N_("Metal"), N_("New Age"), N_("Oldies"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
38 N_("Other"), N_("Pop"), N_("R&B"), N_("Rap"), N_("Reggae"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
39 N_("Rock"), N_("Techno"), N_("Industrial"), N_("Alternative"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
40 N_("Ska"), N_("Death Metal"), N_("Pranks"), N_("Soundtrack"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
41 N_("Euro-Techno"), N_("Ambient"), N_("Trip-Hop"), N_("Vocal"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
42 N_("Jazz+Funk"), N_("Fusion"), N_("Trance"), N_("Classical"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
43 N_("Instrumental"), N_("Acid"), N_("House"), N_("Game"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
44 N_("Sound Clip"), N_("Gospel"), N_("Noise"), N_("AlternRock"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
45 N_("Bass"), N_("Soul"), N_("Punk"), N_("Space"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
46 N_("Meditative"), N_("Instrumental Pop"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
47 N_("Instrumental Rock"), N_("Ethnic"), N_("Gothic"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
48 N_("Darkwave"), N_("Techno-Industrial"), N_("Electronic"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
49 N_("Pop-Folk"), N_("Eurodance"), N_("Dream"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
50 N_("Southern Rock"), N_("Comedy"), N_("Cult"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
51 N_("Gangsta Rap"), N_("Top 40"), N_("Christian Rap"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
52 N_("Pop/Funk"), N_("Jungle"), N_("Native American"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
53 N_("Cabaret"), N_("New Wave"), N_("Psychedelic"), N_("Rave"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
54 N_("Showtunes"), N_("Trailer"), N_("Lo-Fi"), N_("Tribal"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
55 N_("Acid Punk"), N_("Acid Jazz"), N_("Polka"), N_("Retro"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
56 N_("Musical"), N_("Rock & Roll"), N_("Hard Rock"), N_("Folk"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
57 N_("Folk/Rock"), N_("National Folk"), N_("Swing"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
58 N_("Fast-Fusion"), N_("Bebob"), N_("Latin"), N_("Revival"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
59 N_("Celtic"), N_("Bluegrass"), N_("Avantgarde"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
60 N_("Gothic Rock"), N_("Progressive Rock"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
61 N_("Psychedelic Rock"), N_("Symphonic Rock"), N_("Slow Rock"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
62 N_("Big Band"), N_("Chorus"), N_("Easy Listening"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
63 N_("Acoustic"), N_("Humour"), N_("Speech"), N_("Chanson"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
64 N_("Opera"), N_("Chamber Music"), N_("Sonata"), N_("Symphony"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
65 N_("Booty Bass"), N_("Primus"), N_("Porn Groove"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
66 N_("Satire"), N_("Slow Jam"), N_("Club"), N_("Tango"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
67 N_("Samba"), N_("Folklore"), N_("Ballad"), N_("Power Ballad"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
68 N_("Rhythmic Soul"), N_("Freestyle"), N_("Duet"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
69 N_("Punk Rock"), N_("Drum Solo"), N_("A Cappella"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
70 N_("Euro-House"), N_("Dance Hall"), N_("Goa"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
71 N_("Drum & Bass"), N_("Club-House"), N_("Hardcore"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
72 N_("Terror"), N_("Indie"), N_("BritPop"), N_("Negerpunk"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
73 N_("Polsk Punk"), N_("Beat"), N_("Christian Gangsta Rap"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
74 N_("Heavy Metal"), N_("Black Metal"), N_("Crossover"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
75 N_("Contemporary Christian"), N_("Christian Rock"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
76 N_("Merengue"), N_("Salsa"), N_("Thrash Metal"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
77 N_("Anime"), N_("JPop"), N_("Synthpop")
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
78 };
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
79
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
80 double
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
81 mpg123_compute_tpf(struct frame *fr)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
82 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
83 const int bs[4] = { 0, 384, 1152, 1152 };
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
84 double tpf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
85
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
86 tpf = bs[fr->lay];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
87 tpf /= mpg123_freqs[fr->sampling_frequency] << (fr->lsf);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
88 return tpf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
89 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
90
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
91 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
92 set_synth_functions(struct frame *fr)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
93 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
94 typedef int (*func) (real *, int, unsigned char *, int *);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
95 typedef int (*func_mono) (real *, unsigned char *, int *);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
96 typedef void (*func_dct36) (real *, real *, real *, real *, real *);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
97
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
98 int ds = fr->down_sample;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
99 int p8 = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
100
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
101 static func funcs[][3] = {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
102 {mpg123_synth_1to1,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
103 mpg123_synth_2to1,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
104 mpg123_synth_4to1},
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
105 {mpg123_synth_1to1_8bit,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
106 mpg123_synth_2to1_8bit,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
107 mpg123_synth_4to1_8bit},
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
108 };
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
109
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
110 static func_mono funcs_mono[2][4] = {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
111 {mpg123_synth_1to1_mono,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
112 mpg123_synth_2to1_mono,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
113 mpg123_synth_4to1_mono},
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
114 {mpg123_synth_1to1_8bit_mono,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
115 mpg123_synth_2to1_8bit_mono,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
116 mpg123_synth_4to1_8bit_mono}
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
117 };
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
118
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
119 if (mpg123_cfg.resolution == 8)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
120 p8 = 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
121 fr->synth = funcs[p8][ds];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
122 fr->synth_mono = funcs_mono[p8][ds];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
123 fr->synth_type = SYNTH_FPU;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
124
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
125 if (p8) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
126 mpg123_make_conv16to8_table();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
127 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
128 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
129
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
130 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
131 init(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
132 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
133 ConfigDb *db;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
134
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
135 mpg123_make_decode_tables(outscale);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
136
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
137 mpg123_cfg.resolution = 16;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
138 mpg123_cfg.channels = 2;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
139 mpg123_cfg.downsample = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
140 mpg123_cfg.http_buffer_size = 128;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
141 mpg123_cfg.http_prebuffer = 25;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
142 mpg123_cfg.proxy_port = 8080;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
143 mpg123_cfg.proxy_use_auth = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
144 mpg123_cfg.proxy_user = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
145 mpg123_cfg.proxy_pass = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
146 mpg123_cfg.use_udp_channel = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
147 mpg123_cfg.title_override = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
148 mpg123_cfg.disable_id3v2 = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
149 mpg123_cfg.detect_by = DETECT_EXTENSION;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
150 mpg123_cfg.default_synth = SYNTH_AUTO;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
151
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
152 mpg123_cfg.title_encoding_enabled = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
153 mpg123_cfg.title_encoding = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
154
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
155 db = bmp_cfg_db_open();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
156
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
157 bmp_cfg_db_get_int(db, "MPG123", "resolution", &mpg123_cfg.resolution);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
158 bmp_cfg_db_get_int(db, "MPG123", "channels", &mpg123_cfg.channels);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
159 bmp_cfg_db_get_int(db, "MPG123", "downsample", &mpg123_cfg.downsample);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
160 bmp_cfg_db_get_int(db, "MPG123", "http_buffer_size",
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
161 &mpg123_cfg.http_buffer_size);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
162 bmp_cfg_db_get_int(db, "MPG123", "http_prebuffer",
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
163 &mpg123_cfg.http_prebuffer);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
164 bmp_cfg_db_get_bool(db, "MPG123", "save_http_stream",
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
165 &mpg123_cfg.save_http_stream);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
166 if (!bmp_cfg_db_get_string
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
167 (db, "MPG123", "save_http_path", &mpg123_cfg.save_http_path))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
168 mpg123_cfg.save_http_path = g_strdup(g_get_home_dir());
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
169
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
170 bmp_cfg_db_get_bool(db, "MPG123", "use_udp_channel",
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
171 &mpg123_cfg.use_udp_channel);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
172
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
173 bmp_cfg_db_get_bool(db, "MPG123", "use_proxy", &mpg123_cfg.use_proxy);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
174 if (!bmp_cfg_db_get_string
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
175 (db, "MPG123", "proxy_host", &mpg123_cfg.proxy_host))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
176 mpg123_cfg.proxy_host = g_strdup("localhost");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
177 bmp_cfg_db_get_int(db, "MPG123", "proxy_port", &mpg123_cfg.proxy_port);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
178 bmp_cfg_db_get_bool(db, "MPG123", "proxy_use_auth",
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
179 &mpg123_cfg.proxy_use_auth);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
180 bmp_cfg_db_get_string(db, "MPG123", "proxy_user", &mpg123_cfg.proxy_user);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
181 bmp_cfg_db_get_string(db, "MPG123", "proxy_pass", &mpg123_cfg.proxy_pass);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
182
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
183 bmp_cfg_db_get_bool(db, "MPG123", "title_override",
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
184 &mpg123_cfg.title_override);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
185 bmp_cfg_db_get_bool(db, "MPG123", "disable_id3v2",
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
186 &mpg123_cfg.disable_id3v2);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
187 if (!bmp_cfg_db_get_string
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
188 (db, "MPG123", "id3_format", &mpg123_cfg.id3_format))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
189 mpg123_cfg.id3_format = g_strdup("%p - %t");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
190 bmp_cfg_db_get_int(db, "MPG123", "detect_by", &mpg123_cfg.detect_by);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
191 bmp_cfg_db_get_int(db, "MPG123", "default_synth",
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
192 &mpg123_cfg.default_synth);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
193
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
194 bmp_cfg_db_get_bool(db, "MPG123", "title_encoding_enabled", &mpg123_cfg.title_encoding_enabled);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
195 bmp_cfg_db_get_string(db, "MPG123", "title_encoding", &mpg123_cfg.title_encoding);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
196 if (mpg123_cfg.title_encoding_enabled)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
197 mpg123_id3_encoding_list = g_strsplit_set(mpg123_cfg.title_encoding, ENCODING_SEPARATOR, 0);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
198
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
199 bmp_cfg_db_close(db);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
200
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
201 if (mpg123_cfg.resolution != 16 && mpg123_cfg.resolution != 8)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
202 mpg123_cfg.resolution = 16;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
203
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
204 mpg123_cfg.channels = CLAMP(mpg123_cfg.channels, 0, 2);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
205 mpg123_cfg.downsample = CLAMP(mpg123_cfg.downsample, 0, 2);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
206 mpg123_getcpuflags(&cpu_fflags, &cpu_efflags);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
207 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
208
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
209 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
210 cleanup(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
211 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
212 g_strfreev(mpg123_id3_encoding_list);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
213 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
214
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
215 /* needed for is_our_file() */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
216 static int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
217 read_n_bytes(VFSFile * file, guint8 * buf, int n)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
218 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
219
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
220 if (vfs_fread(buf, 1, n, file) != n) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
221 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
222 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
223 return TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
224 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
225
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
226 static guint32
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
227 convert_to_header(guint8 * buf)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
228 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
229
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
230 return (buf[0] << 24) + (buf[1] << 16) + (buf[2] << 8) + buf[3];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
231 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
232
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
233 static guint32
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
234 convert_to_long(guint8 * buf)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
235 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
236
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
237 return (buf[3] << 24) + (buf[2] << 16) + (buf[1] << 8) + buf[0];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
238 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
239
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
240 static guint16
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
241 read_wav_id(char *filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
242 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
243 VFSFile *file;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
244 guint16 wavid;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
245 guint8 buf[4];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
246 guint32 head;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
247 long seek;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
248
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
249 if (!(file = vfs_fopen(filename, "rb"))) { /* Could not open file */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
250 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
251 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
252 if (!(read_n_bytes(file, buf, 4))) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
253 vfs_fclose(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
254 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
255 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
256 head = convert_to_header(buf);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
257 if (head == ('R' << 24) + ('I' << 16) + ('F' << 8) + 'F') { /* Found a riff -- maybe WAVE */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
258 if (vfs_fseek(file, 4, SEEK_CUR) != 0) { /* some error occured */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
259 vfs_fclose(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
260 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
261 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
262 if (!(read_n_bytes(file, buf, 4))) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
263 vfs_fclose(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
264 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
265 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
266 head = convert_to_header(buf);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
267 if (head == ('W' << 24) + ('A' << 16) + ('V' << 8) + 'E') { /* Found a WAVE */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
268 seek = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
269 do {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
270 /* we'll be looking for the fmt-chunk which comes before the data-chunk */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
271 /* A chunk consists of an header identifier (4 bytes), the length of the chunk
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
272 (4 bytes), and the chunkdata itself, padded to be an even number of bytes.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
273 We'll skip all chunks until we find the "data"-one which could contain
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
274 mpeg-data */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
275 if (seek != 0) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
276 if (vfs_fseek(file, seek, SEEK_CUR) != 0) { /* some error occured */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
277 vfs_fclose(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
278 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
279 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
280 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
281 if (!(read_n_bytes(file, buf, 4))) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
282 vfs_fclose(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
283 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
284 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
285 head = convert_to_header(buf);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
286 if (!(read_n_bytes(file, buf, 4))) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
287 vfs_fclose(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
288 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
289 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
290 seek = convert_to_long(buf);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
291 seek = seek + (seek % 2); /* Has to be even (padding) */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
292 if (seek >= 2
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
293 && head == ('f' << 24) + ('m' << 16) + ('t' << 8) + ' ') {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
294 if (!(read_n_bytes(file, buf, 2))) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
295 vfs_fclose(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
296 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
297 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
298 wavid = buf[0] + 256 * buf[1];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
299 seek -= 2;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
300 /* we could go on looking for
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
301 other things, but all we
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
302 wanted was the wavid */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
303 vfs_fclose(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
304 return wavid;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
305 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
306 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
307 while (head != ('d' << 24) + ('a' << 16) + ('t' << 8) + 'a');
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
308 /* it's RIFF WAVE */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
309 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
310 /* it's RIFF */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
311 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
312 /* it's not even RIFF */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
313 vfs_fclose(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
314 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
315 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
316
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
317 #define DET_BUF_SIZE 1024
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
318
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
319 static gboolean
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
320 mpg123_detect_by_content(char *filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
321 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
322 VFSFile *file;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
323 guchar tmp[4];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
324 guint32 head;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
325 struct frame fr;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
326 guchar buf[DET_BUF_SIZE];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
327 int in_buf, i;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
328 gboolean ret = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
329
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
330 if ((file = vfs_fopen(filename, "rb")) == NULL)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
331 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
332 if (vfs_fread(tmp, 1, 4, file) != 4)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
333 goto done;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
334 head = convert_to_header(tmp);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
335 while (!mpg123_head_check(head)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
336 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
337 * The mpeg-stream can start anywhere in the file,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
338 * so we check the entire file
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
339 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
340 /* Optimize this */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
341 in_buf = vfs_fread(buf, 1, DET_BUF_SIZE, file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
342 if (in_buf == 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
343 goto done;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
344
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
345 for (i = 0; i < in_buf; i++) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
346 head <<= 8;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
347 head |= buf[i];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
348 if (mpg123_head_check(head)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
349 vfs_fseek(file, i + 1 - in_buf, SEEK_CUR);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
350 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
351 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
352 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
353 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
354 if (mpg123_decode_header(&fr, head)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
355 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
356 * We found something which looks like a MPEG-header.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
357 * We check the next frame too, to be sure
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
358 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
359
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
360 if (vfs_fseek(file, fr.framesize, SEEK_CUR) != 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
361 goto done;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
362 if (vfs_fread(tmp, 1, 4, file) != 4)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
363 goto done;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
364 head = convert_to_header(tmp);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
365 if (mpg123_head_check(head) && mpg123_decode_header(&fr, head))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
366 ret = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
367 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
368
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
369 done:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
370 vfs_fclose(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
371 return ret;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
372 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
373
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
374 static int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
375 is_our_file(char *filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
376 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
377 char *ext;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
378 guint16 wavid;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
379
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
380 /* FIXME: wtf? */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
381 /* We assume all http:// (except those ending in .ogg) are mpeg --
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
382 * why do we do that? */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
383 if (!strncasecmp(filename, "http://", 7)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
384 ext = strrchr(filename, '.');
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
385 if (ext) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
386 if (!strncasecmp(ext, ".ogg", 4))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
387 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
388 if (!strncasecmp(ext, ".rm", 3) ||
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
389 !strncasecmp(ext, ".ra", 3) ||
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
390 !strncasecmp(ext, ".rpm", 4) ||
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
391 !strncasecmp(ext, ".ram", 4))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
392 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
393 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
394 return TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
395 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
396 if (mpg123_cfg.detect_by == DETECT_CONTENT)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
397 return (mpg123_detect_by_content(filename));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
398
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
399 ext = strrchr(filename, '.');
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
400 if (ext) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
401 if (!strncasecmp(ext, ".mp2", 4) || !strncasecmp(ext, ".mp3", 4)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
402 return TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
403 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
404 if (!strncasecmp(ext, ".wav", 4)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
405 wavid = read_wav_id(filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
406 if (wavid == 85 || wavid == 80) { /* Microsoft says 80, files say 85... */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
407 return TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
408 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
409 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
410 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
411
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
412 if (mpg123_cfg.detect_by == DETECT_BOTH)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
413 return (mpg123_detect_by_content(filename));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
414 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
415 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
416
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
417 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
418 play_frame(struct frame *fr)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
419 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
420 if (fr->error_protection) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
421 bsi.wordpointer += 2;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
422 /* mpg123_getbits(16); *//* skip crc */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
423 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
424 if (!fr->do_layer(fr)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
425 skip_frames = 2;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
426 mpg123_info->output_audio = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
427 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
428 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
429 if (!skip_frames)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
430 mpg123_info->output_audio = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
431 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
432 skip_frames--;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
433 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
434 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
435
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
436 static const char *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
437 get_id3_genre(unsigned char genre_code)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
438 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
439 if (genre_code < GENRE_MAX)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
440 return gettext(mpg123_id3_genres[genre_code]);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
441
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
442 return "";
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
443 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
444
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
445 guint
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
446 mpg123_strip_spaces(char *src, size_t n)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
447 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
448 gchar *space = NULL, /* last space in src */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
449 *start = src;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
450
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
451 while (n--)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
452 switch (*src++) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
453 case '\0':
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
454 n = 0; /* breaks out of while loop */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
455
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
456 src--;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
457 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
458 case ' ':
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
459 if (space == NULL)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
460 space = src - 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
461 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
462 default:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
463 space = NULL; /* don't terminate intermediate spaces */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
464
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
465 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
466 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
467 if (space != NULL) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
468 src = space;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
469 *src = '\0';
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
470 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
471 return src - start;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
472 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
473
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
474 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
475 * Function extname (filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
476 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
477 * Return pointer within filename to its extenstion, or NULL if
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
478 * filename has no extension.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
479 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
480 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
481 static gchar *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
482 extname(const char *filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
483 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
484 gchar *ext = strrchr(filename, '.');
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
485
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
486 if (ext != NULL)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
487 ++ext;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
488
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
489 return ext;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
490 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
491
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
492 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
493 * Function id3v1_to_id3v2 (v1, v2)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
494 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
495 * Convert ID3v1 tag `v1' to ID3v2 tag `v2'.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
496 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
497 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
498 void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
499 mpg123_id3v1_to_id3v2(struct id3v1tag_t *v1, struct id3tag_t *v2)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
500 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
501 memset(v2, 0, sizeof(struct id3tag_t));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
502 strncpy(v2->title, v1->title, 30);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
503 strncpy(v2->artist, v1->artist, 30);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
504 strncpy(v2->album, v1->album, 30);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
505 strncpy(v2->comment, v1->u.v1_0.comment, 30);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
506 strncpy(v2->genre, get_id3_genre(v1->genre), sizeof(v2->genre));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
507 g_strstrip(v2->title);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
508 g_strstrip(v2->artist);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
509 g_strstrip(v2->album);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
510 g_strstrip(v2->comment);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
511 g_strstrip(v2->genre);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
512 v2->year = atoi(v1->year);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
513
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
514 /* Check for v1.1 tags. */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
515 if (v1->u.v1_1.__zero == 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
516 v2->track_number = v1->u.v1_1.track_number;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
517 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
518 v2->track_number = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
519 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
520
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
521 static char *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
522 mpg123_getstr(char *str)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
523 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
524 if (str && strlen(str) > 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
525 return str;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
526 return NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
527 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
528
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
529 static gchar *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
530 convert_id3_title(gchar * title)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
531 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
532 gchar **encoding = mpg123_id3_encoding_list;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
533 gchar *new_title = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
534
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
535 if (g_utf8_validate(title, -1, NULL))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
536 return title;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
537
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
538 while (*encoding && !new_title) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
539 new_title = g_convert(title, strlen(title), "UTF-8", *encoding++,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
540 NULL, NULL, NULL);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
541 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
542
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
543 if (new_title) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
544 g_free(title);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
545 return new_title;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
546 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
547
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
548 /* FIXME: We're relying on BMP core to provide fallback
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
549 * conversion */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
550 return title;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
551 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
552
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
553 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
554 * Function mpg123_format_song_title (tag, filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
555 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
556 * Create song title according to `tag' and/or `filename' and
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
557 * return it. The title must be subsequently freed using g_free().
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
558 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
559 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
560 gchar *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
561 mpg123_format_song_title(struct id3tag_t * tag, gchar * filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
562 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
563 gchar *title = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
564 TitleInput *input;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
565
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
566 input = bmp_title_input_new();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
567
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
568 if (tag) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
569 input->performer = mpg123_getstr(tag->artist);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
570 input->album_name = mpg123_getstr(tag->album);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
571 input->track_name = mpg123_getstr(tag->title);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
572 input->year = tag->year;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
573 input->track_number = tag->track_number;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
574 input->genre = mpg123_getstr(tag->genre);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
575 input->comment = mpg123_getstr(tag->comment);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
576 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
577
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
578 input->file_name = g_path_get_basename(filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
579 input->file_path = g_path_get_dirname(filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
580 input->file_ext = extname(filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
581
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
582 title = xmms_get_titlestring(mpg123_cfg.title_override ?
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
583 mpg123_cfg.id3_format :
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
584 xmms_get_gentitle_format(), input);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
585
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
586 if (!title) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
587 /* Format according to filename. */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
588 title = g_path_get_basename(filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
589 if (extname(title))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
590 *(extname(title) - 1) = '\0'; /* removes period */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
591 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
592
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
593 g_free(input->file_path);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
594 g_free(input->file_name);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
595 g_free(input);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
596
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
597 if (mpg123_cfg.title_encoding_enabled)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
598 title = convert_id3_title(title);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
599
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
600 return title;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
601 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
602
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
603 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
604 * Function mpg123_get_id3v2 (id3d, tag)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
605 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
606 * Get desired contents from the indicated id3tag and store it in
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
607 * `tag'.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
608 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
609 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
610 void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
611 mpg123_get_id3v2(struct id3_tag *id3d, struct id3tag_t *tag)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
612 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
613 struct id3_frame *id3frm;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
614 gchar *txt;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
615 gint tlen, num;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
616
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
617 #define ID3_SET(_tid,_fld) \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
618 { \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
619 id3frm = id3_get_frame( id3d, _tid, 1 ); \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
620 if (id3frm) { \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
621 txt = _tid == ID3_TCON ? id3_get_content(id3frm) \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
622 : id3_get_text(id3frm); \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
623 if(txt) \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
624 { \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
625 tlen = strlen(txt); \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
626 if ( tlen >= sizeof(tag->_fld) ) \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
627 tlen = sizeof(tag->_fld)-1; \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
628 strncpy( tag->_fld, txt, tlen ); \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
629 tag->_fld[tlen] = 0; \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
630 g_free(txt); \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
631 } \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
632 else \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
633 tag->_fld[0] = 0; \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
634 } else { \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
635 tag->_fld[0] = 0; \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
636 } \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
637 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
638
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
639 #define ID3_SET_NUM(_tid,_fld) \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
640 { \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
641 id3frm = id3_get_frame(id3d, _tid, 1); \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
642 if (id3frm) { \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
643 num = id3_get_text_number(id3frm); \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
644 tag->_fld = num >= 0 ? num : 0; \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
645 } else \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
646 tag->_fld = 0; \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
647 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
648
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
649 ID3_SET(ID3_TIT2, title);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
650 ID3_SET(ID3_TPE1, artist);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
651 if (strlen(tag->artist) == 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
652 ID3_SET(ID3_TPE2, artist);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
653 ID3_SET(ID3_TALB, album);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
654 ID3_SET_NUM(ID3_TYER, year);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
655 ID3_SET_NUM(ID3_TRCK, track_number);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
656 ID3_SET(ID3_COMM, comment);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
657 ID3_SET(ID3_TCON, genre);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
658 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
659
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
660
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
661 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
662 * Function get_song_title (fd, filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
663 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
664 * Get song title of file. File position of `fd' will be
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
665 * clobbered. `fd' may be NULL, in which case `filename' is opened
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
666 * separately. The returned song title must be subsequently freed
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
667 * using g_free().
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
668 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
669 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
670 static gchar *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
671 get_song_title(VFSFile * fd, char *filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
672 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
673 VFSFile *file = fd;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
674 char *ret = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
675 struct id3v1tag_t id3v1tag;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
676 struct id3tag_t id3tag;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
677
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
678 if (file || (file = vfs_fopen(filename, "rb")) != 0) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
679 struct id3_tag *id3 = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
680
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
681 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
682 * Try reading ID3v2 tag.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
683 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
684 if (!mpg123_cfg.disable_id3v2) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
685 vfs_fseek(file, 0, SEEK_SET);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
686 id3 = id3_open_fp(file, 0);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
687 if (id3) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
688 mpg123_get_id3v2(id3, &id3tag);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
689 ret = mpg123_format_song_title(&id3tag, filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
690 id3_close(id3);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
691 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
692 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
693
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
694 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
695 * Try reading ID3v1 tag.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
696 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
697 if (!id3 && (vfs_fseek(file, -1 * sizeof(id3v1tag), SEEK_END) == 0) &&
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
698 (vfs_fread(&id3v1tag, 1, sizeof(id3v1tag), file) ==
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
699 sizeof(id3v1tag)) && (strncmp(id3v1tag.tag, "TAG", 3) == 0)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
700 mpg123_id3v1_to_id3v2(&id3v1tag, &id3tag);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
701 ret = mpg123_format_song_title(&id3tag, filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
702 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
703
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
704 if (!fd)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
705 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
706 * File was opened in this function.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
707 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
708 vfs_fclose(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
709 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
710
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
711 if (ret == NULL)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
712 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
713 * Unable to get ID3 tag.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
714 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
715 ret = mpg123_format_song_title(NULL, filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
716
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
717 return ret;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
718 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
719
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
720 static long
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
721 get_song_length(VFSFile * file)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
722 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
723 int len;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
724 char tmp[4];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
725
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
726 vfs_fseek(file, 0, SEEK_END);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
727 len = vfs_ftell(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
728 vfs_fseek(file, -128, SEEK_END);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
729 vfs_fread(tmp, 1, 3, file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
730 if (!strncmp(tmp, "TAG", 3))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
731 len -= 128;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
732 return len;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
733 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
734
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
735
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
736 static guint
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
737 get_song_time(VFSFile * file)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
738 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
739 guint32 head;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
740 guchar tmp[4], *buf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
741 struct frame frm;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
742 xing_header_t xing_header;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
743 double tpf, bpf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
744 guint32 len;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
745
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
746 if (!file)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
747 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
748
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
749 vfs_fseek(file, 0, SEEK_SET);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
750 if (vfs_fread(tmp, 1, 4, file) != 4)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
751 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
752 head = convert_to_header(tmp);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
753 while (!mpg123_head_check(head)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
754 head <<= 8;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
755 if (vfs_fread(tmp, 1, 1, file) != 1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
756 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
757 head |= tmp[0];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
758 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
759 if (mpg123_decode_header(&frm, head)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
760 buf = g_malloc(frm.framesize + 4);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
761 vfs_fseek(file, -4, SEEK_CUR);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
762 vfs_fread(buf, 1, frm.framesize + 4, file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
763 tpf = mpg123_compute_tpf(&frm);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
764 if (mpg123_get_xing_header(&xing_header, buf)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
765 g_free(buf);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
766 if (xing_header.bytes == 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
767 xing_header.bytes = get_song_length(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
768 return (tpf * xing_header.frames * 1000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
769 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
770 g_free(buf);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
771 bpf = mpg123_compute_bpf(&frm);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
772 len = get_song_length(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
773 return ((guint) (len / bpf) * tpf * 1000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
774 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
775 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
776 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
777
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
778 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
779 get_song_info(char *filename, char **title_real, int *len_real)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
780 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
781 VFSFile *file;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
782
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
783 (*len_real) = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
784 (*title_real) = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
785
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
786 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
787 * TODO: Getting song info from http streams.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
788 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
789 if (!strncasecmp(filename, "http://", 7))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
790 return;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
791
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
792 if ((file = vfs_fopen(filename, "rb")) != NULL) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
793 (*len_real) = get_song_time(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
794 (*title_real) = get_song_title(file, filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
795 vfs_fclose(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
796 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
797 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
798
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
799 static int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
800 open_output(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
801 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
802 int r;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
803 AFormat fmt = mpg123_cfg.resolution == 16 ? FMT_S16_NE : FMT_U8;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
804 int freq = mpg123_freqs[fr.sampling_frequency] >> mpg123_cfg.downsample;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
805 int channels = mpg123_cfg.channels == 2 ? fr.stereo : 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
806 r = mpg123_ip.output->open_audio(fmt, freq, channels);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
807
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
808 if (r && dopause) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
809 mpg123_ip.output->pause(TRUE);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
810 dopause = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
811 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
812
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
813 return r;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
814 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
815
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
816
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
817 static int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
818 mpg123_seek(struct frame *fr, xing_header_t * xh, gboolean vbr, int time)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
819 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
820 int jumped = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
821
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
822 if (xh) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
823 int percent = ((double) time * 100.0) /
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
824 (mpg123_info->num_frames * mpg123_info->tpf);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
825 int byte = mpg123_seek_point(xh, percent);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
826 jumped = mpg123_stream_jump_to_byte(fr, byte);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
827 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
828 else if (vbr && mpg123_length > 0) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
829 int byte = ((guint64) time * 1000 * mpg123_info->filesize) /
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
830 mpg123_length;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
831 jumped = mpg123_stream_jump_to_byte(fr, byte);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
832 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
833 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
834 int frame = time / mpg123_info->tpf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
835 jumped = mpg123_stream_jump_to_frame(fr, frame);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
836 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
837
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
838 return jumped;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
839 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
840
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
841
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
842 static void *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
843 decode_loop(void *arg)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
844 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
845 gboolean have_xing_header = FALSE, vbr = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
846 int disp_count = 0, temp_time;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
847 char *filename = arg;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
848 xing_header_t xing_header;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
849
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
850 /* This is used by fileinfo on http streams */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
851 mpg123_bitrate = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
852
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
853 mpg123_pcm_sample = g_malloc0(32768);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
854 mpg123_pcm_point = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
855 mpg123_filename = filename;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
856
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
857 mpg123_read_frame_init();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
858
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
859 mpg123_open_stream(filename, -1);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
860
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
861 if (mpg123_info->eof || !mpg123_read_frame(&fr))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
862 mpg123_info->eof = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
863
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
864 if (!mpg123_info->eof && mpg123_info->going) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
865 if (mpg123_cfg.channels == 2)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
866 fr.single = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
867 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
868 fr.single = 3;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
869
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
870 fr.down_sample = mpg123_cfg.downsample;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
871 fr.down_sample_sblimit = SBLIMIT >> mpg123_cfg.downsample;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
872 set_synth_functions(&fr);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
873 mpg123_init_layer3(fr.down_sample_sblimit);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
874
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
875 mpg123_info->tpf = mpg123_compute_tpf(&fr);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
876 if (strncasecmp(filename, "http://", 7)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
877 if (mpg123_stream_check_for_xing_header(&fr, &xing_header)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
878 mpg123_info->num_frames = xing_header.frames;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
879 have_xing_header = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
880 mpg123_read_frame(&fr);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
881 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
882 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
883
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
884 for (;;) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
885 memcpy(&temp_fr, &fr, sizeof(struct frame));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
886 if (!mpg123_read_frame(&temp_fr)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
887 mpg123_info->eof = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
888 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
889 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
890 if (fr.lay != temp_fr.lay ||
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
891 fr.sampling_frequency != temp_fr.sampling_frequency ||
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
892 fr.stereo != temp_fr.stereo || fr.lsf != temp_fr.lsf)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
893 memcpy(&fr, &temp_fr, sizeof(struct frame));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
894 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
895 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
896 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
897
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
898 if (!have_xing_header && strncasecmp(filename, "http://", 7))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
899 mpg123_info->num_frames = mpg123_calc_numframes(&fr);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
900
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
901 memcpy(&fr, &temp_fr, sizeof(struct frame));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
902 mpg123_bitrate = tabsel_123[fr.lsf][fr.lay - 1][fr.bitrate_index];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
903 disp_bitrate = mpg123_bitrate;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
904 mpg123_frequency = mpg123_freqs[fr.sampling_frequency];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
905 mpg123_stereo = fr.stereo;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
906 mpg123_layer = fr.lay;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
907 mpg123_lsf = fr.lsf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
908 mpg123_mpeg25 = fr.mpeg25;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
909 mpg123_mode = fr.mode;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
910
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
911 if (strncasecmp(filename, "http://", 7)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
912 mpg123_length = mpg123_info->num_frames * mpg123_info->tpf * 1000;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
913 if (!mpg123_title)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
914 mpg123_title = get_song_title(NULL, filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
915 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
916 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
917 if (!mpg123_title)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
918 mpg123_title = mpg123_http_get_title(filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
919 mpg123_length = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
920 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
921
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
922 mpg123_ip.set_info(mpg123_title, mpg123_length,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
923 mpg123_bitrate * 1000,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
924 mpg123_freqs[fr.sampling_frequency], fr.stereo);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
925
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
926 output_opened = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
927
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
928 if (!open_output()) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
929 audio_error = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
930 mpg123_info->eof = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
931 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
932 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
933 play_frame(&fr);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
934 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
935
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
936 mpg123_info->first_frame = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
937 while (mpg123_info->going) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
938 if (mpg123_info->jump_to_time != -1) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
939 void *xp = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
940 if (have_xing_header)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
941 xp = &xing_header;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
942 if (mpg123_seek(&fr, xp, vbr, mpg123_info->jump_to_time) > -1) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
943 mpg123_ip.output->flush(mpg123_info->jump_to_time * 1000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
944 mpg123_info->eof = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
945 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
946 mpg123_info->jump_to_time = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
947 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
948 if (!mpg123_info->eof) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
949 if (mpg123_read_frame(&fr) != 0) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
950 if (fr.lay != mpg123_layer || fr.lsf != mpg123_lsf) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
951 memcpy(&temp_fr, &fr, sizeof(struct frame));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
952 if (mpg123_read_frame(&temp_fr) != 0) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
953 if (fr.lay == temp_fr.lay && fr.lsf == temp_fr.lsf) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
954 mpg123_layer = fr.lay;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
955 mpg123_lsf = fr.lsf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
956 memcpy(&fr, &temp_fr, sizeof(struct frame));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
957 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
958 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
959 memcpy(&fr, &temp_fr, sizeof(struct frame));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
960 skip_frames = 2;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
961 mpg123_info->output_audio = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
962 continue;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
963 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
964
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
965 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
966 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
967 if (mpg123_freqs[fr.sampling_frequency] != mpg123_frequency
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
968 || mpg123_stereo != fr.stereo) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
969 memcpy(&temp_fr, &fr, sizeof(struct frame));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
970 if (mpg123_read_frame(&temp_fr) != 0) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
971 if (fr.sampling_frequency ==
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
972 temp_fr.sampling_frequency
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
973 && temp_fr.stereo == fr.stereo) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
974 mpg123_ip.output->buffer_free();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
975 mpg123_ip.output->buffer_free();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
976 while (mpg123_ip.output->buffer_playing()
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
977 && mpg123_info->going
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
978 && mpg123_info->jump_to_time == -1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
979 xmms_usleep(20000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
980 if (!mpg123_info->going)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
981 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
982 temp_time = mpg123_ip.output->output_time();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
983 mpg123_ip.output->close_audio();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
984 mpg123_frequency =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
985 mpg123_freqs[fr.sampling_frequency];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
986 mpg123_stereo = fr.stereo;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
987 if (!mpg123_ip.output->
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
988 open_audio(mpg123_cfg.resolution ==
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
989 16 ? FMT_S16_NE : FMT_U8,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
990 mpg123_freqs[fr.sampling_frequency]
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
991 >> mpg123_cfg.downsample,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
992 mpg123_cfg.channels ==
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
993 2 ? fr.stereo : 1)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
994 audio_error = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
995 mpg123_info->eof = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
996 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
997 mpg123_ip.output->flush(temp_time);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
998 mpg123_ip.set_info(mpg123_title, mpg123_length,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
999 mpg123_bitrate * 1000,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1000 mpg123_frequency,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1001 mpg123_stereo);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1002 memcpy(&fr, &temp_fr, sizeof(struct frame));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1003 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1004 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1005 memcpy(&fr, &temp_fr, sizeof(struct frame));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1006 skip_frames = 2;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1007 mpg123_info->output_audio = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1008 continue;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1009 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1010 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1011 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1012
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1013 if (tabsel_123[fr.lsf][fr.lay - 1][fr.bitrate_index] !=
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1014 mpg123_bitrate)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1015 mpg123_bitrate =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1016 tabsel_123[fr.lsf][fr.lay - 1][fr.bitrate_index];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1017
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1018 if (!disp_count) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1019 disp_count = 20;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1020 if (mpg123_bitrate != disp_bitrate) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1021 /* FIXME networks streams */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1022 disp_bitrate = mpg123_bitrate;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1023 if (!have_xing_header
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1024 && strncasecmp(filename, "http://", 7)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1025 double rel = mpg123_relative_pos();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1026 if (rel) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1027 mpg123_length =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1028 mpg123_ip.output->written_time() / rel;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1029 vbr = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1030 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1031
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1032 if (rel == 0 || !(mpg123_length > 0)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1033 mpg123_info->num_frames =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1034 mpg123_calc_numframes(&fr);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1035 mpg123_info->tpf = mpg123_compute_tpf(&fr);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1036 mpg123_length =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1037 mpg123_info->num_frames *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1038 mpg123_info->tpf * 1000;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1039 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1040
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1041
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1042 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1043 mpg123_ip.set_info(mpg123_title, mpg123_length,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1044 mpg123_bitrate * 1000,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1045 mpg123_frequency, mpg123_stereo);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1046 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1047 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1048 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1049 disp_count--;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1050 play_frame(&fr);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1051 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1052 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1053 mpg123_ip.output->buffer_free();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1054 mpg123_ip.output->buffer_free();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1055 mpg123_info->eof = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1056 xmms_usleep(10000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1057 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1058 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1059 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1060 xmms_usleep(10000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1061 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1062 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1063 g_free(mpg123_title);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1064 mpg123_title = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1065 mpg123_stream_close();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1066 if (output_opened && !audio_error)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1067 mpg123_ip.output->close_audio();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1068 g_free(mpg123_pcm_sample);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1069 mpg123_filename = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1070 g_free(filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1071
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1072 return NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1073 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1074
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1075 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1076 play_file(char *filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1077 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1078 memset(&fr, 0, sizeof(struct frame));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1079 memset(&temp_fr, 0, sizeof(struct frame));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1080
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1081 mpg123_info = g_malloc0(sizeof(PlayerInfo));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1082 mpg123_info->going = 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1083 mpg123_info->first_frame = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1084 mpg123_info->output_audio = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1085 mpg123_info->jump_to_time = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1086 skip_frames = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1087 audio_error = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1088 output_opened = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1089 dopause = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1090
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1091 decode_thread = g_thread_create(decode_loop, g_strdup(filename), TRUE,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1092 NULL);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1093 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1094
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1095 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1096 stop(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1097 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1098 if (mpg123_info && mpg123_info->going) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1099 mpg123_info->going = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1100 g_thread_join(decode_thread);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1101 g_free(mpg123_info);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1102 mpg123_info = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1103 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1104 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1105
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1106 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1107 seek(int time)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1108 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1109 mpg123_info->jump_to_time = time;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1110
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1111 while (mpg123_info->jump_to_time != -1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1112 xmms_usleep(10000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1113 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1114
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1115 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1116 do_pause(short p)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1117 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1118 if (output_opened)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1119 mpg123_ip.output->pause(p);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1120 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1121 dopause = p;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1122 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1123
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1124 static int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1125 get_time(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1126 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1127 if (audio_error)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1128 return -2;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1129 if (!mpg123_info)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1130 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1131 if (!mpg123_info->going
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1132 || (mpg123_info->eof && !mpg123_ip.output->buffer_playing()))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1133 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1134 return mpg123_ip.output->output_time();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1135 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1136
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1137 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1138 aboutbox(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1139 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1140 static GtkWidget *aboutbox;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1141
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1142 if (aboutbox != NULL)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1143 return;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1144
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1145 aboutbox = xmms_show_message(_("About MPEG Audio Plugin"),
223
e7e9a86c0c01 [svn] Update credits on here reflecting audacious-decoder changes.
nenolod
parents: 177
diff changeset
1146 _("Audacious decoding engine by William Pitcock <nenolod@nenolod.net>, derived from:\n"
e7e9a86c0c01 [svn] Update credits on here reflecting audacious-decoder changes.
nenolod
parents: 177
diff changeset
1147 "mpg123 decoding engine by Michael Hipp <mh@mpg123.de>\n"
e7e9a86c0c01 [svn] Update credits on here reflecting audacious-decoder changes.
nenolod
parents: 177
diff changeset
1148 "Derived partially from mpg123 0.59s.mc3 as well.\n"
129
ce9d4aa5889a [svn] Update the credits to note the code sync that occured.
nenolod
parents: 61
diff changeset
1149 "Based on the original XMMS plugin."),
ce9d4aa5889a [svn] Update the credits to note the code sync that occured.
nenolod
parents: 61
diff changeset
1150 _("Ok"),
ce9d4aa5889a [svn] Update the credits to note the code sync that occured.
nenolod
parents: 61
diff changeset
1151 FALSE, NULL, NULL);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1152
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1153 g_signal_connect(G_OBJECT(aboutbox), "destroy",
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1154 G_CALLBACK(gtk_widget_destroyed), &aboutbox);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1155 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1156
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1157 InputPlugin mpg123_ip = {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1158 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1159 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1160 NULL, /* Description */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1161 init,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1162 aboutbox,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1163 mpg123_configure,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1164 is_our_file,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1165 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1166 play_file,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1167 stop,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1168 do_pause,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1169 seek,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1170 mpg123_set_eq,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1171 get_time,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1172 NULL, NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1173 cleanup,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1174 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1175 NULL, NULL, NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1176 get_song_info,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1177 mpg123_file_info_box, /* file_info_box */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1178 NULL
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1179 };
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1180
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1181 InputPlugin *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1182 get_iplugin_info(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1183 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1184 mpg123_ip.description = g_strdup_printf(_("MPEG Audio Plugin"));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1185 return &mpg123_ip;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1186 }