From 2915b611a1c64c6c9b3dd5dcda951e0787916ca9 Mon Sep 17 00:00:00 2001 From: Laurent Aimar Date: Mon, 24 May 2010 17:36:44 +0200 Subject: [PATCH] Moved var_InheritURational to the core. --- include/vlc_variables.h | 3 +++ modules/access/imem.c | 57 ++--------------------------------------- src/libvlccore.sym | 1 + src/misc/variables.c | 53 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 55 deletions(-) diff --git a/include/vlc_variables.h b/include/vlc_variables.h index 4a0de14f21..0a9d7057b2 100644 --- a/include/vlc_variables.h +++ b/include/vlc_variables.h @@ -712,6 +712,9 @@ static inline mtime_t var_InheritTime( vlc_object_t *obj, const char *name ) } #define var_InheritTime(o, n) var_InheritTime(VLC_OBJECT(o), n) +VLC_EXPORT( int, var_InheritURational, ( vlc_object_t *, unsigned *num, unsigned *den, const char *var ) ); +#define var_InheritURational(a,b,c,d) var_InheritURational(VLC_OBJECT(a), b, c, d) + #define var_GetInteger(a,b) var_GetInteger( VLC_OBJECT(a),b) #define var_GetBool(a,b) var_GetBool( VLC_OBJECT(a),b) #define var_GetTime(a,b) var_GetTime( VLC_OBJECT(a),b) diff --git a/modules/access/imem.c b/modules/access/imem.c index c3e17fbd03..e924097af3 100644 --- a/modules/access/imem.c +++ b/modules/access/imem.c @@ -224,10 +224,6 @@ typedef struct { } imem_sys_t; static void ParseMRL(vlc_object_t *, const char *); -#define var_InheritRational(a,b,c,d) var_InheritRational(VLC_OBJECT(a),b,c,d) -static int (var_InheritRational)(vlc_object_t *, - unsigned *num, unsigned *den, - const char *var); /** * It closes the common part of the access and access_demux @@ -440,13 +436,13 @@ static int OpenDemux(vlc_object_t *object) fmt.video.i_width = var_InheritInteger(object, "imem-width"); fmt.video.i_height = var_InheritInteger(object, "imem-height"); unsigned num, den; - if (!var_InheritRational(object, &num, &den, "imem-dar") && num > 0 && den > 0) { + if (!var_InheritURational(object, &num, &den, "imem-dar") && num > 0 && den > 0) { if (fmt.video.i_width > 0 && fmt.video.i_height > 0) { fmt.video.i_sar_num = num * fmt.video.i_height; fmt.video.i_sar_den = den * fmt.video.i_width; } } - if (!var_InheritRational(object, &num, &den, "imem-fps") && num > 0 && den > 0) { + if (!var_InheritURational(object, &num, &den, "imem-fps") && num > 0 && den > 0) { fmt.video.i_frame_rate = num; fmt.video.i_frame_rate_base = den; } @@ -610,55 +606,6 @@ static int Demux(demux_t *demux) return 1; } -/** - * It parses a rational number (it also accepts basic float number). - * - * It returns an error if the rational number cannot be parsed (0/0 is valid). - */ -static int (var_InheritRational)(vlc_object_t *object, - unsigned *num, unsigned *den, - const char *var) -{ - /* */ - *num = 0; - *den = 0; - - /* */ - char *tmp = var_InheritString(object, var); - if (!tmp) - goto error; - - char *next; - unsigned n = strtol(tmp, &next, 0); - unsigned d = strtol(*next ? &next[1] : "0", NULL, 0); - - if (*next == '.') { - /* Interpret as a float number */ - double r = us_atof(tmp); - double c = ceil(r); - if (c >= UINT_MAX) - goto error; - unsigned m = c; - if (m > 0) { - d = UINT_MAX / m; - n = r * d; - } else { - n = 0; - d = 0; - } - } - - if (n > 0 && d > 0) - vlc_ureduce(num, den, n, d, 0); - - free(tmp); - return VLC_SUCCESS; - -error: - free(tmp); - return VLC_EGENERIC; -} - /** * Parse the MRL and extract configuration from it. * diff --git a/src/libvlccore.sym b/src/libvlccore.sym index 74e2efe6b2..4c4d5b0247 100644 --- a/src/libvlccore.sym +++ b/src/libvlccore.sym @@ -465,6 +465,7 @@ var_SetChecked var_TriggerCallback var_Type var_Inherit +var_InheritURational video_format_FixRgb video_format_IsSimilar video_format_Setup diff --git a/src/misc/variables.c b/src/misc/variables.c index 9df5a40079..a280c8e9df 100644 --- a/src/misc/variables.c +++ b/src/misc/variables.c @@ -36,6 +36,8 @@ #include #include +#include +#include /***************************************************************************** * Private types @@ -1342,6 +1344,57 @@ int var_Inherit( vlc_object_t *p_this, const char *psz_name, int i_type, } +/** + * It inherits a string as an unsigned rational number (it also accepts basic + * float number). + * + * It returns an error if the rational number cannot be parsed (0/0 is valid). + * The rational is already reduced. + */ +int (var_InheritURational)(vlc_object_t *object, + unsigned *num, unsigned *den, + const char *var) +{ + /* */ + *num = 0; + *den = 0; + + /* */ + char *tmp = var_InheritString(object, var); + if (!tmp) + goto error; + + char *next; + unsigned n = strtol(tmp, &next, 0); + unsigned d = strtol(*next ? &next[1] : "0", NULL, 0); + + if (*next == '.') { + /* Interpret as a float number */ + double r = us_atof(tmp); + double c = ceil(r); + if (c >= UINT_MAX) + goto error; + unsigned m = c; + if (m > 0) { + d = UINT_MAX / m; + n = r * d; + } else { + n = 0; + d = 0; + } + } + + if (n > 0 && d > 0) + vlc_ureduce(num, den, n, d, 0); + + free(tmp); + return VLC_SUCCESS; + +error: + free(tmp); + return VLC_EGENERIC; +} + /********************************************************************** * Trigger the callbacks. * Tell we're in a callback, release the lock, call stored functions, -- 2.39.2