summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfred <fred@home.lan>2011-04-09 21:38:00 (GMT)
committer fred <fred@home.lan>2011-04-09 21:38:00 (GMT)
commit97640b1d450c99a5bd64a9252287d376ac4fb6e5 (patch)
treeeabf8ca17b79453374d817648f9abcc212e22f9f
parent79dab6f905616cb5107858c4fa428ad6dbf44ae4 (diff)
tried to tune the FPS (frame rate)
- in FPS::calc, rate renamed _period and now in the class declaration. commented out the stats stuff ... does not seem to be used. In FPS::delay, added an other nanosleep function for the last 100 us + a viariable for fine tuning. Seems to work not to bad on my machine, but needs to be tested on others. - In VideoLayer, deleted some printed information.
-rw-r--r--qt/QqWidget.cpp2
-rw-r--r--src/fps.cpp54
-rw-r--r--src/include/context.h2
-rw-r--r--src/include/fps.h20
-rw-r--r--src/theorautils.cpp3
-rw-r--r--src/video_layer.cpp2
6 files changed, 58 insertions, 25 deletions
diff --git a/qt/QqWidget.cpp b/qt/QqWidget.cpp
index b9faee5..7ab0048 100644
--- a/qt/QqWidget.cpp
+++ b/qt/QqWidget.cpp
@@ -55,7 +55,7 @@ QqWidget::QqWidget(Context *freej, QqTabWidget* tabWidget, Qfreej* qfreej, QStri
normalFps = qLayer->frame_rate;
actualFps = qLayer->frame_rate;
fpsP = 100;
- qDebug() << "--- actualFps :" << actualFps;
+// qDebug() << "--- actualFps :" << actualFps;
tabWidget->addTab(this, qLayer->get_filename());
qLayer->move(freej->screen->layers.len()); //put the layer at the end of the list
m_tabWidg = tabWidget;
diff --git a/src/fps.cpp b/src/fps.cpp
index a7ea0e3..97d4535 100644
--- a/src/fps.cpp
+++ b/src/fps.cpp
@@ -19,6 +19,7 @@
*
*/
+#include <iostream>
#include <stdlib.h>
#include <errno.h>
@@ -33,7 +34,7 @@
FPS::FPS() {
_fps = 0;
-
+ _period = 0;
fpsd.sum = 0;
fpsd.i = 0;
fpsd.n = 30;
@@ -58,7 +59,7 @@ FPS::~FPS() {
error("error destroying POSIX thread feed attribute");*/
}
-void FPS::init(float rate) {
+void FPS::init(double rate) {
this->set(rate);
@@ -84,10 +85,12 @@ void FPS::calc() {
}
timersub(&now_tv, &start_tv, &done);
- int rate = 1000000 / _fps;
+ _period = 1000000 / _fps;
+// std::cerr << "++ tv_sec :" << done.tv_sec << " us :" << done.tv_usec \
+// << " _period :" << _period << " _fps :" << _fps << std::endl;
if ( (done.tv_sec > 0)
- || (done.tv_usec >= rate) ) {
+ || (done.tv_usec >= _period) ) {
start_tv.tv_sec = now_tv.tv_sec;
start_tv.tv_usec = now_tv.tv_usec;
@@ -96,17 +99,17 @@ void FPS::calc() {
}
wake_ts.tv_sec = 0;
- wake_ts.tv_nsec = (rate - done.tv_usec)*1000; // set the delay
+ wake_ts.tv_nsec = (_period - done.tv_usec)*1000; // set the delay
// statistic only
- if (done.tv_usec)
+/* if (done.tv_usec)
curr_fps = 1000000 / done.tv_usec;
else
curr_fps = 0;
fpsd.sum = fpsd.sum - fpsd.data[fpsd.i] + curr_fps;
fpsd.data[fpsd.i] = curr_fps;
- if (++fpsd.i >= fpsd.n) fpsd.i = 0;
+ if (++fpsd.i >= fpsd.n) fpsd.i = 0;*/
}
@@ -114,7 +117,7 @@ float FPS::get() {
return (_fps ? fpsd.sum / fpsd.n : 0 );
}
-float FPS::set(float rate) {
+double FPS::set(double rate) {
func("FPS set to %f",rate);
if (rate < 0) // invalid
return fps_old;
@@ -132,7 +135,12 @@ float FPS::set(float rate) {
#if 1 // use nanosleep (otherwise select_sleep)
void FPS::delay() {
struct timespec remaining = { 0, 0 };
-
+ long int waitTime = 0;
+ wake_ts.tv_sec = 0;
+ if(wake_ts.tv_nsec >= 1000000) {
+ wake_ts.tv_nsec = wake_ts.tv_nsec - 1000000; // set the delay
+ waitTime = wake_ts.tv_nsec;
+ }
do {
if (nanosleep(&wake_ts, &remaining) == -1) {
if (errno == EINTR) {
@@ -150,7 +158,33 @@ void FPS::delay() {
} while (wake_ts.tv_nsec > 0);
// update lo start time
gettimeofday(&start_tv,NULL);
-
+ timeval did;
+ timersub(&start_tv, &m_OldTime, &did);
+ int fineAdjust;
+ if ((_period - did.tv_usec) > 100) {
+ wake_ts.tv_nsec = ((_period - did.tv_usec)-(100 + fineAdjust)) * 1000; // set the delay
+ do {
+ if (nanosleep(&wake_ts, &remaining) == -1) {
+ if (errno == EINTR) {
+ // we've been interrupted use remaining and then reset it
+ wake_ts.tv_nsec = remaining.tv_nsec;
+ remaining.tv_sec = remaining.tv_nsec = 0;
+ } else {
+ error("nanosleep returned an error, not performing delay!");
+ wake_ts.tv_sec = wake_ts.tv_nsec = 0;
+ }
+ } else {
+ // nanosleep successful, reset wake_ts
+ wake_ts.tv_sec = wake_ts.tv_nsec = 0;
+ }
+ } while (wake_ts.tv_nsec > 0);
+ gettimeofday(&start_tv,NULL);
+ timersub(&start_tv, &m_OldTime, &did);
+ }
+ fineAdjust = _period - did.tv_usec;
+// std::cerr << "++ did in us :" << did.tv_usec << std::endl;
+ m_OldTime.tv_sec = start_tv.tv_sec;
+ m_OldTime.tv_usec = start_tv.tv_usec;
}
#else
diff --git a/src/include/context.h b/src/include/context.h
index bb78272..0c2583f 100644
--- a/src/include/context.h
+++ b/src/include/context.h
@@ -164,7 +164,7 @@ class Context {
/* Set the interval (in frames) after
the fps counter is updated */
FPS fps;
- float fps_speed;
+ double fps_speed;
bool clear_all;
bool start_running;
diff --git a/src/include/fps.h b/src/include/fps.h
index 4286694..c6182ea 100644
--- a/src/include/fps.h
+++ b/src/include/fps.h
@@ -21,7 +21,7 @@
#ifndef __FPS_H__
#define __FPS_H__
-#include <pthread.h>
+// #include <pthread.h>
#include <inttypes.h>
class FPS {
@@ -29,16 +29,15 @@ class FPS {
FPS();
~FPS();
- void init(float rate);
+ void init(double rate);
float get();
- float set(float rate);
+ double set(double rate);
void calc();
void delay();
void select_sleep(long usec);
- float fps, fps_old;
- struct timespec wake_ts;
+ double fps, fps_old;
private:
@@ -49,12 +48,13 @@ class FPS {
float *data;
} fpsd;
- float _delay, _fps;
- struct timeval start_tv;
-
+ struct timespec wake_ts;
+ double _delay, _fps;
+ struct timeval start_tv, m_OldTime;
+ long int _period;
/* mutex and conditional for the delay */
-// pthread_mutex_t _mutex;
-// pthread_cond_t _cond;
+// pthread_mutex_t _mutex;
+// pthread_cond_t _cond;
};
diff --git a/src/theorautils.cpp b/src/theorautils.cpp
index 44ab7a7..3526519 100644
--- a/src/theorautils.cpp
+++ b/src/theorautils.cpp
@@ -1028,7 +1028,8 @@ void oggmux_flush (oggmux_info *info, int e_o_s)
// std::cerr << " resampled at:" << ratio << std::endl;
}
}
-// std::cerr << "Vorbis time :" << info->audiotime << std::endl << std::flush;
+/* std::cerr << "--- Vorbis time :" << info->audiotime << " Theora time :" \
+ << info->videotime << std::endl << std::flush;*/
}
}
diff --git a/src/video_layer.cpp b/src/video_layer.cpp
index ba275ff..a127b07 100644
--- a/src/video_layer.cpp
+++ b/src/video_layer.cpp
@@ -218,7 +218,6 @@ bool VideoLayer::open(const char *file) {
*/
case CODEC_TYPE_VIDEO:
// enc->flags |= CODEC_FLAG_LOOP_FILTER;
- std::cout << "CODEC_TYPE_VIDEO i:" << i << std::endl;
video_index = i;
video_codec_ctx = enc;
@@ -262,7 +261,6 @@ bool VideoLayer::open(const char *file) {
break; // //////////////// end of video section
case CODEC_TYPE_AUDIO:
- std::cout << "CODEC_TYPE_AUDIO i:" << i << std::endl;
audio_index = i;
audio_codec_ctx = enc;
func ("VideoLayer :: audio id=%i", audio_index);