Commit 2915b611 authored by Laurent Aimar's avatar Laurent Aimar

Moved var_InheritURational to the core.

parent 67b39ef6
......@@ -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)
......
......@@ -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.
*
......
......@@ -465,6 +465,7 @@ var_SetChecked
var_TriggerCallback
var_Type
var_Inherit
var_InheritURational
video_format_FixRgb
video_format_IsSimilar
video_format_Setup
......
......@@ -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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment