Commit abcc95e3 authored by Mickaël Turnel's avatar Mickaël Turnel

Use of MSFramerateController to change the framerate in Linux, Mac and Windows

parent d01ecbed
......@@ -293,9 +293,8 @@ typedef struct v4mState {
NsMsWebCam * webcam;
int frame_ind;
float fps;
float start_time;
int frame_count;
MSAverageFPS afps;
MSFrameRateController framerate_controller;
} v4mState;
......@@ -304,8 +303,6 @@ static void v4m_init(MSFilter *f) {
NSAutoreleasePool* myPool = [[NSAutoreleasePool alloc] init];
v4mState *s = ms_new0(v4mState,1);
s->webcam = [[NsMsWebCam alloc] init];
s->start_time = 0;
s->frame_count = -1;
s->fps = 15;
f->data = s;
[myPool drain];
......@@ -342,18 +339,12 @@ static void v4m_uninit(MSFilter *f) {
static void v4m_process(MSFilter * obj){
v4mState *s = (v4mState*)obj->data;
uint32_t timestamp;
int cur_frame;
if (s->frame_count == -1){
s->start_time=obj->ticker->time;
s->frame_count=0;
}
NSAutoreleasePool* myPool = [[NSAutoreleasePool alloc] init];
ms_mutex_lock([s->webcam mutex]);
cur_frame = ((obj->ticker->time-s->start_time)*s->fps/1000.0);
if (cur_frame >= s->frame_count) {
if (ms_video_capture_new_frame(&s->framerate_controller, obj->ticker->time)) {
mblk_t *om=NULL;
mblk_t *m;
/*keep the most recent frame if several frames have been captured */
......@@ -369,7 +360,6 @@ static void v4m_process(MSFilter * obj){
mblk_set_timestamp_info(om,timestamp);
mblk_set_marker_info(om,TRUE);
ms_queue_put(obj->outputs[0],om);
s->frame_count++;
ms_average_fps_update(&s->afps, obj->ticker->time);
}
} else {
......@@ -396,7 +386,8 @@ static void v4m_postprocess(MSFilter *f) {
static int v4m_set_fps(MSFilter *f, void *arg) {
v4mState *s = (v4mState*)f->data;
s->fps = *((float*)arg);
s->frame_count = -1;
ms_video_init_framerate_controller(&s->framerate_controller, s->fps);
ms_average_fps_init(&s->afps, "AV capture average fps = %f");
return 0;
}
......
......@@ -147,8 +147,6 @@ public:
_vsize.width=MS_VIDEO_SIZE_CIF_W;
_vsize.height=MS_VIDEO_SIZE_CIF_H;
_fps=15;
_start_time=0;
_frame_count=0;
_pixfmt=MS_YUV420P;
_ready=false;
m_refCount=1;
......@@ -194,6 +192,7 @@ public:
_devid=index;
}
MSAverageFPS avgfps;
MSFrameRateController framerate_controller;
protected:
long m_refCount;
private:
......@@ -205,8 +204,6 @@ private:
queue_t _rq;
ms_mutex_t _mutex;
float _fps;
float _start_time;
int _frame_count;
MSPixFmt _pixfmt;
SharedComPtr< IGraphBuilder > _graphBuilder;
SharedComPtr< IBaseFilter > _source;
......@@ -535,16 +532,7 @@ void DSCapture::stopAndClean(){
}
bool DSCapture::isTimeToSend(uint64_t ticker_time){
if (_frame_count==-1){
_start_time=(float)ticker_time;
_frame_count=0;
}
int cur_frame=(int)(((float)ticker_time-_start_time)*_fps/1000.0);
if (cur_frame>_frame_count){
_frame_count++;
return true;
}
return false;
return ms_video_capture_new_frame(&framerate_controller, ticker_time);
}
......@@ -605,6 +593,8 @@ static void dscap_process(MSFilter * obj){
static int dscap_set_fps(MSFilter *f, void *arg){
DSCapture *s=(DSCapture*)f->data;
s->setFps(*(float*)arg);
ms_video_init_framerate_controller(&s->framerate_controller, *(float*)arg);
ms_average_fps_init(&s->avgfps,"msdscap: fps=%f");
return 0;
}
......
......@@ -83,11 +83,10 @@ typedef struct V4l2State{
int frame_ind;
int frame_max;
float fps;
unsigned int start_time;
MSAverageFPS avgfps;
int th_frame_count;
int queued;
bool_t configured;
MSFrameRateController framerate_controller;
}V4l2State;
static int msv4l2_open(V4l2State *s){
......@@ -718,25 +717,14 @@ static void msv4l2_preprocess(MSFilter *f){
V4l2State *s=(V4l2State*)f->data;
s->thread_run=TRUE;
ms_thread_create(&s->thread,NULL,msv4l2_thread,s);
s->th_frame_count=-1;
ms_average_fps_init(&s->avgfps,"V4L2 capture: fps=%f");
}
static void msv4l2_process(MSFilter *f){
V4l2State *s=(V4l2State*)f->data;
uint32_t timestamp;
int cur_frame;
uint32_t curtime=f->ticker->time;
float elapsed;
if (s->th_frame_count==-1){
s->start_time=curtime;
s->th_frame_count=0;
}
elapsed=((float)(curtime-s->start_time))/1000.0;
cur_frame=elapsed*s->fps;
if (cur_frame>=s->th_frame_count){
if (ms_video_capture_new_frame(&s->framerate_controller, f->ticker->time)){
mblk_t *om=NULL;
ms_mutex_lock(&s->mutex);
/*keep the most recent frame if several frames have been captured */
......@@ -755,7 +743,6 @@ static void msv4l2_process(MSFilter *f){
ms_queue_put(f->outputs[0],om);
ms_average_fps_update(&s->avgfps,f->ticker->time);
}
s->th_frame_count++;
}
}
......@@ -777,6 +764,8 @@ static void msv4l2_postprocess(MSFilter *f){
static int msv4l2_set_fps(MSFilter *f, void *arg){
V4l2State *s=(V4l2State*)f->data;
s->fps=*(float*)arg;
ms_video_init_framerate_controller(&s->framerate_controller, s->fps);
ms_average_fps_init(&s->avgfps,"V4L2 capture: fps=%f");
return 0;
}
......
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