Skip to content

Instantly share code, notes, and snippets.

@feliwir
Created October 3, 2017 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save feliwir/94eba85944d22d94fdf7c1fb7a8eca5c to your computer and use it in GitHub Desktop.
Save feliwir/94eba85944d22d94fdf7c1fb7a8eca5c to your computer and use it in GitHub Desktop.
void arda::Video::Start()
{
//get the thread pool
auto& pool = GetGlobal().GetThreadPool();
auto& avstream = m_internals->avstream;
m_state = PLAYING;
pool.AddJob([this,&avstream]()
{
auto last = std::chrono::high_resolution_clock::now();
while (m_state == PLAYING)
{
if (!GetFrames())
{
if (!m_loop)
{
m_state = STOPPED;
break;
}
else
{
ARDA_LOG("Reset video!");
auto& format_ctx = m_internals->format_ctx;
auto& stream = format_ctx->streams[COLOR];
avio_seek(avstream->GetContext(), 0, SEEK_SET);
avformat_seek_file(format_ctx, COLOR, 0, 0, stream->duration, 0);
if (m_hasAlpha)
{
auto& stream_a = format_ctx->streams[ALPHA];
avformat_seek_file(format_ctx, ALPHA, 0, 0, stream_a->duration, 0);
}
}
}
std::this_thread::sleep_until(last+std::chrono::microseconds(m_frameTime));
last = last + std::chrono::microseconds(m_frameTime);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment