Fix good thumbnail generation in sibling stories.

This commit is contained in:
John Preston 2023-05-31 10:39:45 +04:00
parent d76c80bf0e
commit 1f1e543df7
2 changed files with 38 additions and 22 deletions

View file

@ -75,6 +75,7 @@ public:
private: private:
void waitForGoodThumbnail(); void waitForGoodThumbnail();
bool updateAfterGoodCheck(); bool updateAfterGoodCheck();
void createStreamedPlayer();
void streamedFailed(); void streamedFailed();
const not_null<DocumentData*> _video; const not_null<DocumentData*> _video;
@ -148,13 +149,22 @@ QImage Sibling::LoaderVideo::blurred() {
QImage Sibling::LoaderVideo::good() { QImage Sibling::LoaderVideo::good() {
if (const auto image = _media->goodThumbnail()) { if (const auto image = _media->goodThumbnail()) {
return image->original(); return image->original();
} else if (!_video->goodThumbnailChecked()) { } else if (!_video->goodThumbnailChecked()
&& !_video->goodThumbnailNoData()) {
if (!_checkingGoodInCache) { if (!_checkingGoodInCache) {
waitForGoodThumbnail(); waitForGoodThumbnail();
} }
} else if (_failed) { } else if (_failed) {
return QImage(); return QImage();
} else if (!_streamed) { } else if (!_streamed) {
createStreamedPlayer();
} else if (_streamed->ready()) {
return _streamed->info().video.cover;
}
return QImage();
}
void Sibling::LoaderVideo::createStreamedPlayer() {
_streamed = std::make_unique<Streaming::Instance>( _streamed = std::make_unique<Streaming::Instance>(
_video, _video,
_origin, _origin,
@ -173,11 +183,13 @@ QImage Sibling::LoaderVideo::good() {
_update(); _update();
} else if (!_streamed->valid()) { } else if (!_streamed->valid()) {
streamedFailed(); streamedFailed();
} else if (!_streamed->player().active()
&& !_streamed->player().finished()) {
_streamed->play({
.mode = Streaming::Mode::Video,
});
_streamed->pause();
} }
} else if (_streamed->ready()) {
return _streamed->info().video.cover;
}
return QImage();
} }
void Sibling::LoaderVideo::streamedFailed() { void Sibling::LoaderVideo::streamedFailed() {
@ -204,7 +216,8 @@ void Sibling::LoaderVideo::waitForGoodThumbnail() {
} }
bool Sibling::LoaderVideo::updateAfterGoodCheck() { bool Sibling::LoaderVideo::updateAfterGoodCheck() {
if (!_video->goodThumbnailChecked()) { if (!_video->goodThumbnailChecked()
&& !_video->goodThumbnailNoData()) {
return false; return false;
} }
_checkingGoodInCache = false; _checkingGoodInCache = false;

View file

@ -257,12 +257,15 @@ void Document::validateGoodThumbnail() {
const auto length = bytes.size(); const auto length = bytes.size();
if (!length || length > Storage::kMaxFileInMemory) { if (!length || length > Storage::kMaxFileInMemory) {
LOG(("App Error: Bad thumbnail data for saving to cache.")); LOG(("App Error: Bad thumbnail data for saving to cache."));
bytes = "(failed)"; bytes = "(failed)"_q;
} }
crl::on_main(guard, [=] { crl::on_main(guard, [=] {
if (const auto active = document->activeMediaView()) { if (const auto active = document->activeMediaView()) {
active->setGoodThumbnail(image); active->setGoodThumbnail(image);
} }
if (bytes != "(failed)"_q) {
document->setGoodThumbnailChecked(true);
}
document->owner().cache().putIfEmpty( document->owner().cache().putIfEmpty(
document->goodThumbnailCacheKey(), document->goodThumbnailCacheKey(),
Storage::Cache::Database::TaggedValue( Storage::Cache::Database::TaggedValue(