Fix crash when closing video while a frame request is pending

This commit is contained in:
Thomas Goyne 2013-02-08 21:04:19 -08:00
parent e7306ae642
commit d99647ba28
2 changed files with 4 additions and 8 deletions

View File

@ -125,6 +125,8 @@ ThreadedFrameSource::ThreadedFrameSource(agi::fs::path const& video_filename, wx
} }
ThreadedFrameSource::~ThreadedFrameSource() { ThreadedFrameSource::~ThreadedFrameSource() {
// Block until all currently queued jobs are complete
worker->Sync([]{});
} }
void ThreadedFrameSource::LoadSubtitles(const AssFile *new_subs) throw() { void ThreadedFrameSource::LoadSubtitles(const AssFile *new_subs) throw() {
@ -193,15 +195,9 @@ void ThreadedFrameSource::ProcAsync(uint_fast32_t req_version) {
std::shared_ptr<AegiVideoFrame> ThreadedFrameSource::GetFrame(int frame, double time, bool raw) { std::shared_ptr<AegiVideoFrame> ThreadedFrameSource::GetFrame(int frame, double time, bool raw) {
std::shared_ptr<AegiVideoFrame> ret; std::shared_ptr<AegiVideoFrame> ret;
std::mutex m; worker->Sync([&]{
std::condition_variable cv;
std::unique_lock<std::mutex> l(m);
worker->Async([&]{
std::unique_lock<std::mutex> l(m);
ret = ProcFrame(frame, time, raw); ret = ProcFrame(frame, time, raw);
cv.notify_all();
}); });
cv.wait(l, [&]{ return !!ret; }); // predicate is to deal with spurious wakeups
return ret; return ret;
} }

View File

@ -105,7 +105,7 @@ void VideoContext::Reset() {
// Remove provider // Remove provider
provider.reset(); provider.reset();
video_provider = 0; video_provider = nullptr;
keyframes.clear(); keyframes.clear();
keyframes_filename.clear(); keyframes_filename.clear();