annotate src/flac112/plugin.c @ 522:2d3fad6a3842 trunk

[svn] - flac 112 plugin: do not try to pick tuple from file if file is not accessible via stdio (and stop crashing when such attempts are done); TODO: pick tags from flac via vfs
author giacomo
date Mon, 22 Jan 2007 12:32:00 -0800
parents 8f1785471613
children bb7312f3ec1a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
1 /* libxmms-flac - XMMS FLAC input plugin
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
2 * Copyright (C) 2000,2001,2002,2003,2004,2005 Josh Coalson
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
3 *
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
5 * modify it under the terms of the GNU General Public License
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
6 * as published by the Free Software Foundation; either version 2
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
7 * of the License, or (at your option) any later version.
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
8 *
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
9 * This program is distributed in the hope that it will be useful,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
12 * GNU General Public License for more details.
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
13 *
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
15 * along with this program; if not, write to the Free Software
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
17 */
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
18
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
19 #include <stdlib.h>
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
20 #include <string.h>
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
21 #include <stdio.h>
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
22 #include <glib.h>
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
23 #include <pwd.h>
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
24 #include <sys/types.h>
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
25 #include <unistd.h>
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
26
489
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
27 #include <audacious/plugin.h>
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
28 #include <audacious/output.h>
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
29 #include <audacious/util.h>
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
30 #include <audacious/configdb.h>
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
31 #include <audacious/titlestring.h>
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
32 #include <audacious/vfs.h>
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
33
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
34 #ifdef HAVE_CONFIG_H
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
35 #include <config.h>
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
36 #endif
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
37
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
38 #ifdef HAVE_LANGINFO_CODESET
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
39 #include <langinfo.h>
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
40 #endif
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
41
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
42 #include "FLAC/all.h"
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
43 #include "plugin_common/all.h"
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
44 #include "grabbag.h"
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
45 #include "replaygain_synthesis.h"
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
46 #include "configure.h"
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
47 #include "charset.h"
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
48 #include "tag.h"
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
49
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
50 #ifdef min
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
51 #undef min
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
52 #endif
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
53 #define min(x,y) ((x)<(y)?(x):(y))
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
54
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
55 /* adjust for compilers that can't understand using LLU suffix for uint64_t literals */
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
56 #ifdef _MSC_VER
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
57 #define FLAC__U64L(x) x
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
58 #else
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
59 #define FLAC__U64L(x) x##LLU
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
60 #endif
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
61
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
62 extern void FLAC_XMMS__file_info_box(char *filename);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
63
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
64 typedef struct {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
65 FLAC__bool abort_flag;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
66 FLAC__bool is_playing;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
67 FLAC__bool eof;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
68 FLAC__bool play_thread_open; /* if true, is_playing must also be true */
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
69 unsigned total_samples;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
70 unsigned bits_per_sample;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
71 unsigned channels;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
72 unsigned sample_rate;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
73 unsigned length_in_msec;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
74 gchar *title;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
75 AFormat sample_format;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
76 unsigned sample_format_bytes_per_sample;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
77 int seek_to_in_sec;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
78 FLAC__bool has_replaygain;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
79 double replay_scale;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
80 DitherContext dither_context;
489
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
81 VFSFile *vfsfile;
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
82 } file_info_struct;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
83
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
84 typedef FLAC__StreamDecoderWriteStatus (*WriteCallback) (const void *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
85 typedef void (*MetadataCallback) (const void *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
86 typedef void (*ErrorCallback) (const void *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
87
511
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
88 #define NUM_DECODER_TYPES 1
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
89 typedef enum {
511
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
90 DECODER_FILE
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
91 } decoder_t;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
92
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
93 static void FLAC_XMMS__init();
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
94 static int FLAC_XMMS__is_our_file(char *filename);
489
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
95 static int FLAC_XMMS__is_our_file_from_vfs(char *filename, VFSFile *vfsfile);
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
96 static void FLAC_XMMS__play_file(char *filename);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
97 static void FLAC_XMMS__stop();
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
98 static void FLAC_XMMS__pause(short p);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
99 static void FLAC_XMMS__seek(int time);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
100 static int FLAC_XMMS__get_time();
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
101 static void FLAC_XMMS__cleanup();
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
102 static void FLAC_XMMS__get_song_info(char *filename, char **title, int *length);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
103
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
104 static void *play_loop_(void *arg);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
105
511
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
106 static FLAC__bool safe_decoder_init_(const char *filename, void *decoder);
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
107 static void file_decoder_safe_decoder_finish_(void *decoder);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
108 static void file_decoder_safe_decoder_delete_(void *decoder);
511
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
109 static FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__SeekableStreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
110 static void metadata_callback_(const FLAC__SeekableStreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
111 static void error_callback_(const FLAC__SeekableStreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
112 static FLAC__bool file_decoder_is_eof(void *decoder);
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
113
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
114 static decoder_t source_to_decoder_type (const char *source);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
115
372
a157306caf03 [svn] - finalize the plugin-side of the extension-assist ABI
nenolod
parents: 368
diff changeset
116 gchar *flac_fmts[] = { "flac", NULL };
a157306caf03 [svn] - finalize the plugin-side of the extension-assist ABI
nenolod
parents: 368
diff changeset
117
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
118 InputPlugin flac_ip =
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
119 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
120 NULL,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
121 NULL,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
122 NULL,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
123 FLAC_XMMS__init,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
124 FLAC_XMMS__aboutbox,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
125 FLAC_XMMS__configure,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
126 FLAC_XMMS__is_our_file,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
127 NULL,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
128 FLAC_XMMS__play_file,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
129 FLAC_XMMS__stop,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
130 FLAC_XMMS__pause,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
131 FLAC_XMMS__seek,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
132 NULL,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
133 FLAC_XMMS__get_time,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
134 NULL,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
135 NULL,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
136 FLAC_XMMS__cleanup,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
137 NULL,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
138 NULL,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
139 NULL,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
140 NULL,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
141 FLAC_XMMS__get_song_info,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
142 FLAC_XMMS__file_info_box,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
143 NULL,
372
a157306caf03 [svn] - finalize the plugin-side of the extension-assist ABI
nenolod
parents: 368
diff changeset
144 flac_get_tuple,
a157306caf03 [svn] - finalize the plugin-side of the extension-assist ABI
nenolod
parents: 368
diff changeset
145 NULL, // set tuple
368
c812e846b84e [svn] - add support for extension probing to many plugins.
nenolod
parents: 207
diff changeset
146 NULL,
489
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
147 FLAC_XMMS__is_our_file_from_vfs,
372
a157306caf03 [svn] - finalize the plugin-side of the extension-assist ABI
nenolod
parents: 368
diff changeset
148 flac_fmts,
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
149 };
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
150
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
151 #define SAMPLES_PER_WRITE 512
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
152 #define SAMPLE_BUFFER_SIZE ((FLAC__MAX_BLOCK_SIZE + SAMPLES_PER_WRITE) * FLAC_PLUGIN__MAX_SUPPORTED_CHANNELS * (24/8))
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
153 static FLAC__byte sample_buffer_[SAMPLE_BUFFER_SIZE];
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
154 static unsigned sample_buffer_first_, sample_buffer_last_;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
155
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
156 static void *decoder_ = 0, *decoder2 = 0;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
157 static file_info_struct file_info_;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
158 static GThread *decode_thread_;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
159 static FLAC__bool audio_error_ = false;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
160 static FLAC__bool is_big_endian_host_;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
161
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
162 #define BITRATE_HIST_SEGMENT_MSEC 500
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
163 /* 500ms * 50 = 25s should be enough */
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
164 #define BITRATE_HIST_SIZE 50
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
165 static unsigned bitrate_history_[BITRATE_HIST_SIZE];
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
166
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
167
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
168 InputPlugin *get_iplugin_info()
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
169 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
170 flac_ip.description = g_strdup_printf(_("FLAC Audio Plugin"));
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
171 return &flac_ip;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
172 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
173
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
174 void set_track_info(const char* title, int length_in_msec)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
175 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
176 if (file_info_.is_playing) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
177 flac_ip.set_info((char*) title, length_in_msec, file_info_.sample_rate * file_info_.channels * file_info_.bits_per_sample, file_info_.sample_rate, file_info_.channels);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
178 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
179 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
180
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
181 static gchar* homedir()
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
182 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
183 gchar *result;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
184 char *env_home = getenv("HOME");
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
185 if (env_home) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
186 result = g_strdup (env_home);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
187 } else {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
188 uid_t uid = getuid();
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
189 struct passwd *pwent;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
190 do {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
191 pwent = getpwent();
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
192 } while (pwent && pwent->pw_uid != uid);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
193 result = pwent ? g_strdup (pwent->pw_dir) : NULL;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
194 endpwent();
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
195 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
196 return result;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
197 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
198
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
199 void FLAC_XMMS__init()
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
200 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
201 ConfigDb *db;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
202 FLAC__uint32 test = 1;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
203 gchar *tmp = NULL;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
204
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
205 is_big_endian_host_ = (*((FLAC__byte*)(&test)))? false : true;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
206
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
207 memset(&flac_cfg, 0, sizeof(flac_cfg));
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
208
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
209 db = bmp_cfg_db_open();
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
210
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
211 /* title */
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
212
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
213 bmp_cfg_db_get_bool(db, "flac", "title.tag_override", &flac_cfg.title.tag_override);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
214
492
0dd1ff7e5ba7 [svn] flac 112 plugin: stability fixes and a new option to disable bitrate update in player window during playback (saves cpu, this is the solution for most people playing flac and reporting high cpu usage)
giacomo
parents: 490
diff changeset
215 bmp_cfg_db_get_bool(db, "flac", "title.disable_bitrate_update", &flac_cfg.title.disable_bitrate_update);
0dd1ff7e5ba7 [svn] flac 112 plugin: stability fixes and a new option to disable bitrate update in player window during playback (saves cpu, this is the solution for most people playing flac and reporting high cpu usage)
giacomo
parents: 490
diff changeset
216
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
217 if(!bmp_cfg_db_get_string(db, "flac", "title.tag_format", &flac_cfg.title.tag_format))
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
218 flac_cfg.title.tag_format = g_strdup("%p - %t");
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
219
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
220 bmp_cfg_db_get_bool(db, "flac", "title.convert_char_set", &flac_cfg.title.convert_char_set);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
221
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
222 if(!bmp_cfg_db_get_string(db, "flac", "title.user_char_set", &flac_cfg.title.user_char_set))
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
223 flac_cfg.title.user_char_set = FLAC_plugin__charset_get_current();
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
224
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
225 /* replaygain */
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
226
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
227 bmp_cfg_db_get_bool(db, "flac", "output.replaygain.enable", &flac_cfg.output.replaygain.enable);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
228
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
229 bmp_cfg_db_get_bool(db, "flac", "output.replaygain.album_mode", &flac_cfg.output.replaygain.album_mode);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
230
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
231 if(!bmp_cfg_db_get_int(db, "flac", "output.replaygain.preamp", &flac_cfg.output.replaygain.preamp))
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
232 flac_cfg.output.replaygain.preamp = 0;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
233
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
234 bmp_cfg_db_get_bool(db, "flac", "output.replaygain.hard_limit", &flac_cfg.output.replaygain.hard_limit);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
235
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
236 bmp_cfg_db_get_bool(db, "flac", "output.resolution.normal.dither_24_to_16", &flac_cfg.output.resolution.normal.dither_24_to_16);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
237 bmp_cfg_db_get_bool(db, "flac", "output.resolution.replaygain.dither", &flac_cfg.output.resolution.replaygain.dither);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
238
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
239 if(!bmp_cfg_db_get_int(db, "flac", "output.resolution.replaygain.noise_shaping", &flac_cfg.output.resolution.replaygain.noise_shaping))
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
240 flac_cfg.output.resolution.replaygain.noise_shaping = 1;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
241
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
242 if(!bmp_cfg_db_get_int(db, "flac", "output.resolution.replaygain.bps_out", &flac_cfg.output.resolution.replaygain.bps_out))
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
243 flac_cfg.output.resolution.replaygain.bps_out = 16;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
244
513
77012d414f58 [svn] - flac 112 plugin: removed ui options related to old http support
giacomo
parents: 512
diff changeset
245 bmp_cfg_db_close(db);
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
246
511
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
247 decoder_ = FLAC__seekable_stream_decoder_new();
520
8f1785471613 [svn] - add missing inclusion of audacious/strings.h where necessary
giacomo
parents: 513
diff changeset
248 file_info_.vfsfile = NULL;
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
249 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
250
489
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
251 int FLAC_XMMS__is_our_file_from_vfs( gchar * filename , VFSFile * vfsfile )
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
252 {
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
253 gchar magic_bytes[4];
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
254
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
255 if ( vfsfile == NULL )
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
256 return 0;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
257
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
258 if ( vfs_fread( magic_bytes , 1 , 4 , vfsfile ) != 4 )
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
259 return 0;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
260
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
261 if ( !strncmp( magic_bytes , "fLaC" , 4 ) )
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
262 return 1;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
263 else
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
264 return 0;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
265 }
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
266
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
267 int FLAC_XMMS__is_our_file(char *filename)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
268 {
489
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
269 VFSFile *vfsfile;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
270 gint result = 0;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
271
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
272 vfsfile = vfs_fopen( filename , "rb" );
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
273
489
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
274 if ( vfsfile == NULL ) return 0;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
275
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
276 result = FLAC_XMMS__is_our_file_from_vfs( filename , vfsfile );
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
277
489
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
278 vfs_fclose( vfsfile );
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
279
489
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
280 return result;
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
281 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
282
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
283 void FLAC_XMMS__play_file(char *filename)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
284 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
285 sample_buffer_first_ = sample_buffer_last_ = 0;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
286 audio_error_ = false;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
287 file_info_.abort_flag = false;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
288 file_info_.is_playing = false;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
289 file_info_.eof = false;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
290 file_info_.play_thread_open = false;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
291 file_info_.has_replaygain = false;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
292
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
293 if(decoder_ == 0)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
294 return;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
295
511
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
296 if(!safe_decoder_init_(filename, decoder_))
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
297 return;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
298
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
299 if(file_info_.has_replaygain && flac_cfg.output.replaygain.enable) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
300 if(flac_cfg.output.resolution.replaygain.bps_out == 8) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
301 file_info_.sample_format = FMT_U8;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
302 file_info_.sample_format_bytes_per_sample = 1;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
303 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
304 else if(flac_cfg.output.resolution.replaygain.bps_out == 16) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
305 file_info_.sample_format = (is_big_endian_host_) ? FMT_S16_BE : FMT_S16_LE;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
306 file_info_.sample_format_bytes_per_sample = 2;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
307 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
308 else {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
309 /*@@@ need some error here like wa2: MessageBox(mod_.hMainWindow, "ERROR: plugin can only handle 8/16-bit samples\n", "ERROR: plugin can only handle 8/16-bit samples", 0); */
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
310 fprintf(stderr, "libxmms-flac: can't handle %d bit output\n", flac_cfg.output.resolution.replaygain.bps_out);
511
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
311 file_decoder_safe_decoder_finish_(decoder_);
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
312 return;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
313 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
314 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
315 else {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
316 if(file_info_.bits_per_sample == 8) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
317 file_info_.sample_format = FMT_U8;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
318 file_info_.sample_format_bytes_per_sample = 1;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
319 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
320 else if(file_info_.bits_per_sample == 16 || (file_info_.bits_per_sample == 24 && flac_cfg.output.resolution.normal.dither_24_to_16)) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
321 file_info_.sample_format = (is_big_endian_host_) ? FMT_S16_BE : FMT_S16_LE;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
322 file_info_.sample_format_bytes_per_sample = 2;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
323 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
324 else {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
325 /*@@@ need some error here like wa2: MessageBox(mod_.hMainWindow, "ERROR: plugin can only handle 8/16-bit samples\n", "ERROR: plugin can only handle 8/16-bit samples", 0); */
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
326 fprintf(stderr, "libxmms-flac: can't handle %d bit output\n", file_info_.bits_per_sample);
511
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
327 file_decoder_safe_decoder_finish_(decoder_);
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
328 return;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
329 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
330 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
331 FLAC__replaygain_synthesis__init_dither_context(&file_info_.dither_context, file_info_.sample_format_bytes_per_sample * 8, flac_cfg.output.resolution.replaygain.noise_shaping);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
332 file_info_.is_playing = true;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
333
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
334 if(flac_ip.output->open_audio(file_info_.sample_format, file_info_.sample_rate, file_info_.channels) == 0) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
335 audio_error_ = true;
511
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
336 file_decoder_safe_decoder_finish_(decoder_);
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
337 return;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
338 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
339
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
340 file_info_.title = flac_format_song_title(filename);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
341 flac_ip.set_info(file_info_.title, file_info_.length_in_msec, file_info_.sample_rate * file_info_.channels * file_info_.bits_per_sample, file_info_.sample_rate, file_info_.channels);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
342
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
343 file_info_.seek_to_in_sec = -1;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
344 file_info_.play_thread_open = true;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
345 decode_thread_ = g_thread_create((GThreadFunc)play_loop_, NULL, TRUE, NULL);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
346 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
347
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
348 void FLAC_XMMS__stop()
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
349 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
350 if(file_info_.is_playing) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
351 file_info_.is_playing = false;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
352 if(file_info_.play_thread_open) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
353 file_info_.play_thread_open = false;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
354 g_thread_join(decode_thread_);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
355 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
356 flac_ip.output->close_audio();
511
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
357 file_decoder_safe_decoder_finish_(decoder_);
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
358 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
359 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
360
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
361 void FLAC_XMMS__pause(short p)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
362 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
363 flac_ip.output->pause(p);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
364 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
365
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
366 void FLAC_XMMS__seek(int time)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
367 {
511
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
368 file_info_.seek_to_in_sec = time;
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
369 file_info_.eof = false;
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
370
511
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
371 while(file_info_.seek_to_in_sec != -1)
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
372 xmms_usleep(10000);
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
373 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
374
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
375 int FLAC_XMMS__get_time()
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
376 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
377 if(audio_error_)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
378 return -2;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
379 if(!file_info_.is_playing || (file_info_.eof && !flac_ip.output->buffer_playing()))
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
380 return -1;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
381 else
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
382 return flac_ip.output->output_time();
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
383 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
384
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
385 void FLAC_XMMS__cleanup()
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
386 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
387 g_free(flac_ip.description);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
388 flac_ip.description = NULL;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
389
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
390 if (flac_cfg.title.tag_format) {
492
0dd1ff7e5ba7 [svn] flac 112 plugin: stability fixes and a new option to disable bitrate update in player window during playback (saves cpu, this is the solution for most people playing flac and reporting high cpu usage)
giacomo
parents: 490
diff changeset
391 g_free(flac_cfg.title.tag_format);
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
392 flac_cfg.title.tag_format = NULL;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
393 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
394
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
395 if (flac_cfg.title.user_char_set) {
492
0dd1ff7e5ba7 [svn] flac 112 plugin: stability fixes and a new option to disable bitrate update in player window during playback (saves cpu, this is the solution for most people playing flac and reporting high cpu usage)
giacomo
parents: 490
diff changeset
396 g_free(flac_cfg.title.user_char_set);
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
397 flac_cfg.title.user_char_set = NULL;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
398 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
399
511
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
400 file_decoder_safe_decoder_delete_(decoder_);
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
401 decoder_ = 0;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
402 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
403
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
404 void FLAC_XMMS__get_song_info(char *filename, char **title, int *length_in_msec)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
405 {
522
2d3fad6a3842 [svn] - flac 112 plugin: do not try to pick tuple from file if file is not accessible via stdio (and stop crashing when such attempts are done); TODO: pick tags from flac via vfs
giacomo
parents: 520
diff changeset
406 /* NOTE vfs is not yet used here, so only try
2d3fad6a3842 [svn] - flac 112 plugin: do not try to pick tuple from file if file is not accessible via stdio (and stop crashing when such attempts are done); TODO: pick tags from flac via vfs
giacomo
parents: 520
diff changeset
407 to pick tags if you can do it with flac library stdio */
2d3fad6a3842 [svn] - flac 112 plugin: do not try to pick tuple from file if file is not accessible via stdio (and stop crashing when such attempts are done); TODO: pick tags from flac via vfs
giacomo
parents: 520
diff changeset
408 if ( strncmp(filename,"/",1) )
2d3fad6a3842 [svn] - flac 112 plugin: do not try to pick tuple from file if file is not accessible via stdio (and stop crashing when such attempts are done); TODO: pick tags from flac via vfs
giacomo
parents: 520
diff changeset
409 {
2d3fad6a3842 [svn] - flac 112 plugin: do not try to pick tuple from file if file is not accessible via stdio (and stop crashing when such attempts are done); TODO: pick tags from flac via vfs
giacomo
parents: 520
diff changeset
410 FLAC__StreamMetadata streaminfo;
2d3fad6a3842 [svn] - flac 112 plugin: do not try to pick tuple from file if file is not accessible via stdio (and stop crashing when such attempts are done); TODO: pick tags from flac via vfs
giacomo
parents: 520
diff changeset
411 if(!FLAC__metadata_get_streaminfo(filename, &streaminfo)) {
2d3fad6a3842 [svn] - flac 112 plugin: do not try to pick tuple from file if file is not accessible via stdio (and stop crashing when such attempts are done); TODO: pick tags from flac via vfs
giacomo
parents: 520
diff changeset
412 /* @@@ how to report the error? */
2d3fad6a3842 [svn] - flac 112 plugin: do not try to pick tuple from file if file is not accessible via stdio (and stop crashing when such attempts are done); TODO: pick tags from flac via vfs
giacomo
parents: 520
diff changeset
413 if(title) {
2d3fad6a3842 [svn] - flac 112 plugin: do not try to pick tuple from file if file is not accessible via stdio (and stop crashing when such attempts are done); TODO: pick tags from flac via vfs
giacomo
parents: 520
diff changeset
414 if (source_to_decoder_type (filename) == DECODER_FILE) {
2d3fad6a3842 [svn] - flac 112 plugin: do not try to pick tuple from file if file is not accessible via stdio (and stop crashing when such attempts are done); TODO: pick tags from flac via vfs
giacomo
parents: 520
diff changeset
415 static const char *errtitle = "Invalid FLAC File: ";
2d3fad6a3842 [svn] - flac 112 plugin: do not try to pick tuple from file if file is not accessible via stdio (and stop crashing when such attempts are done); TODO: pick tags from flac via vfs
giacomo
parents: 520
diff changeset
416 *title = g_malloc(strlen(errtitle) + 1 + strlen(filename) + 1 + 1);
2d3fad6a3842 [svn] - flac 112 plugin: do not try to pick tuple from file if file is not accessible via stdio (and stop crashing when such attempts are done); TODO: pick tags from flac via vfs
giacomo
parents: 520
diff changeset
417 sprintf(*title, "%s\"%s\"", errtitle, filename);
2d3fad6a3842 [svn] - flac 112 plugin: do not try to pick tuple from file if file is not accessible via stdio (and stop crashing when such attempts are done); TODO: pick tags from flac via vfs
giacomo
parents: 520
diff changeset
418 } else {
2d3fad6a3842 [svn] - flac 112 plugin: do not try to pick tuple from file if file is not accessible via stdio (and stop crashing when such attempts are done); TODO: pick tags from flac via vfs
giacomo
parents: 520
diff changeset
419 *title = NULL;
2d3fad6a3842 [svn] - flac 112 plugin: do not try to pick tuple from file if file is not accessible via stdio (and stop crashing when such attempts are done); TODO: pick tags from flac via vfs
giacomo
parents: 520
diff changeset
420 }
2d3fad6a3842 [svn] - flac 112 plugin: do not try to pick tuple from file if file is not accessible via stdio (and stop crashing when such attempts are done); TODO: pick tags from flac via vfs
giacomo
parents: 520
diff changeset
421 }
2d3fad6a3842 [svn] - flac 112 plugin: do not try to pick tuple from file if file is not accessible via stdio (and stop crashing when such attempts are done); TODO: pick tags from flac via vfs
giacomo
parents: 520
diff changeset
422 if(length_in_msec)
2d3fad6a3842 [svn] - flac 112 plugin: do not try to pick tuple from file if file is not accessible via stdio (and stop crashing when such attempts are done); TODO: pick tags from flac via vfs
giacomo
parents: 520
diff changeset
423 *length_in_msec = -1;
2d3fad6a3842 [svn] - flac 112 plugin: do not try to pick tuple from file if file is not accessible via stdio (and stop crashing when such attempts are done); TODO: pick tags from flac via vfs
giacomo
parents: 520
diff changeset
424 return;
2d3fad6a3842 [svn] - flac 112 plugin: do not try to pick tuple from file if file is not accessible via stdio (and stop crashing when such attempts are done); TODO: pick tags from flac via vfs
giacomo
parents: 520
diff changeset
425 }
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
426
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
427 if(title) {
522
2d3fad6a3842 [svn] - flac 112 plugin: do not try to pick tuple from file if file is not accessible via stdio (and stop crashing when such attempts are done); TODO: pick tags from flac via vfs
giacomo
parents: 520
diff changeset
428 *title = flac_format_song_title(filename);
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
429 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
430 if(length_in_msec)
522
2d3fad6a3842 [svn] - flac 112 plugin: do not try to pick tuple from file if file is not accessible via stdio (and stop crashing when such attempts are done); TODO: pick tags from flac via vfs
giacomo
parents: 520
diff changeset
431 *length_in_msec = (unsigned)((double)streaminfo.data.stream_info.total_samples / (double)streaminfo.data.stream_info.sample_rate * 1000.0 + 0.5);
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
432 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
433 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
434
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
435 /***********************************************************************
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
436 * local routines
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
437 **********************************************************************/
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
438
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
439 void *play_loop_(void *arg)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
440 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
441 unsigned written_time_last = 0, bh_index_last_w = 0, bh_index_last_o = BITRATE_HIST_SIZE, blocksize = 1;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
442 FLAC__uint64 decode_position_last = 0, decode_position_frame_last = 0, decode_position_frame = 0;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
443
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
444 (void)arg;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
445
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
446 while(file_info_.is_playing) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
447 if(!file_info_.eof) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
448 while(sample_buffer_last_ - sample_buffer_first_ < SAMPLES_PER_WRITE) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
449 unsigned s;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
450
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
451 s = sample_buffer_last_ - sample_buffer_first_;
511
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
452 if(file_decoder_is_eof(decoder_)) {
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
453 file_info_.eof = true;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
454 break;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
455 }
511
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
456 else if (!FLAC__seekable_stream_decoder_process_single(decoder_)) {
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
457 /*@@@ this should probably be a dialog */
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
458 fprintf(stderr, "libxmms-flac: READ ERROR processing frame\n");
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
459 file_info_.eof = true;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
460 break;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
461 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
462 blocksize = sample_buffer_last_ - sample_buffer_first_ - s;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
463 decode_position_frame_last = decode_position_frame;
511
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
464 if(!FLAC__seekable_stream_decoder_get_decode_position(decoder_, &decode_position_frame))
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
465 decode_position_frame = 0;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
466 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
467 if(sample_buffer_last_ - sample_buffer_first_ > 0) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
468 const unsigned n = min(sample_buffer_last_ - sample_buffer_first_, SAMPLES_PER_WRITE);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
469 int bytes = n * file_info_.channels * file_info_.sample_format_bytes_per_sample;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
470 FLAC__byte *sample_buffer_start = sample_buffer_ + sample_buffer_first_ * file_info_.channels * file_info_.sample_format_bytes_per_sample;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
471 unsigned written_time, bh_index_w;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
472 FLAC__uint64 decode_position;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
473
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
474 sample_buffer_first_ += n;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
475 while(flac_ip.output->buffer_free() < (int)bytes && file_info_.is_playing && file_info_.seek_to_in_sec == -1)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
476 xmms_usleep(10000);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
477 if(file_info_.is_playing && file_info_.seek_to_in_sec == -1)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
478 produce_audio(flac_ip.output->written_time(), file_info_.sample_format,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
479 file_info_.channels, bytes, sample_buffer_start, NULL);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
480
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
481 /* compute current bitrate */
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
482
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
483 written_time = flac_ip.output->written_time();
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
484 bh_index_w = written_time / BITRATE_HIST_SEGMENT_MSEC % BITRATE_HIST_SIZE;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
485 if(bh_index_w != bh_index_last_w) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
486 bh_index_last_w = bh_index_w;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
487 decode_position = decode_position_frame - (double)(sample_buffer_last_ - sample_buffer_first_) * (double)(decode_position_frame - decode_position_frame_last) / (double)blocksize;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
488 bitrate_history_[(bh_index_w + BITRATE_HIST_SIZE - 1) % BITRATE_HIST_SIZE] =
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
489 decode_position > decode_position_last && written_time > written_time_last ?
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
490 8000 * (decode_position - decode_position_last) / (written_time - written_time_last) :
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
491 file_info_.sample_rate * file_info_.channels * file_info_.bits_per_sample;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
492 decode_position_last = decode_position;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
493 written_time_last = written_time;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
494 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
495 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
496 else {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
497 file_info_.eof = true;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
498 xmms_usleep(10000);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
499 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
500 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
501 else
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
502 xmms_usleep(10000);
511
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
503 if(file_info_.seek_to_in_sec != -1) {
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
504 const double distance = (double)file_info_.seek_to_in_sec * 1000.0 / (double)file_info_.length_in_msec;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
505 unsigned target_sample = (unsigned)(distance * (double)file_info_.total_samples);
489
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
506 if(FLAC__seekable_stream_decoder_seek_absolute(decoder_, (FLAC__uint64)target_sample)) {
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
507 flac_ip.output->flush(file_info_.seek_to_in_sec * 1000);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
508 bh_index_last_w = bh_index_last_o = flac_ip.output->output_time() / BITRATE_HIST_SEGMENT_MSEC % BITRATE_HIST_SIZE;
489
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
509 if(!FLAC__seekable_stream_decoder_get_decode_position(decoder_, &decode_position_frame))
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
510 decode_position_frame = 0;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
511 file_info_.seek_to_in_sec = -1;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
512 file_info_.eof = false;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
513 sample_buffer_first_ = sample_buffer_last_ = 0;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
514 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
515 }
492
0dd1ff7e5ba7 [svn] flac 112 plugin: stability fixes and a new option to disable bitrate update in player window during playback (saves cpu, this is the solution for most people playing flac and reporting high cpu usage)
giacomo
parents: 490
diff changeset
516 else if ( !flac_cfg.title.disable_bitrate_update )
0dd1ff7e5ba7 [svn] flac 112 plugin: stability fixes and a new option to disable bitrate update in player window during playback (saves cpu, this is the solution for most people playing flac and reporting high cpu usage)
giacomo
parents: 490
diff changeset
517 {
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
518 /* display the right bitrate from history */
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
519 unsigned bh_index_o = flac_ip.output->output_time() / BITRATE_HIST_SEGMENT_MSEC % BITRATE_HIST_SIZE;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
520 if(bh_index_o != bh_index_last_o && bh_index_o != bh_index_last_w && bh_index_o != (bh_index_last_w + 1) % BITRATE_HIST_SIZE) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
521 bh_index_last_o = bh_index_o;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
522 flac_ip.set_info(file_info_.title, file_info_.length_in_msec, bitrate_history_[bh_index_o], file_info_.sample_rate, file_info_.channels);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
523 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
524 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
525 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
526
511
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
527 file_decoder_safe_decoder_finish_(decoder_);
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
528
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
529 /* are these two calls necessary? */
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
530 flac_ip.output->buffer_free();
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
531 flac_ip.output->buffer_free();
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
532
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
533 g_free(file_info_.title);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
534
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
535 g_thread_exit(NULL);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
536 return 0; /* to silence the compiler warning about not returning a value */
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
537 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
538
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
539 /*********** File decoder functions */
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
540
489
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
541 static FLAC__bool file_decoder_unset_source(void *decoder)
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
542 {
489
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
543 if ( file_info_.vfsfile != NULL )
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
544 {
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
545 vfs_fclose( file_info_.vfsfile );
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
546 file_info_.vfsfile = NULL;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
547 }
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
548 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
549
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
550 static void file_decoder_safe_decoder_finish_(void *decoder)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
551 {
489
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
552 file_decoder_unset_source(decoder);
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
553 if(decoder && FLAC__seekable_stream_decoder_get_state((FLAC__SeekableStreamDecoder *) decoder) != FLAC__SEEKABLE_STREAM_DECODER_UNINITIALIZED)
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
554 FLAC__seekable_stream_decoder_finish((FLAC__SeekableStreamDecoder *) decoder);
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
555 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
556
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
557 static void file_decoder_safe_decoder_delete_(void *decoder)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
558 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
559 if(decoder) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
560 file_decoder_safe_decoder_finish_(decoder);
489
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
561 FLAC__seekable_stream_decoder_delete( (FLAC__SeekableStreamDecoder *) decoder);
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
562 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
563 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
564
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
565 static FLAC__bool file_decoder_is_eof(void *decoder)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
566 {
489
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
567 return FLAC__seekable_stream_decoder_get_state((FLAC__SeekableStreamDecoder *) decoder) == FLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
568 }
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
569
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
570 static FLAC__bool file_decoder_set_source(void *decoder, const char *filename)
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
571 {
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
572 if ( ( file_info_.vfsfile = vfs_fopen( filename , "rb" ) ) == NULL )
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
573 return false;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
574 else
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
575 return true;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
576 }
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
577
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
578 static FLAC__SeekableStreamDecoderReadStatus file_decoder_read_callback (const FLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data)
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
579 {
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
580 file_info_struct *file_info = (file_info_struct *)client_data;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
581 (void) decoder;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
582
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
583 if( *bytes > 0 )
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
584 {
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
585 *bytes = vfs_fread( buffer , sizeof(FLAC__byte) , *bytes , file_info->vfsfile );
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
586 if ( *bytes == 0 )
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
587 return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
588 else
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
589 return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
590 }
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
591 else
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
592 return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
593 }
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
594
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
595 static FLAC__SeekableStreamDecoderSeekStatus file_decoder_seek_callback(const FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
596 {
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
597 file_info_struct *file_info = (file_info_struct *)client_data;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
598 (void) decoder;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
599
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
600 if ( vfs_fseek( file_info->vfsfile , (glong)absolute_byte_offset , SEEK_SET ) < 0 )
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
601 return FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
602 else
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
603 return FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
604 }
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
605
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
606 static FLAC__SeekableStreamDecoderTellStatus file_decoder_tell_callback(const FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
607 {
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
608 file_info_struct *file_info = (file_info_struct *)client_data;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
609 glong pos;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
610 (void)decoder;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
611
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
612 if ( (pos = vfs_ftell(file_info->vfsfile)) < 0 )
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
613 return FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
614 else
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
615 {
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
616 *absolute_byte_offset = (FLAC__uint64)pos;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
617 return FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
618 }
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
619 }
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
620
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
621 static FLAC__SeekableStreamDecoderLengthStatus file_decoder_length_callback(const FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
622 {
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
623 file_info_struct *file_info = (file_info_struct *)client_data;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
624 glong current_pos = 0;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
625 glong length = 0;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
626 (void)decoder;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
627
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
628 current_pos = vfs_ftell(file_info->vfsfile);
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
629 if ( current_pos < 0 )
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
630 return FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_ERROR;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
631
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
632 if ( vfs_fseek( file_info->vfsfile , 0 , SEEK_END ) < 0 )
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
633 return FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_ERROR;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
634
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
635 length = vfs_ftell(file_info->vfsfile);
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
636 if ( length < 0 )
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
637 return FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_ERROR;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
638
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
639 /* put back stream position */
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
640 if ( vfs_fseek( file_info->vfsfile , current_pos , SEEK_SET ) < 0 )
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
641 return FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_ERROR;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
642 else
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
643 {
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
644 *stream_length = (FLAC__uint64)length;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
645 return FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
646 }
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
647 }
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
648
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
649 static FLAC__bool file_decoder_eof_callback (const FLAC__SeekableStreamDecoder *decoder, void *client_data)
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
650 {
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
651 file_info_struct *file_info = (file_info_struct *)client_data;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
652 (void)decoder;
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
653
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
654 return vfs_feof( file_info->vfsfile );
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
655 }
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
656
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
657 static FLAC__bool file_decoder_init (void *decoder)
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
658 {
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
659 return FLAC__seekable_stream_decoder_init( (FLAC__SeekableStreamDecoder*) decoder) == FLAC__SEEKABLE_STREAM_DECODER_OK;
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
660 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
661
511
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
662 static decoder_t source_to_decoder_type (const char *source)
489
ce4efa148521 [svn] flac 112 plugin: playback and detection use vfs; current situation is pretty similar to the one of flac 113 plugin
giacomo
parents: 372
diff changeset
663 {
511
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
664 /* NOTE: in Audacious, always use DECODER_FILE to pick files via VFS */
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
665 return DECODER_FILE;
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
666 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
667
511
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
668 FLAC__bool safe_decoder_init_(const char *filename, void *decoder)
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
669 {
511
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
670 if(decoder == 0)
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
671 return false;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
672
511
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
673 file_decoder_safe_decoder_finish_(decoder);
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
674
511
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
675 file_decoder_set_source(decoder,filename);
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
676 FLAC__seekable_stream_decoder_set_md5_checking(decoder,false);
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
677 FLAC__seekable_stream_decoder_set_metadata_ignore_all(decoder);
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
678 FLAC__seekable_stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_STREAMINFO);
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
679 FLAC__seekable_stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT);
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
680 FLAC__seekable_stream_decoder_set_write_callback(decoder, write_callback_);
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
681 FLAC__seekable_stream_decoder_set_metadata_callback(decoder, metadata_callback_);
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
682 FLAC__seekable_stream_decoder_set_error_callback(decoder, error_callback_);
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
683 FLAC__seekable_stream_decoder_set_client_data(decoder, &file_info_);
512
5be9b8f7ac03 [svn] - flac 112 plugin: removed http.c and http.h, plus some fixes
giacomo
parents: 511
diff changeset
684 FLAC__seekable_stream_decoder_set_read_callback(decoder, file_decoder_read_callback);
5be9b8f7ac03 [svn] - flac 112 plugin: removed http.c and http.h, plus some fixes
giacomo
parents: 511
diff changeset
685 FLAC__seekable_stream_decoder_set_seek_callback(decoder, file_decoder_seek_callback);
5be9b8f7ac03 [svn] - flac 112 plugin: removed http.c and http.h, plus some fixes
giacomo
parents: 511
diff changeset
686 FLAC__seekable_stream_decoder_set_tell_callback(decoder, file_decoder_tell_callback);
5be9b8f7ac03 [svn] - flac 112 plugin: removed http.c and http.h, plus some fixes
giacomo
parents: 511
diff changeset
687 FLAC__seekable_stream_decoder_set_length_callback(decoder, file_decoder_length_callback);
5be9b8f7ac03 [svn] - flac 112 plugin: removed http.c and http.h, plus some fixes
giacomo
parents: 511
diff changeset
688 FLAC__seekable_stream_decoder_set_eof_callback(decoder, file_decoder_eof_callback);
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
689
511
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
690 if ( !file_decoder_init(decoder) )
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
691 {
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
692 file_decoder_unset_source(decoder);
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
693 return false;
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
694 }
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
695
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
696 if(!FLAC__seekable_stream_decoder_process_until_end_of_metadata(decoder))
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
697 {
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
698 file_decoder_unset_source(decoder);
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
699 return false;
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
700 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
701
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
702 return true;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
703 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
704
511
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
705 FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__SeekableStreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
706 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
707 file_info_struct *file_info = (file_info_struct *)client_data;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
708 const unsigned channels = file_info->channels, wide_samples = frame->header.blocksize;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
709 const unsigned bits_per_sample = file_info->bits_per_sample;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
710 FLAC__byte *sample_buffer_start;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
711
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
712 (void)decoder;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
713
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
714 if(file_info->abort_flag)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
715 return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
716
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
717 if((sample_buffer_last_ + wide_samples) > (SAMPLE_BUFFER_SIZE / (channels * file_info->sample_format_bytes_per_sample))) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
718 memmove(sample_buffer_, sample_buffer_ + sample_buffer_first_ * channels * file_info->sample_format_bytes_per_sample, (sample_buffer_last_ - sample_buffer_first_) * channels * file_info->sample_format_bytes_per_sample);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
719 sample_buffer_last_ -= sample_buffer_first_;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
720 sample_buffer_first_ = 0;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
721 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
722 sample_buffer_start = sample_buffer_ + sample_buffer_last_ * channels * file_info->sample_format_bytes_per_sample;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
723 if(file_info->has_replaygain && flac_cfg.output.replaygain.enable) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
724 FLAC__replaygain_synthesis__apply_gain(
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
725 sample_buffer_start,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
726 !is_big_endian_host_,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
727 file_info->sample_format_bytes_per_sample == 1, /* unsigned_data_out */
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
728 buffer,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
729 wide_samples,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
730 channels,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
731 bits_per_sample,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
732 file_info->sample_format_bytes_per_sample * 8,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
733 file_info->replay_scale,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
734 flac_cfg.output.replaygain.hard_limit,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
735 flac_cfg.output.resolution.replaygain.dither,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
736 &file_info->dither_context
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
737 );
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
738 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
739 else if(is_big_endian_host_) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
740 FLAC__plugin_common__pack_pcm_signed_big_endian(
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
741 sample_buffer_start,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
742 buffer,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
743 wide_samples,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
744 channels,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
745 bits_per_sample,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
746 file_info->sample_format_bytes_per_sample * 8
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
747 );
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
748 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
749 else {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
750 FLAC__plugin_common__pack_pcm_signed_little_endian(
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
751 sample_buffer_start,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
752 buffer,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
753 wide_samples,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
754 channels,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
755 bits_per_sample,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
756 file_info->sample_format_bytes_per_sample * 8
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
757 );
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
758 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
759
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
760 sample_buffer_last_ += wide_samples;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
761
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
762 return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
763 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
764
511
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
765 void metadata_callback_(const FLAC__SeekableStreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
766 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
767 file_info_struct *file_info = (file_info_struct *)client_data;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
768 (void)decoder;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
769 if(metadata->type == FLAC__METADATA_TYPE_STREAMINFO) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
770 FLAC__ASSERT(metadata->data.stream_info.total_samples < FLAC__U64L(0x100000000)); /* this plugin can only handle < 4 gigasamples */
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
771 file_info->total_samples = (unsigned)(metadata->data.stream_info.total_samples&0xffffffff);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
772 file_info->bits_per_sample = metadata->data.stream_info.bits_per_sample;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
773 file_info->channels = metadata->data.stream_info.channels;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
774 file_info->sample_rate = metadata->data.stream_info.sample_rate;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
775 file_info->length_in_msec = (unsigned)((double)file_info->total_samples / (double)file_info->sample_rate * 1000.0 + 0.5);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
776 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
777 else if(metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
778 double gain, peak;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
779 if(grabbag__replaygain_load_from_vorbiscomment(metadata, flac_cfg.output.replaygain.album_mode, &gain, &peak)) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
780 file_info->has_replaygain = true;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
781 file_info->replay_scale = grabbag__replaygain_compute_scale_factor(peak, gain, (double)flac_cfg.output.replaygain.preamp, /*prevent_clipping=*/!flac_cfg.output.replaygain.hard_limit);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
782 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
783 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
784 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
785
511
5f2145032f46 [svn] - removed http code from flac 112 plugin; still have to remove http options from gui
giacomo
parents: 492
diff changeset
786 void error_callback_(const FLAC__SeekableStreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
787 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
788 file_info_struct *file_info = (file_info_struct *)client_data;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
789 (void)decoder;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
790 if(status != FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
791 file_info->abort_flag = true;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
792 }