summaryrefslogtreecommitdiff
path: root/plugins/converter
diff options
context:
space:
mode:
authorGravatar waker <wakeroid@gmail.com>2012-04-08 20:44:02 +0200
committerGravatar waker <wakeroid@gmail.com>2012-04-08 20:44:02 +0200
commitd9e6d749a5376ac1c613d832cec9437b3dfc6987 (patch)
tree05cf54281a6290df8ff4176bab35c9122648752e /plugins/converter
parentda6a525031fd2a8bb1577220c1a2191834edfcca (diff)
converter: moved duplicate code into converter plugin and exposed via API, converter API is now v1.2
Diffstat (limited to 'plugins/converter')
-rw-r--r--plugins/converter/converter.c81
-rw-r--r--plugins/converter/converter.h15
-rw-r--r--plugins/converter/convgui.c41
3 files changed, 79 insertions, 58 deletions
diff --git a/plugins/converter/converter.c b/plugins/converter/converter.c
index 4ffe4433..c53040d7 100644
--- a/plugins/converter/converter.c
+++ b/plugins/converter/converter.c
@@ -665,11 +665,41 @@ get_output_field (DB_playItem_t *it, const char *field, char *out, int sz)
trace ("field '%s' expanded to '%s'\n", field, out);
}
-static void
-get_output_path (DB_playItem_t *it, const char *outfolder, const char *outfile, ddb_encoder_preset_t *encoder_preset, char *out, int sz) {
+void
+get_output_path (DB_playItem_t *it, const char *outfolder_user, const char *outfile, ddb_encoder_preset_t *encoder_preset, int preserve_folder_structure, const char *root_folder, int write_to_source_folder, char *out, int sz) {
+
+ const char *uri = strdupa (deadbeef->pl_find_meta (it, ":URI"));
+ char outfolder_preserve[2000];
+ if (preserve_folder_structure) {
+ // generate new outfolder
+ int rootlen = strlen (root_folder);
+ const char *e = strrchr (uri, '/');
+ if (e) {
+ const char *s = uri + rootlen;
+ char subpath[e-s+1];
+ memcpy (subpath, s, e-s);
+ subpath[e-s] = 0;
+ snprintf (outfolder_preserve, sizeof (outfolder_preserve), "%s/%s", outfolder_user[0] ? outfolder_user : getenv("HOME"), subpath);
+ }
+ }
+
+ const char *outfolder;
+
+ if (write_to_source_folder) {
+ char *path = strdupa (uri);
+ char *sep = strrchr (path, '/');
+ if (sep) {
+ *sep = 0;
+ }
+ outfolder = path;
+ }
+ else {
+ outfolder = preserve_folder_structure ? outfolder_preserve : outfolder_user;
+ }
+
int l;
char fname[PATH_MAX];
- char *path = outfolder[0] ? strdupa (outfolder) : strdupa (getenv("HOME"));
+ char *path = strdupa (outfolder);
char *pattern = strdupa (outfile);
// replace invalid chars
@@ -708,6 +738,13 @@ get_output_path (DB_playItem_t *it, const char *outfolder, const char *outfile,
trace ("converter output file is '%s'\n", out);
}
+static void
+get_output_path_1_0 (DB_playItem_t *it, const char *outfolder, const char *outfile, ddb_encoder_preset_t *encoder_preset, char *out, int sz) {
+ fprintf (stderr, "converter: warning: old version of \"get_output_path\" has been called, please update your plugins which depend on converter 1.1\n");
+ *out = 0;
+ sz = 0;
+}
+
static int
check_dir (const char *dir, mode_t mode)
{
@@ -724,7 +761,7 @@ check_dir (const char *dir, mode_t mode)
trace ("creating dir %s\n", tmp);
if (0 != mkdir (tmp, mode))
{
- trace ("Failed to create %s (%d)\n", tmp, errno);
+ trace ("Failed to create %s\n", tmp);
free (tmp);
return 0;
}
@@ -737,7 +774,7 @@ check_dir (const char *dir, mode_t mode)
}
int
-convert (DB_playItem_t *it, const char *outfolder, const char *outfile, int output_bps, int output_is_float, int preserve_folder_structure, const char *root_folder, int write_to_source_folder, ddb_encoder_preset_t *encoder_preset, ddb_dsp_preset_t *dsp_preset, int *abort) {
+convert (DB_playItem_t *it, const char *out, int output_bps, int output_is_float, ddb_encoder_preset_t *encoder_preset, ddb_dsp_preset_t *dsp_preset, int *abort) {
if (deadbeef->pl_get_item_duration (it) <= 0) {
deadbeef->pl_lock ();
const char *fname = deadbeef->pl_find_meta (it, ":URI");
@@ -746,18 +783,11 @@ convert (DB_playItem_t *it, const char *outfolder, const char *outfile, int outp
return -1;
}
- char *path = preserve_folder_structure ? strdupa (root_folder) : (outfolder[0] ? strdupa (outfolder) : strdupa (getenv("HOME")));
- if (!check_dir (path, 0755)) {
- fprintf (stderr, "converter: failed to create output folder: %s\n", outfolder);
- return -1;
- }
-
int err = -1;
FILE *enc_pipe = NULL;
int temp_file = -1;
DB_decoder_t *dec = NULL;
DB_fileinfo_t *fileinfo = NULL;
- char out[PATH_MAX] = ""; // full path to output file
char input_file_name[PATH_MAX] = "";
dec = (DB_decoder_t *)deadbeef->plug_get_for_id (deadbeef->pl_find_meta (it, ":DECODER"));
@@ -774,21 +804,17 @@ convert (DB_playItem_t *it, const char *outfolder, const char *outfile, int outp
output_bps = fileinfo->fmt.bps;
output_is_float = fileinfo->fmt.is_float;
}
- const char *outpath;
- if (write_to_source_folder) {
- char *path = strdupa (deadbeef->pl_find_meta (it, ":URI"));
- char *sep = strrchr (path, '/');
- if (sep) {
- *sep = 0;
+ char *final_path = strdupa (out);
+ char *sep = strrchr (final_path, '/');
+ if (sep) {
+ *sep = 0;
+ if (!check_dir (final_path, 0755)) {
+ fprintf (stderr, "converter: failed to create output folder: %s\n", final_path);
+ goto error;
}
- outpath = path;
- }
- else {
- outpath = preserve_folder_structure ? root_folder : outfolder;
}
- get_output_path (it, outpath, outfile, encoder_preset, out, sizeof (out));
if (encoder_preset->method == DDB_ENCODER_METHOD_FILE) {
const char *tmp = getenv ("TMPDIR");
if (!tmp) {
@@ -1104,7 +1130,8 @@ error:
int
convert_1_0 (DB_playItem_t *it, const char *outfolder, const char *outfile, int output_bps, int output_is_float, int preserve_folder_structure, const char *root_folder, ddb_encoder_preset_t *encoder_preset, ddb_dsp_preset_t *dsp_preset, int *abort) {
- return convert (it, outfolder, outfile, output_bps, output_is_float, preserve_folder_structure, root_folder, 0, encoder_preset, dsp_preset, abort);
+ fprintf (stderr, "converter: warning: old version of \"convert\" has been called, please update your plugins which depend on converter 1.1\n");
+ return -1;
}
int
@@ -1179,14 +1206,16 @@ static ddb_converter_t plugin = {
.dsp_preset_append = dsp_preset_append,
.dsp_preset_remove = dsp_preset_remove,
.dsp_preset_replace = dsp_preset_replace,
- .get_output_path = get_output_path,
+ .get_output_path_1_0 = get_output_path_1_0,
.convert_1_0 = convert_1_0,
- .convert = convert,
// 1.1 entry points
.load_encoder_presets = load_encoder_presets,
.load_dsp_presets = load_dsp_presets,
.free_encoder_presets = free_encoder_presets,
.free_dsp_presets = free_dsp_presets,
+ // 1.2 entry points
+ .convert = convert,
+ .get_output_path = get_output_path,
};
DB_plugin_t *
diff --git a/plugins/converter/converter.h b/plugins/converter/converter.h
index 1bad0449..530b192c 100644
--- a/plugins/converter/converter.h
+++ b/plugins/converter/converter.h
@@ -139,8 +139,9 @@ typedef struct {
/////////////////////////////
+ // this function is deprecated, please don't use directly
void
- (*get_output_path) (DB_playItem_t *it, const char *outfolder, const char *outfile, ddb_encoder_preset_t *encoder_preset, char *out, int sz);
+ (*get_output_path_1_0) (DB_playItem_t *it, const char *outfolder, const char *outfile, ddb_encoder_preset_t *encoder_preset, char *out, int sz);
// this function is deprecated, please don't use directly
int
@@ -163,7 +164,17 @@ typedef struct {
// new APIs for converter-1.2
/////////////////////////////
int
- (*convert) (DB_playItem_t *it, const char *outfolder, const char *outfile, int output_bps, int output_is_float, int preserve_folder_structure, const char *root_folder, int write_to_source_folder, ddb_encoder_preset_t *encoder_preset, ddb_dsp_preset_t *dsp_preset, int *abort);
+ (*convert) (
+ DB_playItem_t *it, // track to be converted
+ const char *outpath, // final path to write the file (should normally be obtained using get_output_path)
+ int output_bps, // stream should be pre-converted to this resolution
+ int output_is_float, // stream should be converted to float
+ ddb_encoder_preset_t *encoder_preset, // encoder preset to use
+ ddb_dsp_preset_t *dsp_preset, // dsp preset to use
+ int *abort // *abort will be checked regularly, conversion will be interrupted if it's non-zero
+ );
+ void
+ (*get_output_path) (DB_playItem_t *it, const char *outfolder, const char *outfile, ddb_encoder_preset_t *encoder_preset, int preserve_folder_structure, const char *root_folder, int write_to_source_folder, char *out, int sz);
} ddb_converter_t;
#endif
diff --git a/plugins/converter/convgui.c b/plugins/converter/convgui.c
index 1a931ba0..f2b9d1a2 100644
--- a/plugins/converter/convgui.c
+++ b/plugins/converter/convgui.c
@@ -165,34 +165,7 @@ converter_worker (void *ctx) {
char outpath[2000];
- char outfolder_preserve[2000];
- if (conv->preserve_folder_structure) {
- // generate new outfolder
- const char *e = strrchr (info->text, '/');
- if (e) {
- const char *s = info->text + rootlen;
- char subpath[e-s+1];
- memcpy (subpath, s, e-s);
- subpath[e-s] = 0;
- snprintf (outfolder_preserve, sizeof (outfolder_preserve), "%s/%s", conv->outfolder[0] ? conv->outfolder : getenv("HOME"), subpath);
- }
- }
-
- const char *outfolder;
-
- if (conv->write_to_source_folder) {
- char *path = strdupa (info->text);
- char *sep = strrchr (path, '/');
- if (sep) {
- *sep = 0;
- }
- outfolder = path;
- }
- else {
- outfolder = conv->preserve_folder_structure ? outfolder_preserve : conv->outfolder;
- }
-
- converter_plugin->get_output_path (conv->convert_items[n], outfolder, conv->outfile, conv->encoder_preset, outpath, sizeof (outpath));
+ converter_plugin->get_output_path (conv->convert_items[n], conv->outfolder, conv->outfile, conv->encoder_preset, conv->preserve_folder_structure, root, conv->write_to_source_folder, outpath, sizeof (outpath));
int skip = 0;
struct stat st;
@@ -225,7 +198,7 @@ converter_worker (void *ctx) {
}
if (!skip) {
- converter_plugin->convert (conv->convert_items[n], conv->outfolder, conv->outfile, conv->output_bps, conv->output_is_float, conv->preserve_folder_structure, outfolder_preserve, conv->write_to_source_folder, conv->encoder_preset, conv->dsp_preset, &conv->cancelled);
+ converter_plugin->convert (conv->convert_items[n], outpath, conv->output_bps, conv->output_is_float, conv->encoder_preset, conv->dsp_preset, &conv->cancelled);
}
if (conv->cancelled) {
for (; n < conv->convert_items_count; n++) {
@@ -1315,7 +1288,15 @@ convgui_connect (void) {
gtkui_plugin = (ddb_gtkui_t *)deadbeef->plug_get_for_id ("gtkui");
#endif
converter_plugin = (ddb_converter_t *)deadbeef->plug_get_for_id ("converter");
- if (!gtkui_plugin || !converter_plugin) {
+ if (!gtkui_plugin) {
+ fprintf (stderr, "convgui: gtkui plugin not found\n");
+ return -1;
+ }
+ if (!converter_plugin) {
+ fprintf (stderr, "convgui: converter plugin not found\n");
+ }
+ if (converter_plugin->misc.plugin.version_major != 1 || converter_plugin->misc.plugin.version_minor < 2) {
+ fprintf (stderr, "convgui: need converter>=1.2, but found %d.%d\n", converter_plugin->misc.plugin.version_major, converter_plugin->misc.plugin.version_minor);
return -1;
}
return 0;