/***************************************************************************** * config_PutPsz: set the string value of a string variable ***************************************************************************** * This function is used to set the value of variables which are internally * represented by a string (CONFIG_ITEM_STRING, CONFIG_ITEM_*FILE, * CONFIG_ITEM_DIRECTORY, CONFIG_ITEM_PASSWORD, and CONFIG_ITEM_MODULE). *****************************************************************************/ void config_PutPsz( vlc_object_t *p_this, const char *psz_name, const char *psz_value ) { module_config_t *p_config; p_config = config_FindConfig( p_this, psz_name ); /* sanity checks */ if( !p_config ) { msg_Warn( p_this, "option %s does not exist", psz_name ); return; } if (!IsConfigStringType (p_config->i_type)) { msg_Err( p_this, "option %s does not refer to a string", psz_name ); return; } char *str, *oldstr; if ((psz_value != NULL) && *psz_value) str = strdup (psz_value); else str = NULL; vlc_rwlock_wrlock (&config_lock); oldstr = (char *)p_config->value.psz; p_config->value.psz = str; config_dirty = true; vlc_rwlock_unlock (&config_lock); free (oldstr); }
/** * Initializes the messages logging subsystem and drain the early messages to * the configured log. * * \return 0 on success, -1 on error. */ int vlc_LogInit(libvlc_int_t *vlc) { vlc_logger_t *logger = libvlc_priv(vlc)->logger; if (unlikely(logger == NULL)) return -1; vlc_log_cb cb; void *sys, *early_sys = NULL; /* TODO: module configuration item */ module_t *module = vlc_module_load(logger, "logger", NULL, false, vlc_logger_load, logger, &cb, &sys); if (module == NULL) cb = vlc_vaLogDiscard; vlc_rwlock_wrlock(&logger->lock); if (logger->log == vlc_vaLogEarly) early_sys = logger->sys; logger->log = cb; logger->sys = sys; assert(logger->module == NULL); /* Only one call to vlc_LogInit()! */ logger->module = module; vlc_rwlock_unlock(&logger->lock); if (early_sys != NULL) vlc_LogEarlyClose(logger, early_sys); return 0; }
/** * Sets the message logging callback. * \param cb message callback, or NULL to reset * \param data data pointer for the message callback */ void vlc_LogSet (libvlc_int_t *vlc, vlc_log_cb cb, void *opaque) { libvlc_priv_t *priv = libvlc_priv (vlc); if (cb == NULL) { #if defined (HAVE_ISATTY) && !defined (_WIN32) if (isatty (STDERR_FILENO) && var_InheritBool (vlc, "color")) cb = PrintColorMsg; else #endif cb = PrintMsg; opaque = (void *)(intptr_t)priv->log.verbose; } vlc_rwlock_wrlock (&priv->log.lock); priv->log.cb = cb; priv->log.opaque = opaque; vlc_rwlock_unlock (&priv->log.lock); /* Announce who we are */ msg_Dbg (vlc, "VLC media player - %s", VERSION_MESSAGE); msg_Dbg (vlc, "%s", COPYRIGHT_MESSAGE); msg_Dbg (vlc, "revision %s", psz_vlc_changeset); msg_Dbg (vlc, "configured with %s", CONFIGURE_LINE); }
/***************************************************************************** * config_PutInt: set the integer value of an int variable ***************************************************************************** * This function is used to set the value of variables which are internally * represented by an integer (CONFIG_ITEM_INTEGER and * CONFIG_ITEM_BOOL). *****************************************************************************/ void config_PutInt( vlc_object_t *p_this, const char *psz_name, int64_t i_value ) { module_config_t *p_config; p_config = config_FindConfig( p_this, psz_name ); /* sanity checks */ if( !p_config ) { msg_Warn( p_this, "option %s does not exist", psz_name ); return; } if (!IsConfigIntegerType (p_config->i_type)) { msg_Err( p_this, "option %s does not refer to an int", psz_name ); return; } if (i_value < p_config->min.i) i_value = p_config->min.i; if (i_value > p_config->max.i) i_value = p_config->max.i; vlc_rwlock_wrlock (&config_lock); p_config->value.i = i_value; config_dirty = true; vlc_rwlock_unlock (&config_lock); }
/** * Sets the message logging callback. * \param cb message callback, or NULL to clear * \param data data pointer for the message callback */ void vlc_LogSet(libvlc_int_t *vlc, vlc_log_cb cb, void *opaque) { vlc_logger_t *logger = libvlc_priv(vlc)->logger; if (unlikely(logger == NULL)) return; module_t *module; void *sys; if (cb == NULL) cb = vlc_vaLogDiscard; vlc_rwlock_wrlock(&logger->lock); sys = logger->sys; module = logger->module; logger->log = cb; logger->sys = opaque; logger->module = NULL; vlc_rwlock_unlock(&logger->lock); if (module != NULL) vlc_module_unload(module, vlc_logger_unload, sys); /* Announce who we are */ msg_Dbg (vlc, "VLC media player - %s", VERSION_MESSAGE); msg_Dbg (vlc, "%s", COPYRIGHT_MESSAGE); msg_Dbg (vlc, "revision %s", psz_vlc_changeset); msg_Dbg (vlc, "configured with %s", CONFIGURE_LINE); }
/***************************************************************************** * config_ResetAll: reset the configuration data for all the modules. *****************************************************************************/ void config_ResetAll( vlc_object_t *p_this ) { VLC_UNUSED(p_this); module_t *p_module; module_t **list = module_list_get (NULL); vlc_rwlock_wrlock (&config_lock); for (size_t j = 0; (p_module = list[j]) != NULL; j++) { if( p_module->b_submodule ) continue; for (size_t i = 0; i < p_module->confsize; i++ ) { module_config_t *p_config = p_module->p_config + i; if (IsConfigIntegerType (p_config->i_type)) p_config->value.i = p_config->orig.i; else if (IsConfigFloatType (p_config->i_type)) p_config->value.f = p_config->orig.f; else if (IsConfigStringType (p_config->i_type)) { free ((char *)p_config->value.psz); p_config->value.psz = strdupnull (p_config->orig.psz); } } } vlc_rwlock_unlock (&config_lock); module_list_free (list); }
/***************************************************************************** * config_PutFloat: set the value of a float variable ***************************************************************************** * This function is used to set the value of variables which are internally * represented by a float (CONFIG_ITEM_FLOAT). *****************************************************************************/ void config_PutFloat( vlc_object_t *p_this, const char *psz_name, float f_value ) { module_config_t *p_config; p_config = config_FindConfig( p_this, psz_name ); /* sanity checks */ if( !p_config ) { msg_Warn( p_this, "option %s does not exist", psz_name ); return; } if (!IsConfigFloatType (p_config->i_type)) { msg_Err( p_this, "option %s does not refer to a float", psz_name ); return; } /* if f_min == f_max == 0, then do not use them */ if ((p_config->min.f == 0) && (p_config->max.f == 0)) ; else if (f_value < p_config->min.f) f_value = p_config->min.f; else if (f_value > p_config->max.f) f_value = p_config->max.f; vlc_rwlock_wrlock (&config_lock); p_config->value.f = f_value; config_dirty = true; vlc_rwlock_unlock (&config_lock); }
/** * Unsubscribe from the message queue. * This function waits for the message callback to return if needed. */ void msg_Unsubscribe (msg_subscription_t *sub) { msg_bank_t *bank = libvlc_bank (sub->instance); vlc_rwlock_wrlock (&bank->lock); TAB_REMOVE (bank->i_sub, bank->pp_sub, sub); vlc_rwlock_unlock (&bank->lock); free (sub); }
/** * Deinitializes an interruption context. * The context shall no longer be used by any thread. */ void vlc_interrupt_deinit(vlc_interrupt_t *ctx) { assert(ctx->callback == NULL); assert(!ctx->attached); vlc_mutex_destroy(&ctx->lock); vlc_rwlock_wrlock(&vlc_interrupt_lock); assert(vlc_interrupt_refs > 0); if (--vlc_interrupt_refs == 0) vlc_threadvar_delete(&vlc_interrupt_var); vlc_rwlock_unlock(&vlc_interrupt_lock); }
void msg_DisableObjectPrinting (vlc_object_t *obj, const char * psz_object) { msg_bank_t *bank = libvlc_bank (obj->p_libvlc); vlc_rwlock_wrlock (&bank->lock); if( !strcmp(psz_object, "all") ) bank->all_objects_enabled = false; else vlc_dictionary_insert (&bank->enabled_objects, psz_object, (void *)kObjectPrintingDisabled); vlc_rwlock_unlock (&bank->lock); }
void msg_SubscriptionSetVerbosity( msg_subscription_t *sub, const int i_verbosity ) { if( i_verbosity < 0 || i_verbosity > 2 ) return; msg_bank_t *bank = libvlc_bank ( sub->instance ); vlc_rwlock_wrlock (&bank->lock); sub->verbosity = i_verbosity; vlc_rwlock_unlock (&bank->lock); }
/** * Unsubscribe from the message queue. * This function waits for the message callback to return if needed. */ void vlc_Unsubscribe (msg_subscription_t *sub) { vlc_rwlock_wrlock (&msg_lock); if (sub->next != NULL) sub->next->prev = sub->prev; if (sub->prev != NULL) sub->prev->next = sub->next; else { assert (msg_head == sub); msg_head = sub->next; } vlc_rwlock_unlock (&msg_lock); free (sub); }
/***************************************************************************** * config_PutPsz: set the string value of a string variable ***************************************************************************** * This function is used to set the value of variables which are internally * represented by a string (CONFIG_ITEM_STRING, CONFIG_ITEM_FILE, * CONFIG_ITEM_DIRECTORY, CONFIG_ITEM_PASSWORD, and CONFIG_ITEM_MODULE). *****************************************************************************/ void config_PutPsz( vlc_object_t *p_this, const char *psz_name, const char *psz_value ) { module_config_t *p_config; vlc_value_t oldval; p_config = config_FindConfig( p_this, psz_name ); /* sanity checks */ if( !p_config ) { msg_Warn( p_this, "option %s does not exist", psz_name ); return; } if (!IsConfigStringType (p_config->i_type)) { msg_Err( p_this, "option %s does not refer to a string", psz_name ); return; } vlc_rwlock_wrlock (&config_lock); /* backup old value */ oldval.psz_string = (char *)p_config->value.psz; if ((psz_value != NULL) && *psz_value) p_config->value.psz = strdup (psz_value); else p_config->value.psz = NULL; p_config->b_dirty = true; vlc_rwlock_unlock (&config_lock); if( p_config->pf_callback ) { vlc_value_t val; val.psz_string = (char *)psz_value; p_config->pf_callback( p_this, psz_name, oldval, val, p_config->p_callback_data ); } /* free old string */ free( oldval.psz_string ); }
/** * Subscribe to the message queue. * Whenever a message is emitted, a callback will be called. * Callback invocation are serialized within a subscription. * * @param cb callback function * @param opaque data for the callback function * @return a subscription pointer, or NULL in case of failure */ msg_subscription_t *vlc_Subscribe (msg_callback_t cb, void *opaque) { msg_subscription_t *sub = malloc (sizeof (*sub)); if (sub == NULL) return NULL; sub->prev = NULL; sub->func = cb; sub->opaque = opaque; vlc_rwlock_wrlock (&msg_lock); sub->next = msg_head; msg_head = sub; vlc_rwlock_unlock (&msg_lock); return sub; }
/***************************************************************************** * config_PutInt: set the integer value of an int variable ***************************************************************************** * This function is used to set the value of variables which are internally * represented by an integer (CONFIG_ITEM_INTEGER and * CONFIG_ITEM_BOOL). *****************************************************************************/ void config_PutInt( vlc_object_t *p_this, const char *psz_name, int i_value ) { module_config_t *p_config; vlc_value_t oldval; p_config = config_FindConfig( p_this, psz_name ); /* sanity checks */ if( !p_config ) { msg_Warn( p_this, "option %s does not exist", psz_name ); return; } if (!IsConfigIntegerType (p_config->i_type)) { msg_Err( p_this, "option %s does not refer to an int", psz_name ); return; } /* if i_min == i_max == 0, then do not use them */ if ((p_config->min.i == 0) && (p_config->max.i == 0)) ; else if (i_value < p_config->min.i) i_value = p_config->min.i; else if (i_value > p_config->max.i) i_value = p_config->max.i; vlc_rwlock_wrlock (&config_lock); /* backup old value */ oldval.i_int = p_config->value.i; p_config->value.i = i_value; p_config->b_dirty = true; vlc_rwlock_unlock (&config_lock); if( p_config->pf_callback ) { vlc_value_t val; val.i_int = i_value; p_config->pf_callback( p_this, psz_name, oldval, val, p_config->p_callback_data ); } }
/** * Subscribe to the message queue. * Whenever a message is emitted, a callback will be called. * Callback invocation are serialized within a subscription. * * @param instance LibVLC instance to get messages from * @param cb callback function * @param opaque data for the callback function * @return a subscription pointer, or NULL in case of failure */ msg_subscription_t *msg_Subscribe (libvlc_int_t *instance, msg_callback_t cb, msg_cb_data_t *opaque) { msg_subscription_t *sub = malloc (sizeof (*sub)); if (sub == NULL) return NULL; sub->instance = instance; sub->func = cb; sub->opaque = opaque; msg_bank_t *bank = libvlc_bank (instance); vlc_rwlock_wrlock (&bank->lock); TAB_APPEND (bank->i_sub, bank->pp_sub, sub); vlc_rwlock_unlock (&bank->lock); return sub; }
/** * Initializes an interruption context. */ void vlc_interrupt_init(vlc_interrupt_t *ctx) { vlc_rwlock_wrlock(&vlc_interrupt_lock); assert(vlc_interrupt_refs < UINT_MAX); if (vlc_interrupt_refs++ == 0) #ifndef NDEBUG vlc_threadvar_create(&vlc_interrupt_var, vlc_interrupt_destructor); #else vlc_threadvar_create(&vlc_interrupt_var, NULL); #endif vlc_rwlock_unlock(&vlc_interrupt_lock); vlc_mutex_init(&ctx->lock); ctx->interrupted = false; atomic_init(&ctx->killed, false); #ifndef NDEBUG ctx->attached = false; #endif ctx->callback = NULL; }
/***************************************************************************** * config_LoadConfigFile: loads the configuration file. ***************************************************************************** * This function is called to load the config options stored in the config * file. *****************************************************************************/ int config_LoadConfigFile( vlc_object_t *p_this ) { FILE *file; file = config_OpenConfigFile (p_this); if (file == NULL) return VLC_EGENERIC; /* Look for UTF-8 Byte Order Mark */ char * (*convert) (const char *) = strdupnull; char bom[3]; if ((fread (bom, 1, 3, file) != 3) || memcmp (bom, "\xEF\xBB\xBF", 3)) { convert = FromLocaleDup; rewind (file); /* no BOM, rewind */ } char *line = NULL; size_t bufsize; ssize_t linelen; /* Ensure consistent number formatting... */ locale_t loc = newlocale (LC_NUMERIC_MASK, "C", NULL); locale_t baseloc = uselocale (loc); vlc_rwlock_wrlock (&config_lock); while ((linelen = getline (&line, &bufsize, file)) != -1) { line[linelen - 1] = '\0'; /* trim newline */ /* Ignore comments, section and empty lines */ if (memchr ("#[", line[0], 3) != NULL) continue; /* look for option name */ const char *psz_option_name = line; char *ptr = strchr (line, '='); if (ptr == NULL) continue; /* syntax error */ *ptr = '\0'; module_config_t *item = config_FindConfig (p_this, psz_option_name); if (item == NULL) continue; const char *psz_option_value = ptr + 1; switch (item->i_type) { case CONFIG_ITEM_BOOL: case CONFIG_ITEM_INTEGER: { int64_t l; errno = 0; l = strtoi (psz_option_value); if ((l > item->max.i) || (l < item->min.i)) errno = ERANGE; if (errno) msg_Warn (p_this, "Integer value (%s) for %s: %m", psz_option_value, psz_option_name); else item->saved.i = item->value.i = l; break; } case CONFIG_ITEM_FLOAT: if (!*psz_option_value) break; /* ignore empty option */ item->value.f = (float)atof (psz_option_value); item->saved.f = item->value.f; break; default: free ((char *)item->value.psz); free ((char *)item->saved.psz); item->value.psz = convert (psz_option_value); item->saved.psz = strdupnull (item->value.psz); break; } } vlc_rwlock_unlock (&config_lock); free (line); if (ferror (file)) { msg_Err (p_this, "error reading configuration: %m"); clearerr (file); } fclose (file); if (loc != (locale_t)0) { uselocale (baseloc); freelocale (loc); } return 0; }