mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 15:43:55 +02:00
Fix good thumbnail generation in sibling stories.
This commit is contained in:
parent
d76c80bf0e
commit
1f1e543df7
2 changed files with 38 additions and 22 deletions
|
@ -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,38 +149,49 @@ 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) {
|
||||||
_streamed = std::make_unique<Streaming::Instance>(
|
createStreamedPlayer();
|
||||||
_video,
|
|
||||||
_origin,
|
|
||||||
[] {}); // waitingCallback
|
|
||||||
_streamed->lockPlayer();
|
|
||||||
_streamed->player().updates(
|
|
||||||
) | rpl::start_with_next_error([=](Streaming::Update &&update) {
|
|
||||||
v::match(update.data, [&](Streaming::Information &update) {
|
|
||||||
_update();
|
|
||||||
}, [](const auto &update) {
|
|
||||||
});
|
|
||||||
}, [=](Streaming::Error &&error) {
|
|
||||||
streamedFailed();
|
|
||||||
}, _streamed->lifetime());
|
|
||||||
if (_streamed->ready()) {
|
|
||||||
_update();
|
|
||||||
} else if (!_streamed->valid()) {
|
|
||||||
streamedFailed();
|
|
||||||
}
|
|
||||||
} else if (_streamed->ready()) {
|
} else if (_streamed->ready()) {
|
||||||
return _streamed->info().video.cover;
|
return _streamed->info().video.cover;
|
||||||
}
|
}
|
||||||
return QImage();
|
return QImage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Sibling::LoaderVideo::createStreamedPlayer() {
|
||||||
|
_streamed = std::make_unique<Streaming::Instance>(
|
||||||
|
_video,
|
||||||
|
_origin,
|
||||||
|
[] {}); // waitingCallback
|
||||||
|
_streamed->lockPlayer();
|
||||||
|
_streamed->player().updates(
|
||||||
|
) | rpl::start_with_next_error([=](Streaming::Update &&update) {
|
||||||
|
v::match(update.data, [&](Streaming::Information &update) {
|
||||||
|
_update();
|
||||||
|
}, [](const auto &update) {
|
||||||
|
});
|
||||||
|
}, [=](Streaming::Error &&error) {
|
||||||
|
streamedFailed();
|
||||||
|
}, _streamed->lifetime());
|
||||||
|
if (_streamed->ready()) {
|
||||||
|
_update();
|
||||||
|
} else if (!_streamed->valid()) {
|
||||||
|
streamedFailed();
|
||||||
|
} else if (!_streamed->player().active()
|
||||||
|
&& !_streamed->player().finished()) {
|
||||||
|
_streamed->play({
|
||||||
|
.mode = Streaming::Mode::Video,
|
||||||
|
});
|
||||||
|
_streamed->pause();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Sibling::LoaderVideo::streamedFailed() {
|
void Sibling::LoaderVideo::streamedFailed() {
|
||||||
_failed = true;
|
_failed = true;
|
||||||
_streamed = nullptr;
|
_streamed = nullptr;
|
||||||
|
@ -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;
|
||||||
|
|
|
@ -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(
|
||||||
|
|
Loading…
Add table
Reference in a new issue