[vlc-commits] commit: Moved var_InheritURational to the core. (Laurent Aimar )
git at videolan.org
git at videolan.org
Mon May 24 23:59:56 CEST 2010
vlc | branch: master | Laurent Aimar <fenrir at videolan.org> | Mon May 24 17:36:44 2010 +0200| [2915b611a1c64c6c9b3dd5dcda951e0787916ca9] | committer: Laurent Aimar
Moved var_InheritURational to the core.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=2915b611a1c64c6c9b3dd5dcda951e0787916ca9
---
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 4a0de14..0a9d705 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 c3e17fb..e924097 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;
}
@@ -611,55 +607,6 @@ static int Demux(demux_t *demux)
}
/**
- * 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.
*
* Syntax: option1=value1[:option2=value2[...]]
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 74e2efe..4c4d5b0 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 9df5a40..a280c8e 100644
--- a/src/misc/variables.c
+++ b/src/misc/variables.c
@@ -36,6 +36,8 @@
#include <search.h>
#include <assert.h>
+#include <math.h>
+#include <limits.h>
/*****************************************************************************
* 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,
More information about the vlc-commits
mailing list