annotate src/ffmpeg/ffmpeg.c @ 842:47144a91649d trunk

[svn] - remove some old wma leftovers
author nenolod
date Mon, 12 Mar 2007 18:07:46 -0700
parents 9b50e71f7307
children 534375e63cc8
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 ST_BUFF 1024
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
50
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
51 static int ffmpeg_decode = 0;
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
52 static gboolean ffmpeg_pause = 0;
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
53 static int ffmpeg_seekpos = -1;
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
54 static int ffmpeg_st_buff, ffmpeg_idx, ffmpeg_idx2;
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
55 static GThread *ffmpeg_decode_thread;
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
56 GStaticMutex ffmpeg_mutex = G_STATIC_MUTEX_INIT;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
57 static AVCodecContext *c = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
58 static AVFormatContext *ic = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
59 static AVCodecContext *c2 = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
60 static AVFormatContext *ic2 = NULL;
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
61 static uint8_t *ffmpeg_outbuf, *ffmpeg_s_outbuf;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
62
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
63 char description[64];
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
64 static void ffmpeg_init(void);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
65 static int ffmpeg_is_our_file(char *filename);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
66 static int ffmpeg_is_our_fd(char *filename, VFSFile *fd);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
67 static void ffmpeg_play_file(InputPlayback *data);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
68 static void ffmpeg_stop(InputPlayback *data);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
69 static void ffmpeg_seek(InputPlayback *data, int time);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
70 static void ffmpeg_do_pause(InputPlayback *data, short p);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
71 static int ffmpeg_get_time(InputPlayback *data);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
72 static void ffmpeg_get_song_info(char *filename, char **title, int *length);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
73 static TitleInput *ffmpeg_get_song_tuple(char *filename);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
74 static char *wsong_title;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
75 static int wsong_time;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
76
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
77 static GtkWidget *dialog1, *button1, *label1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
78
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
79 InputPlugin *get_iplugin_info(void);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
80
841
9b50e71f7307 [svn] - implement shorten support more correctly.
nenolod
parents: 838
diff changeset
81 gchar *ffmpeg_fmts[] = { "wma", "shn", NULL };
372
a157306caf03 [svn] - finalize the plugin-side of the extension-assist ABI
nenolod
parents: 368
diff changeset
82
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
83 InputPlugin ffmpeg_ip =
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
84 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
85 NULL, // Filled in by xmms
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
86 NULL, // Filled in by xmms
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
87 description, // The description that is shown in the preferences box
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
88 ffmpeg_init, // Called when the plugin is loaded
842
47144a91649d [svn] - remove some old wma leftovers
nenolod
parents: 841
diff changeset
89 NULL, // Show the about box
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
90 NULL, // Show the configure box
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
91 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
92 NULL, // Scan dir
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
93 ffmpeg_play_file, // Play file
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
94 ffmpeg_stop, // Stop
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
95 ffmpeg_do_pause, // Pause
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
96 ffmpeg_seek, // Seek
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
97 NULL, // Set the equalizer, most plugins won't be able to do this
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
98 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
99 NULL, // Get volume
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
100 NULL, // Set volume
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
101 NULL, // OBSOLETE!
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
102 NULL, // OBSOLETE!
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
103 NULL, // Send data to the visualization plugins
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
104 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
105 NULL, // Show some text in the song title box. Filled in by xmms
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
106 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
107 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
108 NULL, // Handle to the current output plugin. Filled in by xmms
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
109 ffmpeg_get_song_tuple, // Tuple builder
368
c812e846b84e [svn] - add support for extension probing to many plugins.
nenolod
parents: 65
diff changeset
110 NULL,
c812e846b84e [svn] - add support for extension probing to many plugins.
nenolod
parents: 65
diff changeset
111 NULL,
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
112 ffmpeg_is_our_fd, // vfs
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
113 ffmpeg_fmts
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
114 };
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
115
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
116 InputPlugin *get_iplugin_info(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
117 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
118 memset(description, 0, 64);
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
119 ffmpeg_ip.description = g_strdup_printf(_("WMA Player %s"), PACKAGE_VERSION);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
120 return &ffmpeg_ip;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
121 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
122
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
123 static gchar *str_twenty_to_space(gchar * str)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
124 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
125 gchar *match, *match_end;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
126
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
127 g_return_val_if_fail(str != NULL, NULL);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
128
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
129 while ((match = strstr(str, "%20"))) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
130 match_end = match + 3;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
131 *match++ = ' ';
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
132 while (*match_end)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
133 *match++ = *match_end++;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
134 *match = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
135 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
136
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
137 return str;
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
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
140 static void ffmpeg_init(void)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
141 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
142 avcodec_init();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
143 avcodec_register_all();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
144 av_register_all();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
145 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
146
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
147 static int ffmpeg_is_our_file(char *filename)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
148 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
149 AVCodec *codec2;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
150
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
151 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
152
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
153 for(ffmpeg_idx2 = 0; ffmpeg_idx2 < ic2->nb_streams; ffmpeg_idx2++) {
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
154 c2 = ic2->streams[ffmpeg_idx2]->codec;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
155 if(c2->codec_type == CODEC_TYPE_AUDIO) break;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
156 }
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 av_find_stream_info(ic2);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
159
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
160 codec2 = avcodec_find_decoder(c2->codec_id);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
161
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
162 if(!codec2) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
163 av_close_input_file(ic2);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
164 return 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
165 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
166
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
167 av_close_input_file(ic2);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
168 return 1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
169 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
170
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
171 static int ffmpeg_is_our_fd(char *filename, VFSFile *fd)
508
1e5df88b631d [svn] - newvfs probing
nenolod
parents: 372
diff changeset
172 {
1e5df88b631d [svn] - newvfs probing
nenolod
parents: 372
diff changeset
173 AVCodec *codec2;
1e5df88b631d [svn] - newvfs probing
nenolod
parents: 372
diff changeset
174
1e5df88b631d [svn] - newvfs probing
nenolod
parents: 372
diff changeset
175 if(av_open_input_vfsfile(&ic2, filename, fd, NULL, 0, NULL) < 0) return 0;
1e5df88b631d [svn] - newvfs probing
nenolod
parents: 372
diff changeset
176
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
177 for(ffmpeg_idx2 = 0; ffmpeg_idx2 < ic2->nb_streams; ffmpeg_idx2++) {
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
178 c2 = ic2->streams[ffmpeg_idx2]->codec;
508
1e5df88b631d [svn] - newvfs probing
nenolod
parents: 372
diff changeset
179 if(c2->codec_type == CODEC_TYPE_AUDIO) break;
1e5df88b631d [svn] - newvfs probing
nenolod
parents: 372
diff changeset
180 }
1e5df88b631d [svn] - newvfs probing
nenolod
parents: 372
diff changeset
181
1e5df88b631d [svn] - newvfs probing
nenolod
parents: 372
diff changeset
182 av_find_stream_info(ic2);
1e5df88b631d [svn] - newvfs probing
nenolod
parents: 372
diff changeset
183
1e5df88b631d [svn] - newvfs probing
nenolod
parents: 372
diff changeset
184 codec2 = avcodec_find_decoder(c2->codec_id);
1e5df88b631d [svn] - newvfs probing
nenolod
parents: 372
diff changeset
185
838
8561bcf928a3 [svn] - fix crash
nenolod
parents: 836
diff changeset
186 if(!codec2)
8561bcf928a3 [svn] - fix crash
nenolod
parents: 836
diff changeset
187 return 0;
8561bcf928a3 [svn] - fix crash
nenolod
parents: 836
diff changeset
188
508
1e5df88b631d [svn] - newvfs probing
nenolod
parents: 372
diff changeset
189 return 1;
1e5df88b631d [svn] - newvfs probing
nenolod
parents: 372
diff changeset
190 }
1e5df88b631d [svn] - newvfs probing
nenolod
parents: 372
diff changeset
191
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
192 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
193 {
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
194 ffmpeg_pause = p;
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
195 playback->output->pause(ffmpeg_pause);
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
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
198 static void ffmpeg_seek(InputPlayback *playback, int time)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
199 {
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
200 ffmpeg_seekpos = time;
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
201 if(ffmpeg_pause) playback->output->pause(0);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
202 while(ffmpeg_decode && ffmpeg_seekpos!=-1) xmms_usleep(10000);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
203 if(ffmpeg_pause) playback->output->pause(1);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
204 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
205
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
206 static int ffmpeg_get_time(InputPlayback *playback)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
207 {
561
914c96de3244 [svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents: 559
diff changeset
208 playback->output->buffer_free();
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
209 if(ffmpeg_decode) return playback->output->output_time();
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
210 return -1;
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 static gchar *extname(const char *filename)
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 gchar *ext = strrchr(filename, '.');
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
216 if(ext != NULL) ++ext;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
217 return ext;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
218 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
219
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
220 static char* w_getstr(char* str)
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 if(str && strlen(str) > 0) return g_strdup(str);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
223 return NULL;
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 TitleInput *ffmpeg_get_song_tuple(gchar * filename)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
227 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
228 TitleInput *tuple = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
229 AVFormatContext *in = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
230 gchar *filename_proxy = g_strdup(filename);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
231
838
8561bcf928a3 [svn] - fix crash
nenolod
parents: 836
diff changeset
232 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
233 return NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
234
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
235 tuple = bmp_title_input_new();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
236
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
237 tuple->file_name = g_path_get_basename(filename_proxy);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
238 tuple->file_path = g_path_get_dirname(filename_proxy);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
239 tuple->file_ext = extname(filename_proxy);
838
8561bcf928a3 [svn] - fix crash
nenolod
parents: 836
diff changeset
240
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
241 av_find_stream_info(in);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
242
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
243 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
244 (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
245 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
246 tuple->performer = str_to_utf8(w_getstr(in->author));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
247 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
248 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
249 tuple->year = in->year;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
250 tuple->track_number = in->track;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
251 tuple->genre = str_to_utf8(w_getstr(in->genre));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
252 tuple->comment = str_to_utf8(w_getstr(in->comment));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
253 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
254
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
255 if (in->duration)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
256 tuple->length = in->duration / 1000;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
257
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
258 av_close_input_file(in);
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 return tuple;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
261 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
262
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
263 static gchar *get_song_title(AVFormatContext *in, gchar * filename)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
264 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
265 gchar *ret = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
266 TitleInput *input;
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 input = bmp_title_input_new();
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 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
271 (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
272 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
273 input->performer = w_getstr(in->author);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
274 input->album_name = w_getstr(in->album);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
275 input->track_name = w_getstr(in->title);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
276 input->year = in->year;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
277 input->track_number = in->track;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
278 input->genre = w_getstr(in->genre);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
279 input->comment = w_getstr(in->comment);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
280 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
281 input->file_name = g_path_get_basename(filename);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
282 input->file_path = g_path_get_dirname(filename);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
283 input->file_ext = extname(filename);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
284 ret = xmms_get_titlestring(xmms_get_gentitle_format(), input);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
285 if(input) g_free(input);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
286
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
287 if(!ret)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
288 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
289 ret = g_strdup(input->file_name);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
290 if (extname(ret) != NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
291 *(extname(ret) - 1) = '\0';
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
292 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
293 return ret;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
294 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
295
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
296 static guint get_song_time(AVFormatContext *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->duration)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
299 return in->duration/1000;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
300 else
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
301 return 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
302 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
303
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
304 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
305 {
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
306 TitleInput *tuple = ffmpeg_get_song_tuple(filename);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
307
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
308 if (tuple == NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
309 return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
310
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
311 (*len_real) = tuple->length;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
312 (*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
313 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
314
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
315 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
316 {
818
07107d476f32 [svn] - remove some more stuff
nenolod
parents: 814
diff changeset
317 AVFifoBuffer f;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
318 int sst_buff;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
319
818
07107d476f32 [svn] - remove some more stuff
nenolod
parents: 814
diff changeset
320 av_fifo_init(&f, out_size*2);
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
321 av_fifo_write(&f, ffmpeg_outbuf, out_size);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
322 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
323 {
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
324 sst_buff = ffmpeg_st_buff;
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
325 if(ffmpeg_pause) memset(ffmpeg_s_outbuf, 0, sst_buff);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
326 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
327 produce_audio(playback->output->written_time(), FMT_S16_NE,
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
328 c->channels, sst_buff, (short *)ffmpeg_s_outbuf, NULL);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
329 memset(ffmpeg_s_outbuf, 0, sst_buff);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
330 }
818
07107d476f32 [svn] - remove some more stuff
nenolod
parents: 814
diff changeset
331 av_fifo_free(&f);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
332 return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
333 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
334
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
335 static void *ffmpeg_play_loop(void *arg)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
336 {
561
914c96de3244 [svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents: 559
diff changeset
337 InputPlayback *playback = arg;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
338 uint8_t *inbuf_ptr;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
339 int out_size, size, len;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
340 AVPacket pkt;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
341
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
342 g_static_mutex_lock(&ffmpeg_mutex);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
343 while(ffmpeg_decode){
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
344
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
345 if(ffmpeg_seekpos != -1)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
346 {
841
9b50e71f7307 [svn] - implement shorten support more correctly.
nenolod
parents: 838
diff changeset
347 av_seek_frame(ic, ffmpeg_idx, ffmpeg_seekpos * 1000000LL, AVSEEK_FLAG_BYTE);
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
348 playback->output->flush(ffmpeg_seekpos * 1000);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
349 ffmpeg_seekpos = -1;
0
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
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
352 if(av_read_frame(ic, &pkt) < 0) break;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
353
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
354 size = pkt.size;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
355 inbuf_ptr = pkt.data;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
356
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
357 if(size == 0) break;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
358
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
359 while(size > 0){
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
360 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
361 inbuf_ptr, size);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
362 if(len < 0) break;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
363
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
364 if(out_size <= 0) continue;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
365
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
366 ffmpeg_playbuff(playback, out_size);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
367
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
368 size -= len;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
369 inbuf_ptr += len;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
370 if(pkt.data) av_free_packet(&pkt);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
371 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
372 }
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
373 while(ffmpeg_decode && playback->output->buffer_playing()) xmms_usleep(30000);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
374 ffmpeg_decode = 0;
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
375 if(ffmpeg_s_outbuf) g_free(ffmpeg_s_outbuf);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
376 if(ffmpeg_outbuf) g_free(ffmpeg_outbuf);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
377 if(pkt.data) av_free_packet(&pkt);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
378 if(c) avcodec_close(c);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
379 if(ic) av_close_input_file(ic);
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
380 g_static_mutex_unlock(&ffmpeg_mutex);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
381 g_thread_exit(NULL);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
382 return(NULL);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
383 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
384
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
385 static void ffmpeg_play_file(InputPlayback *playback)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
386 {
561
914c96de3244 [svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents: 559
diff changeset
387 char *filename = playback->filename;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
388 AVCodec *codec;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
389
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
390 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
391
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
392 for(ffmpeg_idx = 0; ffmpeg_idx < ic->nb_streams; ffmpeg_idx++) {
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
393 c = ic->streams[ffmpeg_idx]->codec;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
394 if(c->codec_type == CODEC_TYPE_AUDIO) break;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
395 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
396
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
397 av_find_stream_info(ic);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
398
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
399 codec = avcodec_find_decoder(c->codec_id);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
400
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
401 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
402
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
403 if(avcodec_open(c, codec) < 0) return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
404
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
405 wsong_title = get_song_title(ic, filename);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
406 wsong_time = get_song_time(ic);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
407
561
914c96de3244 [svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents: 559
diff changeset
408 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
409
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
410 ffmpeg_st_buff = ST_BUFF;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
411
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
412 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
413
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
414 /* av_malloc() will wrap posix_memalign() if necessary -nenolod */
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
415 ffmpeg_s_outbuf = av_malloc(ffmpeg_st_buff);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
416 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
417
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
418 ffmpeg_seekpos = -1;
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
419 ffmpeg_decode = 1;
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
420 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
421 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
422
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
423 static void ffmpeg_stop(InputPlayback *playback)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
424 {
836
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
425 ffmpeg_decode = 0;
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
426 if(ffmpeg_pause) ffmpeg_do_pause(playback, 0);
7efd0747b362 [svn] - namespace changes
nenolod
parents: 835
diff changeset
427 g_thread_join(ffmpeg_decode_thread);
561
914c96de3244 [svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
iabervon
parents: 559
diff changeset
428 playback->output->close_audio();
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
429 }