annotate src/wma/wma.c @ 1658:5538324eb069

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