summaryrefslogtreecommitdiff
path: root/plugins/converter/converter.c
diff options
context:
space:
mode:
authorGravatar Lithopsian <deadbeef@nartowicz.co.uk>2014-06-22 22:39:47 +0100
committerGravatar Lithopsian <deadbeef@nartowicz.co.uk>2014-06-22 22:39:47 +0100
commit6cd87a40c3a3da1ff8ecdc0f8b980cec38de84aa (patch)
tree7d87af9dae15d6227edc3f0efebe16c49593a973 /plugins/converter/converter.c
parent579a1e72d3c96c2b04f127cc273f3641a56702fe (diff)
parentd43b7c86b8fe7e5ef47a78becbca46b121d33d40 (diff)
Merge pull request #7 from Alexey-Yakovenko/master
Resync
Diffstat (limited to 'plugins/converter/converter.c')
-rw-r--r--plugins/converter/converter.c154
1 files changed, 82 insertions, 72 deletions
diff --git a/plugins/converter/converter.c b/plugins/converter/converter.c
index 41e896dd..a0e7a218 100644
--- a/plugins/converter/converter.c
+++ b/plugins/converter/converter.c
@@ -167,7 +167,7 @@ encoder_preset_save (ddb_encoder_preset_t *p, int overwrite) {
return -1;
}
const char *confdir = deadbeef->get_config_dir ();
- char path[1024];
+ char path[PATH_MAX];
if (snprintf (path, sizeof (path), "%s/presets", confdir) < 0) {
return -1;
}
@@ -371,7 +371,7 @@ dsp_preset_save (ddb_dsp_preset_t *p, int overwrite) {
return -1;
}
const char *confdir = deadbeef->get_config_dir ();
- char path[1024];
+ char path[PATH_MAX];
if (snprintf (path, sizeof (path), "%s/presets", confdir) < 0) {
return -1;
}
@@ -458,77 +458,69 @@ copy_file (const char *in, const char *out) {
int
load_encoder_presets (void) {
// check if we need to install presets
- char ppath[1024];
- char epath[1024];
- char fpath[1024];
+ char ppath[PATH_MAX];
+ char epath[PATH_MAX];
snprintf (ppath, sizeof (ppath), "%s/presets", deadbeef->get_config_dir ());
snprintf (epath, sizeof (epath), "%s/encoders", ppath);
- snprintf (fpath, sizeof (fpath), "%s/.installed", epath);
- struct stat stat_buf;
- if (0 != stat (fpath, &stat_buf)) {
- // file not found, install all presets from plugin_dir/convpresets/
- mkdir (ppath, 0755);
- mkdir (epath, 0755);
- char preset_src_dir[1024];
- snprintf (preset_src_dir, sizeof (preset_src_dir), "%s/convpresets", deadbeef->get_plugin_dir ());
- struct dirent **namelist = NULL;
- int n = scandir (preset_src_dir, &namelist, NULL, dirent_alphasort);
- for (int i = 0; i < n; i++) {
- // replace _ with spaces
- char new_name[1024];
- char *o = new_name;
- char *in = namelist[i]->d_name;
- while (*in) {
- if (*in == '_') {
- *o++ = ' ';
- in++;
- }
- else {
- *o++ = *in++;
- }
- }
- *o = 0;
- char in_name[1024];
- char out_name[1024];
- snprintf (in_name, sizeof (in_name), "%s/%s", preset_src_dir, namelist[i]->d_name);
- snprintf (out_name, sizeof (out_name), "%s/%s", epath, new_name);
- copy_file (in_name, out_name);
- free (namelist[i]);
- }
- if (namelist) {
- free (namelist);
- }
- FILE *fp = fopen (fpath, "w+b");
- if (fp) {
- fclose (fp);
- }
- }
- ddb_encoder_preset_t *tail = NULL;
- char path[1024];
+ char path[PATH_MAX];
if (snprintf (path, sizeof (path), "%s/presets/encoders", deadbeef->get_config_dir ()) < 0) {
return -1;
}
- struct dirent **namelist = NULL;
- int n = scandir (path, &namelist, scandir_preset_filter, dirent_alphasort);
- int i;
- for (i = 0; i < n; i++) {
- char s[1024];
- if (snprintf (s, sizeof (s), "%s/%s", path, namelist[i]->d_name) > 0){
- ddb_encoder_preset_t *p = encoder_preset_load (s);
- if (p) {
- if (tail) {
- tail->next = p;
- tail = p;
- }
- else {
- encoder_presets = tail = p;
+
+ char syspath[PATH_MAX];
+ if (snprintf (syspath, sizeof (syspath), "%s/convpresets", deadbeef->get_plugin_dir ()) < 0) {
+ return -1;
+ }
+
+ const char *preset_dirs[] = {
+ syspath, path, NULL
+ };
+
+ ddb_encoder_preset_t *tail = NULL;
+
+ for (int di = 0; preset_dirs[di]; di++) {
+ const char *path = preset_dirs[di];
+ struct dirent **namelist = NULL;
+ int n = scandir (path, &namelist, scandir_preset_filter, dirent_alphasort);
+ int i;
+ for (i = 0; i < n; i++) {
+ char s[PATH_MAX];
+ if (snprintf (s, sizeof (s), "%s/%s", path, namelist[i]->d_name) > 0){
+ ddb_encoder_preset_t *p = encoder_preset_load (s);
+ if (p) {
+ if (path == syspath) {
+ // don't allow editing stock presets
+ p->readonly = 1;
+ }
+ else {
+ // check if the same RO preset exists
+ for (ddb_encoder_preset_t *pr = encoder_presets; pr; pr = pr->next) {
+ if (pr->readonly && !strcmp (pr->title, p->title)) {
+ encoder_preset_free (p);
+ p = NULL;
+ break;
+ }
+ }
+ if (!p) {
+ // NOTE: we don't delete duplicate presets in $HOME
+ // for compat with <=0.6.1
+ continue;
+ }
+ }
+ if (tail) {
+ tail->next = p;
+ tail = p;
+ }
+ else {
+ encoder_presets = tail = p;
+ }
}
}
+ free (namelist[i]);
}
- free (namelist[i]);
+ free (namelist);
}
- free (namelist);
return 0;
}
@@ -555,7 +547,7 @@ free_encoder_presets (void) {
int
load_dsp_presets (void) {
ddb_dsp_preset_t *tail = NULL;
- char path[1024];
+ char path[PATH_MAX];
if (snprintf (path, sizeof (path), "%s/presets/dsp", deadbeef->get_config_dir ()) < 0) {
return -1;
}
@@ -563,7 +555,7 @@ load_dsp_presets (void) {
int n = scandir (path, &namelist, scandir_preset_filter, dirent_alphasort);
int i;
for (i = 0; i < n; i++) {
- char s[1024];
+ char s[PATH_MAX];
if (snprintf (s, sizeof (s), "%s/%s", path, namelist[i]->d_name) > 0){
ddb_dsp_preset_t *p = dsp_preset_load (s);
if (p) {
@@ -929,10 +921,10 @@ convert (DB_playItem_t *it, const char *out, int output_bps, int output_is_float
// write wave header
char wavehdr_int[] = {
- 0x52, 0x49, 0x46, 0x46, 0x24, 0x70, 0x0d, 0x00, 0x57, 0x41, 0x56, 0x45, 0x66, 0x6d, 0x74, 0x20, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x44, 0xac, 0x00, 0x00, 0x10, 0xb1, 0x02, 0x00, 0x04, 0x00, 0x10, 0x00, 0x64, 0x61, 0x74, 0x61
+ 0x52, 0x49, 0x46, 0x46, 0x00, 0x00, 0x00, 0x00, 0x57, 0x41, 0x56, 0x45, 0x66, 0x6d, 0x74, 0x20, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x44, 0xac, 0x00, 0x00, 0x10, 0xb1, 0x02, 0x00, 0x04, 0x00, 0x10, 0x00, 0x64, 0x61, 0x74, 0x61
};
char wavehdr_float[] = {
- 0x52, 0x49, 0x46, 0x46, 0x2a, 0xdf, 0x02, 0x00, 0x57, 0x41, 0x56, 0x45, 0x66, 0x6d, 0x74, 0x20, 0x28, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x02, 0x00, 0x40, 0x1f, 0x00, 0x00, 0x00, 0xfa, 0x00, 0x00, 0x08, 0x00, 0x20, 0x00, 0x16, 0x00, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71, 0x66, 0x61, 0x63, 0x74, 0x04, 0x00, 0x00, 0x00, 0xc5, 0x5b, 0x00, 0x00, 0x64, 0x61, 0x74, 0x61
+ 0x52, 0x49, 0x46, 0x46, 0x00, 0x00, 0x00, 0x00, 0x57, 0x41, 0x56, 0x45, 0x66, 0x6d, 0x74, 0x20, 0x28, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x02, 0x00, 0x40, 0x1f, 0x00, 0x00, 0x00, 0xfa, 0x00, 0x00, 0x08, 0x00, 0x20, 0x00, 0x16, 0x00, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71, 0x66, 0x61, 0x63, 0x74, 0x04, 0x00, 0x00, 0x00, 0xc5, 0x5b, 0x00, 0x00, 0x64, 0x61, 0x74, 0x61
};
char *wavehdr = output_is_float ? wavehdr_float : wavehdr_int;
int wavehdr_size = output_is_float ? sizeof (wavehdr_float) : sizeof (wavehdr_int);
@@ -1013,9 +1005,9 @@ convert (DB_playItem_t *it, const char *out, int output_bps, int output_is_float
outsize += sz;
if (!header_written) {
- uint32_t size = (it->endsample-it->startsample) * outch * output_bps / 8;
+ uint64_t size = (int64_t)(it->endsample-it->startsample) * outch * output_bps / 8;
if (!size) {
- size = deadbeef->pl_get_item_duration (it) * fileinfo->fmt.samplerate * outch * output_bps / 8;
+ size = (double)deadbeef->pl_get_item_duration (it) * fileinfo->fmt.samplerate * outch * output_bps / 8;
}
@@ -1026,20 +1018,38 @@ convert (DB_playItem_t *it, const char *out, int output_bps, int output_is_float
size = temp;
}
+ uint64_t chunksize;
+ chunksize = size + 36;
+
+ // for float, add 36 more
+ if (output_is_float) {
+ chunksize += 36;
+ }
+
+ uint32_t size32 = 0xffffffff;
+ if (chunksize <= 0xffffffff) {
+ size32 = chunksize;
+ }
+ memcpy (&wavehdr[4], &size32, 4);
memcpy (&wavehdr[22], &outch, 2);
memcpy (&wavehdr[24], &outsr, 4);
uint16_t blockalign = outch * output_bps / 8;
memcpy (&wavehdr[32], &blockalign, 2);
memcpy (&wavehdr[34], &output_bps, 2);
+ size32 = 0xffffffff;
+ if (size <= 0xffffffff) {
+ size32 = size;
+ }
+
if (wavehdr_size != write (temp_file, wavehdr, wavehdr_size)) {
fprintf (stderr, "converter: wave header write error\n");
goto error;
}
if (encoder_preset->method == DDB_ENCODER_METHOD_PIPE) {
- size = 0;
+ size32 = 0;
}
- if (write (temp_file, &size, sizeof (size)) != sizeof (size)) {
+ if (write (temp_file, &size32, sizeof (size32)) != sizeof (size32)) {
fprintf (stderr, "converter: wave header size write error\n");
goto error;
}
@@ -1220,7 +1230,7 @@ static ddb_converter_t plugin = {
.misc.plugin.api_vmajor = 1,
.misc.plugin.api_vminor = 0,
.misc.plugin.version_major = 1,
- .misc.plugin.version_minor = 2,
+ .misc.plugin.version_minor = 3,
.misc.plugin.type = DB_PLUGIN_MISC,
.misc.plugin.name = "Converter",
.misc.plugin.id = "converter",