mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-08 16:59:59 +01:00
Fixed and improved TimeCounter
This commit is contained in:
@@ -605,9 +605,6 @@ void MediaPlayer::play(bool on)
|
|||||||
Log::Info("MediaPlayer %s Stop [%ld]", std::to_string(id_).c_str(), position());
|
Log::Info("MediaPlayer %s Stop [%ld]", std::to_string(id_).c_str(), position());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// reset time counter
|
|
||||||
timecount_.reset();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MediaPlayer::isPlaying(bool testpipeline) const
|
bool MediaPlayer::isPlaying(bool testpipeline) const
|
||||||
@@ -944,6 +941,7 @@ void MediaPlayer::update()
|
|||||||
if (need_loop) {
|
if (need_loop) {
|
||||||
execute_loop_command();
|
execute_loop_command();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MediaPlayer::execute_loop_command()
|
void MediaPlayer::execute_loop_command()
|
||||||
@@ -1233,54 +1231,24 @@ GstFlowReturn MediaPlayer::callback_new_sample (GstAppSink *sink, gpointer p)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
MediaPlayer::TimeCounter::TimeCounter() {
|
MediaPlayer::TimeCounter::TimeCounter()
|
||||||
|
{
|
||||||
|
timer = g_timer_new ();
|
||||||
|
}
|
||||||
|
|
||||||
reset();
|
MediaPlayer::TimeCounter::~TimeCounter()
|
||||||
|
{
|
||||||
|
g_free(timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MediaPlayer::TimeCounter::tic ()
|
void MediaPlayer::TimeCounter::tic ()
|
||||||
{
|
{
|
||||||
// how long since last time
|
double dt = g_timer_elapsed (timer, NULL) * 1000.0;
|
||||||
GstClockTime t = gst_util_get_timestamp ();
|
g_timer_start(timer);
|
||||||
GstClockTime dt = t - last_time -1;
|
|
||||||
|
|
||||||
// one more frame since last time
|
|
||||||
nbFrames++;
|
|
||||||
|
|
||||||
// calculate instantaneous framerate
|
// calculate instantaneous framerate
|
||||||
// Exponential moving averate with previous framerate to filter jitter (70/30)
|
// Exponential moving averate with previous framerate to filter jitter
|
||||||
// The divition of frame/time is done on long integer GstClockTime, counting in microsecond
|
if (dt > 1.0)
|
||||||
// NB: factor 100 to get 0.01 precision
|
fps = 0.5 * fps + 500.0 / dt ;
|
||||||
fps = 0.7 * fps + 0.003 * static_cast<double>( ( 100 * GST_SECOND * nbFrames ) / dt );
|
|
||||||
|
|
||||||
// reset counter every second
|
|
||||||
if ( dt >= GST_SECOND)
|
|
||||||
{
|
|
||||||
last_time = t;
|
|
||||||
nbFrames = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
GstClockTime MediaPlayer::TimeCounter::dt ()
|
|
||||||
{
|
|
||||||
GstClockTime t = gst_util_get_timestamp ();
|
|
||||||
GstClockTime dt = t - tic_time;
|
|
||||||
tic_time = t;
|
|
||||||
|
|
||||||
// return the instantaneous delta t
|
|
||||||
return dt;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MediaPlayer::TimeCounter::reset ()
|
|
||||||
{
|
|
||||||
last_time = gst_util_get_timestamp ();;
|
|
||||||
tic_time = last_time;
|
|
||||||
nbFrames = 0;
|
|
||||||
fps = 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
double MediaPlayer::TimeCounter::frameRate() const
|
|
||||||
{
|
|
||||||
return fps;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -296,17 +296,13 @@ private:
|
|||||||
|
|
||||||
// fps counter
|
// fps counter
|
||||||
struct TimeCounter {
|
struct TimeCounter {
|
||||||
|
GTimer *timer;
|
||||||
GstClockTime last_time;
|
|
||||||
GstClockTime tic_time;
|
|
||||||
long nbFrames;
|
|
||||||
gdouble fps;
|
gdouble fps;
|
||||||
public:
|
public:
|
||||||
TimeCounter();
|
TimeCounter();
|
||||||
GstClockTime dt();
|
~TimeCounter();
|
||||||
void tic();
|
void tic();
|
||||||
void reset();
|
inline gdouble frameRate() const { return fps; }
|
||||||
gdouble frameRate() const;
|
|
||||||
};
|
};
|
||||||
TimeCounter timecount_;
|
TimeCounter timecount_;
|
||||||
|
|
||||||
|
|||||||
58
Stream.cpp
58
Stream.cpp
@@ -349,9 +349,6 @@ void Stream::play(bool on)
|
|||||||
if (live_)
|
if (live_)
|
||||||
gst_element_get_state (pipeline_, NULL, NULL, GST_CLOCK_TIME_NONE);
|
gst_element_get_state (pipeline_, NULL, NULL, GST_CLOCK_TIME_NONE);
|
||||||
|
|
||||||
// reset time counter
|
|
||||||
timecount_.reset();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Stream::isPlaying(bool testpipeline) const
|
bool Stream::isPlaying(bool testpipeline) const
|
||||||
@@ -737,54 +734,23 @@ GstFlowReturn Stream::callback_new_sample (GstAppSink *sink, gpointer p)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
Stream::TimeCounter::TimeCounter() {
|
Stream::TimeCounter::TimeCounter()
|
||||||
|
{
|
||||||
|
timer = g_timer_new ();
|
||||||
|
}
|
||||||
|
|
||||||
reset();
|
Stream::TimeCounter::~TimeCounter()
|
||||||
|
{
|
||||||
|
g_free(timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stream::TimeCounter::tic ()
|
void Stream::TimeCounter::tic ()
|
||||||
{
|
{
|
||||||
// how long since last time
|
double dt = g_timer_elapsed (timer, NULL) * 1000.0;
|
||||||
GstClockTime t = gst_util_get_timestamp ();
|
g_timer_start(timer);
|
||||||
GstClockTime dt = t - last_time - 1;
|
|
||||||
|
|
||||||
// one more frame since last time
|
|
||||||
++nbFrames;
|
|
||||||
|
|
||||||
// calculate instantaneous framerate
|
// calculate instantaneous framerate
|
||||||
// Exponential moving averate with previous framerate to filter jitter (70/30)
|
// Exponential moving averate with previous framerate to filter jitter
|
||||||
// The divition of frame/time is done on long integer GstClockTime, counting in microsecond
|
if (dt > 1.0)
|
||||||
// NB: factor 100 to get 0.01 precision
|
fps = 0.5 * fps + 500.0 / dt ;
|
||||||
fps = 0.7 * fps + 0.003 * static_cast<double>( ( 100 * GST_SECOND * nbFrames ) / dt );
|
|
||||||
|
|
||||||
// reset counter every second
|
|
||||||
if ( dt >= GST_SECOND)
|
|
||||||
{
|
|
||||||
last_time = t;
|
|
||||||
nbFrames = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GstClockTime Stream::TimeCounter::dt ()
|
|
||||||
{
|
|
||||||
GstClockTime t = gst_util_get_timestamp ();
|
|
||||||
GstClockTime dt = t - tic_time;
|
|
||||||
tic_time = t;
|
|
||||||
|
|
||||||
// return the instantaneous delta t
|
|
||||||
return dt;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Stream::TimeCounter::reset ()
|
|
||||||
{
|
|
||||||
last_time = gst_util_get_timestamp ();;
|
|
||||||
tic_time = last_time;
|
|
||||||
nbFrames = 0;
|
|
||||||
fps = 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
double Stream::TimeCounter::frameRate() const
|
|
||||||
{
|
|
||||||
return fps;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
10
Stream.h
10
Stream.h
@@ -144,17 +144,13 @@ protected:
|
|||||||
|
|
||||||
// fps counter
|
// fps counter
|
||||||
struct TimeCounter {
|
struct TimeCounter {
|
||||||
|
GTimer *timer;
|
||||||
GstClockTime last_time;
|
|
||||||
GstClockTime tic_time;
|
|
||||||
long nbFrames;
|
|
||||||
gdouble fps;
|
gdouble fps;
|
||||||
public:
|
public:
|
||||||
TimeCounter();
|
TimeCounter();
|
||||||
GstClockTime dt();
|
~TimeCounter();
|
||||||
void tic();
|
void tic();
|
||||||
void reset();
|
inline gdouble frameRate() const { return fps; }
|
||||||
gdouble frameRate() const;
|
|
||||||
};
|
};
|
||||||
TimeCounter timecount_;
|
TimeCounter timecount_;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user