Skip to content

Commit

Permalink
Initial stab of vmir plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
andoma committed Aug 15, 2016
1 parent af65073 commit 2c00e9a
Show file tree
Hide file tree
Showing 16 changed files with 1,332 additions and 66 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
[submodule "ios/freetype2-ios"]
path = ios/freetype2-ios
url = https://github.com/andoma/freetype2-ios.git
[submodule "ext/vmir"]
path = ext/vmir
url = https://github.com/andoma/vmir
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,24 @@ SRCS-$(CONFIG_SQLITE) += src/ecmascript/es_sqlite.c
${BUILDDIR}/ext/duktape/%.o : CFLAGS = -Wall ${OPTFLAGS} \
-fstrict-aliasing -std=c99 -DDUK_OPT_FASTINT #-DDUK_OPT_ASSERTIONS #-DDUK_OPT_DEBUG -DDUK_OPT_DPRINT -DDUK_OPT_DDPRINT -DDUK_OPT_DDDPRINT

##############################################################
# VMIR
##############################################################

SRCS-${CONFIG_VMIR} += \
ext/vmir/src/vmir.c \
ext/tlsf/tlsf.c \
src/np/np.c \
src/np/np_fs.c \
src/np/np_prop.c \
src/np/np_backend.c \
src/np/np_stats.c \

${BUILDDIR}/ext/vmir/src/vmir.o : CFLAGS = ${CFLAGS_std} ${OPTFLAGS} -DVMIR_USE_TLSF -Iext/tlsf

${BUILDDIR}/src/np/%.o : CFLAGS = ${CFLAGS_std} ${OPTFLAGS} -DNATIVEPLUGIN_HOST -Inativeplugin/include/



##############################################################
# Gumbo
Expand Down
1 change: 1 addition & 0 deletions ext/vmir
Submodule vmir added at 571b8a
21 changes: 21 additions & 0 deletions src/fileaccess/fa_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "metadata/playinfo.h"
#include "misc/minmax.h"
#include "usage.h"
#include "backend/backend.h"

#if ENABLE_LIBGME
#include <gme/gme.h>
Expand All @@ -47,6 +48,7 @@
#include <xmp.h>
#endif

#include "np/np.h"

/**
*
Expand Down Expand Up @@ -156,6 +158,25 @@ be_file_playaudio(const char *url, media_pipe_t *mp,
// ZIP File
return audio_play_zipfile(fh, mp, errbuf, errlen, hold);

metadata_t *md = metadata_create();
if(np_fa_probe(fh, pb, psiz, md, url) == 0) {
fa_close_with_park(fh, 1);
event_t *e = NULL;
if(md->md_redirect == NULL) {
snprintf(errbuf, errlen, "External player provided no redirect URL");
} else if(!strcmp(md->md_redirect, url)) {
snprintf(errbuf, errlen, "Redirect loop %s -> %s", url, md->md_redirect);
} else {
TRACE(TRACE_DEBUG, "Audio", "%s redirects to %s",
url, md->md_redirect);
e = backend_play_audio(md->md_redirect, mp, errbuf, errlen, hold,
mimetype);
}
metadata_destroy(md);
return e;
}
metadata_destroy(md);

// First we need to check for a few other formats
#if ENABLE_LIBGME
if(*gme_identify_header(pb))
Expand Down
11 changes: 11 additions & 0 deletions src/fileaccess/fa_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,17 @@ fs_open(fa_protocol_t *fap, const char *url, char *errbuf, size_t errlen,
int i;
int fd;


if(!strcmp(url, "/dev/stdout") || !strcmp(url, "/dev/stderr")) {
fd = open(url, O_WRONLY);
if(fd == -1) {
snprintf(errbuf, errlen, "%s", strerror(errno));
return NULL;
}
goto open_ok;
}


if(flags & FA_WRITE) {

int open_flags = O_RDWR | O_CREAT;
Expand Down
95 changes: 34 additions & 61 deletions src/fileaccess/fa_probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
#include "libav.h"
#endif

#if ENABLE_VMIR
#include "np/np.h"
#endif

/**
*
*/
Expand Down Expand Up @@ -178,44 +182,17 @@ fa_probe_playlist(metadata_t *md, const char *url, uint8_t *pb, size_t pbsize)
}
#endif

/**
* Probe SPC files
*/
static void
fa_probe_spc(metadata_t *md, const uint8_t *pb, const char *filename)
{
char buf[33];
buf[32] = 0;

if(memcmp("v0.30", pb + 0x1c, 4))
return;

if(pb[0x23] != 0x1a)
return;

memcpy(buf, pb + 0x2e, 32);
md->md_title = rstr_alloc(buf);

memcpy(buf, pb + 0x4e, 32);
md->md_album = rstr_alloc(buf);

memcpy(buf, pb + 0xa9, 3);
buf[3] = 0;

md->md_duration = atoi(buf);
md->md_track = filename ? atoi(filename) : 0;
}


#if 0
/**
*
*/
static void
fa_probe_psid(metadata_t *md, uint8_t *pb)
fa_probe_psid(metadata_t *md, const uint8_t *pb)
{
md->md_title = rstr_from_bytes_len((char *)pb + 0x16, 32, NULL, 0);
md->md_artist = rstr_from_bytes_len((char *)pb + 0x36, 32, NULL, 0);
md->md_title = rstr_from_bytes_len((const char *)pb + 0x16, 32, NULL, 0);
md->md_artist = rstr_from_bytes_len((const char *)pb + 0x36, 32, NULL, 0);
}
#endif


/**
Expand Down Expand Up @@ -247,8 +224,8 @@ jpeginfo_reader(void *handle, void *buf, int64_t offset, size_t size)


static void
fa_probe_exif(metadata_t *md, const char *url, uint8_t *pb, fa_handle_t *fh,
int buflen)
fa_probe_exif(metadata_t *md, const char *url, const uint8_t *pb,
fa_handle_t *fh, int buflen)
{
jpeginfo_t ji;

Expand All @@ -270,30 +247,19 @@ fa_probe_exif(metadata_t *md, const char *url, uint8_t *pb, fa_handle_t *fh,
*/
static int
fa_probe_header(metadata_t *md, const char *url, fa_handle_t *fh,
const char *filename)
const char *filename, const uint8_t *buf, size_t l)
{
uint16_t flags;
uint8_t buf[1025];

int l = fa_read(fh, buf, sizeof(buf) - 1);
if(l < 8)
return 0;

buf[l] = 0;

if(l >= 256 && !memcmp(buf, "SNES-SPC700 Sound File Data", 27)) {
fa_probe_spc(md, buf, filename);
md->md_contenttype = CONTENT_AUDIO;
return 1;
}

#if 0
if(l >= 256 && (!memcmp(buf, "PSID", 4) || !memcmp(buf, "RSID", 4))) {
fa_probe_psid(md, buf);
md->md_contenttype = CONTENT_ALBUM;
metdata_set_redirect(md, "sidfile://%s/", url);
return 1;
}

#endif

if(l >= 256 && (!memcmp(buf, "d8:announce", 11))) {
md->md_contenttype = CONTENT_ARCHIVE;
metdata_set_redirect(md, "torrentfile://%s/", url);
Expand Down Expand Up @@ -480,7 +446,7 @@ fa_probe_iso(metadata_t *md, fa_handle_t *fh)
/**
*
*/
#if ENABLE_XMP
#if 0
static int
xmp_probe(metadata_t *md, const char *url, fa_handle_t *fh)
{
Expand Down Expand Up @@ -734,25 +700,32 @@ fa_probe_metadata(const char *url, char *errbuf, size_t errsize,

metadata_t *md = metadata_create();

#if ENABLE_LIBGME
if(gme_probe(md, url, fh)) {
fa_park(fh);
return md;
}
uint8_t buf[1025];

int l = fa_read(fh, buf, sizeof(buf) - 1);
if(l > 0) {
#if ENABLE_VMIR
if(np_fa_probe(fh, buf, l, md, url) == 0) {
fa_close_with_park(fh, park);
return md;
}
#endif
buf[l] = 0;
if(fa_probe_header(md, url, fh, filename, buf, l)) {
fa_close_with_park(fh, park);
return md;
}
}
fa_seek(fh, 0, SEEK_SET);

#if 0
#if ENABLE_XMP
if(xmp_probe(md, url, fh)) {
fa_close_with_park(fh, park);
return md;
}
#endif

fa_seek(fh, 0, SEEK_SET);
if(fa_probe_header(md, url, fh, filename)) {
fa_close_with_park(fh, park);
return md;
}
#endif

if(!fa_probe_iso(md, fh)) {
fa_close_with_park(fh, park);
Expand Down
4 changes: 4 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,10 @@ parse_opts(int argc, char **argv)
gconf.load_ecmascript = argv[1];
argc -= 2; argv += 2;
continue;
} else if(!strcmp(argv[0], "--vmir-bitcode") && argc > 1) {
gconf.load_np = argv[1];
argc -= 2; argv += 2;
continue;
} else if (!strcmp(argv[0], "-v") && argc > 1) {
gconf.initial_view = argv[1];
argc -= 2; argv += 2;
Expand Down
2 changes: 2 additions & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ typedef struct gconf {
const char *load_ecmascript;
int bypass_ecmascript_acl;

const char *load_np;

const char *initial_url;
const char *initial_view;

Expand Down
Loading

0 comments on commit 2c00e9a

Please sign in to comment.