annotate src/wma/wma.c @ 3053:a3734dd60d7a

Change the flow of codec probing to avoid the possibility of a null pointer dereference. From code analysis, unique IDs mPqomY & 8B8oHC.
author Tony Vroon <chainsaw@gentoo.org>
date Sat, 18 Apr 2009 21:28:56 +0100
parents 13a0e4377c20
children 03f247c0d31d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
878
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
1 /*
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
2 * Audacious WMA input plugin
1072
1c6a18ddc874 [svn] Port to plugin API v2.
chainsaw
parents: 895
diff changeset
3 * (C) 2005, 2006, 2007 Audacious development team
878
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
4 *
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
5 * Based on:
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
6 * xmms-wma - WMA player for BMP
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
7 * Copyright (C) 2004,2005 McMCC <mcmcc@mail.ru>
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
8 * bmp-wma - WMA player for BMP
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
9 * Copyright (C) 2004 Roman Bogorodskiy <bogorodskiy@inbox.ru>
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
10 *
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
11 * This program is free software; you can redistribute it and/or modify
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
12 * it under the terms of the GNU General Public License as published by
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
13 * the Free Software Foundation; either version 2 of the License, or
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
14 * (at your option) any later version.
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
15 *
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
16 * This program is distributed in the hope that it will be useful,
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
19 * GNU General Public License for more details.
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
20 *
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
21 * You should have received a copy of the GNU General Public License
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
22 * along with this program; if not, write to the Free Software
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
24 */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
25 #define _XOPEN_SOURCE 600
1784
add71276abfc wma: Mk2
William Pitcock <nenolod@atheme.org>
parents: 1697
diff changeset
26
add71276abfc wma: Mk2
William Pitcock <nenolod@atheme.org>
parents: 1697
diff changeset
27 #include "config.h"
add71276abfc wma: Mk2
William Pitcock <nenolod@atheme.org>
parents: 1697
diff changeset
28
878
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
29 #include <stdlib.h>
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
30 #include <unistd.h>
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
31 #include <math.h>
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
32 #include <stdbool.h>
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
33 #include <stdio.h>
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
34 #include <string.h>
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
35 #include <strings.h>
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
36 #include <glib.h>
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
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
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
41
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
42 #include "avcodec.h"
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
43 #include "avformat.h"
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
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
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
48
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
49 static int wma_decode = 0;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
50 static gboolean wma_pause = 0;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
51 static int wma_seekpos = -1;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
52 static GThread *wma_decode_thread;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
53
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
54 char description[64];
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
55 static void wma_about(void);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
56 static void wma_init(void);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
57 static int wma_is_our_fd(char *filename, VFSFile *fd);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
58 static void wma_play_file(InputPlayback *data);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
59 static void wma_stop(InputPlayback *data);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
60 static void wma_seek(InputPlayback *data, int time);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
61 static void wma_do_pause(InputPlayback *data, short p);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
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
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
64 static char *wsong_title;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
65 static int wsong_time;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
66
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
67 static GtkWidget *dialog1, *button1, *label1;
1072
1c6a18ddc874 [svn] Port to plugin API v2.
chainsaw
parents: 895
diff changeset
68 static gchar *fmts[] = { "wma", NULL };
878
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
69
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
70 InputPlugin wma_ip =
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
71 {
1072
1c6a18ddc874 [svn] Port to plugin API v2.
chainsaw
parents: 895
diff changeset
72 .description = "Windows Media Audio (WMA) Plugin",
1c6a18ddc874 [svn] Port to plugin API v2.
chainsaw
parents: 895
diff changeset
73 .init = wma_init,
1c6a18ddc874 [svn] Port to plugin API v2.
chainsaw
parents: 895
diff changeset
74 .about = wma_about,
1c6a18ddc874 [svn] Port to plugin API v2.
chainsaw
parents: 895
diff changeset
75 .play_file = wma_play_file,
1c6a18ddc874 [svn] Port to plugin API v2.
chainsaw
parents: 895
diff changeset
76 .stop = wma_stop,
1c6a18ddc874 [svn] Port to plugin API v2.
chainsaw
parents: 895
diff changeset
77 .pause = wma_do_pause,
1c6a18ddc874 [svn] Port to plugin API v2.
chainsaw
parents: 895
diff changeset
78 .seek = wma_seek,
1c6a18ddc874 [svn] Port to plugin API v2.
chainsaw
parents: 895
diff changeset
79 .get_song_info = wma_get_song_info,
1c6a18ddc874 [svn] Port to plugin API v2.
chainsaw
parents: 895
diff changeset
80 .get_song_tuple = wma_get_song_tuple,
1c6a18ddc874 [svn] Port to plugin API v2.
chainsaw
parents: 895
diff changeset
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
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
83 };
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
84
1072
1c6a18ddc874 [svn] Port to plugin API v2.
chainsaw
parents: 895
diff changeset
85 InputPlugin *wma_iplist[] = { &wma_ip, NULL };
1c6a18ddc874 [svn] Port to plugin API v2.
chainsaw
parents: 895
diff changeset
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
1c6a18ddc874 [svn] Port to plugin API v2.
chainsaw
parents: 895
diff changeset
88
878
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
89 static gchar *str_twenty_to_space(gchar * str)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
90 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
91 gchar *match, *match_end;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
92
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
93 g_return_val_if_fail(str != NULL, NULL);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
94
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
95 while ((match = strstr(str, "%20"))) {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
96 match_end = match + 3;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
97 *match++ = ' ';
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
98 while (*match_end)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
99 *match++ = *match_end++;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
100 *match = 0;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
101 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
102
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
103 return str;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
104 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
105
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
106 static void wma_about(void)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
107 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
108 char *title;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
109 char *message;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
110
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
111 if (dialog1) return;
2092
e60ad26664d6 adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents: 2055
diff changeset
112
878
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
113 title = (char *)g_malloc(80);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
114 message = (char *)g_malloc(1000);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
115 memset(title, 0, 80);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
116 memset(message, 0, 1000);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
117
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
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
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
134
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
135 dialog1 = gtk_dialog_new();
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
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
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
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
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
141 label1 = gtk_label_new(message);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
142 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog1)->vbox), label1, TRUE, TRUE, 0);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
143 gtk_widget_show(label1);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
144
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
145 button1 = gtk_button_new_with_label(_(" Close "));
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
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
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
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
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
151
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
152 gtk_widget_show(button1);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
153 gtk_widget_show(dialog1);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
154 gtk_widget_grab_focus(button1);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
155 g_free(title);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
156 g_free(message);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
157 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
158
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
159 static void wma_init(void)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
160 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
161 avcodec_init();
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
162 avcodec_register_all();
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
163 av_register_all();
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
164 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
165
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
166 static int wma_is_our_fd(char *filename, VFSFile *fd)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
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
be645fc2980d Add wma_idx2.
William Pitcock <nenolod@atheme.org>
parents: 2438
diff changeset
171 int wma_idx2;
878
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
172
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
173 if(av_open_input_vfsfile(&ic2, filename, fd, NULL, 0, NULL) < 0) return 0;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
174
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
175 for(wma_idx2 = 0; wma_idx2 < ic2->nb_streams; wma_idx2++) {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
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
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
183 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
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
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
187 av_find_stream_info(ic2);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
188
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
189 codec2 = avcodec_find_decoder(c2->codec_id);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
190
1156
46476de8fc64 [svn] - avoid a memory leak with FD probing
nenolod
parents: 1075
diff changeset
191 if (!codec2) {
46476de8fc64 [svn] - avoid a memory leak with FD probing
nenolod
parents: 1075
diff changeset
192 av_close_input_vfsfile(ic2);
46476de8fc64 [svn] - avoid a memory leak with FD probing
nenolod
parents: 1075
diff changeset
193 return 0;
46476de8fc64 [svn] - avoid a memory leak with FD probing
nenolod
parents: 1075
diff changeset
194 }
46476de8fc64 [svn] - avoid a memory leak with FD probing
nenolod
parents: 1075
diff changeset
195
46476de8fc64 [svn] - avoid a memory leak with FD probing
nenolod
parents: 1075
diff changeset
196 av_close_input_vfsfile(ic2);
2436
7576404c8415 Severe refactoring phase 1.
William Pitcock <nenolod@atheme.org>
parents: 2092
diff changeset
197
878
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
198 return 1;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
199 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
200
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
201 static void wma_do_pause(InputPlayback *playback, short p)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
202 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
203 wma_pause = p;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
204 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
205
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
206 static void wma_seek(InputPlayback *playback, int time)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
207 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
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
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
210 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
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
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
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
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
227 AVFormatContext *in = NULL;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
228
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
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
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
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
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
235 av_find_stream_info(in);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
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
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
245
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
246 av_close_input_file(in);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
247
1430
bf7d4c236d9f Start using tuple_new_from_filename.
Tony Vroon <chainsaw@gentoo.org>
parents: 1425
diff changeset
248 return ti;
878
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
249 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
250
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
251 static gchar *get_song_title(AVFormatContext *in, gchar * filename)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
252 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
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
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
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
2f2ffbc2d04d gentitle changes
William Pitcock <nenolod@atheme.org>
parents: 1998
diff changeset
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
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
270 return ret;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
271 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
272
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
273 static guint get_song_time(AVFormatContext *in)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
274 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
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
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
277 else
2092
e60ad26664d6 adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents: 2055
diff changeset
278 return 0;
878
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
279 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
280
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
281 static void wma_get_song_info(char *filename, char **title_real, int *len_real)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
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
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
284
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
285 if (tuple == NULL)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
286 return;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
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
2f2ffbc2d04d gentitle changes
William Pitcock <nenolod@atheme.org>
parents: 1998
diff changeset
289 (*title_real) = aud_tuple_formatter_make_title_string(tuple, aud_get_gentitle_format());
878
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
290 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
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
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
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
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
313 uint8_t *inbuf_ptr;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
314 int out_size, size, len;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
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
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
360
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
361 if(av_read_frame(ic, &pkt) < 0) break;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
362
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
363 size = pkt.size;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
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
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
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
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
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
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
372 len = avcodec_decode_audio(c, (short *)wma_outbuf, &out_size,
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
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
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
376 if(out_size <= 0) continue;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
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 if (wma_pause)
6b07b92a0308 Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents: 2436
diff changeset
385 memset(wma_s_outbuf, 0, sst_buff);
6b07b92a0308 Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents: 2436
diff changeset
386 playback->pass_audio(playback, FMT_S16_NE,
6b07b92a0308 Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents: 2436
diff changeset
387 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
388 memset(wma_s_outbuf, 0, sst_buff);
6b07b92a0308 Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents: 2436
diff changeset
389 }
6b07b92a0308 Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents: 2436
diff changeset
390
6b07b92a0308 Drop wma_playbuff(). Not re-entrant.
William Pitcock <nenolod@atheme.org>
parents: 2436
diff changeset
391 fifo_free(&f);
878
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
392
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
393 size -= len;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
394 inbuf_ptr += len;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
395 if(pkt.data) av_free_packet(&pkt);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
396 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
397 }
1676
aee4ebea943a xmms_usleep() was removed, use g_usleep()
Matti Hamalainen <ccr@tnsp.org>
parents: 1510
diff changeset
398 while(playback->playing && playback->output->buffer_playing()) g_usleep(30000);
1168
940b7ded5756 [svn] - ditto. this is necessary too.
yaz
parents: 1164
diff changeset
399 playback->playing = 0;
878
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
400 if(wma_s_outbuf) g_free(wma_s_outbuf);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
401 if(wma_outbuf) g_free(wma_outbuf);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
402 if(pkt.data) av_free_packet(&pkt);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
403 if(c) avcodec_close(c);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
404 if(ic) av_close_input_file(ic);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
405 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
406
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
407 static void wma_stop(InputPlayback *playback)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
408 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
409 wma_decode = 0;
1168
940b7ded5756 [svn] - ditto. this is necessary too.
yaz
parents: 1164
diff changeset
410 playback->playing = 0;
878
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
411 if(wma_pause) wma_do_pause(playback, 0);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
412 g_thread_join(wma_decode_thread);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
413 playback->output->close_audio();
2092
e60ad26664d6 adapted WMA plugin for internationalization, fixed compiler warning
mf0102 <0102@gmx.at>
parents: 2055
diff changeset
414 }