changeset 511:5f2145032f46 trunk

[svn] - removed http code from flac 112 plugin; still have to remove http options from gui
author giacomo
date Mon, 22 Jan 2007 08:27:39 -0800
parents 48e9efba7eb0
children 5be9b8f7ac03
files ChangeLog src/flac112/Makefile src/flac112/fileinfo.c src/flac112/plugin.c
diffstat 4 files changed, 60 insertions(+), 220 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Jan 22 06:19:50 2007 -0800
+++ b/ChangeLog	Mon Jan 22 08:27:39 2007 -0800
@@ -1,3 +1,10 @@
+2007-01-22 14:19:50 +0000  Giacomo Lozito <james@develia.org>
+  revision [1106]
+  - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
+  trunk/src/curl/curl.c |  154 +++++++++++++++++++-------------------------------
+  1 file changed, 61 insertions(+), 93 deletions(-)
+
+
 2007-01-22 13:15:36 +0000  William Pitcock <nenolod@sacredspiral.co.uk>
   revision [1104]
   - add japanese translation from dai
--- a/src/flac112/Makefile	Mon Jan 22 06:19:50 2007 -0800
+++ b/src/flac112/Makefile	Mon Jan 22 08:27:39 2007 -0800
@@ -6,7 +6,6 @@
 noinst_HEADERS = \
 	charset.h \
 	configure.h \
-	http.h \
 	plugin.h \
 	tag.h \
 	fast_float_math_hack.h \
@@ -24,7 +23,6 @@
 	charset.c \
 	configure.c \
 	fileinfo.c \
-	http.c \
 	plugin.c \
 	tag.c \
 	replaygain_synthesis.c \
--- a/src/flac112/fileinfo.c	Mon Jan 22 06:19:50 2007 -0800
+++ b/src/flac112/fileinfo.c	Mon Jan 22 08:27:39 2007 -0800
@@ -26,7 +26,7 @@
 #include <stdarg.h>
 #include <gtk/gtk.h>
 
-#include "audacious/util.h"
+#include <audacious/util.h>
 #include "FLAC/metadata.h"
 #include "charset.h"
 #include "configure.h"
@@ -411,7 +411,7 @@
 	if(!(current_filename = g_strdup(filename)))
 		return;
 
-	filename_utf8 = filename_to_utf8(current_filename);
+	filename_utf8 = g_locale_to_utf8(current_filename, -1, NULL, NULL, NULL);
 	title = g_strdup_printf(_("File Info - %s"), g_basename(filename_utf8));
 	gtk_window_set_title(GTK_WINDOW(window), title);
 	g_free(title);
--- a/src/flac112/plugin.c	Mon Jan 22 06:19:50 2007 -0800
+++ b/src/flac112/plugin.c	Mon Jan 22 08:27:39 2007 -0800
@@ -45,7 +45,6 @@
 #include "replaygain_synthesis.h"
 #include "configure.h"
 #include "charset.h"
-#include "http.h"
 #include "tag.h"
 
 #ifdef min
@@ -86,30 +85,9 @@
 typedef void (*MetadataCallback) (const void *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
 typedef void (*ErrorCallback) (const void *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
 
-typedef struct {
-	FLAC__bool seekable;
-	void* (*new_decoder) (void);
-	FLAC__bool (*set_source) (void *decoder, const char* source);
-	FLAC__bool (*unset_source) (void *decoder);
-	FLAC__bool (*set_md5_checking) (void *decoder, FLAC__bool value);
-	FLAC__bool (*set_metadata_ignore_all) (void *decoder);
-	FLAC__bool (*set_metadata_respond) (void *decoder, FLAC__MetadataType type);
-	FLAC__bool (*set_write_callback) (void *decoder, WriteCallback value);
-	FLAC__bool (*set_metadata_callback) (void *decoder, MetadataCallback value);
-	FLAC__bool (*set_error_callback) (void *decoder, ErrorCallback value);
-	FLAC__bool (*set_client_data) (void *decoder, void *value);
-	FLAC__bool (*decoder_init) (void *decoder);
-	void (*safe_decoder_finish) (void *decoder);
-	void (*safe_decoder_delete) (void *decoder);
-	FLAC__bool (*process_until_end_of_metadata) (void *decoder);
-	FLAC__bool (*process_single) (void *decoder);
-	FLAC__bool (*is_eof) (void *decoder);
-} decoder_funcs_t;
-
-#define NUM_DECODER_TYPES 2
+#define NUM_DECODER_TYPES 1
 typedef enum {
-	DECODER_FILE,
-	DECODER_HTTP
+	DECODER_FILE
 } decoder_t;
 
 static void FLAC_XMMS__init();
@@ -125,14 +103,14 @@
 
 static void *play_loop_(void *arg);
 
-static FLAC__bool safe_decoder_init_(const char *filename, void **decoderp, decoder_funcs_t const ** fnsp);
+static FLAC__bool safe_decoder_init_(const char *filename, void *decoder);
 static void file_decoder_safe_decoder_finish_(void *decoder);
 static void file_decoder_safe_decoder_delete_(void *decoder);
-static FLAC__StreamDecoderWriteStatus write_callback_(const void *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
-static void metadata_callback_(const void *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
-static void error_callback_(const void *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
+static FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__SeekableStreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
+static void metadata_callback_(const FLAC__SeekableStreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
+static void error_callback_(const FLAC__SeekableStreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
+static FLAC__bool file_decoder_is_eof(void *decoder);
 
-static void init_decoder_func_tables();
 static decoder_t source_to_decoder_type (const char *source);
 
 gchar *flac_fmts[] = { "flac", NULL };
@@ -186,11 +164,6 @@
 #define BITRATE_HIST_SIZE 50
 static unsigned bitrate_history_[BITRATE_HIST_SIZE];
 
-/* A table of sets of decoder functions, indexed by decoder_t */
-static const decoder_funcs_t* DECODER_FUNCS[NUM_DECODER_TYPES];
-
-static decoder_funcs_t const * decoder_func_table_, * decoder_func_table2;
-
 
 InputPlugin *get_iplugin_info()
 {
@@ -286,9 +259,7 @@
 	bmp_cfg_db_get_bool(db, "flac", "stream.cast_title_streaming", &flac_cfg.stream.cast_title_streaming);
 	bmp_cfg_db_get_bool(db, "flac", "stream.use_udp_channel", &flac_cfg.stream.use_udp_channel);
 
-	init_decoder_func_tables();
- 	decoder_func_table_ = DECODER_FUNCS [DECODER_FILE];
-	decoder_ = decoder_func_table_ -> new_decoder();
+	decoder_ = FLAC__seekable_stream_decoder_new();
 
 	bmp_cfg_db_get_bool(db, NULL, "use_proxy", &flac_cfg.stream.use_proxy);
 	if(!bmp_cfg_db_get_string(db, NULL, "proxy_host", &flac_cfg.stream.proxy_host))
@@ -352,7 +323,7 @@
 	if(decoder_ == 0)
 		return;
 
-	if(!safe_decoder_init_(filename, &decoder_, &decoder_func_table_))
+	if(!safe_decoder_init_(filename, decoder_))
 		return;
 
 	if(file_info_.has_replaygain && flac_cfg.output.replaygain.enable) {
@@ -367,7 +338,7 @@
 		else {
 			/*@@@ 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); */
 			fprintf(stderr, "libxmms-flac: can't handle %d bit output\n", flac_cfg.output.resolution.replaygain.bps_out);
-			decoder_func_table_ -> safe_decoder_finish(decoder_);
+			file_decoder_safe_decoder_finish_(decoder_);
 			return;
 		}
 	}
@@ -383,7 +354,7 @@
 		else {
 			/*@@@ 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); */
 			fprintf(stderr, "libxmms-flac: can't handle %d bit output\n", file_info_.bits_per_sample);
-			decoder_func_table_ -> safe_decoder_finish(decoder_);
+			file_decoder_safe_decoder_finish_(decoder_);
 			return;
 		}
 	}
@@ -392,7 +363,7 @@
 
 	if(flac_ip.output->open_audio(file_info_.sample_format, file_info_.sample_rate, file_info_.channels) == 0) {
 		audio_error_ = true;
-		decoder_func_table_ -> safe_decoder_finish(decoder_);
+		file_decoder_safe_decoder_finish_(decoder_);
 		return;
 	}
 
@@ -413,7 +384,7 @@
 			g_thread_join(decode_thread_);
 		}
 		flac_ip.output->close_audio();
-		decoder_func_table_ -> safe_decoder_finish (decoder_);
+		file_decoder_safe_decoder_finish_(decoder_);
 	}
 }
 
@@ -424,13 +395,11 @@
 
 void FLAC_XMMS__seek(int time)
 {
-	if (decoder_func_table_->seekable) {
-		file_info_.seek_to_in_sec = time;
-		file_info_.eof = false;
+	file_info_.seek_to_in_sec = time;
+	file_info_.eof = false;
 
-		while(file_info_.seek_to_in_sec != -1)
-			xmms_usleep(10000);
-	}
+	while(file_info_.seek_to_in_sec != -1)
+		xmms_usleep(10000);
 }
 
 int FLAC_XMMS__get_time()
@@ -474,7 +443,7 @@
         flac_cfg.stream.proxy_pass = NULL;
     }
 
-	decoder_func_table_ -> safe_decoder_delete(decoder_);
+	file_decoder_safe_decoder_delete_(decoder_);
 	decoder_ = 0;
 }
 
@@ -525,11 +494,11 @@
 				unsigned s;
 
 				s = sample_buffer_last_ - sample_buffer_first_;
-				if(decoder_func_table_ -> is_eof(decoder_)) {
+				if(file_decoder_is_eof(decoder_)) {
 					file_info_.eof = true;
 					break;
 				}
-				else if (!decoder_func_table_ -> process_single(decoder_)) {
+				else if (!FLAC__seekable_stream_decoder_process_single(decoder_)) {
 					/*@@@ this should probably be a dialog */
 					fprintf(stderr, "libxmms-flac: READ ERROR processing frame\n");
 					file_info_.eof = true;
@@ -537,7 +506,7 @@
 				}
 				blocksize = sample_buffer_last_ - sample_buffer_first_ - s;
 				decode_position_frame_last = decode_position_frame;
-				if(!decoder_func_table_->seekable || !FLAC__seekable_stream_decoder_get_decode_position(decoder_, &decode_position_frame))
+				if(!FLAC__seekable_stream_decoder_get_decode_position(decoder_, &decode_position_frame))
 					decode_position_frame = 0;
 			}
 			if(sample_buffer_last_ - sample_buffer_first_ > 0) {
@@ -576,7 +545,7 @@
 		}
 		else
 			xmms_usleep(10000);
-		if(decoder_func_table_->seekable && file_info_.seek_to_in_sec != -1) {
+		if(file_info_.seek_to_in_sec != -1) {
 			const double distance = (double)file_info_.seek_to_in_sec * 1000.0 / (double)file_info_.length_in_msec;
 			unsigned target_sample = (unsigned)(distance * (double)file_info_.total_samples);
 			if(FLAC__seekable_stream_decoder_seek_absolute(decoder_, (FLAC__uint64)target_sample)) {
@@ -600,7 +569,7 @@
 		}
 	}
 
-	decoder_func_table_ -> safe_decoder_finish(decoder_);
+	file_decoder_safe_decoder_finish_(decoder_);
 
 	/* are these two calls necessary? */
 	flac_ip.output->buffer_free();
@@ -741,179 +710,45 @@
 	return FLAC__seekable_stream_decoder_init( (FLAC__SeekableStreamDecoder*) decoder) == FLAC__SEEKABLE_STREAM_DECODER_OK;
 }
 
-static const decoder_funcs_t FILE_DECODER_FUNCTIONS = {
-	true,
-	(void* (*) (void)) FLAC__seekable_stream_decoder_new,
-	(FLAC__bool (*) (void *, const char*)) file_decoder_set_source,
-	(FLAC__bool (*) (void *)) file_decoder_unset_source,
-	(FLAC__bool (*) (void *, FLAC__bool)) FLAC__seekable_stream_decoder_set_md5_checking,
-	(FLAC__bool (*) (void *)) FLAC__seekable_stream_decoder_set_metadata_ignore_all,
-	(FLAC__bool (*) (void *, FLAC__MetadataType)) FLAC__seekable_stream_decoder_set_metadata_respond,
-	(FLAC__bool (*) (void *, WriteCallback)) FLAC__seekable_stream_decoder_set_write_callback,
-	(FLAC__bool (*) (void *, MetadataCallback)) FLAC__seekable_stream_decoder_set_metadata_callback,
-	(FLAC__bool (*) (void *, ErrorCallback)) FLAC__seekable_stream_decoder_set_error_callback,
-	(FLAC__bool (*) (void *, void *)) FLAC__seekable_stream_decoder_set_client_data,
-	(FLAC__bool (*) (void *)) file_decoder_init,
-	(void (*) (void *)) file_decoder_safe_decoder_finish_,
-	(void (*) (void *)) file_decoder_safe_decoder_delete_,
-	(FLAC__bool (*) (void *)) FLAC__seekable_stream_decoder_process_until_end_of_metadata,
-	(FLAC__bool (*) (void *)) FLAC__seekable_stream_decoder_process_single,
-	file_decoder_is_eof
-};
-
-/*********** HTTP decoder functions */
-
-static gchar *url_ = NULL;
-
-static FLAC__bool http_decoder_set_url (void *decoder, const char* url)
-{
-	(void) decoder;
-	url_ = g_strdup (url);
-	return true;
-}
-
-static FLAC__bool http_decoder_unset_url (void *decoder)
+static decoder_t source_to_decoder_type (const char *source)
 {
-	(void) decoder;
-	if ( url_ != NULL )
-	{
-		g_free(url_);
-		url_ = NULL;
-	}
-	return true;
-}
-
-static FLAC__StreamDecoderReadStatus http_decoder_read_callback (const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data)
-{
-	(void) decoder;
-	(void) client_data;
-	*bytes = flac_http_read (buffer, *bytes);
-	return *bytes ? FLAC__STREAM_DECODER_READ_STATUS_CONTINUE : FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
-}
-
-static FLAC__bool http_decoder_init (void *decoder)
-{
-	flac_http_open (url_, 0);
-	http_decoder_unset_url(decoder);
-	FLAC__stream_decoder_set_read_callback (decoder, http_decoder_read_callback);
-	return FLAC__stream_decoder_init( (FLAC__StreamDecoder*) decoder) == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA;
-}
-
-static FLAC__bool http_decoder_set_md5_checking (void *decoder, FLAC__bool value)
-{
-	return false;
-}
-
-static void http_decoder_safe_decoder_finish_(void *decoder)
-{
-	if(decoder && FLAC__stream_decoder_get_state((FLAC__StreamDecoder *) decoder) != FLAC__STREAM_DECODER_UNINITIALIZED) {
-		FLAC__stream_decoder_finish((FLAC__StreamDecoder *) decoder);
-		flac_http_close();
-	}
-}
-
-static void http_decoder_safe_decoder_delete_(void *decoder)
-{
-	if(decoder) {
-		http_decoder_safe_decoder_finish_(decoder);
-		FLAC__stream_decoder_delete( (FLAC__StreamDecoder *) decoder);
-	}
-}
-
-static FLAC__bool http_decoder_is_eof(void *decoder)
-{
-	return FLAC__stream_decoder_get_state((FLAC__StreamDecoder *) decoder) == FLAC__STREAM_DECODER_END_OF_STREAM;
+	/* NOTE: in Audacious, always use DECODER_FILE to pick files via VFS */
+	return DECODER_FILE;
 }
 
-static const decoder_funcs_t HTTP_DECODER_FUNCTIONS = {
-	false,
-	(void* (*) (void)) FLAC__stream_decoder_new,
-	(FLAC__bool (*) (void *, const char*)) http_decoder_set_url,
-	(FLAC__bool (*) (void *)) http_decoder_unset_url,
-	(FLAC__bool (*) (void *, FLAC__bool)) http_decoder_set_md5_checking,
-	(FLAC__bool (*) (void *)) FLAC__stream_decoder_set_metadata_ignore_all,
-	(FLAC__bool (*) (void *, FLAC__MetadataType)) FLAC__stream_decoder_set_metadata_respond,
-	(FLAC__bool (*) (void *, WriteCallback)) FLAC__stream_decoder_set_write_callback,
-	(FLAC__bool (*) (void *, MetadataCallback)) FLAC__stream_decoder_set_metadata_callback,
-	(FLAC__bool (*) (void *, ErrorCallback)) FLAC__stream_decoder_set_error_callback,
-	(FLAC__bool (*) (void *, void *)) FLAC__stream_decoder_set_client_data,
-	(FLAC__bool (*) (void *)) http_decoder_init,
-	(void (*) (void *)) http_decoder_safe_decoder_finish_,
-	(void (*) (void *)) http_decoder_safe_decoder_delete_,
-	(FLAC__bool (*) (void *)) FLAC__stream_decoder_process_until_end_of_metadata,
-	(FLAC__bool (*) (void *)) FLAC__stream_decoder_process_single,
-	http_decoder_is_eof
-};
-
-static decoder_funcs_t const *decoder_func_table_;
-
-static void init_decoder_func_tables()
+FLAC__bool safe_decoder_init_(const char *filename, void *decoder)
 {
-	DECODER_FUNCS [DECODER_FILE] = & FILE_DECODER_FUNCTIONS;
-	DECODER_FUNCS [DECODER_HTTP] = & HTTP_DECODER_FUNCTIONS;
-}
-
-static decoder_t source_to_decoder_type (const char *source)
-{
-	/* NOTE: in Audacious, always use DECODER_FILE to pick files via VFS;
-                 http flac stream support is not used */
-	return DECODER_FILE;
-
-/*	return strncasecmp(source, "http://", 7) ? DECODER_FILE : DECODER_HTTP; */
-}
-
-static void change_decoder_if_needed (decoder_t new_decoder_type, void **decoderp, decoder_funcs_t const ** fntabp)
-{
-	const decoder_funcs_t *new_fn_table = DECODER_FUNCS [new_decoder_type];
-	if (*fntabp != new_fn_table) {
-		(*fntabp)->safe_decoder_delete(*decoderp);
-		*fntabp = new_fn_table;
-		*decoderp = new_fn_table -> new_decoder();
-	}
-}
-
-FLAC__bool safe_decoder_init_(const char *filename, void **decoderp, decoder_funcs_t const ** fntabp)
-{
-	if(decoderp == 0 || *decoderp == 0)
+	if(decoder == 0)
 		return false;
 
-	(*fntabp)->safe_decoder_finish(*decoderp);
-
-	change_decoder_if_needed(source_to_decoder_type(filename), decoderp, fntabp);
-
-	{
-		decoder_funcs_t const *fntab = *fntabp;
-		void *decoder = *decoderp;
-
-		decoder = *decoderp;
-		fntab = *fntabp;
+	file_decoder_safe_decoder_finish_(decoder);
 
-		fntab -> set_source(decoder, filename);
-		fntab -> set_md5_checking(decoder, false);
-		fntab -> set_metadata_ignore_all(decoder);
-		fntab -> set_metadata_respond(decoder, FLAC__METADATA_TYPE_STREAMINFO);
-		fntab -> set_metadata_respond(decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT);
-		fntab -> set_write_callback(decoder, write_callback_);
-		fntab -> set_metadata_callback(decoder, metadata_callback_);
-		fntab -> set_error_callback(decoder, error_callback_);
-		fntab -> set_client_data(decoder, &file_info_);
-		if(!fntab -> decoder_init(decoder))
-		{
-			fntab -> unset_source(decoder);
-			return false;
-		}
+	file_decoder_set_source(decoder,filename);
+	FLAC__seekable_stream_decoder_set_md5_checking(decoder,false);
+	FLAC__seekable_stream_decoder_set_metadata_ignore_all(decoder);
+	FLAC__seekable_stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_STREAMINFO);
+	FLAC__seekable_stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT);
+	FLAC__seekable_stream_decoder_set_write_callback(decoder, write_callback_);
+	FLAC__seekable_stream_decoder_set_metadata_callback(decoder, metadata_callback_);
+	FLAC__seekable_stream_decoder_set_error_callback(decoder, error_callback_);
+	FLAC__seekable_stream_decoder_set_client_data(decoder, &file_info_);
 
-		if(!fntab -> process_until_end_of_metadata(decoder))
-		{
-			fntab -> unset_source(decoder);
-			return false;
-		}
+	if ( !file_decoder_init(decoder) )
+	{
+		file_decoder_unset_source(decoder);
+		return false;
+	}
+
+	if(!FLAC__seekable_stream_decoder_process_until_end_of_metadata(decoder))
+	{
+		file_decoder_unset_source(decoder);
+		return false;
 	}
 
 	return true;
 }
 
-FLAC__StreamDecoderWriteStatus write_callback_(const void *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
+FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__SeekableStreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
 {
 	file_info_struct *file_info = (file_info_struct *)client_data;
 	const unsigned channels = file_info->channels, wide_samples = frame->header.blocksize;
@@ -973,7 +808,7 @@
 	return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
 }
 
-void metadata_callback_(const void *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
+void metadata_callback_(const FLAC__SeekableStreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
 {
 	file_info_struct *file_info = (file_info_struct *)client_data;
 	(void)decoder;
@@ -994,7 +829,7 @@
 	}
 }
 
-void error_callback_(const void *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
+void error_callback_(const FLAC__SeekableStreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
 {
 	file_info_struct *file_info = (file_info_struct *)client_data;
 	(void)decoder;