Created
October 3, 2017 10:13
-
-
Save feliwir/94eba85944d22d94fdf7c1fb7a8eca5c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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