annotate src/ffmpeg/ffmpeg.c @ 838:8561bcf928a3 trunk

[svn] - fix crash
author nenolod
date Mon, 12 Mar 2007 17:14:31 -0700
parents 7efd0747b362
children 9b50e71f7307
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1 /*
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
2 * Audacious WMA input plugin
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
3 * (C) 2005 Audacious development team
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
4 *
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
5 * Based on:
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
6 * xmms-wma - WMA player for BMP
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
7 * Copyright (C) 2004,2005 McMCC <mcmcc@mail.ru>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
8 * bmp-wma - WMA player for BMP
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
9 * Copyright (C) 2004 Roman Bogorodskiy <bogorodskiy@inbox.ru>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
10 *
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
11 * This program is free software; you can redistribute it and/or modify
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
12 * it under the terms of the GNU General Public License as published by
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
13 * the Free Software Foundation; either version 2 of the License, or
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
14 * (at your option) any later version.
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
15 *
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
16 * This program is distributed in the hope that it will be useful,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
19 * GNU General Public License for more details.
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
20 *
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
21 * You should have received a copy of the GNU General Public License
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
22 * along with this program; if not, write to the Free Software
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
24 */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
25 #define _XOPEN_SOURCE 600
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
26 #include <stdlib.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
27 #include <unistd.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
28 #include <math.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
29 #include <stdbool.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
30 #include <stdio.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
31 #include <string.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
32 #include <strings.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
33 #include <glib.h>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
34
520
8f1785471613 [svn] - add missing inclusion of audacious/strings.h where necessary
giacomo
parents: 508
diff changeset
35 #include <audacious/plugin.h>
8f1785471613 [svn] - add missing inclusion of audacious/strings.h where necessary
giacomo
parents: 508
diff changeset
36 #include <audacious/output.h>
8f1785471613 [svn] - add missing inclusion of audacious/strings.h where necessary
giacomo
parents: 508
diff changeset
37 #include <audacious/util.h>
8f1785471613 [svn] - add missing inclusion of audacious/strings.h where necessary
giacomo
parents: 508
diff changeset
38 #include <audacious/titlestring.h>
8f1785471613 [svn] - add missing inclusion of audacious/strings.h where necessary
giacomo
parents: 508
diff changeset
39 #include <audacious/vfs.h>
8f1785471613 [svn] - add missing inclusion of audacious/strings.h where necessary
giacomo
parents: 508
diff changeset
40 #include <audacious/strings.h>
527
d124034ebea3 [svn] - glib/gi18n.h -> audacious/i18n.h for automatic dgettext support
nenolod
parents: 520
diff changeset
41 #include <audacious/i18n.h>
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
42
818
07107d476f32 [svn] - remove some more stuff
nenolod
parents: 814
diff changeset
43 #include "config.h"
07107d476f32 [svn] - remove some more stuff
nenolod
parents: 814
diff changeset
44
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
45 #include "avcodec.h"
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
46 #include "avformat.h"
818
07107d476f32 [svn] - remove some more stuff
nenolod
parents: 814
diff changeset
47 #include "avutil.h"
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
48
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
49 #define ABOUT_TXT "Adapted for use in audacious by Tony Vroon (chainsaw@gentoo.org) from\n \
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
50 the BEEP-WMA plugin which is Copyright (C) 2004,2005 Mokrushin I.V. aka McMCC (mcmcc@mail.ru)\n \
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
51 and the BMP-WMA plugin which is Copyright (C) 2004 Roman Bogorodskiy <bogorodskiy@inbox.ru>.\n \
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
52 This plugin based on source code " LIBAVCODEC_IDENT "\nby Fabrice Bellard from \
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
53 http://ffmpeg.sourceforge.net.\n\n \
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
54 This program is free software; you can redistribute it and/or modify \n \
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
55 it under the terms of the GNU General Public License as published by \n \
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
56 the Free Software Foundation; either version 2 of the License, or \n \
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
57 (at your option) any later version. \n\n \
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
58 This program is distributed in the hope that it will be useful, \n \
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
59 but WITHOUT ANY WARRANTY; without even the implied warranty of \n \
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
60 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. \n \
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
61 See the GNU General Public License for more details.\n"
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
62 #define PLUGIN_NAME "Audacious-WMA"
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
63 #define PLUGIN_VERSION "v.1.0.5"
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
64 #define ST_BUFF 1024
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
65
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
66 static int ffmpeg_decode = 0;
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
67 static gboolean ffmpeg_pause = 0;
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
68 static int ffmpeg_seekpos = -1;
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
69 static int ffmpeg_st_buff, ffmpeg_idx, ffmpeg_idx2;
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
70 static GThread *ffmpeg_decode_thread;
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
71 GStaticMutex ffmpeg_mutex = G_STATIC_MUTEX_INIT;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
72 static AVCodecContext *c = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
73 static AVFormatContext *ic = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
74 static AVCodecContext *c2 = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
75 static AVFormatContext *ic2 = NULL;
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
76 static uint8_t *ffmpeg_outbuf, *ffmpeg_s_outbuf;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
77
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
78 char description[64];
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
79 static void ffmpeg_about(void);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
80 static void ffmpeg_init(void);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
81 static int ffmpeg_is_our_file(char *filename);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
82 static int ffmpeg_is_our_fd(char *filename, VFSFile *fd);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
83 static void ffmpeg_play_file(InputPlayback *data);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
84 static void ffmpeg_stop(InputPlayback *data);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
85 static void ffmpeg_seek(InputPlayback *data, int time);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
86 static void ffmpeg_do_pause(InputPlayback *data, short p);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
87 static int ffmpeg_get_time(InputPlayback *data);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
88 static void ffmpeg_get_song_info(char *filename, char **title, int *length);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
89 static TitleInput *ffmpeg_get_song_tuple(char *filename);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
90 static char *wsong_title;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
91 static int wsong_time;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
92
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
93 static GtkWidget *dialog1, *button1, *label1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
94
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
95 InputPlugin *get_iplugin_info(void);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
96
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
97 gchar *ffmpeg_fmts[] = { "wma", NULL };
372
a157306caf03 [svn] - finalize the plugin-side of the extension-assist ABI
nenolod
parents: 368
diff changeset
98
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
99 InputPlugin ffmpeg_ip =
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
100 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
101 NULL, // Filled in by xmms
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
102 NULL, // Filled in by xmms
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
103 description, // The description that is shown in the preferences box
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
104 ffmpeg_init, // Called when the plugin is loaded
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
105 ffmpeg_about, // Show the about box
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
106 NULL, // Show the configure box
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
107 ffmpeg_is_our_file, // Return 1 if the plugin can handle the file
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
108 NULL, // Scan dir
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
109 ffmpeg_play_file, // Play file
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
110 ffmpeg_stop, // Stop
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
111 ffmpeg_do_pause, // Pause
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
112 ffmpeg_seek, // Seek
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
113 NULL, // Set the equalizer, most plugins won't be able to do this
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
114 ffmpeg_get_time, // Get the time, usually returns the output plugins output time
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
115 NULL, // Get volume
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
116 NULL, // Set volume
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
117 NULL, // OBSOLETE!
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
118 NULL, // OBSOLETE!
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
119 NULL, // Send data to the visualization plugins
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
120 NULL, // Fill in the stuff that is shown in the player window
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
121 NULL, // Show some text in the song title box. Filled in by xmms
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
122 ffmpeg_get_song_info, // Function to grab the title string
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
123 NULL, // Bring up an info window for the filename passed in
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
124 NULL, // Handle to the current output plugin. Filled in by xmms
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
125 ffmpeg_get_song_tuple, // Tuple builder
368
c812e846b84e [svn] - add support for extension probing to many plugins.
nenolod
parents: 65
diff changeset
126 NULL,
c812e846b84e [svn] - add support for extension probing to many plugins.
nenolod
parents: 65
diff changeset
127 NULL,
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
128 ffmpeg_is_our_fd, // vfs
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
129 ffmpeg_fmts
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
130 };
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
131
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
132 InputPlugin *get_iplugin_info(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
133 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
134 memset(description, 0, 64);
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
135 ffmpeg_ip.description = g_strdup_printf(_("WMA Player %s"), PACKAGE_VERSION);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
136 return &ffmpeg_ip;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
137 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
138
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
139 static gchar *str_twenty_to_space(gchar * str)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
140 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
141 gchar *match, *match_end;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
142
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
143 g_return_val_if_fail(str != NULL, NULL);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
144
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
145 while ((match = strstr(str, "%20"))) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
146 match_end = match + 3;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
147 *match++ = ' ';
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
148 while (*match_end)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
149 *match++ = *match_end++;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
150 *match = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
151 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
152
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
153 return str;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
154 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
155
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
156 static void ffmpeg_about(void)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
157 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
158 char *title;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
159 char *message;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
160
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
161 if (dialog1) return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
162
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
163 title = (char *)g_malloc(80);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
164 message = (char *)g_malloc(1000);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
165 memset(title, 0, 80);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
166 memset(message, 0, 1000);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
167
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
168 sprintf(title, _("About %s"), PLUGIN_NAME);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
169 sprintf(message, "%s %s\n\n%s", PLUGIN_NAME, PLUGIN_VERSION, ABOUT_TXT);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
170
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
171 dialog1 = gtk_dialog_new();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
172 g_signal_connect(G_OBJECT(dialog1), "destroy",
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
173 G_CALLBACK(gtk_widget_destroyed), &dialog1);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
174 gtk_window_set_title(GTK_WINDOW(dialog1), title);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
175 gtk_window_set_policy(GTK_WINDOW(dialog1), FALSE, FALSE, FALSE);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
176 gtk_container_border_width(GTK_CONTAINER(dialog1), 5);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
177 label1 = gtk_label_new(message);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
178 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog1)->vbox), label1, TRUE, TRUE, 0);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
179 gtk_widget_show(label1);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
180
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
181 button1 = gtk_button_new_with_label(_(" Close "));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
182 g_signal_connect_swapped(G_OBJECT(button1), "clicked",
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
183 G_CALLBACK(gtk_widget_destroy),
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
184 GTK_OBJECT(dialog1));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
185 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog1)->action_area), button1,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
186 FALSE, FALSE, 0);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
187
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
188 gtk_widget_show(button1);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
189 gtk_widget_show(dialog1);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
190 gtk_widget_grab_focus(button1);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
191 g_free(title);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
192 g_free(message);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
193 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
194
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
195 static void ffmpeg_init(void)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
196 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
197 avcodec_init();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
198 avcodec_register_all();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
199 av_register_all();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
200 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
201
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
202 static int ffmpeg_is_our_file(char *filename)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
203 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
204 AVCodec *codec2;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
205
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
206 if(av_open_input_file(&ic2, str_twenty_to_space(filename), NULL, 0, NULL) < 0) return 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
207
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
208 for(ffmpeg_idx2 = 0; ffmpeg_idx2 < ic2->nb_streams; ffmpeg_idx2++) {
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
209 c2 = ic2->streams[ffmpeg_idx2]->codec;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
210 if(c2->codec_type == CODEC_TYPE_AUDIO) break;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
211 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
212
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
213 av_find_stream_info(ic2);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
214
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
215 codec2 = avcodec_find_decoder(c2->codec_id);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
216
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
217 if(!codec2) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
218 av_close_input_file(ic2);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
219 return 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
220 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
221
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
222 av_close_input_file(ic2);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
223 return 1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
224 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
225
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
226 static int ffmpeg_is_our_fd(char *filename, VFSFile *fd)
508
1e5df88b631d [svn] - newvfs probing
nenolod
parents: 372
diff changeset
227 {
1e5df88b631d [svn] - newvfs probing
nenolod
parents: 372
diff changeset
228 AVCodec *codec2;
1e5df88b631d [svn] - newvfs probing
nenolod
parents: 372
diff changeset
229
1e5df88b631d [svn] - newvfs probing
nenolod
parents: 372
diff changeset
230 if(av_open_input_vfsfile(&ic2, filename, fd, NULL, 0, NULL) < 0) return 0;
1e5df88b631d [svn] - newvfs probing
nenolod
parents: 372
diff changeset
231
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
232 for(ffmpeg_idx2 = 0; ffmpeg_idx2 < ic2->nb_streams; ffmpeg_idx2++) {
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
233 c2 = ic2->streams[ffmpeg_idx2]->codec;
508
1e5df88b631d [svn] - newvfs probing
nenolod
parents: 372
diff changeset
234 if(c2->codec_type == CODEC_TYPE_AUDIO) break;
1e5df88b631d [svn] - newvfs probing
nenolod
parents: 372
diff changeset
235 }
1e5df88b631d [svn] - newvfs probing
nenolod
parents: 372
diff changeset
236
1e5df88b631d [svn] - newvfs probing
nenolod
parents: 372
diff changeset
237 av_find_stream_info(ic2);
1e5df88b631d [svn] - newvfs probing
nenolod
parents: 372
diff changeset
238
1e5df88b631d [svn] - newvfs probing
nenolod
parents: 372
diff changeset
239 codec2 = avcodec_find_decoder(c2->codec_id);
1e5df88b631d [svn] - newvfs probing
nenolod
parents: 372
diff changeset
240
838
8561bcf928a3 [svn] - fix crash
nenolod
parents: 836
diff changeset
241 if(!codec2)
8561bcf928a3 [svn] - fix crash
nenolod
parents: 836
diff changeset
242 return 0;
8561bcf928a3 [svn] - fix crash
nenolod
parents: 836
diff changeset
243
508
1e5df88b631d [svn] - newvfs probing
nenolod
parents: 372
diff changeset
244 return 1;
1e5df88b631d [svn] - newvfs probing
nenolod
parents: 372
diff changeset
245 }
1e5df88b631d [svn] - newvfs probing
nenolod
parents: 372
diff changeset
246
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
247 static void ffmpeg_do_pause(InputPlayback *playback, short p)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
248 {
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
249 ffmpeg_pause = p;
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
250 playback->output->pause(ffmpeg_pause);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
251 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
252
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
253 static void ffmpeg_seek(InputPlayback *playback, int time)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
254 {
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
255 ffmpeg_seekpos = time;
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
256 if(ffmpeg_pause) playback->output->pause(0);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
257 while(ffmpeg_decode && ffmpeg_seekpos!=-1) xmms_usleep(10000);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
258 if(ffmpeg_pause) playback->output->pause(1);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
259 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
260
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
261 static int ffmpeg_get_time(InputPlayback *playback)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
262 {
561
914c96de3244 [svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents: 559
diff changeset
263 playback->output->buffer_free();
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
264 if(ffmpeg_decode) return playback->output->output_time();
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
265 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
266 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
267
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
268 static gchar *extname(const char *filename)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
269 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
270 gchar *ext = strrchr(filename, '.');
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
271 if(ext != NULL) ++ext;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
272 return ext;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
273 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
274
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
275 static char* w_getstr(char* str)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
276 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
277 if(str && strlen(str) > 0) return g_strdup(str);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
278 return NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
279 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
280
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
281 static TitleInput *ffmpeg_get_song_tuple(gchar * filename)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
282 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
283 TitleInput *tuple = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
284 AVFormatContext *in = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
285 gchar *filename_proxy = g_strdup(filename);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
286
838
8561bcf928a3 [svn] - fix crash
nenolod
parents: 836
diff changeset
287 if(av_open_input_file(&in, str_twenty_to_space(filename), NULL, 0, NULL) < 0)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
288 return NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
289
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
290 tuple = bmp_title_input_new();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
291
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
292 tuple->file_name = g_path_get_basename(filename_proxy);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
293 tuple->file_path = g_path_get_dirname(filename_proxy);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
294 tuple->file_ext = extname(filename_proxy);
838
8561bcf928a3 [svn] - fix crash
nenolod
parents: 836
diff changeset
295
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
296 av_find_stream_info(in);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
297
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
298 if((in->title[0] != '\0') || (in->author[0] != '\0') || (in->album[0] != '\0') ||
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
299 (in->comment[0] != '\0') || (in->genre[0] != '\0') || (in->year != 0) || (in->track != 0))
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
300 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
301 tuple->performer = str_to_utf8(w_getstr(in->author));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
302 tuple->album_name = str_to_utf8(w_getstr(in->album));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
303 tuple->track_name = str_to_utf8(w_getstr(in->title));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
304 tuple->year = in->year;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
305 tuple->track_number = in->track;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
306 tuple->genre = str_to_utf8(w_getstr(in->genre));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
307 tuple->comment = str_to_utf8(w_getstr(in->comment));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
308 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
309
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
310 if (in->duration)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
311 tuple->length = in->duration / 1000;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
312
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
313 av_close_input_file(in);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
314
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
315 return tuple;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
316 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
317
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
318 static gchar *get_song_title(AVFormatContext *in, gchar * filename)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
319 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
320 gchar *ret = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
321 TitleInput *input;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
322
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
323 input = bmp_title_input_new();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
324
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
325 if((in->title[0] != '\0') || (in->author[0] != '\0') || (in->album[0] != '\0') ||
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
326 (in->comment[0] != '\0') || (in->genre[0] != '\0') || (in->year != 0) || (in->track != 0))
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
327 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
328 input->performer = w_getstr(in->author);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
329 input->album_name = w_getstr(in->album);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
330 input->track_name = w_getstr(in->title);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
331 input->year = in->year;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
332 input->track_number = in->track;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
333 input->genre = w_getstr(in->genre);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
334 input->comment = w_getstr(in->comment);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
335 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
336 input->file_name = g_path_get_basename(filename);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
337 input->file_path = g_path_get_dirname(filename);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
338 input->file_ext = extname(filename);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
339 ret = xmms_get_titlestring(xmms_get_gentitle_format(), input);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
340 if(input) g_free(input);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
341
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
342 if(!ret)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
343 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
344 ret = g_strdup(input->file_name);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
345 if (extname(ret) != NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
346 *(extname(ret) - 1) = '\0';
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
347 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
348 return ret;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
349 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
350
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
351 static guint get_song_time(AVFormatContext *in)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
352 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
353 if(in->duration)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
354 return in->duration/1000;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
355 else
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
356 return 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
357 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
358
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
359 static void ffmpeg_get_song_info(char *filename, char **title_real, int *len_real)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
360 {
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
361 TitleInput *tuple = ffmpeg_get_song_tuple(filename);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
362
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
363 if (tuple == NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
364 return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
365
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
366 (*len_real) = tuple->length;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
367 (*title_real) = xmms_get_titlestring(xmms_get_gentitle_format(), tuple);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
368 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
369
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
370 static void ffmpeg_playbuff(InputPlayback *playback, int out_size)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
371 {
818
07107d476f32 [svn] - remove some more stuff
nenolod
parents: 814
diff changeset
372 AVFifoBuffer f;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
373 int sst_buff;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
374
818
07107d476f32 [svn] - remove some more stuff
nenolod
parents: 814
diff changeset
375 av_fifo_init(&f, out_size*2);
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
376 av_fifo_write(&f, ffmpeg_outbuf, out_size);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
377 while(!av_fifo_read(&f, ffmpeg_s_outbuf, ffmpeg_st_buff) && ffmpeg_decode)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
378 {
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
379 sst_buff = ffmpeg_st_buff;
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
380 if(ffmpeg_pause) memset(ffmpeg_s_outbuf, 0, sst_buff);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
381 while(playback->output->buffer_free() < ffmpeg_st_buff) xmms_usleep(20000);
561
914c96de3244 [svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents: 559
diff changeset
382 produce_audio(playback->output->written_time(), FMT_S16_NE,
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
383 c->channels, sst_buff, (short *)ffmpeg_s_outbuf, NULL);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
384 memset(ffmpeg_s_outbuf, 0, sst_buff);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
385 }
818
07107d476f32 [svn] - remove some more stuff
nenolod
parents: 814
diff changeset
386 av_fifo_free(&f);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
387 return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
388 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
389
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
390 static void *ffmpeg_play_loop(void *arg)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
391 {
561
914c96de3244 [svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents: 559
diff changeset
392 InputPlayback *playback = arg;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
393 uint8_t *inbuf_ptr;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
394 int out_size, size, len;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
395 AVPacket pkt;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
396
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
397 g_static_mutex_lock(&ffmpeg_mutex);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
398 while(ffmpeg_decode){
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
399
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
400 if(ffmpeg_seekpos != -1)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
401 {
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
402 av_seek_frame(ic, ffmpeg_idx, ffmpeg_seekpos * 1000000LL, 0);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
403 playback->output->flush(ffmpeg_seekpos * 1000);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
404 ffmpeg_seekpos = -1;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
405 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
406
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
407 if(av_read_frame(ic, &pkt) < 0) break;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
408
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
409 size = pkt.size;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
410 inbuf_ptr = pkt.data;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
411
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
412 if(size == 0) break;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
413
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
414 while(size > 0){
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
415 len = avcodec_decode_audio(c, (short *)ffmpeg_outbuf, &out_size,
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
416 inbuf_ptr, size);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
417 if(len < 0) break;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
418
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
419 if(out_size <= 0) continue;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
420
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
421 ffmpeg_playbuff(playback, out_size);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
422
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
423 size -= len;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
424 inbuf_ptr += len;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
425 if(pkt.data) av_free_packet(&pkt);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
426 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
427 }
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
428 while(ffmpeg_decode && playback->output->buffer_playing()) xmms_usleep(30000);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
429 ffmpeg_decode = 0;
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
430 if(ffmpeg_s_outbuf) g_free(ffmpeg_s_outbuf);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
431 if(ffmpeg_outbuf) g_free(ffmpeg_outbuf);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
432 if(pkt.data) av_free_packet(&pkt);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
433 if(c) avcodec_close(c);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
434 if(ic) av_close_input_file(ic);
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
435 g_static_mutex_unlock(&ffmpeg_mutex);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
436 g_thread_exit(NULL);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
437 return(NULL);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
438 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
439
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
440 static void ffmpeg_play_file(InputPlayback *playback)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
441 {
561
914c96de3244 [svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents: 559
diff changeset
442 char *filename = playback->filename;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
443 AVCodec *codec;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
444
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
445 if(av_open_input_file(&ic, str_twenty_to_space(filename), NULL, 0, NULL) < 0) return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
446
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
447 for(ffmpeg_idx = 0; ffmpeg_idx < ic->nb_streams; ffmpeg_idx++) {
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
448 c = ic->streams[ffmpeg_idx]->codec;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
449 if(c->codec_type == CODEC_TYPE_AUDIO) break;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
450 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
451
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
452 av_find_stream_info(ic);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
453
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
454 codec = avcodec_find_decoder(c->codec_id);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
455
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
456 if(!codec) return;
835
485ba2ba5976 [svn] - working WMA playback. thanks to chainsaw for providing a ton and a half of WMA files.
nenolod
parents: 818
diff changeset
457
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
458 if(avcodec_open(c, codec) < 0) return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
459
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
460 wsong_title = get_song_title(ic, filename);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
461 wsong_time = get_song_time(ic);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
462
561
914c96de3244 [svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents: 559
diff changeset
463 if(playback->output->open_audio(FMT_S16_NE, c->sample_rate, c->channels) <= 0) return;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
464
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
465 ffmpeg_st_buff = ST_BUFF;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
466
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
467 ffmpeg_ip.set_info(wsong_title, wsong_time, c->bit_rate, c->sample_rate, c->channels);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
468
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
469 /* av_malloc() will wrap posix_memalign() if necessary -nenolod */
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
470 ffmpeg_s_outbuf = av_malloc(ffmpeg_st_buff);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
471 ffmpeg_outbuf = av_malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
472
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
473 ffmpeg_seekpos = -1;
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
474 ffmpeg_decode = 1;
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
475 ffmpeg_decode_thread = g_thread_create((GThreadFunc)ffmpeg_play_loop, playback, TRUE, NULL);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
476 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
477
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
478 static void ffmpeg_stop(InputPlayback *playback)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
479 {
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
480 ffmpeg_decode = 0;
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
481 if(ffmpeg_pause) ffmpeg_do_pause(playback, 0);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
482 g_thread_join(ffmpeg_decode_thread);
561
914c96de3244 [svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents: 559
diff changeset
483 playback->output->close_audio();
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
484 }