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