Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add framerate control to sherlock265 #310

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
19 changes: 19 additions & 0 deletions sherlock265/VideoDecoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,18 @@ using namespace videogfx;
//#include "decctx.h"
#include "visualize.h"

#include <chrono>

using namespace std;
using namespace std::chrono;

VideoDecoder::VideoDecoder()
: mFH(NULL),
ctx(NULL),
img(NULL),
mNextBuffer(0),
mFrameCount(0),
mFramerate(30),
mPlayingVideo(false),
mVideoEnded(false),
mSingleStep(false),
Expand Down Expand Up @@ -127,6 +132,8 @@ void VideoDecoder::decoder_loop()
img = de265_peek_next_picture(ctx);
while (img==NULL)
{
auto decode_start_time = system_clock::now();

mutex.unlock();
int more=1;
de265_error err = de265_decode(ctx, &more);
Expand All @@ -135,6 +142,14 @@ void VideoDecoder::decoder_loop()
if (more && err == DE265_OK) {
// try again to get picture

duration<double> decode_time = system_clock::now() - decode_start_time;
duration<double> sleep_for_time = milliseconds(1000 / mFramerate) - decode_time;

if (sleep_for_time.count() > 0)
{
QThread::usleep(sleep_for_time.count() * 1000000);
}

img = de265_peek_next_picture(ctx);
}
else if (more && err == DE265_ERROR_WAITING_FOR_INPUT_DATA) {
Expand Down Expand Up @@ -336,6 +351,10 @@ void VideoDecoder::show_frame(const de265_image* img)
mFrameCount++;
}

void VideoDecoder::setFramerate(int framerate)
{
mFramerate = framerate;
}

void VideoDecoder::showCBPartitioning(bool flag)
{
Expand Down
2 changes: 2 additions & 0 deletions sherlock265/VideoDecoder.hh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public slots:
void stopDecoder();
void singleStepDecoder();

void setFramerate(int framerate);
void showCBPartitioning(bool flag);
void showTBPartitioning(bool flag);
void showPBPartitioning(bool flag);
Expand Down Expand Up @@ -92,6 +93,7 @@ private:
QImage mImgBuffers[2];
int mNextBuffer;
int mFrameCount;
int mFramerate;

bool mPlayingVideo;
bool mVideoEnded;
Expand Down
7 changes: 7 additions & 0 deletions sherlock265/VideoPlayer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ VideoPlayer::VideoPlayer(const char* filename)
QObject::connect(mDecoder, SIGNAL(displayImage(QImage*)),
videoWidget, SLOT(setImage(QImage*)), Qt::QueuedConnection);

QSpinBox *framerateSpinbox = new QSpinBox();
framerateSpinbox->setMinimum(1);
framerateSpinbox->setMaximum(300);
framerateSpinbox->setValue(30);
framerateSpinbox->setSuffix(" FPS");

QObject::connect(framerateSpinbox, QOverload<int>::of(&QSpinBox::valueChanged), mDecoder, &VideoDecoder::setFramerate);

QPushButton* showCBPartitioningButton = new QPushButton("CB-tree");
showCBPartitioningButton->setCheckable(true);
Expand Down Expand Up @@ -116,6 +122,7 @@ VideoPlayer::VideoPlayer(const char* filename)
layout->addWidget(showPBPredModeButton, 2,4,1,1);
layout->addWidget(showQuantPYButton, 2,5,1,1);
layout->addWidget(showMotionVecButton, 2,6,1,1);
layout->addWidget(framerateSpinbox, 1,3,1,1);
setLayout(layout);


Expand Down