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