Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get mp4dump working with Emscripten #36

Merged
merged 1 commit into from
Oct 15, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Source/C++/Apps/Mp4Dump/Mp4Dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@

#include "Ap4.h"

#ifdef __EMSCRIPTEN__
#include "emscripten.h"
#endif

/*----------------------------------------------------------------------
| constants
+---------------------------------------------------------------------*/
Expand Down Expand Up @@ -288,8 +292,25 @@ main(int argc, char** argv)
return 1;
}
} else {
#ifdef __EMSCRIPTEN__
// Emscripten has to "mount" the filesystem to a virtual directory.
EM_ASM(FS.mkdir('/working'));
EM_ASM(FS.mount(NODEFS, { root: '.' }, '/working'));
const char* const mount_name = "/working/%s";
const int filename_size = snprintf(NULL, 0, mount_name, arg);
char* mounted_filename = (char*) malloc(filename_size + 1);
sprintf(mounted_filename, mount_name, arg);
filename = mounted_filename;
#else
filename = arg;
#endif
AP4_Result result = AP4_FileByteStream::Create(filename, AP4_FileByteStream::STREAM_MODE_READ, input);

#ifdef __EMSCRIPTEN__
free(mounted_filename);
mounted_filename = NULL;
#endif

if (AP4_FAILED(result)) {
fprintf(stderr, "ERROR: cannot open input (%d)\n", result);
return 1;
Expand Down