Merge pull request #124 from jp9000/new-locale-handling

Update to new module locale API
This commit is contained in:
Jim
2014-06-25 12:58:05 -07:00
46 changed files with 210 additions and 208 deletions

View File

@@ -30,10 +30,10 @@ static inline struct obs_encoder_info *get_encoder_info(const char *id)
return NULL;
}
const char *obs_encoder_getdisplayname(const char *id, const char *locale)
const char *obs_encoder_getdisplayname(const char *id)
{
struct obs_encoder_info *ei = get_encoder_info(id);
return ei ? ei->getname(locale) : NULL;
return ei ? ei->getname() : NULL;
}
static bool init_encoder(struct obs_encoder *encoder, const char *name,
@@ -227,14 +227,14 @@ obs_data_t obs_encoder_defaults(const char *id)
return (info) ? get_defaults(info) : NULL;
}
obs_properties_t obs_get_encoder_properties(const char *id, const char *locale)
obs_properties_t obs_get_encoder_properties(const char *id)
{
const struct obs_encoder_info *ei = get_encoder_info(id);
if (ei && ei->properties) {
obs_data_t defaults = get_defaults(ei);
obs_properties_t properties;
properties = ei->properties(locale);
properties = ei->properties();
obs_properties_apply_settings(properties, defaults);
obs_data_release(defaults);
return properties;
@@ -242,12 +242,11 @@ obs_properties_t obs_get_encoder_properties(const char *id, const char *locale)
return NULL;
}
obs_properties_t obs_encoder_properties(obs_encoder_t encoder,
const char *locale)
obs_properties_t obs_encoder_properties(obs_encoder_t encoder)
{
if (encoder && encoder->info.properties) {
obs_properties_t props;
props = encoder->info.properties(locale);
props = encoder->info.properties();
obs_properties_apply_settings(props, encoder->context.settings);
return props;
}

View File

@@ -102,10 +102,9 @@ struct obs_encoder_info {
/**
* Gets the full translated name of this encoder
*
* @param locale Locale to use for translation
* @return Translated name of the encoder
*/
const char *(*getname)(const char *locale);
const char *(*getname)(void);
/**
* Creates the encoder with the specified settings
@@ -155,10 +154,9 @@ struct obs_encoder_info {
/**
* Gets the property information of this encoder
*
* @param locale The locale to translate with
* @return The properties data
*/
obs_properties_t (*properties)(const char *locale);
obs_properties_t (*properties)(void);
/**
* Updates the settings for this encoder (usually used for things like

View File

@@ -52,6 +52,7 @@ struct draw_callback {
struct obs_module {
char *name;
void *module;
void (*set_locale)(const char *locale);
};
extern void free_module(struct obs_module *mod);
@@ -173,6 +174,8 @@ struct obs_core {
signal_handler_t signals;
proc_handler_t procs;
char *locale;
/* segmented into multiple sub-structures to keep things a bit more
* clean and organized */
struct obs_core_video video;

View File

@@ -73,7 +73,12 @@ int obs_load_module(const char *path)
return errorcode;
}
mod.name = bstrdup(path);
mod.name = bstrdup(path);
mod.set_locale = os_dlsym(mod.module, "obs_module_set_locale");
if (mod.set_locale)
mod.set_locale(obs->locale);
da_push_back(obs->modules, &mod);
return MODULE_SUCCESS;
}

View File

@@ -50,6 +50,9 @@ MODULE_EXPORT bool obs_module_load(uint32_t libobs_version);
/** Optional: Called when the module is unloaded. */
MODULE_EXPORT void obs_module_unload(void);
/** Called to set the current locale data for the module. */
MODULE_EXPORT void obs_module_set_locale(const char *locale);
/**
* Optional: Declares the author(s) of the module
*
@@ -59,9 +62,5 @@ MODULE_EXPORT void obs_module_unload(void);
MODULE_EXPORT const char *obs_module_author(void); \
const char *obs_module_author(void) {return name;}
/**
* Optional: Declares the author of the module
*
* @param locale Locale to look up the description for.
*/
MODULE_EXPORT const char *obs_module_description(const char *locale);
/** Optional: Returns a description of the module */
MODULE_EXPORT const char *obs_module_description(void);

View File

@@ -30,10 +30,10 @@ static inline const struct obs_output_info *find_output(const char *id)
return NULL;
}
const char *obs_output_getdisplayname(const char *id, const char *locale)
const char *obs_output_getdisplayname(const char *id)
{
const struct obs_output_info *info = find_output(id);
return (info != NULL) ? info->getname(locale) : NULL;
return (info != NULL) ? info->getname() : NULL;
}
static const char *output_signals[] = {
@@ -166,14 +166,14 @@ obs_data_t obs_output_defaults(const char *id)
return (info) ? get_defaults(info) : NULL;
}
obs_properties_t obs_get_output_properties(const char *id, const char *locale)
obs_properties_t obs_get_output_properties(const char *id)
{
const struct obs_output_info *info = find_output(id);
if (info && info->properties) {
obs_data_t defaults = get_defaults(info);
obs_properties_t properties;
properties = info->properties(locale);
properties = info->properties();
obs_properties_apply_settings(properties, defaults);
obs_data_release(defaults);
return properties;
@@ -181,11 +181,11 @@ obs_properties_t obs_get_output_properties(const char *id, const char *locale)
return NULL;
}
obs_properties_t obs_output_properties(obs_output_t output, const char *locale)
obs_properties_t obs_output_properties(obs_output_t output)
{
if (output && output->info.properties) {
obs_properties_t props;
props = output->info.properties(locale);
props = output->info.properties();
obs_properties_apply_settings(props, output->context.settings);
return props;
}

View File

@@ -31,7 +31,7 @@ struct obs_output_info {
uint32_t flags;
const char *(*getname)(const char *locale);
const char *(*getname)(void);
void *(*create)(obs_data_t settings, obs_output_t output);
void (*destroy)(void *data);
@@ -49,7 +49,7 @@ struct obs_output_info {
void (*defaults)(obs_data_t settings);
obs_properties_t (*properties)(const char *locale);
obs_properties_t (*properties)(void);
void (*pause)(void *data);
};

View File

@@ -90,7 +90,6 @@ struct obs_property {
};
struct obs_properties {
const char *locale;
void *param;
void (*destroy)(void *param);
@@ -98,12 +97,11 @@ struct obs_properties {
struct obs_property **last;
};
obs_properties_t obs_properties_create(const char *locale)
obs_properties_t obs_properties_create(void)
{
struct obs_properties *props;
props = bzalloc(sizeof(struct obs_properties));
props->locale = locale;
props->last = &props->first_property;
props->last = &props->first_property;
return props;
}
@@ -125,10 +123,10 @@ void *obs_properties_get_param(obs_properties_t props)
return props ? props->param : NULL;
}
obs_properties_t obs_properties_create_param(const char *locale,
void *param, void (*destroy)(void *param))
obs_properties_t obs_properties_create_param(void *param,
void (*destroy)(void *param))
{
struct obs_properties *props = obs_properties_create(locale);
struct obs_properties *props = obs_properties_create();
obs_properties_set_param(props, param, destroy);
return props;
}
@@ -161,11 +159,6 @@ void obs_properties_destroy(obs_properties_t props)
}
}
const char *obs_properties_locale(obs_properties_t props)
{
return props ? props->locale : NULL;
}
obs_property_t obs_properties_first(obs_properties_t props)
{
return (props != NULL) ? props->first_property : NULL;

View File

@@ -61,17 +61,15 @@ typedef struct obs_property *obs_property_t;
/* ------------------------------------------------------------------------- */
EXPORT obs_properties_t obs_properties_create(const char *locale);
EXPORT obs_properties_t obs_properties_create_param(const char *locale,
void *param, void (*destroy)(void *param));
EXPORT obs_properties_t obs_properties_create(void);
EXPORT obs_properties_t obs_properties_create_param(void *param,
void (*destroy)(void *param));
EXPORT void obs_properties_destroy(obs_properties_t props);
EXPORT void obs_properties_set_param(obs_properties_t props,
void *param, void (*destroy)(void *param));
EXPORT void *obs_properties_get_param(obs_properties_t props);
EXPORT const char *obs_properties_locale(obs_properties_t props);
EXPORT obs_property_t obs_properties_first(obs_properties_t props);
EXPORT obs_property_t obs_properties_get(obs_properties_t props,

View File

@@ -43,10 +43,9 @@ static inline void signal_item_remove(struct obs_scene_item *item)
calldata_free(&params);
}
static const char *scene_getname(const char *locale)
static const char *scene_getname(void)
{
/* TODO: locale */
UNUSED_PARAMETER(locale);
return "Scene";
}

View File

@@ -27,10 +27,10 @@ static inline const struct obs_service_info *find_service(const char *id)
return NULL;
}
const char *obs_service_getdisplayname(const char *id, const char *locale)
const char *obs_service_getdisplayname(const char *id)
{
const struct obs_service_info *info = find_service(id);
return (info != NULL) ? info->getname(locale) : NULL;
return (info != NULL) ? info->getname() : NULL;
}
obs_service_t obs_service_create(const char *id, const char *name,
@@ -112,14 +112,14 @@ obs_data_t obs_service_defaults(const char *id)
return (info) ? get_defaults(info) : NULL;
}
obs_properties_t obs_get_service_properties(const char *id, const char *locale)
obs_properties_t obs_get_service_properties(const char *id)
{
const struct obs_service_info *info = find_service(id);
if (info && info->properties) {
obs_data_t defaults = get_defaults(info);
obs_properties_t properties;
properties = info->properties(locale);
properties = info->properties();
obs_properties_apply_settings(properties, defaults);
obs_data_release(defaults);
return properties;
@@ -127,12 +127,11 @@ obs_properties_t obs_get_service_properties(const char *id, const char *locale)
return NULL;
}
obs_properties_t obs_service_properties(obs_service_t service,
const char *locale)
obs_properties_t obs_service_properties(obs_service_t service)
{
if (service && service->info.properties) {
obs_properties_t props;
props = service->info.properties(locale);
props = service->info.properties();
obs_properties_apply_settings(props, service->context.settings);
return props;
}

View File

@@ -21,7 +21,7 @@ struct obs_service_info {
/* required */
const char *id;
const char *(*getname)(const char *locale);
const char *(*getname)(void);
void *(*create)(obs_data_t settings, obs_service_t service);
void (*destroy)(void *data);
@@ -33,7 +33,7 @@ struct obs_service_info {
void (*defaults)(obs_data_t settings);
obs_properties_t (*properties)(const char *locale);
obs_properties_t (*properties)(void);
/**
* Called when getting ready to start up an output, before the encoders

View File

@@ -95,11 +95,10 @@ bool obs_source_init_context(struct obs_source *source,
source_signals);
}
const char *obs_source_getdisplayname(enum obs_source_type type,
const char *id, const char *locale)
const char *obs_source_getdisplayname(enum obs_source_type type, const char *id)
{
const struct obs_source_info *info = get_source_info(type, id);
return (info != NULL) ? info->getname(locale) : NULL;
return (info != NULL) ? info->getname() : NULL;
}
/* internal initialization */
@@ -322,14 +321,14 @@ obs_data_t obs_source_settings(enum obs_source_type type, const char *id)
}
obs_properties_t obs_get_source_properties(enum obs_source_type type,
const char *id, const char *locale)
const char *id)
{
const struct obs_source_info *info = get_source_info(type, id);
if (info && info->properties) {
obs_data_t defaults = get_defaults(info);
obs_properties_t properties;
properties = info->properties(locale);
properties = info->properties();
obs_properties_apply_settings(properties, defaults);
obs_data_release(defaults);
return properties;
@@ -337,11 +336,11 @@ obs_properties_t obs_get_source_properties(enum obs_source_type type,
return NULL;
}
obs_properties_t obs_source_properties(obs_source_t source, const char *locale)
obs_properties_t obs_source_properties(obs_source_t source)
{
if (source_valid(source) && source->info.properties) {
obs_properties_t props;
props = source->info.properties(locale);
props = source->info.properties();
obs_properties_apply_settings(props, source->context.settings);
return props;
}

View File

@@ -118,10 +118,9 @@ struct obs_source_info {
/**
* Get the translated name of the source type
*
* @param locale The locale to translate with
* @return The translated name of the source type
*/
const char *(*getname)(const char *locale);
const char *(*getname)(void);
/**
* Creates the source data for the source
@@ -161,10 +160,9 @@ struct obs_source_info {
/**
* Gets the property information of this source
*
* @param locale The locale to translate with
* @return The properties data
*/
obs_properties_t (*properties)(const char *locale);
obs_properties_t (*properties)(void);
/**
* Updates the settings for this source

View File

@@ -503,7 +503,7 @@ static inline bool obs_init_handlers(void)
extern const struct obs_source_info scene_info;
static bool obs_init(void)
static bool obs_init(const char *locale)
{
obs = bzalloc(sizeof(struct obs_core));
@@ -512,11 +512,12 @@ static bool obs_init(void)
if (!obs_init_handlers())
return false;
obs->locale = bstrdup(locale);
obs_register_source(&scene_info);
return true;
}
bool obs_startup(void)
bool obs_startup(const char *locale)
{
bool success;
@@ -525,7 +526,7 @@ bool obs_startup(void)
return false;
}
success = obs_init();
success = obs_init(locale);
if (!success)
obs_shutdown();
@@ -559,6 +560,7 @@ void obs_shutdown(void)
free_module(obs->modules.array+i);
da_free(obs->modules);
bfree(obs->locale);
bfree(obs);
obs = NULL;
}
@@ -568,6 +570,28 @@ bool obs_initialized(void)
return obs != NULL;
}
void obs_set_locale(const char *locale)
{
if (!obs)
return;
if (obs->locale)
bfree(obs->locale);
obs->locale = bstrdup(locale);
for (size_t i = 0; i < obs->modules.num; i++) {
struct obs_module *module = obs->modules.array+i;
if (module->set_locale)
module->set_locale(locale);
}
}
const char *obs_get_locale(void)
{
return obs ? obs->locale : NULL;
}
bool obs_reset_video(struct obs_video_info *ovi)
{
if (!obs) return false;

View File

@@ -197,8 +197,12 @@ struct source_frame {
/* ------------------------------------------------------------------------- */
/* OBS context */
/** Initializes OBS */
EXPORT bool obs_startup(void);
/**
* Initializes OBS
*
* @param locale The locale to use for modules
*/
EXPORT bool obs_startup(const char *locale);
/** Releases all data associated with OBS and terminates the OBS context */
EXPORT void obs_shutdown(void);
@@ -206,6 +210,17 @@ EXPORT void obs_shutdown(void);
/** @return true if the main OBS context has been initialized */
EXPORT bool obs_initialized(void);
/**
* Sets a new locale to use for modules. This will call obs_module_set_locale
* for each module with the new locale.
*
* @param locale The locale to use for modules
*/
EXPORT void obs_set_locale(const char *locale);
/** @return the current locale */
EXPORT const char *obs_get_locale(void);
/**
* Sets base video ouput base resolution/fps/format
*
@@ -462,7 +477,7 @@ EXPORT void obs_display_remove_draw_callback(obs_display_t display,
/** Returns the translated display name of a source */
EXPORT const char *obs_source_getdisplayname(enum obs_source_type type,
const char *id, const char *locale);
const char *id);
/**
* Creates a source of the specified type with the specified settings.
@@ -497,14 +512,13 @@ EXPORT obs_data_t obs_get_source_defaults(enum obs_source_type type,
/** Returns the property list, if any. Free with obs_properties_destroy */
EXPORT obs_properties_t obs_get_source_properties(enum obs_source_type type,
const char *id, const char *locale);
const char *id);
/**
* Returns the properties list for a specific existing source. Free with
* obs_properties_destroy
*/
EXPORT obs_properties_t obs_source_properties(obs_source_t source,
const char *locale);
EXPORT obs_properties_t obs_source_properties(obs_source_t source);
/** Updates settings for this source */
EXPORT void obs_source_update(obs_source_t source, obs_data_t settings);
@@ -737,8 +751,7 @@ EXPORT void obs_sceneitem_get_box_transform(obs_sceneitem_t item,
/* ------------------------------------------------------------------------- */
/* Outputs */
EXPORT const char *obs_output_getdisplayname(const char *id,
const char *locale);
EXPORT const char *obs_output_getdisplayname(const char *id);
/**
* Creates an output.
@@ -763,15 +776,13 @@ EXPORT bool obs_output_active(obs_output_t output);
EXPORT obs_data_t obs_output_defaults(const char *id);
/** Returns the property list, if any. Free with obs_properties_destroy */
EXPORT obs_properties_t obs_get_output_properties(const char *id,
const char *locale);
EXPORT obs_properties_t obs_get_output_properties(const char *id);
/**
* Returns the property list of an existing output, if any. Free with
* obs_properties_destroy
*/
EXPORT obs_properties_t obs_output_properties(obs_output_t output,
const char *locale);
EXPORT obs_properties_t obs_output_properties(obs_output_t output);
/** Updates the settings for this output context */
EXPORT void obs_output_update(obs_output_t output, obs_data_t settings);
@@ -883,8 +894,7 @@ EXPORT void obs_output_signal_stop(obs_output_t output, int code);
/* ------------------------------------------------------------------------- */
/* Encoders */
EXPORT const char *obs_encoder_getdisplayname(const char *id,
const char *locale);
EXPORT const char *obs_encoder_getdisplayname(const char *id);
/**
* Creates a video encoder context
@@ -918,15 +928,13 @@ EXPORT const char *obs_encoder_get_codec(obs_encoder_t encoder);
EXPORT obs_data_t obs_encoder_defaults(const char *id);
/** Returns the property list, if any. Free with obs_properties_destroy */
EXPORT obs_properties_t obs_get_encoder_properties(const char *id,
const char *locale);
EXPORT obs_properties_t obs_get_encoder_properties(const char *id);
/**
* Returns the property list of an existing encoder, if any. Free with
* obs_properties_destroy
*/
EXPORT obs_properties_t obs_encoder_properties(obs_encoder_t encoder,
const char *locale);
EXPORT obs_properties_t obs_encoder_properties(obs_encoder_t encoder);
/**
* Updates the settings of the encoder context. Usually used for changing
@@ -972,8 +980,7 @@ EXPORT void obs_free_encoder_packet(struct encoder_packet *packet);
/* ------------------------------------------------------------------------- */
/* Stream Services */
EXPORT const char *obs_service_getdisplayname(const char *id,
const char *locale);
EXPORT const char *obs_service_getdisplayname(const char *id);
EXPORT obs_service_t obs_service_create(const char *id, const char *name,
obs_data_t settings);
@@ -985,15 +992,13 @@ EXPORT const char *obs_service_getname(obs_service_t service);
EXPORT obs_data_t obs_service_defaults(const char *id);
/** Returns the property list, if any. Free with obs_properties_destroy */
EXPORT obs_properties_t obs_get_service_properties(const char *id,
const char *locale);
EXPORT obs_properties_t obs_get_service_properties(const char *id);
/**
* Returns the property list of an existing service context, if any. Free with
* obs_properties_destroy
*/
EXPORT obs_properties_t obs_service_properties(obs_service_t service,
const char *locale);
EXPORT obs_properties_t obs_service_properties(obs_service_t service);
/** Gets the service type */
EXPORT const char *obs_service_gettype(obs_service_t service);