Mercurial > audlegacy-plugins
annotate src/wma/wma.c @ 3110:a522493de76e
Set up a hook_call for showing the main menu, since it's implemented in a plugin now (fixes #38).
author | John Lindgren <john.lindgren@tds.net> |
---|---|
date | Sat, 02 May 2009 11:16:23 -0400 |
parents | 03f247c0d31d |
children |
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 | |
3056
03f247c0d31d
Fix stutter when resuming WMA audio playback.
John Lindgren <john.lindgren@tds.net>
parents:
3053
diff
changeset
|
106 static void wma_about(void) |
878 | 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 { | |
3053
a3734dd60d7a
Change the flow of codec probing to avoid the possibility of a null pointer dereference. From code analysis, unique IDs mPqomY & 8B8oHC.
Tony Vroon <chainsaw@gentoo.org>
parents:
3035
diff
changeset
|
168 AVCodec *codec2 = NULL; |
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; | |
3053
a3734dd60d7a
Change the flow of codec probing to avoid the possibility of a null pointer dereference. From code analysis, unique IDs mPqomY & 8B8oHC.
Tony Vroon <chainsaw@gentoo.org>
parents:
3035
diff
changeset
|
177 if(c2->codec_type == CODEC_TYPE_AUDIO) |
a3734dd60d7a
Change the flow of codec probing to avoid the possibility of a null pointer dereference. From code analysis, unique IDs mPqomY & 8B8oHC.
Tony Vroon <chainsaw@gentoo.org>
parents:
3035
diff
changeset
|
178 { |
a3734dd60d7a
Change the flow of codec probing to avoid the possibility of a null pointer dereference. From code analysis, unique IDs mPqomY & 8B8oHC.
Tony Vroon <chainsaw@gentoo.org>
parents:
3035
diff
changeset
|
179 av_find_stream_info(ic2); |
a3734dd60d7a
Change the flow of codec probing to avoid the possibility of a null pointer dereference. From code analysis, unique IDs mPqomY & 8B8oHC.
Tony Vroon <chainsaw@gentoo.org>
parents:
3035
diff
changeset
|
180 codec2 = avcodec_find_decoder(c2->codec_id); |
a3734dd60d7a
Change the flow of codec probing to avoid the possibility of a null pointer dereference. From code analysis, unique IDs mPqomY & 8B8oHC.
Tony Vroon <chainsaw@gentoo.org>
parents:
3035
diff
changeset
|
181 if (codec2) break; |
a3734dd60d7a
Change the flow of codec probing to avoid the possibility of a null pointer dereference. From code analysis, unique IDs mPqomY & 8B8oHC.
Tony Vroon <chainsaw@gentoo.org>
parents:
3035
diff
changeset
|
182 } |
878 | 183 } |
184 | |
3053
a3734dd60d7a
Change the flow of codec probing to avoid the possibility of a null pointer dereference. From code analysis, unique IDs mPqomY & 8B8oHC.
Tony Vroon <chainsaw@gentoo.org>
parents:
3035
diff
changeset
|
185 if (!codec2) return 0; |
a3734dd60d7a
Change the flow of codec probing to avoid the possibility of a null pointer dereference. From code analysis, unique IDs mPqomY & 8B8oHC.
Tony Vroon <chainsaw@gentoo.org>
parents:
3035
diff
changeset
|
186 |
878 | 187 av_find_stream_info(ic2); |
188 | |
189 codec2 = avcodec_find_decoder(c2->codec_id); | |
190 | |
1156 | 191 if (!codec2) { |
192 av_close_input_vfsfile(ic2); | |
193 return 0; | |
194 } | |
195 | |
196 av_close_input_vfsfile(ic2); | |
2436
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
197 |
878 | 198 return 1; |
199 } | |
200 | |
201 static void wma_do_pause(InputPlayback *playback, short p) | |
202 { | |
203 wma_pause = p; | |
204 } | |
205 | |
3056
03f247c0d31d
Fix stutter when resuming WMA audio playback.
John Lindgren <john.lindgren@tds.net>
parents:
3053
diff
changeset
|
206 static void wma_seek(InputPlayback *playback, int time) |
878 | 207 { |
208 wma_seekpos = time; | |
1676
aee4ebea943a
xmms_usleep() was removed, use g_usleep()
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
209 while(wma_decode && wma_seekpos!=-1) g_usleep(10000); |
878 | 210 } |
211 | |
1687
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
212 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
|
213 { |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
214 if (strlen(str) > 0) |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1954
diff
changeset
|
215 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
|
216 } |
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 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
|
219 { |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
220 if (val > 0) |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1954
diff
changeset
|
221 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
|
222 } |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
223 |
1425
a25c2cfcce83
New tuple API conversion for WMA, first try.
Tony Vroon <chainsaw@gentoo.org>
parents:
1395
diff
changeset
|
224 static Tuple *wma_get_song_tuple(gchar * filename) |
878 | 225 { |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1954
diff
changeset
|
226 Tuple *ti = aud_tuple_new_from_filename(filename); |
878 | 227 AVFormatContext *in = NULL; |
228 | |
229 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
|
230 return NULL; |
878 | 231 |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1954
diff
changeset
|
232 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
|
233 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
|
234 |
878 | 235 av_find_stream_info(in); |
236 | |
1687
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
237 _assoc_string(ti, FIELD_TITLE, in->title); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
238 _assoc_string(ti, FIELD_ARTIST, in->author); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
239 _assoc_string(ti, FIELD_ALBUM, in->album); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
240 _assoc_string(ti, FIELD_COMMENT, in->comment); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
241 _assoc_string(ti, FIELD_GENRE, in->genre); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
242 _assoc_int(ti, FIELD_YEAR, in->year); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
243 _assoc_int(ti, FIELD_TRACK_NUMBER, in->track); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
244 _assoc_int(ti, FIELD_LENGTH, in->duration / 1000); |
878 | 245 |
246 av_close_input_file(in); | |
247 | |
1430
bf7d4c236d9f
Start using tuple_new_from_filename.
Tony Vroon <chainsaw@gentoo.org>
parents:
1425
diff
changeset
|
248 return ti; |
878 | 249 } |
250 | |
251 static gchar *get_song_title(AVFormatContext *in, gchar * filename) | |
252 { | |
253 gchar *ret = NULL; | |
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 |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1954
diff
changeset
|
256 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
|
257 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
|
258 |
1687
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
259 _assoc_string(ti, FIELD_TITLE, in->title); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
260 _assoc_string(ti, FIELD_ARTIST, in->author); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
261 _assoc_string(ti, FIELD_ALBUM, in->album); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
262 _assoc_string(ti, FIELD_COMMENT, in->comment); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
263 _assoc_string(ti, FIELD_GENRE, in->genre); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
264 _assoc_int(ti, FIELD_YEAR, in->year); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
265 _assoc_int(ti, FIELD_TRACK_NUMBER, in->track); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
266 _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
|
267 |
2055 | 268 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
|
269 |
878 | 270 return ret; |
271 } | |
272 | |
273 static guint get_song_time(AVFormatContext *in) | |
274 { | |
275 if(in->duration) | |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
276 return in->duration/1000; |
878 | 277 else |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
278 return 0; |
878 | 279 } |
280 | |
281 static void wma_get_song_info(char *filename, char **title_real, int *len_real) | |
282 { | |
1438
dc3e28d3b92a
mpc: convert, wma: fixes
William Pitcock <nenolod@atheme-project.org>
parents:
1430
diff
changeset
|
283 Tuple *tuple = wma_get_song_tuple(filename); |
878 | 284 |
285 if (tuple == NULL) | |
286 return; | |
287 | |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1954
diff
changeset
|
288 (*len_real) = aud_tuple_get_int(tuple, FIELD_LENGTH, NULL); |
2055 | 289 (*title_real) = aud_tuple_formatter_make_title_string(tuple, aud_get_gentitle_format()); |
878 | 290 } |
291 | |
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
|
292 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
|
293 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
|
294 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
|
295 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
|
296 } |
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 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
|
299 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
|
300 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
|
301 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
|
302 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
|
303 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
|
304 } |
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
|
305 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
|
306 } |
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
|
307 |
2436
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
308 static void wma_play_file(InputPlayback *playback) |
878 | 309 { |
3053
a3734dd60d7a
Change the flow of codec probing to avoid the possibility of a null pointer dereference. From code analysis, unique IDs mPqomY & 8B8oHC.
Tony Vroon <chainsaw@gentoo.org>
parents:
3035
diff
changeset
|
310 AVCodec *codec = NULL; |
2436
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
311 AVCodecContext *c = NULL; |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
312 AVFormatContext *ic = NULL; |
878 | 313 uint8_t *inbuf_ptr; |
314 int out_size, size, len; | |
315 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
|
316 guint8 *wma_outbuf, *wma_s_outbuf; |
2440
5e87f7cc8d13
Remove unneeded vars.
William Pitcock <nenolod@atheme.org>
parents:
2439
diff
changeset
|
317 int wma_st_buff, wma_idx; |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
318 |
2436
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
319 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
|
320 |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
321 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
|
322 c = &ic->streams[wma_idx]->codec; |
3053
a3734dd60d7a
Change the flow of codec probing to avoid the possibility of a null pointer dereference. From code analysis, unique IDs mPqomY & 8B8oHC.
Tony Vroon <chainsaw@gentoo.org>
parents:
3035
diff
changeset
|
323 if(c->codec_type == CODEC_TYPE_AUDIO) |
a3734dd60d7a
Change the flow of codec probing to avoid the possibility of a null pointer dereference. From code analysis, unique IDs mPqomY & 8B8oHC.
Tony Vroon <chainsaw@gentoo.org>
parents:
3035
diff
changeset
|
324 { |
a3734dd60d7a
Change the flow of codec probing to avoid the possibility of a null pointer dereference. From code analysis, unique IDs mPqomY & 8B8oHC.
Tony Vroon <chainsaw@gentoo.org>
parents:
3035
diff
changeset
|
325 av_find_stream_info(ic); |
a3734dd60d7a
Change the flow of codec probing to avoid the possibility of a null pointer dereference. From code analysis, unique IDs mPqomY & 8B8oHC.
Tony Vroon <chainsaw@gentoo.org>
parents:
3035
diff
changeset
|
326 codec = avcodec_find_decoder(c->codec_id); |
a3734dd60d7a
Change the flow of codec probing to avoid the possibility of a null pointer dereference. From code analysis, unique IDs mPqomY & 8B8oHC.
Tony Vroon <chainsaw@gentoo.org>
parents:
3035
diff
changeset
|
327 if (codec) break; |
a3734dd60d7a
Change the flow of codec probing to avoid the possibility of a null pointer dereference. From code analysis, unique IDs mPqomY & 8B8oHC.
Tony Vroon <chainsaw@gentoo.org>
parents:
3035
diff
changeset
|
328 } |
2436
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 |
3053
a3734dd60d7a
Change the flow of codec probing to avoid the possibility of a null pointer dereference. From code analysis, unique IDs mPqomY & 8B8oHC.
Tony Vroon <chainsaw@gentoo.org>
parents:
3035
diff
changeset
|
331 if (!codec) return; |
2436
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
332 |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
333 if(avcodec_open(c, codec) < 0) return; |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
334 |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
335 wsong_title = get_song_title(ic, playback->filename); |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
336 wsong_time = get_song_time(ic); |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
337 |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
338 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
|
339 |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
340 wma_st_buff = ST_BUFF; |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
341 |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
342 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
|
343 |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
344 /* av_malloc() will wrap posix_memalign() if necessary -nenolod */ |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
345 wma_s_outbuf = av_malloc(wma_st_buff); |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
346 wma_outbuf = av_malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE); |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
347 |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
348 wma_seekpos = -1; |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
349 wma_decode = 1; |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
350 playback->playing = 1; |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
351 wma_decode_thread = g_thread_self(); |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
352 playback->set_pb_ready(playback); |
7576404c8415
Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents:
2092
diff
changeset
|
353 |
1390
095595555e7b
Fix WMA playback.
William Pitcock <nenolod@atheme-project.org>
parents:
1190
diff
changeset
|
354 while(playback->playing) |
095595555e7b
Fix WMA playback.
William Pitcock <nenolod@atheme-project.org>
parents:
1190
diff
changeset
|
355 { |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
356 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
|
357 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
|
358 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
|
359 do_pause (playback, ic, wma_idx); |
878 | 360 |
361 if(av_read_frame(ic, &pkt) < 0) break; | |
362 | |
363 size = pkt.size; | |
364 inbuf_ptr = pkt.data; | |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
365 |
878 | 366 if(size == 0) break; |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
367 |
878 | 368 while(size > 0){ |
2437
6b07b92a0308
Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents:
2436
diff
changeset
|
369 FifoBuffer f; |
6b07b92a0308
Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents:
2436
diff
changeset
|
370 int sst_buff; |
6b07b92a0308
Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents:
2436
diff
changeset
|
371 |
878 | 372 len = avcodec_decode_audio(c, (short *)wma_outbuf, &out_size, |
373 inbuf_ptr, size); | |
2092
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
374 if(len < 0) break; |
e60ad26664d6
adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents:
2055
diff
changeset
|
375 |
878 | 376 if(out_size <= 0) continue; |
377 | |
2437
6b07b92a0308
Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents:
2436
diff
changeset
|
378 fifo_init(&f, out_size*2); |
6b07b92a0308
Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents:
2436
diff
changeset
|
379 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
|
380 |
6b07b92a0308
Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents:
2436
diff
changeset
|
381 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
|
382 { |
6b07b92a0308
Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents:
2436
diff
changeset
|
383 sst_buff = wma_st_buff; |
6b07b92a0308
Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents:
2436
diff
changeset
|
384 playback->pass_audio(playback, FMT_S16_NE, |
6b07b92a0308
Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents:
2436
diff
changeset
|
385 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
|
386 memset(wma_s_outbuf, 0, sst_buff); |
6b07b92a0308
Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents:
2436
diff
changeset
|
387 } |
6b07b92a0308
Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents:
2436
diff
changeset
|
388 |
6b07b92a0308
Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents:
2436
diff
changeset
|
389 fifo_free(&f); |
878 | 390 |
391 size -= len; | |
392 inbuf_ptr += len; | |
393 if(pkt.data) av_free_packet(&pkt); | |
394 } | |
395 } | |
1676
aee4ebea943a
xmms_usleep() was removed, use g_usleep()
Matti Hamalainen <ccr@tnsp.org>
parents:
1510
diff
changeset
|
396 while(playback->playing && playback->output->buffer_playing()) g_usleep(30000); |
1168 | 397 playback->playing = 0; |
878 | 398 if(wma_s_outbuf) g_free(wma_s_outbuf); |
399 if(wma_outbuf) g_free(wma_outbuf); | |
400 if(pkt.data) av_free_packet(&pkt); | |
401 if(c) avcodec_close(c); | |
402 if(ic) av_close_input_file(ic); | |
403 } | |
404 | |
3056
03f247c0d31d
Fix stutter when resuming WMA audio playback.
John Lindgren <john.lindgren@tds.net>
parents:
3053
diff
changeset
|
405 static void wma_stop(InputPlayback *playback) |
878 | 406 { |
407 wma_decode = 0; | |
1168 | 408 playback->playing = 0; |
878 | 409 if(wma_pause) wma_do_pause(playback, 0); |
410 g_thread_join(wma_decode_thread); | |
411 playback->output->close_audio(); | |
3056
03f247c0d31d
Fix stutter when resuming WMA audio playback.
John Lindgren <john.lindgren@tds.net>
parents:
3053
diff
changeset
|
412 } |