Mercurial > audlegacy-plugins
annotate src/wma/wma.c @ 2568:92f6d0503c04
- Print the EOF status in _feof()
author | Ralf Ertzinger <ralf@skytale.net> |
---|---|
date | Fri, 16 May 2008 14:43:59 +0200 |
parents | 42a5c9d5830b |
children | bd3a24b39058 |
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> |
878 | 43 |
44 #include "avcodec.h" | |
45 #include "avformat.h" | |
46 | |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
47 static const gchar * PLUGIN_NAME = "Audacious-WMA"; |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
48 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
|
49 static const int ST_BUFF = 1024; |
878 | 50 |
51 static int wma_decode = 0; | |
52 static gboolean wma_pause = 0; | |
53 static int wma_seekpos = -1; | |
54 static GThread *wma_decode_thread; | |
55 | |
56 char description[64]; | |
57 static void wma_about(void); | |
58 static void wma_init(void); | |
59 static int wma_is_our_fd(char *filename, VFSFile *fd); | |
60 static void wma_play_file(InputPlayback *data); | |
61 static void wma_stop(InputPlayback *data); | |
62 static void wma_seek(InputPlayback *data, int time); | |
63 static void wma_do_pause(InputPlayback *data, short p); | |
64 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
|
65 static Tuple *wma_get_song_tuple(char *filename); |
878 | 66 static char *wsong_title; |
67 static int wsong_time; | |
68 | |
69 static GtkWidget *dialog1, *button1, *label1; | |
1072 | 70 static gchar *fmts[] = { "wma", NULL }; |
878 | 71 |
72 InputPlugin wma_ip = | |
73 { | |
1072 | 74 .description = "Windows Media Audio (WMA) Plugin", |
75 .init = wma_init, | |
76 .about = wma_about, | |
77 .play_file = wma_play_file, | |
78 .stop = wma_stop, | |
79 .pause = wma_do_pause, | |
80 .seek = wma_seek, | |
81 .get_song_info = wma_get_song_info, | |
82 .get_song_tuple = wma_get_song_tuple, | |
83 .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
|
84 .vfs_extensions = fmts, |
878 | 85 }; |
86 | |
1072 | 87 InputPlugin *wma_iplist[] = { &wma_ip, NULL }; |
88 | |
1395
761e17b23e0c
added Discovery plugin type
Cristi Magherusan <majeru@atheme-project.org>
parents:
1390
diff
changeset
|
89 DECLARE_PLUGIN(wma, NULL, NULL, wma_iplist, NULL, NULL, NULL, NULL, NULL); |
1072 | 90 |
878 | 91 static gchar *str_twenty_to_space(gchar * str) |
92 { | |
93 gchar *match, *match_end; | |
94 | |
95 g_return_val_if_fail(str != NULL, NULL); | |
96 | |
97 while ((match = strstr(str, "%20"))) { | |
98 match_end = match + 3; | |
99 *match++ = ' '; | |
100 while (*match_end) | |
101 *match++ = *match_end++; | |
102 *match = 0; | |
103 } | |
104 | |
105 return str; | |
106 } | |
107 | |
108 static void wma_about(void) | |
109 { | |
110 char *title; | |
111 char *message; | |
112 | |
113 if (dialog1) return; | |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
114 |
878 | 115 title = (char *)g_malloc(80); |
116 message = (char *)g_malloc(1000); | |
117 memset(title, 0, 80); | |
118 memset(message, 0, 1000); | |
119 | |
120 sprintf(title, _("About %s"), PLUGIN_NAME); | |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
121 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
|
122 _("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
|
123 "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
|
124 "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
|
125 "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
|
126 "http://ffmpeg.sourceforge.net.\n\n" |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
127 "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
|
128 "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
|
129 "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
|
130 "(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
|
131 "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
|
132 "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
|
133 "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
|
134 "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
|
135 )); |
878 | 136 |
137 dialog1 = gtk_dialog_new(); | |
138 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
|
139 G_CALLBACK(gtk_widget_destroyed), &dialog1); |
878 | 140 gtk_window_set_title(GTK_WINDOW(dialog1), title); |
141 gtk_window_set_policy(GTK_WINDOW(dialog1), FALSE, FALSE, FALSE); | |
142 gtk_container_border_width(GTK_CONTAINER(dialog1), 5); | |
143 label1 = gtk_label_new(message); | |
144 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog1)->vbox), label1, TRUE, TRUE, 0); | |
145 gtk_widget_show(label1); | |
146 | |
147 button1 = gtk_button_new_with_label(_(" Close ")); | |
148 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
|
149 G_CALLBACK(gtk_widget_destroy), |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
150 GTK_OBJECT(dialog1)); |
878 | 151 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
|
152 FALSE, FALSE, 0); |
878 | 153 |
154 gtk_widget_show(button1); | |
155 gtk_widget_show(dialog1); | |
156 gtk_widget_grab_focus(button1); | |
157 g_free(title); | |
158 g_free(message); | |
159 } | |
160 | |
161 static void wma_init(void) | |
162 { | |
163 avcodec_init(); | |
164 avcodec_register_all(); | |
165 av_register_all(); | |
166 } | |
167 | |
168 static int wma_is_our_fd(char *filename, VFSFile *fd) | |
169 { | |
170 AVCodec *codec2; | |
2436
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
171 AVCodecContext *c2 = NULL; |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
172 AVFormatContext *ic2 = NULL; |
2439 | 173 int wma_idx2; |
878 | 174 |
175 if(av_open_input_vfsfile(&ic2, filename, fd, NULL, 0, NULL) < 0) return 0; | |
176 | |
177 for(wma_idx2 = 0; wma_idx2 < ic2->nb_streams; wma_idx2++) { | |
178 c2 = &ic2->streams[wma_idx2]->codec; | |
179 if(c2->codec_type == CODEC_TYPE_AUDIO) break; | |
180 } | |
181 | |
182 av_find_stream_info(ic2); | |
183 | |
184 codec2 = avcodec_find_decoder(c2->codec_id); | |
185 | |
1156 | 186 if (!codec2) { |
187 av_close_input_vfsfile(ic2); | |
188 return 0; | |
189 } | |
190 | |
191 av_close_input_vfsfile(ic2); | |
2436
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
192 |
878 | 193 return 1; |
194 } | |
195 | |
196 static void wma_do_pause(InputPlayback *playback, short p) | |
197 { | |
198 wma_pause = p; | |
199 playback->output->pause(wma_pause); | |
200 } | |
201 | |
202 static void wma_seek(InputPlayback *playback, int time) | |
203 { | |
204 wma_seekpos = time; | |
205 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
|
206 while(wma_decode && wma_seekpos!=-1) g_usleep(10000); |
878 | 207 if(wma_pause) playback->output->pause(1); |
208 } | |
209 | |
1687
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
210 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
|
211 { |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
212 if (strlen(str) > 0) |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1954
diff
changeset
|
213 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
|
214 } |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
215 |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
216 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
|
217 { |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
218 if (val > 0) |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1954
diff
changeset
|
219 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
|
220 } |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
221 |
1425
a25c2cfcce83
New tuple API conversion for WMA, first try.
Tony Vroon <chainsaw@gentoo.org>
parents:
1395
diff
changeset
|
222 static Tuple *wma_get_song_tuple(gchar * filename) |
878 | 223 { |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1954
diff
changeset
|
224 Tuple *ti = aud_tuple_new_from_filename(filename); |
878 | 225 AVFormatContext *in = NULL; |
226 | |
227 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
|
228 return NULL; |
878 | 229 |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1954
diff
changeset
|
230 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
|
231 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
|
232 |
878 | 233 av_find_stream_info(in); |
234 | |
1687
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
235 _assoc_string(ti, FIELD_TITLE, in->title); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
236 _assoc_string(ti, FIELD_ARTIST, in->author); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
237 _assoc_string(ti, FIELD_ALBUM, in->album); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
238 _assoc_string(ti, FIELD_COMMENT, in->comment); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
239 _assoc_string(ti, FIELD_GENRE, in->genre); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
240 _assoc_int(ti, FIELD_YEAR, in->year); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
241 _assoc_int(ti, FIELD_TRACK_NUMBER, in->track); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
242 _assoc_int(ti, FIELD_LENGTH, in->duration / 1000); |
878 | 243 |
244 av_close_input_file(in); | |
245 | |
1430
bf7d4c236d9f
Start using tuple_new_from_filename.
Tony Vroon <chainsaw@gentoo.org>
parents:
1425
diff
changeset
|
246 return ti; |
878 | 247 } |
248 | |
249 static gchar *get_song_title(AVFormatContext *in, gchar * filename) | |
250 { | |
251 gchar *ret = NULL; | |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1954
diff
changeset
|
252 Tuple *ti = aud_tuple_new_from_filename(filename); |
878 | 253 |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1954
diff
changeset
|
254 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
|
255 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
|
256 |
1687
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
257 _assoc_string(ti, FIELD_TITLE, in->title); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
258 _assoc_string(ti, FIELD_ARTIST, in->author); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
259 _assoc_string(ti, FIELD_ALBUM, in->album); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
260 _assoc_string(ti, FIELD_COMMENT, in->comment); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
261 _assoc_string(ti, FIELD_GENRE, in->genre); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
262 _assoc_int(ti, FIELD_YEAR, in->year); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
263 _assoc_int(ti, FIELD_TRACK_NUMBER, in->track); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
264 _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
|
265 |
2055 | 266 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
|
267 |
878 | 268 return ret; |
269 } | |
270 | |
271 static guint get_song_time(AVFormatContext *in) | |
272 { | |
273 if(in->duration) | |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
274 return in->duration/1000; |
878 | 275 else |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
276 return 0; |
878 | 277 } |
278 | |
279 static void wma_get_song_info(char *filename, char **title_real, int *len_real) | |
280 { | |
1438
dc3e28d3b92a
mpc: convert, wma: fixes
William Pitcock <nenolod@atheme-project.org>
parents:
1430
diff
changeset
|
281 Tuple *tuple = wma_get_song_tuple(filename); |
878 | 282 |
283 if (tuple == NULL) | |
284 return; | |
285 | |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1954
diff
changeset
|
286 (*len_real) = aud_tuple_get_int(tuple, FIELD_LENGTH, NULL); |
2055 | 287 (*title_real) = aud_tuple_formatter_make_title_string(tuple, aud_get_gentitle_format()); |
878 | 288 } |
289 | |
2436
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
290 static void wma_play_file(InputPlayback *playback) |
878 | 291 { |
2436
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
292 AVCodec *codec; |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
293 AVCodecContext *c = NULL; |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
294 AVFormatContext *ic = NULL; |
878 | 295 uint8_t *inbuf_ptr; |
296 int out_size, size, len; | |
297 AVPacket pkt; | |
2438
038e90348306
Remove static values, making the plugin re-entrant. As such, remove the now unnecessary playback mutex.
William Pitcock <nenolod@atheme.org>
parents:
2437
diff
changeset
|
298 guint8 *wma_outbuf, *wma_s_outbuf; |
2440
5e87f7cc8d13
Remove unneeded vars.
William Pitcock <nenolod@atheme.org>
parents:
2439
diff
changeset
|
299 int wma_st_buff, wma_idx; |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
300 |
2436
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
301 if(av_open_input_file(&ic, playback->filename, NULL, 0, NULL) < 0) return; |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
302 |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
303 for(wma_idx = 0; wma_idx < ic->nb_streams; wma_idx++) { |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
304 c = &ic->streams[wma_idx]->codec; |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
305 if(c->codec_type == CODEC_TYPE_AUDIO) break; |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
306 } |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
307 |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
308 av_find_stream_info(ic); |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
309 |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
310 codec = avcodec_find_decoder(c->codec_id); |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
311 |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
312 if(!codec) return; |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
313 |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
314 if(avcodec_open(c, codec) < 0) return; |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
315 |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
316 wsong_title = get_song_title(ic, playback->filename); |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
317 wsong_time = get_song_time(ic); |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
318 |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
319 if(playback->output->open_audio(FMT_S16_NE, c->sample_rate, c->channels) <= 0) return; |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
320 |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
321 wma_st_buff = ST_BUFF; |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
322 |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
323 playback->set_params(playback, wsong_title, wsong_time, c->bit_rate, c->sample_rate, c->channels); |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
324 |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
325 /* av_malloc() will wrap posix_memalign() if necessary -nenolod */ |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
326 wma_s_outbuf = av_malloc(wma_st_buff); |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
327 wma_outbuf = av_malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE); |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
328 |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
329 wma_seekpos = -1; |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
330 wma_decode = 1; |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
331 playback->playing = 1; |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
332 wma_decode_thread = g_thread_self(); |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
333 playback->set_pb_ready(playback); |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
334 |
1390
095595555e7b
Fix WMA playback.
William Pitcock <nenolod@atheme-project.org>
parents:
1190
diff
changeset
|
335 while(playback->playing) |
095595555e7b
Fix WMA playback.
William Pitcock <nenolod@atheme-project.org>
parents:
1190
diff
changeset
|
336 { |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
337 if(wma_seekpos != -1) |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
338 { |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
339 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
|
340 playback->output->flush(wma_seekpos * 1000); |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
341 wma_seekpos = -1; |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
342 } |
878 | 343 |
344 if(av_read_frame(ic, &pkt) < 0) break; | |
345 | |
346 size = pkt.size; | |
347 inbuf_ptr = pkt.data; | |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
348 |
878 | 349 if(size == 0) break; |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
350 |
878 | 351 while(size > 0){ |
2437
6b07b92a0308
Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents:
2436
diff
changeset
|
352 FifoBuffer f; |
6b07b92a0308
Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents:
2436
diff
changeset
|
353 int sst_buff; |
6b07b92a0308
Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents:
2436
diff
changeset
|
354 |
878 | 355 len = avcodec_decode_audio(c, (short *)wma_outbuf, &out_size, |
356 inbuf_ptr, size); | |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
357 if(len < 0) break; |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
358 |
878 | 359 if(out_size <= 0) continue; |
360 | |
2437
6b07b92a0308
Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents:
2436
diff
changeset
|
361 fifo_init(&f, out_size*2); |
6b07b92a0308
Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents:
2436
diff
changeset
|
362 fifo_write(&f, wma_outbuf, out_size, &f.wptr); |
6b07b92a0308
Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents:
2436
diff
changeset
|
363 |
6b07b92a0308
Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents:
2436
diff
changeset
|
364 while(!fifo_read(&f, wma_s_outbuf, wma_st_buff, &f.rptr) && wma_decode) |
6b07b92a0308
Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents:
2436
diff
changeset
|
365 { |
6b07b92a0308
Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents:
2436
diff
changeset
|
366 sst_buff = wma_st_buff; |
6b07b92a0308
Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents:
2436
diff
changeset
|
367 if (wma_pause) |
6b07b92a0308
Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents:
2436
diff
changeset
|
368 memset(wma_s_outbuf, 0, sst_buff); |
6b07b92a0308
Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents:
2436
diff
changeset
|
369 playback->pass_audio(playback, FMT_S16_NE, |
6b07b92a0308
Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents:
2436
diff
changeset
|
370 c->channels, sst_buff, (short *)wma_s_outbuf, NULL); |
6b07b92a0308
Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents:
2436
diff
changeset
|
371 memset(wma_s_outbuf, 0, sst_buff); |
6b07b92a0308
Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents:
2436
diff
changeset
|
372 } |
6b07b92a0308
Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents:
2436
diff
changeset
|
373 |
6b07b92a0308
Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents:
2436
diff
changeset
|
374 fifo_free(&f); |
878 | 375 |
376 size -= len; | |
377 inbuf_ptr += len; | |
378 if(pkt.data) av_free_packet(&pkt); | |
379 } | |
380 } | |
1676
aee4ebea943a
xmms_usleep() was removed, use g_usleep()
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
381 while(playback->playing && playback->output->buffer_playing()) g_usleep(30000); |
1168 | 382 playback->playing = 0; |
878 | 383 if(wma_s_outbuf) g_free(wma_s_outbuf); |
384 if(wma_outbuf) g_free(wma_outbuf); | |
385 if(pkt.data) av_free_packet(&pkt); | |
386 if(c) avcodec_close(c); | |
387 if(ic) av_close_input_file(ic); | |
388 } | |
389 | |
390 static void wma_stop(InputPlayback *playback) | |
391 { | |
392 wma_decode = 0; | |
1168 | 393 playback->playing = 0; |
878 | 394 if(wma_pause) wma_do_pause(playback, 0); |
395 g_thread_join(wma_decode_thread); | |
396 playback->output->close_audio(); | |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
397 } |