annotate src/flac112/plugin.c @ 468:2e4d10f3f9cb trunk

[svn] - always make sure the returned data is strdup'd
author nenolod
date Sun, 21 Jan 2007 01:55:08 -0800
parents a157306caf03
children ce4efa148521
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
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
27 #include "audacious/plugin.h"
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
28 #include "audacious/output.h"
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
29 #include "audacious/util.h"
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
30 #include "audacious/configdb.h"
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
31 #include "audacious/titlestring.h"
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
32 #include "audacious/vfs.h"
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 "http.h"
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
49 #include "tag.h"
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
50
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
51 #ifdef min
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
52 #undef min
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
53 #endif
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
54 #define min(x,y) ((x)<(y)?(x):(y))
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
55
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
56 /* 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
57 #ifdef _MSC_VER
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
58 #define FLAC__U64L(x) x
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
59 #else
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
60 #define FLAC__U64L(x) x##LLU
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
61 #endif
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
62
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
63 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
64
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
65 typedef struct {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
66 FLAC__bool abort_flag;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
67 FLAC__bool is_playing;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
68 FLAC__bool eof;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
69 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
70 unsigned total_samples;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
71 unsigned bits_per_sample;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
72 unsigned channels;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
73 unsigned sample_rate;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
74 unsigned length_in_msec;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
75 gchar *title;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
76 AFormat sample_format;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
77 unsigned sample_format_bytes_per_sample;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
78 int seek_to_in_sec;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
79 FLAC__bool has_replaygain;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
80 double replay_scale;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
81 DitherContext dither_context;
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
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
88 typedef struct {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
89 FLAC__bool seekable;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
90 void* (*new_decoder) (void);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
91 FLAC__bool (*set_md5_checking) (void *decoder, FLAC__bool value);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
92 FLAC__bool (*set_source) (void *decoder, const char* source);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
93 FLAC__bool (*set_metadata_ignore_all) (void *decoder);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
94 FLAC__bool (*set_metadata_respond) (void *decoder, FLAC__MetadataType type);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
95 FLAC__bool (*set_write_callback) (void *decoder, WriteCallback value);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
96 FLAC__bool (*set_metadata_callback) (void *decoder, MetadataCallback value);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
97 FLAC__bool (*set_error_callback) (void *decoder, ErrorCallback value);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
98 FLAC__bool (*set_client_data) (void *decoder, void *value);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
99 FLAC__bool (*decoder_init) (void *decoder);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
100 void (*safe_decoder_finish) (void *decoder);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
101 void (*safe_decoder_delete) (void *decoder);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
102 FLAC__bool (*process_until_end_of_metadata) (void *decoder);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
103 FLAC__bool (*process_single) (void *decoder);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
104 FLAC__bool (*is_eof) (void *decoder);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
105 } decoder_funcs_t;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
106
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
107 #define NUM_DECODER_TYPES 2
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
108 typedef enum {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
109 DECODER_FILE,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
110 DECODER_HTTP
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
111 } decoder_t;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
112
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
113 static void FLAC_XMMS__init();
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
114 static int FLAC_XMMS__is_our_file(char *filename);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
115 static void FLAC_XMMS__play_file(char *filename);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
116 static void FLAC_XMMS__stop();
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
117 static void FLAC_XMMS__pause(short p);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
118 static void FLAC_XMMS__seek(int time);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
119 static int FLAC_XMMS__get_time();
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
120 static void FLAC_XMMS__cleanup();
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
121 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
122
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
123 static void *play_loop_(void *arg);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
124
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
125 static FLAC__bool safe_decoder_init_(const char *filename, void **decoderp, decoder_funcs_t const ** fnsp);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
126 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
127 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
128 static FLAC__StreamDecoderWriteStatus write_callback_(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
129 static void metadata_callback_(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
130 static void error_callback_(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
131
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
132 static void init_decoder_func_tables();
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
133 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
134
372
a157306caf03 [svn] - finalize the plugin-side of the extension-assist ABI
nenolod
parents: 368
diff changeset
135 gchar *flac_fmts[] = { "flac", NULL };
a157306caf03 [svn] - finalize the plugin-side of the extension-assist ABI
nenolod
parents: 368
diff changeset
136
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
137 InputPlugin flac_ip =
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
138 {
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 NULL,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
142 FLAC_XMMS__init,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
143 FLAC_XMMS__aboutbox,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
144 FLAC_XMMS__configure,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
145 FLAC_XMMS__is_our_file,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
146 NULL,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
147 FLAC_XMMS__play_file,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
148 FLAC_XMMS__stop,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
149 FLAC_XMMS__pause,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
150 FLAC_XMMS__seek,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
151 NULL,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
152 FLAC_XMMS__get_time,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
153 NULL,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
154 NULL,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
155 FLAC_XMMS__cleanup,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
156 NULL,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
157 NULL,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
158 NULL,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
159 NULL,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
160 FLAC_XMMS__get_song_info,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
161 FLAC_XMMS__file_info_box,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
162 NULL,
372
a157306caf03 [svn] - finalize the plugin-side of the extension-assist ABI
nenolod
parents: 368
diff changeset
163 flac_get_tuple,
a157306caf03 [svn] - finalize the plugin-side of the extension-assist ABI
nenolod
parents: 368
diff changeset
164 NULL, // set tuple
368
c812e846b84e [svn] - add support for extension probing to many plugins.
nenolod
parents: 207
diff changeset
165 NULL,
372
a157306caf03 [svn] - finalize the plugin-side of the extension-assist ABI
nenolod
parents: 368
diff changeset
166 NULL,
a157306caf03 [svn] - finalize the plugin-side of the extension-assist ABI
nenolod
parents: 368
diff changeset
167 flac_fmts,
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
168 };
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 #define SAMPLES_PER_WRITE 512
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
171 #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
172 static FLAC__byte sample_buffer_[SAMPLE_BUFFER_SIZE];
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
173 static unsigned sample_buffer_first_, sample_buffer_last_;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
174
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
175 static void *decoder_ = 0, *decoder2 = 0;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
176 static file_info_struct file_info_;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
177 static GThread *decode_thread_;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
178 static FLAC__bool audio_error_ = false;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
179 static FLAC__bool is_big_endian_host_;
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 #define BITRATE_HIST_SEGMENT_MSEC 500
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
182 /* 500ms * 50 = 25s should be enough */
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
183 #define BITRATE_HIST_SIZE 50
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
184 static unsigned bitrate_history_[BITRATE_HIST_SIZE];
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
185
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
186 /* A table of sets of decoder functions, indexed by decoder_t */
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
187 static const decoder_funcs_t* DECODER_FUNCS[NUM_DECODER_TYPES];
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
188
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
189 static decoder_funcs_t const * decoder_func_table_, * decoder_func_table2;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
190
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
191
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
192 InputPlugin *get_iplugin_info()
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
193 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
194 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
195 return &flac_ip;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
196 }
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 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
199 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
200 if (file_info_.is_playing) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
201 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
202 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
203 }
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 static gchar* homedir()
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 gchar *result;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
208 char *env_home = getenv("HOME");
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
209 if (env_home) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
210 result = g_strdup (env_home);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
211 } else {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
212 uid_t uid = getuid();
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
213 struct passwd *pwent;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
214 do {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
215 pwent = getpwent();
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
216 } while (pwent && pwent->pw_uid != uid);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
217 result = pwent ? g_strdup (pwent->pw_dir) : NULL;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
218 endpwent();
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 return result;
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
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
223 void FLAC_XMMS__init()
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 ConfigDb *db;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
226 FLAC__uint32 test = 1;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
227 gchar *tmp = NULL;
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 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
230
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
231 memset(&flac_cfg, 0, sizeof(flac_cfg));
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
232
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
233 db = bmp_cfg_db_open();
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
234
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
235 /* title */
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
236
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
237 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
238
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
239 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
240 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
241
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
242 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
243
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
244 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
245 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
246
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
247 /* replaygain */
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
248
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
249 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
250
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
251 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
252
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
253 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
254 flac_cfg.output.replaygain.preamp = 0;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
255
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
256 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
257
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
258 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
259 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
260
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
261 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
262 flac_cfg.output.resolution.replaygain.noise_shaping = 1;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
263
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
264 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
265 flac_cfg.output.resolution.replaygain.bps_out = 16;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
266
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
267 /* stream */
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
268
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
269 bmp_cfg_db_get_int(db, "flac", "stream.http_buffer_size", &flac_cfg.stream.http_buffer_size);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
270 bmp_cfg_db_get_int(db, "flac", "stream.http_prebuffer", &flac_cfg.stream.http_prebuffer);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
271 bmp_cfg_db_get_bool(db, "flac", "stream.save_http_stream", &flac_cfg.stream.save_http_stream);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
272 if (!bmp_cfg_db_get_string(db, "flac", "stream.save_http_path", &flac_cfg.stream.save_http_path) ||
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
273 ! *flac_cfg.stream.save_http_path) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
274 /* TODO: Is this a memory leak ?? */
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
275 /*
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
276 if (flac_cfg.stream.save_http_path)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
277 g_free (flac_cfg.stream.save_http_path);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
278 */
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
279 flac_cfg.stream.save_http_path = homedir();
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
280 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
281 bmp_cfg_db_get_bool(db, "flac", "stream.cast_title_streaming", &flac_cfg.stream.cast_title_streaming);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
282 bmp_cfg_db_get_bool(db, "flac", "stream.use_udp_channel", &flac_cfg.stream.use_udp_channel);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
283
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
284 init_decoder_func_tables();
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
285 decoder_func_table_ = DECODER_FUNCS [DECODER_FILE];
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
286 decoder_ = decoder_func_table_ -> new_decoder();
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
287
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
288 bmp_cfg_db_get_bool(db, NULL, "use_proxy", &flac_cfg.stream.use_proxy);
207
063e31ae8f92 [svn] Properly zero out proxy configuration strings if no value is retrieved, otherwise we crash and burn on shutdown.
chainsaw
parents: 104
diff changeset
289 if(!bmp_cfg_db_get_string(db, NULL, "proxy_host", &flac_cfg.stream.proxy_host))
063e31ae8f92 [svn] Properly zero out proxy configuration strings if no value is retrieved, otherwise we crash and burn on shutdown.
chainsaw
parents: 104
diff changeset
290 flac_cfg.stream.proxy_host = NULL;
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
291 bmp_cfg_db_get_string(db, NULL, "proxy_port", &tmp);
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 (tmp != NULL)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
294 flac_cfg.stream.proxy_port = atoi(tmp);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
295
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
296 bmp_cfg_db_get_bool(db, NULL, "proxy_use_auth", &flac_cfg.stream.proxy_use_auth);
207
063e31ae8f92 [svn] Properly zero out proxy configuration strings if no value is retrieved, otherwise we crash and burn on shutdown.
chainsaw
parents: 104
diff changeset
297 if(!bmp_cfg_db_get_string(db, NULL, "proxy_user", &flac_cfg.stream.proxy_user))
063e31ae8f92 [svn] Properly zero out proxy configuration strings if no value is retrieved, otherwise we crash and burn on shutdown.
chainsaw
parents: 104
diff changeset
298 flac_cfg.stream.proxy_user = NULL;
063e31ae8f92 [svn] Properly zero out proxy configuration strings if no value is retrieved, otherwise we crash and burn on shutdown.
chainsaw
parents: 104
diff changeset
299 if(!bmp_cfg_db_get_string(db, NULL, "proxy_pass", &flac_cfg.stream.proxy_pass))
063e31ae8f92 [svn] Properly zero out proxy configuration strings if no value is retrieved, otherwise we crash and burn on shutdown.
chainsaw
parents: 104
diff changeset
300 flac_cfg.stream.proxy_pass = NULL;
104
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
301
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
302 bmp_cfg_db_close(db);
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
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
305 int FLAC_XMMS__is_our_file(char *filename)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
306 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
307 FILE *f;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
308 FLAC__StreamMetadata streaminfo;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
309
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
310 if (source_to_decoder_type (filename) == DECODER_FILE) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
311 if(0 == (f = fopen(filename, "r")))
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
312 return 0;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
313 fclose(f);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
314 if(!FLAC__metadata_get_streaminfo(filename, &streaminfo))
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
315 return 0;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
316 return 1;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
317 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
318
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
319 if(!safe_decoder_init_(filename, &decoder2, &decoder_func_table2))
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
320 return 0;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
321
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
322 decoder_func_table2 -> safe_decoder_finish(decoder2);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
323 return 1;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
324 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
325
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
326 void FLAC_XMMS__play_file(char *filename)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
327 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
328 FILE *f;
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 sample_buffer_first_ = sample_buffer_last_ = 0;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
331 audio_error_ = false;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
332 file_info_.abort_flag = false;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
333 file_info_.is_playing = false;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
334 file_info_.eof = false;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
335 file_info_.play_thread_open = false;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
336 file_info_.has_replaygain = false;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
337
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
338 if (source_to_decoder_type (filename) == DECODER_FILE) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
339 if(0 == (f = fopen(filename, "r")))
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
340 return;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
341 fclose(f);
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
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
344 if(decoder_ == 0)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
345 return;
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 if(!safe_decoder_init_(filename, &decoder_, &decoder_func_table_))
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
348 return;
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_.has_replaygain && flac_cfg.output.replaygain.enable) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
351 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
352 file_info_.sample_format = FMT_U8;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
353 file_info_.sample_format_bytes_per_sample = 1;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
354 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
355 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
356 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
357 file_info_.sample_format_bytes_per_sample = 2;
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 else {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
360 /*@@@ 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
361 fprintf(stderr, "libxmms-flac: can't handle %d bit output\n", flac_cfg.output.resolution.replaygain.bps_out);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
362 decoder_func_table_ -> safe_decoder_finish(decoder_);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
363 return;
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 else {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
367 if(file_info_.bits_per_sample == 8) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
368 file_info_.sample_format = FMT_U8;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
369 file_info_.sample_format_bytes_per_sample = 1;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
370 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
371 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
372 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
373 file_info_.sample_format_bytes_per_sample = 2;
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 else {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
376 /*@@@ 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
377 fprintf(stderr, "libxmms-flac: can't handle %d bit output\n", file_info_.bits_per_sample);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
378 decoder_func_table_ -> safe_decoder_finish(decoder_);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
379 return;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
380 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
381 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
382 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
383 file_info_.is_playing = true;
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 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
386 audio_error_ = true;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
387 decoder_func_table_ -> safe_decoder_finish(decoder_);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
388 return;
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
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
391 file_info_.title = flac_format_song_title(filename);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
392 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
393
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
394 file_info_.seek_to_in_sec = -1;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
395 file_info_.play_thread_open = true;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
396 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
397 }
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 void FLAC_XMMS__stop()
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
400 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
401 if(file_info_.is_playing) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
402 file_info_.is_playing = false;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
403 if(file_info_.play_thread_open) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
404 file_info_.play_thread_open = false;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
405 g_thread_join(decode_thread_);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
406 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
407 flac_ip.output->close_audio();
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
408 decoder_func_table_ -> safe_decoder_finish (decoder_);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
409 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
410 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
411
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
412 void FLAC_XMMS__pause(short p)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
413 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
414 flac_ip.output->pause(p);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
415 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
416
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
417 void FLAC_XMMS__seek(int time)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
418 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
419 if (decoder_func_table_->seekable) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
420 file_info_.seek_to_in_sec = time;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
421 file_info_.eof = false;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
422
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
423 while(file_info_.seek_to_in_sec != -1)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
424 xmms_usleep(10000);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
425 }
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
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
428 int FLAC_XMMS__get_time()
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(audio_error_)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
431 return -2;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
432 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
433 return -1;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
434 else
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
435 return flac_ip.output->output_time();
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
436 }
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 void FLAC_XMMS__cleanup()
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
439 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
440 g_free(flac_ip.description);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
441 flac_ip.description = NULL;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
442
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
443 if (flac_cfg.title.tag_format) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
444 free(flac_cfg.title.tag_format);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
445 flac_cfg.title.tag_format = NULL;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
446 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
447
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
448 if (flac_cfg.title.user_char_set) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
449 free(flac_cfg.title.user_char_set);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
450 flac_cfg.title.user_char_set = NULL;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
451 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
452
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
453 if (flac_cfg.stream.proxy_host) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
454 free(flac_cfg.stream.proxy_host);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
455 flac_cfg.stream.proxy_host = NULL;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
456 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
457
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
458 if (flac_cfg.stream.proxy_user) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
459 free(flac_cfg.stream.proxy_user);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
460 flac_cfg.stream.proxy_user = NULL;
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 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
463
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
464 if (flac_cfg.stream.proxy_pass) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
465 free(flac_cfg.stream.proxy_pass);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
466 flac_cfg.stream.proxy_pass = NULL;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
467 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
468
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
469 decoder_func_table_ -> safe_decoder_delete(decoder_);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
470 decoder_ = 0;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
471 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
472
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
473 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
474 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
475 FLAC__StreamMetadata streaminfo;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
476
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
477 if(0 == filename)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
478 filename = "";
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
479
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
480 if(!FLAC__metadata_get_streaminfo(filename, &streaminfo)) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
481 /* @@@ how to report the error? */
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
482 if(title) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
483 if (source_to_decoder_type (filename) == DECODER_FILE) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
484 static const char *errtitle = "Invalid FLAC File: ";
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
485 *title = g_malloc(strlen(errtitle) + 1 + strlen(filename) + 1 + 1);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
486 sprintf(*title, "%s\"%s\"", errtitle, filename);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
487 } else {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
488 *title = NULL;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
489 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
490 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
491 if(length_in_msec)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
492 *length_in_msec = -1;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
493 return;
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 if(title) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
497 *title = flac_format_song_title(filename);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
498 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
499 if(length_in_msec)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
500 *length_in_msec = (unsigned)((double)streaminfo.data.stream_info.total_samples / (double)streaminfo.data.stream_info.sample_rate * 1000.0 + 0.5);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
501 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
502
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
503 /***********************************************************************
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
504 * local routines
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
505 **********************************************************************/
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
506
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
507 void *play_loop_(void *arg)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
508 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
509 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
510 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
511
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
512 (void)arg;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
513
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
514 while(file_info_.is_playing) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
515 if(!file_info_.eof) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
516 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
517 unsigned s;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
518
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
519 s = sample_buffer_last_ - sample_buffer_first_;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
520 if(decoder_func_table_ -> is_eof(decoder_)) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
521 file_info_.eof = true;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
522 break;
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 else if (!decoder_func_table_ -> process_single(decoder_)) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
525 /*@@@ this should probably be a dialog */
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
526 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
527 file_info_.eof = true;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
528 break;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
529 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
530 blocksize = sample_buffer_last_ - sample_buffer_first_ - s;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
531 decode_position_frame_last = decode_position_frame;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
532 if(!decoder_func_table_->seekable || !FLAC__file_decoder_get_decode_position(decoder_, &decode_position_frame))
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
533 decode_position_frame = 0;
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 if(sample_buffer_last_ - sample_buffer_first_ > 0) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
536 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
537 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
538 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
539 unsigned written_time, bh_index_w;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
540 FLAC__uint64 decode_position;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
541
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
542 sample_buffer_first_ += n;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
543 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
544 xmms_usleep(10000);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
545 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
546 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
547 file_info_.channels, bytes, sample_buffer_start, NULL);
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 /* compute current bitrate */
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
550
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
551 written_time = flac_ip.output->written_time();
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
552 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
553 if(bh_index_w != bh_index_last_w) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
554 bh_index_last_w = bh_index_w;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
555 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
556 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
557 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
558 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
559 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
560 decode_position_last = decode_position;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
561 written_time_last = written_time;
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 else {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
565 file_info_.eof = true;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
566 xmms_usleep(10000);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
567 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
568 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
569 else
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
570 xmms_usleep(10000);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
571 if(decoder_func_table_->seekable && file_info_.seek_to_in_sec != -1) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
572 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
573 unsigned target_sample = (unsigned)(distance * (double)file_info_.total_samples);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
574 if(FLAC__file_decoder_seek_absolute(decoder_, (FLAC__uint64)target_sample)) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
575 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
576 bh_index_last_w = bh_index_last_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
577 if(!FLAC__file_decoder_get_decode_position(decoder_, &decode_position_frame))
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
578 decode_position_frame = 0;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
579 file_info_.seek_to_in_sec = -1;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
580 file_info_.eof = false;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
581 sample_buffer_first_ = sample_buffer_last_ = 0;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
582 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
583 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
584 else {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
585 /* display the right bitrate from history */
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
586 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
587 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
588 bh_index_last_o = bh_index_o;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
589 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
590 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
591 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
592 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
593
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
594 decoder_func_table_ -> safe_decoder_finish(decoder_);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
595
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
596 /* are these two calls necessary? */
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
597 flac_ip.output->buffer_free();
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
598 flac_ip.output->buffer_free();
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
599
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
600 g_free(file_info_.title);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
601
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
602 g_thread_exit(NULL);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
603 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
604 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
605
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
606 /*********** File decoder functions */
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
607
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
608 static FLAC__bool file_decoder_init (void *decoder)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
609 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
610 return FLAC__file_decoder_init( (FLAC__FileDecoder*) decoder) == FLAC__FILE_DECODER_OK;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
611 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
612
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
613 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
614 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
615 if(decoder && FLAC__file_decoder_get_state((FLAC__FileDecoder *) decoder) != FLAC__FILE_DECODER_UNINITIALIZED)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
616 FLAC__file_decoder_finish((FLAC__FileDecoder *) decoder);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
617 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
618
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
619 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
620 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
621 if(decoder) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
622 file_decoder_safe_decoder_finish_(decoder);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
623 FLAC__file_decoder_delete( (FLAC__FileDecoder *) decoder);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
624 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
625 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
626
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
627 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
628 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
629 return FLAC__file_decoder_get_state((FLAC__FileDecoder *) decoder) == FLAC__FILE_DECODER_END_OF_FILE;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
630 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
631
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
632 static const decoder_funcs_t FILE_DECODER_FUNCTIONS = {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
633 true,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
634 (void* (*) (void)) FLAC__file_decoder_new,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
635 (FLAC__bool (*) (void *, FLAC__bool)) FLAC__file_decoder_set_md5_checking,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
636 (FLAC__bool (*) (void *, const char*)) FLAC__file_decoder_set_filename,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
637 (FLAC__bool (*) (void *)) FLAC__file_decoder_set_metadata_ignore_all,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
638 (FLAC__bool (*) (void *, FLAC__MetadataType)) FLAC__file_decoder_set_metadata_respond,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
639 (FLAC__bool (*) (void *, WriteCallback)) FLAC__file_decoder_set_write_callback,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
640 (FLAC__bool (*) (void *, MetadataCallback)) FLAC__file_decoder_set_metadata_callback,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
641 (FLAC__bool (*) (void *, ErrorCallback)) FLAC__file_decoder_set_error_callback,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
642 (FLAC__bool (*) (void *, void *)) FLAC__file_decoder_set_client_data,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
643 (FLAC__bool (*) (void *)) file_decoder_init,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
644 (void (*) (void *)) file_decoder_safe_decoder_finish_,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
645 (void (*) (void *)) file_decoder_safe_decoder_delete_,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
646 (FLAC__bool (*) (void *)) FLAC__file_decoder_process_until_end_of_metadata,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
647 (FLAC__bool (*) (void *)) FLAC__file_decoder_process_single,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
648 file_decoder_is_eof
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
649 };
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
650
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
651 /*********** HTTP decoder functions */
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
652
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
653 static gchar *url_;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
654
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
655 static FLAC__bool http_decoder_set_md5_checking (void *decoder, FLAC__bool value)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
656 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
657 (void) value;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
658 // operation unsupported
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
659 return FLAC__stream_decoder_get_state ((const FLAC__StreamDecoder *) decoder) ==
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
660 FLAC__STREAM_DECODER_UNINITIALIZED;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
661 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
662
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
663 static FLAC__bool http_decoder_set_url (void *decoder, const char* url)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
664 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
665 (void) decoder;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
666 url_ = g_strdup (url);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
667 return true;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
668 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
669
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
670 static FLAC__StreamDecoderReadStatus http_decoder_read_callback (const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
671 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
672 (void) decoder;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
673 (void) client_data;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
674 *bytes = flac_http_read (buffer, *bytes);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
675 return *bytes ? FLAC__STREAM_DECODER_READ_STATUS_CONTINUE : FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
676 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
677
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
678 static FLAC__bool http_decoder_init (void *decoder)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
679 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
680 flac_http_open (url_, 0);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
681 g_free (url_);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
682 FLAC__stream_decoder_set_read_callback (decoder, http_decoder_read_callback);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
683 return FLAC__stream_decoder_init( (FLAC__StreamDecoder*) decoder) == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
684 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
685
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
686 static void http_decoder_safe_decoder_finish_(void *decoder)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
687 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
688 if(decoder && FLAC__stream_decoder_get_state((FLAC__StreamDecoder *) decoder) != FLAC__STREAM_DECODER_UNINITIALIZED) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
689 FLAC__stream_decoder_finish((FLAC__StreamDecoder *) decoder);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
690 flac_http_close();
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
691 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
692 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
693
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
694 static void http_decoder_safe_decoder_delete_(void *decoder)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
695 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
696 if(decoder) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
697 http_decoder_safe_decoder_finish_(decoder);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
698 FLAC__stream_decoder_delete( (FLAC__StreamDecoder *) decoder);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
699 }
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 static FLAC__bool http_decoder_is_eof(void *decoder)
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 return FLAC__stream_decoder_get_state((FLAC__StreamDecoder *) decoder) == FLAC__STREAM_DECODER_END_OF_STREAM;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
705 }
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 static const decoder_funcs_t HTTP_DECODER_FUNCTIONS = {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
708 false,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
709 (void* (*) (void)) FLAC__stream_decoder_new,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
710 http_decoder_set_md5_checking,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
711 (FLAC__bool (*) (void *, const char*)) http_decoder_set_url,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
712 (FLAC__bool (*) (void *)) FLAC__stream_decoder_set_metadata_ignore_all,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
713 (FLAC__bool (*) (void *, FLAC__MetadataType)) FLAC__stream_decoder_set_metadata_respond,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
714 (FLAC__bool (*) (void *, WriteCallback)) FLAC__stream_decoder_set_write_callback,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
715 (FLAC__bool (*) (void *, MetadataCallback)) FLAC__stream_decoder_set_metadata_callback,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
716 (FLAC__bool (*) (void *, ErrorCallback)) FLAC__stream_decoder_set_error_callback,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
717 (FLAC__bool (*) (void *, void *)) FLAC__stream_decoder_set_client_data,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
718 (FLAC__bool (*) (void *)) http_decoder_init,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
719 (void (*) (void *)) http_decoder_safe_decoder_finish_,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
720 (void (*) (void *)) http_decoder_safe_decoder_delete_,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
721 (FLAC__bool (*) (void *)) FLAC__stream_decoder_process_until_end_of_metadata,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
722 (FLAC__bool (*) (void *)) FLAC__stream_decoder_process_single,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
723 http_decoder_is_eof
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
724 };
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
725
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
726 static decoder_funcs_t const *decoder_func_table_;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
727
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
728 static void init_decoder_func_tables()
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
729 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
730 DECODER_FUNCS [DECODER_FILE] = & FILE_DECODER_FUNCTIONS;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
731 DECODER_FUNCS [DECODER_HTTP] = & HTTP_DECODER_FUNCTIONS;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
732 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
733
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
734 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
735 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
736 return strncasecmp(source, "http://", 7) ? DECODER_FILE : DECODER_HTTP;
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 static void change_decoder_if_needed (decoder_t new_decoder_type, void **decoderp, decoder_funcs_t const ** fntabp)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
740 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
741 const decoder_funcs_t *new_fn_table = DECODER_FUNCS [new_decoder_type];
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
742 if (*fntabp != new_fn_table) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
743 (*fntabp)->safe_decoder_delete(*decoderp);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
744 *fntabp = new_fn_table;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
745 *decoderp = new_fn_table -> new_decoder();
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
746 }
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 FLAC__bool safe_decoder_init_(const char *filename, void **decoderp, decoder_funcs_t const ** fntabp)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
750 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
751 if(decoderp == 0 || *decoderp == 0)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
752 return false;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
753
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
754 (*fntabp)->safe_decoder_finish(*decoderp);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
755
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
756 change_decoder_if_needed(source_to_decoder_type(filename), decoderp, fntabp);
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 decoder_funcs_t const *fntab = *fntabp;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
760 void *decoder = *decoderp;
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 decoder = *decoderp;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
763 fntab = *fntabp;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
764
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
765 fntab -> set_md5_checking(decoder, false);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
766 fntab -> set_source(decoder, filename);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
767 fntab -> set_metadata_ignore_all(decoder);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
768 fntab -> set_metadata_respond(decoder, FLAC__METADATA_TYPE_STREAMINFO);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
769 fntab -> set_metadata_respond(decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
770 fntab -> set_write_callback(decoder, write_callback_);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
771 fntab -> set_metadata_callback(decoder, metadata_callback_);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
772 fntab -> set_error_callback(decoder, error_callback_);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
773 fntab -> set_client_data(decoder, &file_info_);
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
774 if(!fntab -> decoder_init(decoder))
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
775 return false;
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 if(!fntab -> process_until_end_of_metadata(decoder))
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
778 return false;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
779 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
780
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
781 return true;
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 FLAC__StreamDecoderWriteStatus write_callback_(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
785 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
786 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
787 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
788 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
789 FLAC__byte *sample_buffer_start;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
790
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
791 (void)decoder;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
792
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
793 if(file_info->abort_flag)
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
794 return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
795
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
796 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
797 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
798 sample_buffer_last_ -= sample_buffer_first_;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
799 sample_buffer_first_ = 0;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
800 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
801 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
802 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
803 FLAC__replaygain_synthesis__apply_gain(
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
804 sample_buffer_start,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
805 !is_big_endian_host_,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
806 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
807 buffer,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
808 wide_samples,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
809 channels,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
810 bits_per_sample,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
811 file_info->sample_format_bytes_per_sample * 8,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
812 file_info->replay_scale,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
813 flac_cfg.output.replaygain.hard_limit,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
814 flac_cfg.output.resolution.replaygain.dither,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
815 &file_info->dither_context
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
816 );
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
817 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
818 else if(is_big_endian_host_) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
819 FLAC__plugin_common__pack_pcm_signed_big_endian(
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
820 sample_buffer_start,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
821 buffer,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
822 wide_samples,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
823 channels,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
824 bits_per_sample,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
825 file_info->sample_format_bytes_per_sample * 8
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
826 );
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
827 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
828 else {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
829 FLAC__plugin_common__pack_pcm_signed_little_endian(
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
830 sample_buffer_start,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
831 buffer,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
832 wide_samples,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
833 channels,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
834 bits_per_sample,
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
835 file_info->sample_format_bytes_per_sample * 8
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
836 );
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
837 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
838
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
839 sample_buffer_last_ += wide_samples;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
840
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
841 return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
842 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
843
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
844 void metadata_callback_(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
845 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
846 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
847 (void)decoder;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
848 if(metadata->type == FLAC__METADATA_TYPE_STREAMINFO) {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
849 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
850 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
851 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
852 file_info->channels = metadata->data.stream_info.channels;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
853 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
854 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
855 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
856 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
857 double gain, peak;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
858 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
859 file_info->has_replaygain = true;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
860 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
861 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
862 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
863 }
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
864
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
865 void error_callback_(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
866 {
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
867 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
868 (void)decoder;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
869 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
870 file_info->abort_flag = true;
4b31176c198a [svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff changeset
871 }