2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Simplify playing video tracking (and fix a crash).

This commit is contained in:
John Preston
2020-06-04 17:26:06 +04:00
parent e1d36cfd50
commit 2b9e4a8ddf
15 changed files with 53 additions and 85 deletions

View File

@@ -3224,43 +3224,19 @@ void Session::unregisterContactItem(
}
}
void Session::registerPlayingVideoFile(not_null<ViewElement*> view) {
if (++_playingVideoFiles[view] == 1) {
registerHeavyViewPart(view);
}
}
void Session::unregisterPlayingVideoFile(not_null<ViewElement*> view) {
const auto i = _playingVideoFiles.find(view);
if (i != _playingVideoFiles.end()) {
if (!--i->second) {
_playingVideoFiles.erase(i);
view->checkHeavyPart();
}
} else {
view->checkHeavyPart();
}
}
void Session::stopPlayingVideoFiles() {
for (const auto &[view, count] : base::take(_playingVideoFiles)) {
void Session::checkPlayingAnimations() {
auto check = base::flat_set<not_null<ViewElement*>>();
for (const auto view : _heavyViewParts) {
if (const auto media = view->media()) {
media->stopAnimation();
}
}
}
void Session::checkPlayingVideoFiles() {
const auto old = base::take(_playingVideoFiles);
for (const auto &[view, count] : old) {
if (const auto media = view->media()) {
if (const auto left = media->checkAnimationCount()) {
_playingVideoFiles.emplace(view, left);
registerHeavyViewPart(view);
continue;
if (const auto document = media->getDocument()) {
if (document->isAnimation() || document->isVideoFile()) {
check.emplace(view);
}
}
}
view->checkHeavyPart();
}
for (const auto view : check) {
view->media()->checkAnimation();
}
}
@@ -3355,7 +3331,6 @@ void Session::registerItemView(not_null<ViewElement*> view) {
}
void Session::unregisterItemView(not_null<ViewElement*> view) {
Expects(!_playingVideoFiles.contains(view));
Expects(!_heavyViewParts.contains(view));
const auto i = _views.find(view->data());