Mercurial > audlegacy-plugins
changeset 2766:6d08e3120615
make some file filewriter backends use callbacks instead of calling VFS directly
author | Andrew O. Shadoura <bugzilla@tut.by> |
---|---|
date | Sat, 26 Apr 2008 15:58:58 +0300 |
parents | 999098953bcd |
children | fa4b58a08f4c |
files | src/filewriter/filewriter.c src/filewriter/filewriter.h src/filewriter/mp3.c src/filewriter/vorbis.c |
diffstat | 4 files changed, 35 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/src/filewriter/filewriter.c Sat Mar 29 13:52:19 2008 +0200 +++ b/src/filewriter/filewriter.c Sat Apr 26 15:58:58 2008 +0300 @@ -77,10 +77,16 @@ static gchar *file_path = NULL; +VFSFile *output_file = NULL; +guint64 written = 0; +guint64 offset = 0; +Tuple *tuple = NULL; + static void file_init(void); static void file_about(void); static gint file_open(AFormat fmt, gint rate, gint nch); static void file_write(void *ptr, gint length); +static gint file_write_output(void *ptr, gint length); static void file_close(void); static void file_flush(gint time); static void file_pause(short p); @@ -155,7 +161,7 @@ set_plugin(); if (plugin.init) - plugin.init(); + plugin.init(&file_write_output); } void file_about(void) @@ -326,6 +332,11 @@ plugin.write(ptr, length); } +static gint file_write_output(void *ptr, gint length) +{ + return aud_vfs_fwrite(ptr, 1, length, output_file); +} + static void file_close(void) { plugin.close(); @@ -407,6 +418,8 @@ { fileext = gtk_combo_box_get_active(GTK_COMBO_BOX(fileext_combo)); set_plugin(); + if (plugin.init) + plugin.init(&file_write_output); gtk_widget_set_sensitive(plugin_button, plugin.configure != NULL); } @@ -630,8 +643,3 @@ gtk_widget_show_all(configure_win); } } - -VFSFile *output_file = NULL; -guint64 written = 0; -guint64 offset = 0; -Tuple *tuple = NULL;
--- a/src/filewriter/filewriter.h Sat Mar 29 13:52:19 2008 +0200 +++ b/src/filewriter/filewriter.h Sat Apr 26 15:58:58 2008 +0300 @@ -52,9 +52,11 @@ typedef struct _FileWriter FileWriter; +typedef gint (*write_output_callback)(void *ptr, gint length); + struct _FileWriter { - void (*init)(void); + void (*init)(write_output_callback write_output_func); void (*configure)(void); gint (*open)(void); void (*write)(void *ptr, gint length);
--- a/src/filewriter/mp3.c Sat Mar 29 13:52:19 2008 +0200 +++ b/src/filewriter/mp3.c Sat Apr 26 15:58:58 2008 +0300 @@ -29,7 +29,7 @@ #include <lame/lame.h> #define ENCBUFFER_SIZE 35000 -static void mp3_init(void); +static void mp3_init(write_output_callback write_output_func); static void mp3_configure(void); static gint mp3_open(void); static void mp3_write(void *ptr, gint length); @@ -37,6 +37,7 @@ static gint mp3_free(void); static gint mp3_playing(void); static gint mp3_get_written_time(void); +static gint (*write_output)(void *ptr, gint length); FileWriter mp3_plugin = { @@ -158,7 +159,7 @@ (void) vfprintf(stdout, format, ap); } -static void mp3_init(void) +static void mp3_init(write_output_callback write_output_func) { ConfigDb *db = aud_cfg_db_open(); aud_cfg_db_get_int(db, "filewriter_mp3", "vbr_on", &vbr_on); @@ -194,6 +195,8 @@ aud_cfg_db_get_int(db, "filewriter_mp3", "error_protect_val", &error_protect_val); aud_cfg_db_close(db); + if (write_output_func) + write_output=write_output_func; } static gint mp3_open(void) @@ -302,7 +305,7 @@ ENCBUFFER_SIZE); } - aud_vfs_fwrite(encbuffer, 1, encout, output_file); + write_output(encbuffer, encout); written += encout; olen += length; } @@ -312,7 +315,7 @@ if (output_file) { encout = lame_encode_flush_nogap(gfp, encbuffer, ENCBUFFER_SIZE); - aud_vfs_fwrite(encbuffer, 1, encout, output_file); + write_output(encbuffer, encout); // lame_mp3_tags_fid(gfp, output_file); // will erase id3v2 tag??
--- a/src/filewriter/vorbis.c Sat Mar 29 13:52:19 2008 +0200 +++ b/src/filewriter/vorbis.c Sat Apr 26 15:58:58 2008 +0300 @@ -26,7 +26,7 @@ #include <vorbis/vorbisenc.h> #include <stdlib.h> -static void vorbis_init(void); +static void vorbis_init(write_output_callback write_output_func); static void vorbis_configure(void); static gint vorbis_open(void); static void vorbis_write(gpointer data, gint length); @@ -34,6 +34,7 @@ static gint vorbis_free(void); static gint vorbis_playing(void); static gint vorbis_get_written_time(void); +static gint (*write_output)(void *ptr, gint length); FileWriter vorbis_plugin = { @@ -61,13 +62,16 @@ static float **encbuffer; static guint64 olen = 0; -static void vorbis_init(void) +static void vorbis_init(write_output_callback write_output_func) { ConfigDb *db = aud_cfg_db_open(); aud_cfg_db_get_float(db, "filewriter_vorbis", "base_quality", &v_base_quality); aud_cfg_db_close(db); + + if (write_output_func) + write_output=write_output_func; } static gint vorbis_open(void) @@ -77,7 +81,7 @@ ogg_packet header_comm; ogg_packet header_code; - vorbis_init(); + vorbis_init(NULL); written = 0; olen = 0; @@ -140,8 +144,8 @@ if (result == 0) break; - written += aud_vfs_fwrite(og.header, 1, og.header_len, output_file); - written += aud_vfs_fwrite(og.body, 1, og.body_len, output_file); + written += write_output(og.header, og.header_len); + written += write_output(og.body, og.body_len); } return 1; @@ -194,8 +198,8 @@ if (result == 0) break; - written += aud_vfs_fwrite(og.header, 1, og.header_len, output_file); - written += aud_vfs_fwrite(og.body, 1, og.body_len, output_file); + written += write_output(og.header, og.header_len); + written += write_output(og.body, og.body_len); } } }