Commit 675151bf authored by Denis Charmet's avatar Denis Charmet Committed by Rémi Denis-Courmont

clock: split files to reuse average functions

parent 99bfdc3f
......@@ -230,6 +230,7 @@ libvlccore_la_SOURCES = \
playlist/renderer.c \
input/item.c \
input/access.c \
clock/clock_internal.c \
clock/clock.c \
input/control.c \
input/decoder.c \
......@@ -242,6 +243,7 @@ libvlccore_la_SOURCES = \
input/info.h \
input/meta.c \
clock/clock.h \
clock/clock_internal.h \
input/decoder.h \
input/demux.h \
input/es_out.h \
......
......@@ -32,6 +32,7 @@
#include <vlc_common.h>
#include <vlc_input.h>
#include "clock.h"
#include "clock_internal.h"
#include <assert.h>
/* TODO:
......@@ -98,42 +99,6 @@
/* Due to some problems in es_out, we cannot use a large value yet */
#define CR_BUFFERING_TARGET (100000)
/*****************************************************************************
* Structures
*****************************************************************************/
/**
* This structure holds long term average
*/
typedef struct
{
mtime_t i_value;
int i_residue;
int i_count;
int i_divider;
} average_t;
static void AvgInit( average_t *, int i_divider );
static void AvgClean( average_t * );
static void AvgReset( average_t * );
static void AvgUpdate( average_t *, mtime_t i_value );
static mtime_t AvgGet( average_t * );
static void AvgRescale( average_t *, int i_divider );
/* */
typedef struct
{
mtime_t i_stream;
mtime_t i_system;
} clock_point_t;
static inline clock_point_t clock_point_Create( mtime_t i_stream, mtime_t i_system )
{
clock_point_t p = { .i_stream = i_stream, .i_system = i_system };
return p;
}
/* */
#define INPUT_CLOCK_LATE_COUNT (3)
......@@ -630,45 +595,3 @@ static mtime_t ClockGetTsOffset( input_clock_t *cl )
return cl->i_pts_delay * ( cl->i_rate - INPUT_RATE_DEFAULT ) / INPUT_RATE_DEFAULT;
}
/*****************************************************************************
* Long term average helpers
*****************************************************************************/
static void AvgInit( average_t *p_avg, int i_divider )
{
p_avg->i_divider = i_divider;
AvgReset( p_avg );
}
static void AvgClean( average_t *p_avg )
{
VLC_UNUSED(p_avg);
}
static void AvgReset( average_t *p_avg )
{
p_avg->i_value = 0;
p_avg->i_residue = 0;
p_avg->i_count = 0;
}
static void AvgUpdate( average_t *p_avg, mtime_t i_value )
{
const int i_f0 = __MIN( p_avg->i_divider - 1, p_avg->i_count );
const int i_f1 = p_avg->i_divider - i_f0;
const mtime_t i_tmp = i_f0 * p_avg->i_value + i_f1 * i_value + p_avg->i_residue;
p_avg->i_value = i_tmp / p_avg->i_divider;
p_avg->i_residue = i_tmp % p_avg->i_divider;
p_avg->i_count++;
}
static mtime_t AvgGet( average_t *p_avg )
{
return p_avg->i_value;
}
static void AvgRescale( average_t *p_avg, int i_divider )
{
const mtime_t i_tmp = p_avg->i_value * p_avg->i_divider + p_avg->i_residue;
p_avg->i_divider = i_divider;
p_avg->i_value = i_tmp / p_avg->i_divider;
p_avg->i_residue = i_tmp % p_avg->i_divider;
}
/*****************************************************************************
* clock_internal.c: Clock internal functions
*****************************************************************************
* Copyright (C) 2018 VLC authors and VideoLAN
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
* Laurent Aimar < fenrir _AT_ videolan _DOT_ org >
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "clock_internal.h"
/*****************************************************************************
* Long term average helpers
*****************************************************************************/
void AvgInit( average_t *p_avg, int i_divider )
{
p_avg->i_divider = i_divider;
AvgReset( p_avg );
}
void AvgClean( average_t *p_avg )
{
VLC_UNUSED(p_avg);
}
void AvgReset( average_t *p_avg )
{
p_avg->i_value = 0;
p_avg->i_residue = 0;
p_avg->i_count = 0;
}
void AvgUpdate( average_t *p_avg, mtime_t i_value )
{
const int i_f0 = __MIN( p_avg->i_divider - 1, p_avg->i_count );
const int i_f1 = p_avg->i_divider - i_f0;
const mtime_t i_tmp = i_f0 * p_avg->i_value + i_f1 * i_value + p_avg->i_residue;
p_avg->i_value = i_tmp / p_avg->i_divider;
p_avg->i_residue = i_tmp % p_avg->i_divider;
p_avg->i_count++;
}
mtime_t AvgGet( average_t *p_avg )
{
return p_avg->i_value;
}
void AvgRescale( average_t *p_avg, int i_divider )
{
const mtime_t i_tmp = p_avg->i_value * p_avg->i_divider + p_avg->i_residue;
p_avg->i_divider = i_divider;
p_avg->i_value = i_tmp / p_avg->i_divider;
p_avg->i_residue = i_tmp % p_avg->i_divider;
}
/*****************************************************************************
* clock_internal.h: Clock internal functions
*****************************************************************************
* Copyright (C) 2018 VLC authors and VideoLAN
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
* Laurent Aimar < fenrir _AT_ videolan _DOT_ org >
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include <vlc_common.h>
/*****************************************************************************
* Structures
*****************************************************************************/
/**
* This structure holds long term average
*/
typedef struct
{
mtime_t i_value;
int i_residue;
int i_count;
int i_divider;
} average_t;
void AvgInit( average_t *, int i_divider );
void AvgClean( average_t * );
void AvgReset( average_t * );
void AvgUpdate( average_t *, mtime_t i_value );
mtime_t AvgGet( average_t * );
void AvgRescale( average_t *, int i_divider );
/* */
typedef struct
{
mtime_t i_stream;
mtime_t i_system;
} clock_point_t;
static inline clock_point_t clock_point_Create( mtime_t i_stream, mtime_t i_system )
{
clock_point_t p = { .i_stream = i_stream, .i_system = i_system };
return p;
}
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