Browse Source

lib: use an internal preparser

Do a lazy initialisation as the preparser is not necessarily required by
the user.

This commit is temporary and will be replaced by the future
libvlc_parser_t API.

It is done now to remove libvlc_GetMainPreparser().
pull/170/head
Thomas Guillem 2 years ago
committed by Steve Lhomme
parent
commit
e863a52dc3
  1. 36
      lib/core.c
  2. 8
      lib/libvlc_internal.h
  3. 10
      lib/media.c

36
lib/core.c

@ -28,6 +28,7 @@
#include <vlc_modules.h>
#include <vlc/vlc.h>
#include <vlc_preparser.h>
#include <vlc_interface.h>
#include <stdarg.h>
@ -78,6 +79,10 @@ libvlc_instance_t * libvlc_new( int argc, const char *const *argv )
p_new->p_libvlc_int = p_libvlc_int;
vlc_atomic_rc_init( &p_new->ref_count );
p_new->p_callback_list = NULL;
vlc_mutex_init(&p_new->lazy_init_lock);
p_new->parser = NULL;
return p_new;
error:
@ -99,6 +104,10 @@ void libvlc_release( libvlc_instance_t *p_instance )
if(vlc_atomic_rc_dec( &p_instance->ref_count ))
{
libvlc_Quit( p_instance->p_libvlc_int );
if (p_instance->parser != NULL)
vlc_preparser_Delete(p_instance->parser);
libvlc_InternalCleanup( p_instance->p_libvlc_int );
libvlc_InternalDestroy( p_instance->p_libvlc_int );
free( p_instance );
@ -235,4 +244,31 @@ int64_t libvlc_clock(void)
return US_FROM_VLC_TICK(vlc_tick_now());
}
vlc_preparser_t *libvlc_get_preparser(libvlc_instance_t *instance)
{
vlc_mutex_lock(&instance->lazy_init_lock);
vlc_preparser_t *parser = instance->parser;
if (parser == NULL)
{
/* Temporary: the 2 following variables will be configured directly
* with future libvlc_parser API */
int max_threads = var_InheritInteger(instance->p_libvlc_int, "preparse-threads");
if (max_threads < 1)
max_threads = 1;
vlc_tick_t default_timeout =
VLC_TICK_FROM_MS(var_InheritInteger(instance->p_libvlc_int, "preparse-timeout"));
if (default_timeout < 0)
default_timeout = 0;
parser = instance->parser =
vlc_preparser_New(VLC_OBJECT(instance->p_libvlc_int), max_threads,
default_timeout);
}
vlc_mutex_unlock(&instance->lazy_init_lock);
return parser;
}
const char vlc_module_name[] = "libvlc";

8
lib/libvlc_internal.h

@ -35,6 +35,8 @@
#include <vlc_arrays.h>
#include <vlc_threads.h>
typedef struct vlc_preparser_t vlc_preparser_t;
/* Note well: this header is included from LibVLC core.
* Therefore, static inline functions MUST NOT call LibVLC functions here
* (this can cause linkage failure on some platforms). */
@ -99,6 +101,10 @@ struct libvlc_instance_t
libvlc_int_t *p_libvlc_int;
vlc_atomic_rc_t ref_count;
struct libvlc_callback_entry_list_t *p_callback_list;
vlc_mutex_t lazy_init_lock;
vlc_preparser_t *parser;
struct
{
void (*cb) (void *, int, const libvlc_log_t *, const char *, va_list);
@ -144,4 +150,6 @@ static inline vlc_tick_t vlc_tick_from_libvlc_time(libvlc_time_t time)
return VLC_TICK_FROM_MS(time);
}
vlc_preparser_t *libvlc_get_preparser(libvlc_instance_t *instance);
#endif

10
lib/media.c

@ -740,8 +740,7 @@ int libvlc_media_parse_request(libvlc_instance_t *inst, libvlc_media_t *media,
|| expected == libvlc_media_parsed_status_done)
return -1;
libvlc_int_t *libvlc = inst->p_libvlc_int;
vlc_preparser_t *parser = libvlc_GetMainPreparser(libvlc);
vlc_preparser_t *parser = libvlc_get_preparser(inst);
if (unlikely(parser == NULL))
return -1;
@ -789,10 +788,9 @@ int libvlc_media_parse_request(libvlc_instance_t *inst, libvlc_media_t *media,
void
libvlc_media_parse_stop(libvlc_instance_t *inst, libvlc_media_t *media)
{
libvlc_int_t *libvlc = inst->p_libvlc_int;
vlc_preparser_t *parser = libvlc_GetMainPreparser(libvlc);
if (unlikely(parser != NULL))
vlc_preparser_Cancel(parser, media);
vlc_preparser_t *parser = libvlc_get_preparser(inst);
assert(parser != NULL);
vlc_preparser_Cancel(parser, media);
}
// Get Parsed status for media descriptor object

Loading…
Cancel
Save