Mercurial > audlegacy-plugins
annotate src/wma/wma.c @ 2160:5ba49a9c053c
fixed uploads, using URI's with libmtp is bad, mmm'kay !
author | Cristi Magherusan <majeru@atheme-project.org> |
---|---|
date | Fri, 09 Nov 2007 00:08:06 +0200 |
parents | e60ad26664d6 |
children | 7576404c8415 |
rev | line source |
---|---|
878 | 1 /* |
2 * Audacious WMA input plugin | |
1072 | 3 * (C) 2005, 2006, 2007 Audacious development team |
878 | 4 * |
5 * Based on: | |
6 * xmms-wma - WMA player for BMP | |
7 * Copyright (C) 2004,2005 McMCC <mcmcc@mail.ru> | |
8 * bmp-wma - WMA player for BMP | |
9 * Copyright (C) 2004 Roman Bogorodskiy <bogorodskiy@inbox.ru> | |
10 * | |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
24 */ | |
25 #define _XOPEN_SOURCE 600 | |
1784 | 26 |
27 #include "config.h" | |
28 | |
878 | 29 #include <stdlib.h> |
30 #include <unistd.h> | |
31 #include <math.h> | |
32 #include <stdbool.h> | |
33 #include <stdio.h> | |
34 #include <string.h> | |
35 #include <strings.h> | |
36 #include <glib.h> | |
37 | |
1950
2ebeb7816c5e
Change from "" to <>-style includes. With thanks to ccr for the correct sed voodoo.
chainsaw@localhost
parents:
1784
diff
changeset
|
38 #include <audacious/plugin.h> |
2ebeb7816c5e
Change from "" to <>-style includes. With thanks to ccr for the correct sed voodoo.
chainsaw@localhost
parents:
1784
diff
changeset
|
39 #include <audacious/output.h> |
2ebeb7816c5e
Change from "" to <>-style includes. With thanks to ccr for the correct sed voodoo.
chainsaw@localhost
parents:
1784
diff
changeset
|
40 #include <audacious/util.h> |
2ebeb7816c5e
Change from "" to <>-style includes. With thanks to ccr for the correct sed voodoo.
chainsaw@localhost
parents:
1784
diff
changeset
|
41 #include <audacious/strings.h> |
1952
17a6441c71b6
Some missed #include "" to <> changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
42 #include <audacious/i18n.h> |
1950
2ebeb7816c5e
Change from "" to <>-style includes. With thanks to ccr for the correct sed voodoo.
chainsaw@localhost
parents:
1784
diff
changeset
|
43 #include <audacious/main.h> |
878 | 44 |
45 #include "avcodec.h" | |
46 #include "avformat.h" | |
47 | |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
48 static const gchar * PLUGIN_NAME = "Audacious-WMA"; |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
49 static const gchar * PLUGIN_VERSION = "v.1.0.5"; |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
50 static const int ST_BUFF = 1024; |
878 | 51 |
52 static int wma_decode = 0; | |
53 static gboolean wma_pause = 0; | |
54 static int wma_seekpos = -1; | |
55 static int wma_st_buff, wma_idx, wma_idx2; | |
56 static GThread *wma_decode_thread; | |
57 GStaticMutex wma_mutex = G_STATIC_MUTEX_INIT; | |
58 static AVCodecContext *c = NULL; | |
59 static AVFormatContext *ic = NULL; | |
60 static AVCodecContext *c2 = NULL; | |
61 static AVFormatContext *ic2 = NULL; | |
62 static uint8_t *wma_outbuf, *wma_s_outbuf; | |
63 | |
64 char description[64]; | |
65 static void wma_about(void); | |
66 static void wma_init(void); | |
67 static int wma_is_our_file(char *filename); | |
68 static int wma_is_our_fd(char *filename, VFSFile *fd); | |
69 static void wma_play_file(InputPlayback *data); | |
70 static void wma_stop(InputPlayback *data); | |
71 static void wma_seek(InputPlayback *data, int time); | |
72 static void wma_do_pause(InputPlayback *data, short p); | |
73 static void wma_get_song_info(char *filename, char **title, int *length); | |
1425
a25c2cfcce83
New tuple API conversion for WMA, first try.
Tony Vroon <chainsaw@gentoo.org>
parents:
1395
diff
changeset
|
74 static Tuple *wma_get_song_tuple(char *filename); |
878 | 75 static char *wsong_title; |
76 static int wsong_time; | |
77 | |
78 static GtkWidget *dialog1, *button1, *label1; | |
1072 | 79 static gchar *fmts[] = { "wma", NULL }; |
878 | 80 |
81 InputPlugin wma_ip = | |
82 { | |
1072 | 83 .description = "Windows Media Audio (WMA) Plugin", |
84 .init = wma_init, | |
85 .about = wma_about, | |
86 .is_our_file = wma_is_our_file, | |
87 .play_file = wma_play_file, | |
88 .stop = wma_stop, | |
89 .pause = wma_do_pause, | |
90 .seek = wma_seek, | |
91 .get_song_info = wma_get_song_info, | |
92 .get_song_tuple = wma_get_song_tuple, | |
93 .is_our_file_from_vfs = wma_is_our_fd, | |
1979
839804c3b3a4
aud_vfs_extensions -> vfs_extensions, some vtable fixes
William Pitcock <nenolod@atheme.org>
parents:
1978
diff
changeset
|
94 .vfs_extensions = fmts, |
878 | 95 }; |
96 | |
1072 | 97 InputPlugin *wma_iplist[] = { &wma_ip, NULL }; |
98 | |
1395
761e17b23e0c
added Discovery plugin type
Cristi Magherusan <majeru@atheme-project.org>
parents:
1390
diff
changeset
|
99 DECLARE_PLUGIN(wma, NULL, NULL, wma_iplist, NULL, NULL, NULL, NULL, NULL); |
1072 | 100 |
878 | 101 static gchar *str_twenty_to_space(gchar * str) |
102 { | |
103 gchar *match, *match_end; | |
104 | |
105 g_return_val_if_fail(str != NULL, NULL); | |
106 | |
107 while ((match = strstr(str, "%20"))) { | |
108 match_end = match + 3; | |
109 *match++ = ' '; | |
110 while (*match_end) | |
111 *match++ = *match_end++; | |
112 *match = 0; | |
113 } | |
114 | |
115 return str; | |
116 } | |
117 | |
118 static void wma_about(void) | |
119 { | |
120 char *title; | |
121 char *message; | |
122 | |
123 if (dialog1) return; | |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
124 |
878 | 125 title = (char *)g_malloc(80); |
126 message = (char *)g_malloc(1000); | |
127 memset(title, 0, 80); | |
128 memset(message, 0, 1000); | |
129 | |
130 sprintf(title, _("About %s"), PLUGIN_NAME); | |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
131 sprintf(message, "%s %s\n\n%s", PLUGIN_NAME, PLUGIN_VERSION, |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
132 _("Adapted for use in Audacious by Tony Vroon (chainsaw@gentoo.org) from\n" |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
133 "the BEEP-WMA plugin which is Copyright (C) 2004,2005 Mokrushin I.V. aka McMCC (mcmcc@mail.ru)\n" |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
134 "and the BMP-WMA plugin which is Copyright (C) 2004 Roman Bogorodskiy <bogorodskiy@inbox.ru>.\n" |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
135 "This plugin based on source code " LIBAVCODEC_IDENT "\nby Fabrice Bellard from" |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
136 "http://ffmpeg.sourceforge.net.\n\n" |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
137 "This program is free software; you can redistribute it and/or modify \n" |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
138 "it under the terms of the GNU General Public License as published by \n" |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
139 "the Free Software Foundation; either version 2 of the License, or \n" |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
140 "(at your option) any later version. \n\n" |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
141 "This program is distributed in the hope that it will be useful, \n" |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
142 "but WITHOUT ANY WARRANTY; without even the implied warranty of \n" |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
143 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. \n" |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
144 "See the GNU General Public License for more details.\n" |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
145 )); |
878 | 146 |
147 dialog1 = gtk_dialog_new(); | |
148 g_signal_connect(G_OBJECT(dialog1), "destroy", | |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
149 G_CALLBACK(gtk_widget_destroyed), &dialog1); |
878 | 150 gtk_window_set_title(GTK_WINDOW(dialog1), title); |
151 gtk_window_set_policy(GTK_WINDOW(dialog1), FALSE, FALSE, FALSE); | |
152 gtk_container_border_width(GTK_CONTAINER(dialog1), 5); | |
153 label1 = gtk_label_new(message); | |
154 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog1)->vbox), label1, TRUE, TRUE, 0); | |
155 gtk_widget_show(label1); | |
156 | |
157 button1 = gtk_button_new_with_label(_(" Close ")); | |
158 g_signal_connect_swapped(G_OBJECT(button1), "clicked", | |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
159 G_CALLBACK(gtk_widget_destroy), |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
160 GTK_OBJECT(dialog1)); |
878 | 161 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog1)->action_area), button1, |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
162 FALSE, FALSE, 0); |
878 | 163 |
164 gtk_widget_show(button1); | |
165 gtk_widget_show(dialog1); | |
166 gtk_widget_grab_focus(button1); | |
167 g_free(title); | |
168 g_free(message); | |
169 } | |
170 | |
171 static void wma_init(void) | |
172 { | |
173 avcodec_init(); | |
174 avcodec_register_all(); | |
175 av_register_all(); | |
176 } | |
177 | |
178 static int wma_is_our_file(char *filename) | |
179 { | |
180 AVCodec *codec2; | |
181 | |
182 if(av_open_input_file(&ic2, str_twenty_to_space(filename), NULL, 0, NULL) < 0) return 0; | |
183 | |
184 for(wma_idx2 = 0; wma_idx2 < ic2->nb_streams; wma_idx2++) { | |
185 c2 = &ic2->streams[wma_idx2]->codec; | |
186 if(c2->codec_type == CODEC_TYPE_AUDIO) break; | |
187 } | |
188 | |
189 av_find_stream_info(ic2); | |
190 | |
191 codec2 = avcodec_find_decoder(c2->codec_id); | |
192 | |
193 if(!codec2) { | |
194 av_close_input_file(ic2); | |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
195 return 0; |
878 | 196 } |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
197 |
878 | 198 av_close_input_file(ic2); |
199 return 1; | |
200 } | |
201 | |
202 static int wma_is_our_fd(char *filename, VFSFile *fd) | |
203 { | |
204 AVCodec *codec2; | |
205 | |
206 if(av_open_input_vfsfile(&ic2, filename, fd, NULL, 0, NULL) < 0) return 0; | |
207 | |
208 for(wma_idx2 = 0; wma_idx2 < ic2->nb_streams; wma_idx2++) { | |
209 c2 = &ic2->streams[wma_idx2]->codec; | |
210 if(c2->codec_type == CODEC_TYPE_AUDIO) break; | |
211 } | |
212 | |
213 av_find_stream_info(ic2); | |
214 | |
215 codec2 = avcodec_find_decoder(c2->codec_id); | |
216 | |
1156 | 217 if (!codec2) { |
218 av_close_input_vfsfile(ic2); | |
219 return 0; | |
220 } | |
221 | |
222 av_close_input_vfsfile(ic2); | |
878 | 223 return 1; |
224 } | |
225 | |
226 static void wma_do_pause(InputPlayback *playback, short p) | |
227 { | |
228 wma_pause = p; | |
229 playback->output->pause(wma_pause); | |
230 } | |
231 | |
232 static void wma_seek(InputPlayback *playback, int time) | |
233 { | |
234 wma_seekpos = time; | |
235 if(wma_pause) playback->output->pause(0); | |
1676
aee4ebea943a
xmms_usleep() was removed, use g_usleep()
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
236 while(wma_decode && wma_seekpos!=-1) g_usleep(10000); |
878 | 237 if(wma_pause) playback->output->pause(1); |
238 } | |
239 | |
1687
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
240 static void _assoc_string(Tuple *tuple, const gint nfield, const gchar *str) |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
241 { |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
242 if (strlen(str) > 0) |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1954
diff
changeset
|
243 aud_tuple_associate_string(tuple, nfield, NULL, str); |
1687
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
244 } |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
245 |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
246 static void _assoc_int(Tuple *tuple, const gint nfield, const gint val) |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
247 { |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
248 if (val > 0) |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1954
diff
changeset
|
249 aud_tuple_associate_int(tuple, nfield, NULL, val); |
1687
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
250 } |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
251 |
1425
a25c2cfcce83
New tuple API conversion for WMA, first try.
Tony Vroon <chainsaw@gentoo.org>
parents:
1395
diff
changeset
|
252 static Tuple *wma_get_song_tuple(gchar * filename) |
878 | 253 { |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1954
diff
changeset
|
254 Tuple *ti = aud_tuple_new_from_filename(filename); |
878 | 255 AVFormatContext *in = NULL; |
256 | |
257 if (av_open_input_file(&in, str_twenty_to_space(filename), NULL, 0, NULL) < 0) | |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
258 return NULL; |
878 | 259 |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1954
diff
changeset
|
260 aud_tuple_associate_string(ti, FIELD_CODEC, NULL, "Windows Media Audio (WMA)"); |
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1954
diff
changeset
|
261 aud_tuple_associate_string(ti, FIELD_QUALITY, NULL, "lossy"); |
1425
a25c2cfcce83
New tuple API conversion for WMA, first try.
Tony Vroon <chainsaw@gentoo.org>
parents:
1395
diff
changeset
|
262 |
878 | 263 av_find_stream_info(in); |
264 | |
1687
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
265 _assoc_string(ti, FIELD_TITLE, in->title); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
266 _assoc_string(ti, FIELD_ARTIST, in->author); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
267 _assoc_string(ti, FIELD_ALBUM, in->album); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
268 _assoc_string(ti, FIELD_COMMENT, in->comment); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
269 _assoc_string(ti, FIELD_GENRE, in->genre); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
270 _assoc_int(ti, FIELD_YEAR, in->year); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
271 _assoc_int(ti, FIELD_TRACK_NUMBER, in->track); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
272 _assoc_int(ti, FIELD_LENGTH, in->duration / 1000); |
878 | 273 |
274 av_close_input_file(in); | |
275 | |
1430
bf7d4c236d9f
Start using tuple_new_from_filename.
Tony Vroon <chainsaw@gentoo.org>
parents:
1425
diff
changeset
|
276 return ti; |
878 | 277 } |
278 | |
279 static gchar *get_song_title(AVFormatContext *in, gchar * filename) | |
280 { | |
281 gchar *ret = NULL; | |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1954
diff
changeset
|
282 Tuple *ti = aud_tuple_new_from_filename(filename); |
878 | 283 |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1954
diff
changeset
|
284 aud_tuple_associate_string(ti, FIELD_CODEC, NULL, "Windows Media Audio (WMA)"); |
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1954
diff
changeset
|
285 aud_tuple_associate_string(ti, FIELD_QUALITY, NULL, "lossy"); |
1438
dc3e28d3b92a
mpc: convert, wma: fixes
William Pitcock <nenolod@atheme-project.org>
parents:
1430
diff
changeset
|
286 |
1687
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
287 _assoc_string(ti, FIELD_TITLE, in->title); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
288 _assoc_string(ti, FIELD_ARTIST, in->author); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
289 _assoc_string(ti, FIELD_ALBUM, in->album); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
290 _assoc_string(ti, FIELD_COMMENT, in->comment); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
291 _assoc_string(ti, FIELD_GENRE, in->genre); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
292 _assoc_int(ti, FIELD_YEAR, in->year); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
293 _assoc_int(ti, FIELD_TRACK_NUMBER, in->track); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
294 _assoc_int(ti, FIELD_LENGTH, in->duration / 1000); |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
295 |
2055 | 296 ret = aud_tuple_formatter_make_title_string(ti, aud_get_gentitle_format()); |
895
5d7e6f06c9b7
[svn] - now wma can handle wide characters in metadata.
yaz
parents:
878
diff
changeset
|
297 |
878 | 298 return ret; |
299 } | |
300 | |
301 static guint get_song_time(AVFormatContext *in) | |
302 { | |
303 if(in->duration) | |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
304 return in->duration/1000; |
878 | 305 else |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
306 return 0; |
878 | 307 } |
308 | |
309 static void wma_get_song_info(char *filename, char **title_real, int *len_real) | |
310 { | |
1438
dc3e28d3b92a
mpc: convert, wma: fixes
William Pitcock <nenolod@atheme-project.org>
parents:
1430
diff
changeset
|
311 Tuple *tuple = wma_get_song_tuple(filename); |
878 | 312 |
313 if (tuple == NULL) | |
314 return; | |
315 | |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1954
diff
changeset
|
316 (*len_real) = aud_tuple_get_int(tuple, FIELD_LENGTH, NULL); |
2055 | 317 (*title_real) = aud_tuple_formatter_make_title_string(tuple, aud_get_gentitle_format()); |
878 | 318 } |
319 | |
320 static void wma_playbuff(InputPlayback *playback, int out_size) | |
321 { | |
322 FifoBuffer f; | |
323 int sst_buff; | |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
324 |
878 | 325 fifo_init(&f, out_size*2); |
326 fifo_write(&f, wma_outbuf, out_size, &f.wptr); | |
327 while(!fifo_read(&f, wma_s_outbuf, wma_st_buff, &f.rptr) && wma_decode) | |
328 { | |
329 sst_buff = wma_st_buff; | |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
330 if(wma_pause) memset(wma_s_outbuf, 0, sst_buff); |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
331 playback->pass_audio(playback, FMT_S16_NE, |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
332 c->channels, sst_buff, (short *)wma_s_outbuf, NULL); |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
333 memset(wma_s_outbuf, 0, sst_buff); |
878 | 334 } |
335 fifo_free(&f); | |
336 return; | |
337 } | |
338 | |
339 static void *wma_play_loop(void *arg) | |
340 { | |
341 InputPlayback *playback = arg; | |
342 uint8_t *inbuf_ptr; | |
343 int out_size, size, len; | |
344 AVPacket pkt; | |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
345 |
878 | 346 g_static_mutex_lock(&wma_mutex); |
1390
095595555e7b
Fix WMA playback.
William Pitcock <nenolod@atheme-project.org>
parents:
1190
diff
changeset
|
347 while(playback->playing) |
095595555e7b
Fix WMA playback.
William Pitcock <nenolod@atheme-project.org>
parents:
1190
diff
changeset
|
348 { |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
349 if(wma_seekpos != -1) |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
350 { |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
351 av_seek_frame(ic, wma_idx, wma_seekpos * 1000000LL); |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
352 playback->output->flush(wma_seekpos * 1000); |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
353 wma_seekpos = -1; |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
354 } |
878 | 355 |
356 if(av_read_frame(ic, &pkt) < 0) break; | |
357 | |
358 size = pkt.size; | |
359 inbuf_ptr = pkt.data; | |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
360 |
878 | 361 if(size == 0) break; |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
362 |
878 | 363 while(size > 0){ |
364 len = avcodec_decode_audio(c, (short *)wma_outbuf, &out_size, | |
365 inbuf_ptr, size); | |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
366 if(len < 0) break; |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
367 |
878 | 368 if(out_size <= 0) continue; |
369 | |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
370 wma_playbuff(playback, out_size); |
878 | 371 |
372 size -= len; | |
373 inbuf_ptr += len; | |
374 if(pkt.data) av_free_packet(&pkt); | |
375 } | |
376 } | |
1676
aee4ebea943a
xmms_usleep() was removed, use g_usleep()
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
377 while(playback->playing && playback->output->buffer_playing()) g_usleep(30000); |
1168 | 378 playback->playing = 0; |
878 | 379 if(wma_s_outbuf) g_free(wma_s_outbuf); |
380 if(wma_outbuf) g_free(wma_outbuf); | |
381 if(pkt.data) av_free_packet(&pkt); | |
382 if(c) avcodec_close(c); | |
383 if(ic) av_close_input_file(ic); | |
384 g_static_mutex_unlock(&wma_mutex); | |
385 return(NULL); | |
386 } | |
387 | |
388 static void wma_play_file(InputPlayback *playback) | |
389 { | |
390 char *filename = playback->filename; | |
391 AVCodec *codec; | |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
392 |
1390
095595555e7b
Fix WMA playback.
William Pitcock <nenolod@atheme-project.org>
parents:
1190
diff
changeset
|
393 if(av_open_input_file(&ic, filename, NULL, 0, NULL) < 0) return; |
878 | 394 |
395 for(wma_idx = 0; wma_idx < ic->nb_streams; wma_idx++) { | |
396 c = &ic->streams[wma_idx]->codec; | |
397 if(c->codec_type == CODEC_TYPE_AUDIO) break; | |
398 } | |
399 | |
400 av_find_stream_info(ic); | |
401 | |
402 codec = avcodec_find_decoder(c->codec_id); | |
403 | |
404 if(!codec) return; | |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
405 |
878 | 406 if(avcodec_open(c, codec) < 0) return; |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
407 |
878 | 408 wsong_title = get_song_title(ic, filename); |
409 wsong_time = get_song_time(ic); | |
410 | |
411 if(playback->output->open_audio(FMT_S16_NE, c->sample_rate, c->channels) <= 0) return; | |
412 | |
413 wma_st_buff = ST_BUFF; | |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
414 |
1990 | 415 playback->set_params(playback, wsong_title, wsong_time, c->bit_rate, c->sample_rate, c->channels); |
878 | 416 |
417 /* av_malloc() will wrap posix_memalign() if necessary -nenolod */ | |
418 wma_s_outbuf = av_malloc(wma_st_buff); | |
419 wma_outbuf = av_malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE); | |
420 | |
421 wma_seekpos = -1; | |
422 wma_decode = 1; | |
1168 | 423 playback->playing = 1; |
1390
095595555e7b
Fix WMA playback.
William Pitcock <nenolod@atheme-project.org>
parents:
1190
diff
changeset
|
424 wma_decode_thread = g_thread_self(); |
1447
195b5657303e
updated input plugins to use set_pb_ready to signal to the core that they're ready for playback
Giacomo Lozito <james@develia.org>
parents:
1438
diff
changeset
|
425 playback->set_pb_ready(playback); |
1390
095595555e7b
Fix WMA playback.
William Pitcock <nenolod@atheme-project.org>
parents:
1190
diff
changeset
|
426 wma_play_loop(playback); |
878 | 427 } |
428 | |
429 static void wma_stop(InputPlayback *playback) | |
430 { | |
431 wma_decode = 0; | |
1168 | 432 playback->playing = 0; |
878 | 433 if(wma_pause) wma_do_pause(playback, 0); |
434 g_thread_join(wma_decode_thread); | |
435 playback->output->close_audio(); | |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
436 } |