[vlc-commits] [Git][videolan/vlc][master] 7 commits: fetcher: configure executor domain
Steve Lhomme (@robUx4)
gitlab at videolan.org
Tue Oct 15 08:35:35 UTC 2024
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
ed25f895 by Thomas Guillem at 2024-10-15T07:56:44+00:00
fetcher: configure executor domain
In order to avoid creating executors (thread) for nothing.
- - - - -
0129f10e by Thomas Guillem at 2024-10-15T07:56:44+00:00
preparse: configure executor domain
Don't create parser/fetchers if not needed (and create local/network one
accordingly).
- - - - -
f9252209 by Thomas Guillem at 2024-10-15T07:56:44+00:00
macosx: configure the network parser for parsing only
This save the creation of 3 threads (local, network fetcher, downloader).
- - - - -
ba586a13 by Thomas Guillem at 2024-10-15T07:56:44+00:00
qt: configure the network parser for parsing only
This save the creation of 3 threads (local, network fetcher, downloader).
- - - - -
17c7829e by Thomas Guillem at 2024-10-15T07:56:44+00:00
qt: configure the fetcher for fetching only
This save the creation of 1 thread (parser).
- - - - -
fa767805 by Thomas Guillem at 2024-10-15T07:56:44+00:00
playlist: configure the preparser for parsing + local fetch
This save the creation of 2 threads (network fetcher + downloader).
- - - - -
999e53e3 by Thomas Guillem at 2024-10-15T07:56:44+00:00
test: configure the preparser for parsing + local fetch
- - - - -
10 changed files:
- include/vlc_preparser.h
- lib/core.c
- modules/gui/macosx/main/VLCMain.m
- modules/gui/qt/maininterface/mainctx.cpp
- modules/gui/qt/player/player_controller.cpp
- src/playlist/playlist.c
- src/preparser/fetcher.c
- src/preparser/fetcher.h
- src/preparser/preparser.c
- test/libvlc/media.c
Changes:
=====================================
include/vlc_preparser.h
=====================================
@@ -61,11 +61,15 @@ typedef enum input_item_meta_request_option_t
* @param obj the parent object
* @param max_threads the maximum number of threads used to parse, must be >= 1
* @param default_timeout default timeout of the preparser, 0 for no limits.
+ * @param request_type a combination of META_REQUEST_OPTION_PARSE,
+ * META_REQUEST_OPTION_FETCH_LOCAL and META_REQUEST_OPTION_FETCH_NETWORK, it is
+ * used to setup the executors for each domain.
* @return a valid preparser object or NULL in case of error
*/
VLC_API vlc_preparser_t *vlc_preparser_New( vlc_object_t *obj,
unsigned max_threads,
- vlc_tick_t default_timeout );
+ vlc_tick_t default_timeout,
+ input_item_meta_request_option_t request_type );
/**
* This function enqueues the provided item to be preparsed or fetched.
=====================================
lib/core.c
=====================================
@@ -268,7 +268,9 @@ vlc_preparser_t *libvlc_get_preparser(libvlc_instance_t *instance)
parser = instance->parser =
vlc_preparser_New(VLC_OBJECT(instance->p_libvlc_int), max_threads,
- default_timeout);
+ default_timeout,
+ META_REQUEST_OPTION_PARSE |
+ META_REQUEST_OPTION_FETCH_ANY);
}
vlc_mutex_unlock(&instance->lazy_init_lock);
=====================================
modules/gui/macosx/main/VLCMain.m
=====================================
@@ -155,7 +155,8 @@ int OpenIntf (vlc_object_t *p_this)
intf_thread_t *p_intf = (intf_thread_t*) p_this;
p_interface_thread = p_intf;
- p_network_preparser = vlc_preparser_New(p_this, 1, 0);
+ p_network_preparser = vlc_preparser_New(p_this, 1, 0,
+ META_REQUEST_OPTION_PARSE);
if (p_network_preparser == nil)
{
retcode = VLC_ENOMEM;
=====================================
modules/gui/qt/maininterface/mainctx.cpp
=====================================
@@ -251,7 +251,8 @@ MainCtx::MainCtx(qt_intf_t *_p_intf)
QMetaObject::invokeMethod(m_medialib, &MediaLib::reload, Qt::QueuedConnection);
}
- m_network_preparser = vlc_preparser_New(VLC_OBJECT(libvlc), 1, 0);
+ m_network_preparser = vlc_preparser_New(VLC_OBJECT(libvlc), 1, 0,
+ META_REQUEST_OPTION_PARSE);
#ifdef UPDATE_CHECK
/* Checking for VLC updates */
=====================================
modules/gui/qt/player/player_controller.cpp
=====================================
@@ -1956,7 +1956,8 @@ void PlayerController::requestArtUpdate( input_item_t *p_item )
default_timeout = 0;
d->m_preparser = vlc_preparser_New(VLC_OBJECT(d->p_intf), 1,
- default_timeout);
+ default_timeout,
+ META_REQUEST_OPTION_FETCH_ANY);
if (unlikely(d->m_preparser == nullptr))
return;
}
=====================================
src/playlist/playlist.c
=====================================
@@ -41,7 +41,9 @@ vlc_playlist_New(vlc_object_t *parent, enum vlc_playlist_preparsing rec,
if (rec != VLC_PLAYLIST_PREPARSING_DISABLED)
{
playlist->parser = vlc_preparser_New(parent, preparse_max_threads,
- preparse_timeout);
+ preparse_timeout,
+ META_REQUEST_OPTION_PARSE |
+ META_REQUEST_OPTION_FETCH_LOCAL);
if (playlist->parser == NULL)
{
free(playlist);
=====================================
src/preparser/fetcher.c
=====================================
@@ -425,8 +425,10 @@ static void RunSearchNetwork(void *userdata)
TaskDelete(task);
}
-input_fetcher_t* input_fetcher_New( vlc_object_t* owner )
+input_fetcher_t* input_fetcher_New( vlc_object_t* owner,
+ input_item_meta_request_option_t request_type )
{
+ assert(request_type & META_REQUEST_OPTION_FETCH_ANY);
input_fetcher_t* fetcher = malloc( sizeof( *fetcher ) );
if( unlikely( !fetcher ) )
@@ -436,28 +438,44 @@ input_fetcher_t* input_fetcher_New( vlc_object_t* owner )
if (max_threads < 1)
max_threads = 1;
- fetcher->executor_local = vlc_executor_New(max_threads);
- if (!fetcher->executor_local)
+ if (request_type & META_REQUEST_OPTION_FETCH_LOCAL)
{
- free(fetcher);
- return NULL;
+ fetcher->executor_local = vlc_executor_New(max_threads);
+ if (!fetcher->executor_local)
+ {
+ free(fetcher);
+ return NULL;
+ }
}
+ else
+ fetcher->executor_local = NULL;
- fetcher->executor_network = vlc_executor_New(max_threads);
- if (!fetcher->executor_network)
+ if (request_type & META_REQUEST_OPTION_FETCH_NETWORK)
{
- vlc_executor_Delete(fetcher->executor_local);
- free(fetcher);
- return NULL;
- }
+ fetcher->executor_network = vlc_executor_New(max_threads);
+ if (!fetcher->executor_network)
+ {
+ if (fetcher->executor_local)
+ vlc_executor_Delete(fetcher->executor_local);
+ free(fetcher);
+ return NULL;
+ }
- fetcher->executor_downloader = vlc_executor_New(max_threads);
- if (!fetcher->executor_downloader)
+ fetcher->executor_downloader = vlc_executor_New(max_threads);
+ if (!fetcher->executor_downloader)
+ {
+ if (fetcher->executor_network)
+ vlc_executor_Delete(fetcher->executor_network);
+ if (fetcher->executor_local)
+ vlc_executor_Delete(fetcher->executor_local);
+ free(fetcher);
+ return NULL;
+ }
+ }
+ else
{
- vlc_executor_Delete(fetcher->executor_network);
- vlc_executor_Delete(fetcher->executor_local);
- free(fetcher);
- return NULL;
+ fetcher->executor_network = NULL;
+ fetcher->executor_downloader = NULL;
}
fetcher->owner = owner;
@@ -475,6 +493,10 @@ int input_fetcher_Push(input_fetcher_t* fetcher, input_item_t* item,
const input_fetcher_callbacks_t *cbs, void *cbs_userdata)
{
assert(options & META_REQUEST_OPTION_FETCH_ANY);
+ if (options & META_REQUEST_OPTION_FETCH_LOCAL)
+ assert(fetcher->executor_local != NULL);
+ if (options & META_REQUEST_OPTION_FETCH_NETWORK)
+ assert(fetcher->executor_network != NULL);
vlc_executor_t *executor = options & META_REQUEST_OPTION_FETCH_LOCAL
? fetcher->executor_local
@@ -508,9 +530,12 @@ void input_fetcher_Delete( input_fetcher_t* fetcher )
{
CancelAllTasks(fetcher);
- vlc_executor_Delete(fetcher->executor_local);
- vlc_executor_Delete(fetcher->executor_network);
- vlc_executor_Delete(fetcher->executor_downloader);
+ if (fetcher->executor_local)
+ vlc_executor_Delete(fetcher->executor_local);
+ if (fetcher->executor_network)
+ vlc_executor_Delete(fetcher->executor_network);
+ if (fetcher->executor_downloader)
+ vlc_executor_Delete(fetcher->executor_downloader);
vlc_dictionary_clear( &fetcher->album_cache, FreeCacheEntry, NULL );
free( fetcher );
=====================================
src/preparser/fetcher.h
=====================================
@@ -41,8 +41,13 @@ typedef struct input_fetcher_callbacks_t {
/**
* This function creates the fetcher object and thread.
+ *
+ * @param request_type a combination of META_REQUEST_OPTION_FETCH_LOCAL and
+ * META_REQUEST_OPTION_FETCH_NETWORK, it is used to setup the executors for
+ * each domain.
*/
-input_fetcher_t *input_fetcher_New( vlc_object_t * );
+input_fetcher_t *input_fetcher_New( vlc_object_t *,
+ input_item_meta_request_option_t request_type );
/**
* This function enqueues the provided item to be art fetched.
=====================================
src/preparser/preparser.c
=====================================
@@ -308,34 +308,51 @@ Interrupt(struct task *task)
}
vlc_preparser_t* vlc_preparser_New( vlc_object_t *parent, unsigned max_threads,
- vlc_tick_t default_timeout )
+ vlc_tick_t default_timeout,
+ input_item_meta_request_option_t request_type )
{
assert(max_threads >= 1);
assert(default_timeout >= 0);
+ assert(request_type & (META_REQUEST_OPTION_FETCH_ANY|META_REQUEST_OPTION_PARSE));
vlc_preparser_t* preparser = malloc( sizeof *preparser );
if (!preparser)
return NULL;
- preparser->executor = vlc_executor_New(max_threads);
- if (!preparser->executor)
+ if (request_type & META_REQUEST_OPTION_PARSE)
{
- free(preparser);
- return NULL;
+ preparser->executor = vlc_executor_New(max_threads);
+ if (!preparser->executor)
+ {
+ free(preparser);
+ return NULL;
+ }
}
+ else
+ preparser->executor = NULL;
preparser->default_timeout = default_timeout;
preparser->owner = parent;
- preparser->fetcher = input_fetcher_New( parent );
+ if (request_type & META_REQUEST_OPTION_FETCH_ANY)
+ {
+ preparser->fetcher = input_fetcher_New(parent, request_type);
+ if (unlikely(preparser->fetcher == NULL))
+ {
+ if (preparser->executor != NULL)
+ vlc_executor_Delete(preparser->executor);
+ free(preparser);
+ return NULL;
+ }
+ }
+ else
+ preparser->fetcher = NULL;
+
atomic_init( &preparser->deactivated, false );
vlc_mutex_init(&preparser->lock);
vlc_list_init(&preparser->submitted_tasks);
- if( unlikely( !preparser->fetcher ) )
- msg_Warn( parent, "unable to create art fetcher" );
-
return preparser;
}
@@ -349,20 +366,33 @@ int vlc_preparser_Push( vlc_preparser_t *preparser,
assert(i_options & META_REQUEST_OPTION_PARSE
|| i_options & META_REQUEST_OPTION_FETCH_ANY);
+ assert(!(i_options & META_REQUEST_OPTION_PARSE)
+ || preparser->executor != NULL);
+ assert(!(i_options & META_REQUEST_OPTION_FETCH_ANY)
+ || preparser->fetcher != NULL);
+
struct task *task =
TaskNew(preparser, item, i_options, cbs, cbs_userdata, id,
preparser->default_timeout);
if( !task )
return VLC_ENOMEM;
- PreparserAddTask(preparser, task);
+ if (preparser->executor != NULL)
+ {
+ PreparserAddTask(preparser, task);
+
+ vlc_executor_Submit(preparser->executor, &task->runnable);
- vlc_executor_Submit(preparser->executor, &task->runnable);
- return VLC_SUCCESS;
+ return VLC_SUCCESS;
+ }
+ return Fetch(task);
}
void vlc_preparser_Cancel( vlc_preparser_t *preparser, void *id )
{
+ if (preparser->executor == NULL)
+ return; /* TODO: the fetcher should be cancellable too */
+
vlc_mutex_lock(&preparser->lock);
struct task *task;
@@ -404,7 +434,8 @@ void vlc_preparser_Delete( vlc_preparser_t *preparser )
/* In case vlc_preparser_Deactivate() has not been called */
vlc_preparser_Cancel(preparser, NULL);
- vlc_executor_Delete(preparser->executor);
+ if (preparser->executor != NULL)
+ vlc_executor_Delete(preparser->executor);
if( preparser->fetcher )
input_fetcher_Delete( preparser->fetcher );
=====================================
test/libvlc/media.c
=====================================
@@ -240,13 +240,14 @@ static void test_input_metadata_timeout(libvlc_instance_t *vlc, int timeout,
.on_ended = input_item_preparse_timeout,
};
+ input_item_meta_request_option_t options =
+ META_REQUEST_OPTION_PARSE | META_REQUEST_OPTION_FETCH_LOCAL;
+
vlc_preparser_t *parser = vlc_preparser_New(VLC_OBJECT(vlc->p_libvlc_int),
- 1, VLC_TICK_FROM_MS(timeout));
+ 1, VLC_TICK_FROM_MS(timeout),
+ options);
assert(parser != NULL);
- i_ret = vlc_preparser_Push(parser, p_item,
- META_REQUEST_OPTION_PARSE |
- META_REQUEST_OPTION_FETCH_LOCAL,
- &cbs, &sem, parser);
+ i_ret = vlc_preparser_Push(parser, p_item, options, &cbs, &sem, parser);
assert(i_ret == 0);
if (wait_and_cancel > 0)
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/9d8130ab8d25b547f8cbc77a94fad087d3cfa885...999e53e3c65f6696563d6d06c5b0d362dd85aa62
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/9d8130ab8d25b547f8cbc77a94fad087d3cfa885...999e53e3c65f6696563d6d06c5b0d362dd85aa62
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