Skip to content

Commit

Permalink
Move fopen out of pl_lock in decoders (DeaDBeeF-Player#2035)
Browse files Browse the repository at this point in the history
  • Loading branch information
BorisCarvajal authored and Oleksiy-Yakovenko committed Jul 18, 2018
1 parent 0e6f657 commit 26dba6d
Show file tree
Hide file tree
Showing 24 changed files with 151 additions and 113 deletions.
2 changes: 0 additions & 2 deletions junklib.c
Original file line number Diff line number Diff line change
Expand Up @@ -4982,9 +4982,7 @@ junk_rewrite_tags (playItem_t *it, uint32_t junk_flags, int id3v2_version, const
free (buffer);
}
if (!err) {
pl_lock ();
rename (tmppath, fname);
pl_unlock ();
}
else {
unlink (tmppath);
Expand Down
4 changes: 3 additions & 1 deletion plugins/aac/aac.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <stdlib.h>
#include <math.h>
#include "../../deadbeef.h"
#include "../../strdupa.h"
#include "aac_parser.h"

#include "mp4ff.h"
Expand Down Expand Up @@ -294,8 +295,9 @@ aac_init (DB_fileinfo_t *_info, DB_playItem_t *it) {
aac_info_t *info = (aac_info_t *)_info;

deadbeef->pl_lock ();
info->file = deadbeef->fopen (deadbeef->pl_find_meta (it, ":URI"));
const char *uri = strdupa (deadbeef->pl_find_meta (it, ":URI"));
deadbeef->pl_unlock ();
info->file = deadbeef->fopen (uri);
if (!info->file) {
return -1;
}
Expand Down
6 changes: 4 additions & 2 deletions plugins/adplug/adplug-db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <string.h>
#include <stdlib.h>
#include "../../deadbeef.h"
#include "../../strdupa.h"
#include "adplug.h"
#include "emuopl.h"
#include "kemuopl.h"
Expand Down Expand Up @@ -95,10 +96,11 @@ adplug_init (DB_fileinfo_t *_info, DB_playItem_t *it) {
}
}
deadbeef->pl_lock ();
info->decoder = CAdPlug::factory (deadbeef->pl_find_meta (it, ":URI"), info->opl, CAdPlug::players);
const char *uri = strdupa (deadbeef->pl_find_meta (it, ":URI"));
deadbeef->pl_unlock ();
info->decoder = CAdPlug::factory (uri, info->opl, CAdPlug::players);
if (!info->decoder) {
trace ("adplug: failed to open %s\n", deadbeef->pl_find_meta (it, ":URI"));
trace ("adplug: failed to open %s\n", uri);
return -1;
}

Expand Down
4 changes: 3 additions & 1 deletion plugins/alac/alac_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include "../../strdupa.h"

#define USE_MP4FF 1

Expand Down Expand Up @@ -226,8 +227,9 @@ alacplug_init (DB_fileinfo_t *_info, DB_playItem_t *it) {
alacplug_info_t *info = (alacplug_info_t *)_info;

deadbeef->pl_lock ();
info->file = deadbeef->fopen (deadbeef->pl_find_meta (it, ":URI"));
const char *uri = strdupa (deadbeef->pl_find_meta (it, ":URI"));
deadbeef->pl_unlock ();
info->file = deadbeef->fopen (uri);
if (!info->file) {
return -1;
}
Expand Down
6 changes: 4 additions & 2 deletions plugins/dca/dcaplug.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
# include <config.h>
#endif
#include "../../deadbeef.h"
#include "../../strdupa.h"
#include "dca.h"
#include "gettimeofday.h"

Expand Down Expand Up @@ -405,10 +406,11 @@ dts_init (DB_fileinfo_t *_info, DB_playItem_t *it) {
ddb_dca_state_t *info = (ddb_dca_state_t *)_info;

deadbeef->pl_lock ();
info->file = deadbeef->fopen (deadbeef->pl_find_meta (it, ":URI"));
const char *uri = strdupa (deadbeef->pl_find_meta (it, ":URI"));
deadbeef->pl_unlock ();
info->file = deadbeef->fopen (uri);
if (!info->file) {
trace ("dca: failed to open %s\n", deadbeef->pl_find_meta (it, ":URI"));
trace ("dca: failed to open %s\n", uri);
return -1;
}

Expand Down
32 changes: 15 additions & 17 deletions plugins/dumb/cdumb.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "internal/it.h"
#include "modloader.h"
#include "../../deadbeef.h"
#include "../../strdupa.h"

//#define trace(...) { fprintf(stderr, __VA_ARGS__); }
#define trace(fmt,...)
Expand Down Expand Up @@ -76,19 +77,17 @@ cdumb_init (DB_fileinfo_t *_info, DB_playItem_t *it) {
trace ("cdumb_init %s\n", deadbeef->pl_find_meta (it, ":URI"));
dumb_info_t *info = (dumb_info_t *)_info;

int is_dos, is_it, is_ptcompat;
deadbeef->pl_lock ();
{
const char *uri = deadbeef->pl_find_meta (it, ":URI");
const char *ext = uri + strlen (uri) - 1;
while (*ext != '.' && ext > uri) {
ext--;
}
ext++;
const char *ftype;
info->duh = g_open_module (uri, &is_it, &is_dos, &is_ptcompat, 0, &ftype);
}
int is_dos, is_it, is_ptcompat;
deadbeef->pl_lock ();
const char *uri = strdupa(deadbeef->pl_find_meta (it, ":URI"));
deadbeef->pl_unlock ();
const char *ext = uri + strlen (uri) - 1;
while (*ext != '.' && ext > uri) {
ext--;
}
ext++;
const char *ftype;
info->duh = g_open_module (uri, &is_it, &is_dos, &is_ptcompat, 0, &ftype);

dumb_it_do_initial_runthrough (info->duh);

Expand Down Expand Up @@ -327,12 +326,11 @@ cdumb_read_metadata (DB_playItem_t *it) {
int is_ptcompat;

deadbeef->pl_lock ();
{
const char *fname = deadbeef->pl_find_meta (it, ":URI");
const char *ftype;
duh = g_open_module(fname, &is_it, &is_dos, &is_ptcompat, 0, &ftype);
}
const char *fname = strdupa(deadbeef->pl_find_meta (it, ":URI"));
deadbeef->pl_unlock ();
const char *ftype;
duh = g_open_module(fname, &is_it, &is_dos, &is_ptcompat, 0, &ftype);

if (!duh) {
unload_duh (duh);
return -1;
Expand Down
7 changes: 5 additions & 2 deletions plugins/ffap/ffap.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <assert.h>
#include <math.h>
#include "../../deadbeef.h"
#include "../../strdupa.h"

#ifdef TARGET_ANDROID
int posix_memalign (void **memptr, size_t alignment, size_t size) {
Expand Down Expand Up @@ -701,8 +702,9 @@ ffap_init (DB_fileinfo_t *_info, DB_playItem_t *it)
ape_info_t *info = (ape_info_t*)_info;

deadbeef->pl_lock ();
info->fp = deadbeef->fopen (deadbeef->pl_find_meta (it, ":URI"));
const char *uri = strdupa (deadbeef->pl_find_meta (it, ":URI"));
deadbeef->pl_unlock ();
info->fp = deadbeef->fopen (uri);
if (!info->fp) {
return -1;
}
Expand Down Expand Up @@ -1855,8 +1857,9 @@ ffap_seek (DB_fileinfo_t *_info, float seconds) {

static int ffap_read_metadata (DB_playItem_t *it) {
deadbeef->pl_lock ();
DB_FILE *fp = deadbeef->fopen (deadbeef->pl_find_meta (it, ":URI"));
const char *uri = strdupa (deadbeef->pl_find_meta (it, ":URI"));
deadbeef->pl_unlock ();
DB_FILE *fp = deadbeef->fopen (uri);
if (!fp) {
return -1;
}
Expand Down
15 changes: 9 additions & 6 deletions plugins/flac/flac.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,12 @@ cflac_open2 (uint32_t hints, DB_playItem_t *it) {
}

deadbeef->pl_lock();
info->file = deadbeef->fopen(deadbeef->pl_find_meta(it, ":URI"));
const char *uri = strdupa (deadbeef->pl_find_meta (it, ":URI"));
deadbeef->pl_unlock();
info->file = deadbeef->fopen(uri);
if (!info->file) {
trace("cflac_open2 failed to open file %s\n", deadbeef->pl_find_meta(it, ":URI"));
trace("cflac_open2 failed to open file %s\n", uri);
}
deadbeef->pl_unlock();

return (DB_fileinfo_t *)info;
}
Expand All @@ -293,10 +294,11 @@ cflac_init (DB_fileinfo_t *_info, DB_playItem_t *it) {

if (!info->file) {
deadbeef->pl_lock ();
info->file = deadbeef->fopen (deadbeef->pl_find_meta (it, ":URI"));
const char *uri = strdupa (deadbeef->pl_find_meta (it, ":URI"));
deadbeef->pl_unlock ();
info->file = deadbeef->fopen (uri);
if (!info->file) {
trace ("cflac_init failed to open file %s\n", deadbeef->pl_find_meta(it, ":URI"));
trace ("cflac_init failed to open file %s\n", uri);
return -1;
}
}
Expand Down Expand Up @@ -1006,8 +1008,9 @@ cflac_read_metadata (DB_playItem_t *it) {
return -1;
}
deadbeef->pl_lock ();
DB_FILE *file = deadbeef->fopen (deadbeef->pl_find_meta (it, ":URI"));
const char *uri = strdupa (deadbeef->pl_find_meta (it, ":URI"));
deadbeef->pl_unlock ();
DB_FILE *file = deadbeef->fopen (uri);
if (!file) {
return -1;
}
Expand Down
65 changes: 30 additions & 35 deletions plugins/gme/cgme.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "gme/gme.h"
#include <zlib.h>
#include "../../deadbeef.h"
#include "../../strdupa.h"
#if HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
Expand Down Expand Up @@ -185,45 +186,39 @@ cgme_init (DB_fileinfo_t *_info, DB_playItem_t *it) {

gme_err_t res = "gme uninitialized";
deadbeef->pl_lock ();
{
const char *fname = deadbeef->pl_find_meta (it, ":URI");
char *buffer;
int sz;
if (!read_gzfile (fname, &buffer, &sz)) {
res = gme_open_data (buffer, sz, &info->emu, samplerate);
free (buffer);
const char *fname = strdupa(deadbeef->pl_find_meta (it, ":URI"));
deadbeef->pl_unlock ();
char *buffer;
int sz;
if (!read_gzfile (fname, &buffer, &sz)) {
res = gme_open_data (buffer, sz, &info->emu, samplerate);
free (buffer);
}
if (res) {
DB_FILE *f = deadbeef->fopen (fname);
if (!f) {
return -1;
}
if (res) {
DB_FILE *f = deadbeef->fopen (fname);
if (!f) {
deadbeef->pl_unlock ();
return -1;
}
int64_t sz = deadbeef->fgetlength (f);
if (sz <= 0) {
deadbeef->fclose (f);
deadbeef->pl_unlock ();
return -1;
}
char *buf = malloc (sz);
if (!buf) {
deadbeef->fclose (f);
deadbeef->pl_unlock ();
return -1;
}
int64_t rb = deadbeef->fread (buf, 1, sz, f);
deadbeef->fclose(f);
if (rb != sz) {
free (buf);
deadbeef->pl_unlock ();
return -1;
}

res = gme_open_data (buf, sz, &info->emu, samplerate);
int64_t sz = deadbeef->fgetlength (f);
if (sz <= 0) {
deadbeef->fclose (f);
return -1;
}
char *buf = malloc (sz);
if (!buf) {
deadbeef->fclose (f);
return -1;
}
int64_t rb = deadbeef->fread (buf, 1, sz, f);
deadbeef->fclose(f);
if (rb != sz) {
free (buf);
return -1;
}

res = gme_open_data (buf, sz, &info->emu, samplerate);
free (buf);
}
deadbeef->pl_unlock ();

if (res) {
trace ("failed with error %d\n", res);
Expand Down
7 changes: 5 additions & 2 deletions plugins/mp3/mp3.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <unistd.h>
#include <sys/time.h>
#include "../../deadbeef.h"
#include "../../strdupa.h"
#include "mp3.h"
#ifdef USE_LIBMAD
#include "mp3_mad.h"
Expand Down Expand Up @@ -807,8 +808,9 @@ cmp3_init (DB_fileinfo_t *_info, DB_playItem_t *it) {
_info->plugin = &plugin;
memset (&info->buffer, 0, sizeof (info->buffer));
deadbeef->pl_lock ();
info->buffer.file = deadbeef->fopen (deadbeef->pl_find_meta (it, ":URI"));
const char *uri = strdupa (deadbeef->pl_find_meta (it, ":URI"));
deadbeef->pl_unlock ();
info->buffer.file = deadbeef->fopen (uri);
if (!info->buffer.file) {
return -1;
}
Expand Down Expand Up @@ -1241,8 +1243,9 @@ cmp3_insert (ddb_playlist_t *plt, DB_playItem_t *after, const char *fname) {
int
cmp3_read_metadata (DB_playItem_t *it) {
deadbeef->pl_lock ();
DB_FILE *fp = deadbeef->fopen (deadbeef->pl_find_meta (it, ":URI"));
const char *uri = strdupa (deadbeef->pl_find_meta (it, ":URI"));
deadbeef->pl_unlock ();
DB_FILE *fp = deadbeef->fopen (uri);
if (!fp) {
return -1;
}
Expand Down
7 changes: 5 additions & 2 deletions plugins/musepack/musepack.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
# include <config.h>
#endif
#include "../../deadbeef.h"
#include "../../strdupa.h"

#define min(x,y) ((x)<(y)?(x):(y))
#define max(x,y) ((x)>(y)?(x):(y))
Expand Down Expand Up @@ -105,8 +106,9 @@ musepack_init (DB_fileinfo_t *_info, DB_playItem_t *it) {
info->reader.canseek = musepack_vfs_canseek;

deadbeef->pl_lock ();
DB_FILE *fp = deadbeef->fopen (deadbeef->pl_find_meta (it, ":URI"));
const char *uri = strdupa (deadbeef->pl_find_meta (it, ":URI"));
deadbeef->pl_unlock ();
DB_FILE *fp = deadbeef->fopen (uri);
if (!fp) {
return -1;
}
Expand Down Expand Up @@ -476,8 +478,9 @@ musepack_insert (ddb_playlist_t *plt, DB_playItem_t *after, const char *fname) {

static int musepack_read_metadata (DB_playItem_t *it) {
deadbeef->pl_lock ();
DB_FILE *fp = deadbeef->fopen (deadbeef->pl_find_meta (it, ":URI"));
const char *uri = strdupa (deadbeef->pl_find_meta (it, ":URI"));
deadbeef->pl_unlock ();
DB_FILE *fp = deadbeef->fopen (uri);
if (!fp) {
return -1;
}
Expand Down
9 changes: 6 additions & 3 deletions plugins/opus/opus.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ opusdec_open (uint32_t hints) {
static DB_fileinfo_t *
opusdec_open2 (uint32_t hints, DB_playItem_t *it) {
deadbeef->pl_lock ();
DB_FILE *fp = deadbeef->fopen (deadbeef->pl_find_meta (it, ":URI"));
const char *uri = strdupa (deadbeef->pl_find_meta (it, ":URI"));
deadbeef->pl_unlock ();
DB_FILE *fp = deadbeef->fopen (uri);

if (!fp) {
return NULL;
Expand Down Expand Up @@ -253,8 +254,9 @@ opusdec_init (DB_fileinfo_t *_info, DB_playItem_t *it) {

if (!info->info.file) {
deadbeef->pl_lock ();
DB_FILE *fp = deadbeef->fopen (deadbeef->pl_find_meta (it, ":URI"));
const char *uri = strdupa (deadbeef->pl_find_meta (it, ":URI"));
deadbeef->pl_unlock ();
DB_FILE *fp = deadbeef->fopen (uri);

if (!fp) {
return -1;
Expand Down Expand Up @@ -568,8 +570,9 @@ opusdec_read_metadata (DB_playItem_t *it) {
const OpusHead *head = NULL;

deadbeef->pl_lock ();
fp = deadbeef->fopen (deadbeef->pl_find_meta (it, ":URI"));
const char *uri = strdupa (deadbeef->pl_find_meta (it, ":URI"));
deadbeef->pl_unlock ();
fp = deadbeef->fopen (uri);
if (!fp) {
goto error;
}
Expand Down
Loading

0 comments on commit 26dba6d

Please sign in to comment.