[vlc-commits] [Git][videolan/vlc][master] 3 commits: emjsfile: close the file on error
Steve Lhomme (@robUx4)
gitlab at videolan.org
Thu Jan 5 13:03:15 UTC 2023
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
c78af463 by Mehdi Sabwat at 2023-01-05T11:28:38+00:00
emjsfile: close the file on error
- - - - -
cba23916 by Mehdi Sabwat at 2023-01-05T11:28:38+00:00
emjsfile: document BigUint64 RangeError with existing specifiers.
- - - - -
a793c249 by Mehdi Sabwat at 2023-01-05T11:28:38+00:00
emjsfile: remove whitespaces and deprecated comment
- - - - -
1 changed file:
- modules/access/emjsfile.c
Changes:
=====================================
modules/access/emjsfile.c
=====================================
@@ -27,7 +27,7 @@
#include <vlc_plugin.h>
#include <vlc_access.h>
#include <vlc_threads.h>
-
+#include <stdalign.h>
#include <emscripten.h>
typedef struct
@@ -40,7 +40,7 @@ static ssize_t Read (stream_t *p_access, void *buffer, size_t size) {
access_sys_t *p_sys = p_access->p_sys;
size_t offset = p_sys->offset;
- size_t js_file_size = p_sys->js_file_size;
+ size_t js_file_size = p_sys->js_file_size;
if (offset >= js_file_size)
return 0;
@@ -67,14 +67,12 @@ static int Seek (stream_t *p_access, uint64_t offset) {
static int get_js_file_size(stream_t *p_access, uint64_t *value) {
/*
+ Note :
to avoid RangeError on BigUint64 view creation,
- the start offset must be a multiple of 8.
+ the start offset (value) must be a multiple of 8.
*/
- if ((uintptr_t)value % 8 != 0) {
- msg_Err(p_access, "error: value is not aligned in get_js_file_size!");
- return VLC_EGENERIC;
- }
- return (EM_ASM_INT({
+ alignas(8) uint64_t file_size = 0;
+ int ret = (EM_ASM_INT({
try {
var v = new BigUint64Array(wasmMemory.buffer, $0, 1);
v[0] = BigInt(Module.vlcAccess[$1].worker_js_file.size);
@@ -84,7 +82,9 @@ static int get_js_file_size(stream_t *p_access, uint64_t *value) {
console.error("get_js_file_size error: " + error);
return 1;
}
- }, value, p_access) == 0) ? VLC_SUCCESS: VLC_EGENERIC;
+ }, &file_size, p_access) == 0) ? VLC_SUCCESS: VLC_EGENERIC;
+ *value = file_size;
+ return ret;
}
static int Control( stream_t *p_access, int i_query, va_list args )
@@ -179,6 +179,14 @@ EM_ASYNC_JS(int, init_js_file, (stream_t *p_access, long id), {
return return_value;
});
+static void EmFileClose (vlc_object_t * p_this) {
+ stream_t *p_access = (stream_t*)p_this;
+ EM_ASM({
+ Module.vlcAccess[$0].worker_js_file = undefined;
+ Module.vlcAccess[$0].reader = undefined;
+ }, p_access);
+}
+
static int EmFileOpen( vlc_object_t *p_this ) {
stream_t *p_access = (stream_t*)p_this;
@@ -187,7 +195,7 @@ static int EmFileOpen( vlc_object_t *p_this ) {
if (Module.vlcAccess === undefined) {
Module.vlcAccess = {};
}
- (Module.vlcAccess[$0] = {worker_js_file: undefined, reader: undefined});
+ (Module.vlcAccess[$0] = {worker_js_file: undefined, reader: undefined});
}, p_access);
/*
@@ -240,6 +248,11 @@ static int EmFileOpen( vlc_object_t *p_this ) {
w.addEventListener('message', handleFileRequest);
}, pthread_self());
+ access_sys_t *p_sys = vlc_obj_malloc(p_this, sizeof (*p_sys));
+ if (unlikely(p_sys == NULL)) {
+ return VLC_ENOMEM;
+ }
+
char *endPtr;
long id = strtol(p_access->psz_location, &endPtr, 10);
if ((endPtr == p_access->psz_location) || (*endPtr != '\0')) {
@@ -253,17 +266,12 @@ static int EmFileOpen( vlc_object_t *p_this ) {
To open a file, we need to call libvlc_media_new_location with
the following uri : emjsfile://<id>
- To avoid confusion with atoi() return error, id starts at 1.
*/
if (init_js_file(p_access, id)) {
msg_Err(p_access, "EMJsFile error: failed init!");
return VLC_EGENERIC;
}
- access_sys_t *p_sys = vlc_obj_malloc(p_this, sizeof (*p_sys));
- if (unlikely(p_sys == NULL))
- return VLC_ENOMEM;
-
p_access->pf_read = Read;
p_access->pf_block = NULL;
p_access->pf_control = Control;
@@ -273,20 +281,13 @@ static int EmFileOpen( vlc_object_t *p_this ) {
p_sys->offset = 0;
if (get_js_file_size(p_access, &p_sys->js_file_size)) {
msg_Err(p_access, "EMJsFile error: could not get file size!");
+ EmFileClose(p_this);
return VLC_EGENERIC;
- }
+ }
return VLC_SUCCESS;
}
-static void EmFileClose (vlc_object_t * p_this) {
- stream_t *p_access = (stream_t*)p_this;
- EM_ASM({
- Module.vlcAccess[$0].worker_js_file = undefined;
- Module.vlcAccess[$0].reader = undefined;
- }, p_access);
-}
-
vlc_module_begin ()
set_description( N_("Emscripten module to allow reading local files from the DOM's <input>") )
set_shortname( N_("Emscripten Local File Input") )
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/b321e59e016d376a8387cf5131e19e94f978db7e...a793c249cddb626b9952af73d17b8b8baa84b524
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/b321e59e016d376a8387cf5131e19e94f978db7e...a793c249cddb626b9952af73d17b8b8baa84b524
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list