Skip to content

Commit

Permalink
added error warning when using download manager in block mode with em…
Browse files Browse the repository at this point in the history
…scripten
  • Loading branch information
jeanlf committed Apr 22, 2024
1 parent b739360 commit f0b85c2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
27 changes: 22 additions & 5 deletions src/filter_core/filter_session.c
Expand Up @@ -1583,8 +1583,13 @@ void gf_fs_print_debug_info(GF_FilterSession *fsess, GF_SessionDebugFlag dbg_fla
//this defines the sleep time for this case
#define MONOTH_MIN_SLEEP 5

#if defined(GPAC_CONFIG_EMSCRIPTEN) && !defined(GPAC_DISABLE_THREADS)
#if defined(GPAC_CONFIG_EMSCRIPTEN)
// && !defined(GPAC_DISABLE_THREADS)
#include <emscripten/threading.h>
#endif

#if defined(GPAC_CONFIG_EMSCRIPTEN) && !defined(GPAC_DISABLE_THREADS)
//#include <emscripten/threading.h>
GF_Err gf_th_async_call(GF_Thread *t, u32 (*Run)(void *param), void *param);
static u32 gf_fs_thread_proc(GF_SessionThread *sess_thread);

Expand Down Expand Up @@ -1631,7 +1636,8 @@ static u32 gf_fs_thread_proc(GF_SessionThread *sess_thread)
Bool skip_next_sema_wait = GF_FALSE;
GF_Filter *current_filter = NULL;

#if defined(GPAC_CONFIG_EMSCRIPTEN) && !defined(GPAC_DISABLE_THREADS)
#if defined(GPAC_CONFIG_EMSCRIPTEN)
// && !defined(GPAC_DISABLE_THREADS)
Bool flush_main_blocking = (!thid && !fsess->is_worker) ? GF_TRUE : GF_FALSE;
if (flush_main_blocking) do_regulate = GF_FALSE;
#endif
Expand Down Expand Up @@ -1696,9 +1702,12 @@ static u32 gf_fs_thread_proc(GF_SessionThread *sess_thread)
}
#endif

#if defined(GPAC_CONFIG_EMSCRIPTEN) && !defined(GPAC_DISABLE_THREADS)
if (flush_main_blocking)
emscripten_main_thread_process_queued_calls();
#if defined(GPAC_CONFIG_EMSCRIPTEN)
//&& !defined(GPAC_DISABLE_THREADS)
if (flush_main_blocking) {
// emscripten_main_thread_process_queued_calls();
emscripten_current_thread_process_queued_calls();
}
#endif

safe_int_dec(&fsess->active_threads);
Expand Down Expand Up @@ -4051,6 +4060,14 @@ static GF_DownloadManager *gf_fs_get_download_manager(GF_FilterSession *fs)
{
#ifdef GPAC_USE_DOWNLOADER
if (!fs->download_manager) {

#ifdef GPAC_CONFIG_EMSCRIPTEN
if (!fs->non_blocking) {
GF_LOG(GF_LOG_ERROR, GF_LOG_HTTP, ("Fetch cannot be used in blocking mode as it requires returning to main/worker JS event loop\n"));
return NULL;
}
#endif

fs->download_manager = gf_dm_new(fs);

#ifndef GPAC_DISABLE_NETWORK
Expand Down
4 changes: 3 additions & 1 deletion src/filters/decrypt_cenc_isma.c
Expand Up @@ -2,7 +2,7 @@
* GPAC - Multimedia Framework C SDK
*
* Authors: Jean Le Feuvre
* Copyright (c) Telecom ParisTech 2018-2023
* Copyright (c) Telecom ParisTech 2018-2024
* All rights reserved
*
* This file is part of GPAC / CENC and ISMA decrypt filter
Expand Down Expand Up @@ -815,6 +815,7 @@ static GF_Err cenc_dec_set_clearkey(GF_CENCDecCtx *ctx, GF_CENCDecStream *cstr,

#ifdef GPAC_USE_DOWNLOADER
GF_DownloadManager *dm = gf_filter_get_download_manager(ctx->filter);
if (!dm) return GF_SERVICE_ERROR;
cstr->sess = gf_dm_sess_new(dm, ck_url, 0, ck_http_io, cstr, &e);
if (e) return e;
ctx->pending_keys++;
Expand Down Expand Up @@ -952,6 +953,7 @@ static GF_Err cenc_dec_set_hls_key(GF_CENCDecCtx *ctx, GF_CENCDecStream *cstr, c
GF_Err e = GF_SERVICE_ERROR;
#ifdef GPAC_USE_DOWNLOADER
GF_DownloadManager *dm = gf_filter_get_download_manager(ctx->filter);
if (!dm) return GF_SERVICE_ERROR;
GF_DownloadSession *sess = gf_dm_sess_new(dm, key_url, GF_NETIO_SESSION_NOT_CACHED, hls_kms_io, cstr, &e);
if (e) {
GF_LOG(GF_LOG_ERROR, GF_LOG_DASH, ("[CENC/HLS] Failed to setup download session for key %s: %s\n", key_url, gf_error_to_string(e)))
Expand Down
5 changes: 2 additions & 3 deletions src/filters/in_http.c
Expand Up @@ -2,7 +2,7 @@
* GPAC - Multimedia Framework C SDK
*
* Authors: Jean Le Feuvre
* Copyright (c) Telecom ParisTech 2017-2023
* Copyright (c) Telecom ParisTech 2017-2024
* All rights reserved
*
* This file is part of GPAC / HTTP input filter using GPAC http stack
Expand Down Expand Up @@ -106,9 +106,8 @@ static GF_Err httpin_initialize(GF_Filter *filter)

if (!ctx || !ctx->src) return GF_BAD_PARAM;
ctx->dm = gf_filter_get_download_manager(filter);
#ifndef GPAC_CONFIG_EMSCRIPTEN
if (!ctx->dm) return GF_SERVICE_ERROR;
#endif

ctx->block = gf_malloc(ctx->block_size +1);

flags = GF_NETIO_SESSION_NOT_THREADED | GF_NETIO_SESSION_PERSISTENT;
Expand Down
7 changes: 6 additions & 1 deletion src/filters/io_fcryp.c
Expand Up @@ -2,7 +2,7 @@
* GPAC - Multimedia Framework C SDK
*
* Authors: Jean Le Feuvre
* Copyright (c) Telecom ParisTech 2021-2023
* Copyright (c) Telecom ParisTech 2021-2024
* All rights reserved
*
* This file is part of GPAC / file crypt/decrypt for full segment encryption filter
Expand Down Expand Up @@ -244,6 +244,11 @@ static GF_Err cryptfin_process(GF_Filter *filter)
//use a threaded session
if (!ctx->key_sess) {
GF_DownloadManager *dm = gf_filter_get_download_manager(filter);
if (!dm) {
ctx->in_error = GF_NOT_SUPPORTED;
ctx->reload_key_state = KEY_STATE_NONE;
return ctx->in_error;
}
ctx->key_sess = gf_dm_sess_new(dm, ctx->key_url, GF_NETIO_SESSION_NOT_CACHED, cryptfin_net_io, ctx, &e);
} else {
e = gf_dm_sess_setup_from_url(ctx->key_sess, ctx->key_url, GF_TRUE);
Expand Down

0 comments on commit f0b85c2

Please sign in to comment.