From 8d780aeb61c5d96722be482462c3136be75aa5a2 Mon Sep 17 00:00:00 2001 From: Tats Date: Wed, 17 Feb 2016 15:55:23 -0500 Subject: [PATCH] Use new methods in MediaImpl to appropriately gather a thumbnail for the video. --- Paint.cpp | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/Paint.cpp b/Paint.cpp index f23e1a8..0b9a916 100644 --- a/Paint.cpp +++ b/Paint.cpp @@ -165,20 +165,30 @@ bool Media::setUri(const QString &uri) } // Try to get thumbnail. - const uint* bits = NULL; - do - { - lockMutex(); - bits = (uint*)impl_->getBits(); - unlockMutex(); - } while (!bits); + // Wait for the first samples to be available to make sure we are ready. + if (!impl_->waitForNextBits(1000)) + { + return false; + } + + // Try seeking to the middle of the movie. if (!impl_->seekTo(0.5)) { impl_->resetMovie(); return false; } - bits = (uint*)impl_->getBits(); + + // Try to get a sample from the current position. + // NOTE: There is no guarantee the sample has yet been acquired. + const uchar* data; + if (!impl_->waitForNextBits(1000, &data)) + { + qDebug() << "Second waiting wrong..." << endl; + return false; + } + + const uint* bits = (uint*)data; // Copy bits into thumbnail QImage. QImage thumbnail(getWidth(), getHeight(), QImage::Format_ARGB32);