mirror of
https://github.com/telegramdesktop/tdesktop
synced 2024-12-28 09:32:56 +00:00
Simplify playing video tracking (and fix a crash).
This commit is contained in:
parent
e1d36cfd50
commit
2b9e4a8ddf
@ -216,11 +216,11 @@ void AutoDownloadBox::setupContent() {
|
||||
_session->data().photoLoadSettingsChanged();
|
||||
}
|
||||
if (ranges::find_if(allowMoreTypes, _1 != Type::Photo)
|
||||
!= allowMoreTypes.end()) {
|
||||
!= allowMoreTypes.end()) {
|
||||
_session->data().documentLoadSettingsChanged();
|
||||
}
|
||||
if (less) {
|
||||
_session->data().checkPlayingVideoFiles();
|
||||
_session->data().checkPlayingAnimations();
|
||||
}
|
||||
closeBox();
|
||||
});
|
||||
|
@ -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());
|
||||
|
@ -613,10 +613,7 @@ public:
|
||||
UserId contactId,
|
||||
not_null<HistoryItem*> item);
|
||||
|
||||
void registerPlayingVideoFile(not_null<ViewElement*> view);
|
||||
void unregisterPlayingVideoFile(not_null<ViewElement*> view);
|
||||
void checkPlayingVideoFiles();
|
||||
void stopPlayingVideoFiles();
|
||||
void checkPlayingAnimations();
|
||||
|
||||
HistoryItem *findWebPageItem(not_null<WebPageData*> page) const;
|
||||
QString findContactPhone(not_null<UserData*> contact) const;
|
||||
@ -958,7 +955,6 @@ private:
|
||||
std::unordered_map<
|
||||
UserId,
|
||||
base::flat_set<not_null<ViewElement*>>> _contactViews;
|
||||
base::flat_map<not_null<ViewElement*>, int> _playingVideoFiles;
|
||||
|
||||
base::flat_set<not_null<WebPageData*>> _webpagesUpdated;
|
||||
base::flat_set<not_null<GameData*>> _gamesUpdated;
|
||||
|
@ -1726,8 +1726,6 @@ void HistoryWidget::showHistory(
|
||||
cancelTypingAction();
|
||||
}
|
||||
|
||||
session().data().stopPlayingVideoFiles();
|
||||
|
||||
clearReplyReturns();
|
||||
if (_history) {
|
||||
if (Ui::InFocusChain(_list)) {
|
||||
|
@ -229,4 +229,12 @@ TextState Contact::textState(QPoint point, StateRequest request) const {
|
||||
return result;
|
||||
}
|
||||
|
||||
void Contact::unloadHeavyPart() {
|
||||
_userpic = nullptr;
|
||||
}
|
||||
|
||||
bool Contact::hasHeavyPart() const {
|
||||
return (_userpic != nullptr);
|
||||
}
|
||||
|
||||
} // namespace HistoryView
|
||||
|
@ -59,13 +59,8 @@ public:
|
||||
// Should be called only by Data::Session.
|
||||
void updateSharedContactUserId(UserId userId) override;
|
||||
|
||||
void unloadHeavyPart() override {
|
||||
_userpic = nullptr;
|
||||
}
|
||||
|
||||
bool hasHeavyPart() const override {
|
||||
return (_userpic != nullptr);
|
||||
}
|
||||
void unloadHeavyPart() override;
|
||||
bool hasHeavyPart() const override;
|
||||
|
||||
private:
|
||||
QSize countOptimalSize() override;
|
||||
|
@ -56,8 +56,8 @@ public:
|
||||
void stopAnimation() override {
|
||||
if (_attach) _attach->stopAnimation();
|
||||
}
|
||||
int checkAnimationCount() override {
|
||||
return _attach ? _attach->checkAnimationCount() : 0;
|
||||
void checkAnimation() override {
|
||||
if (_attach) _attach->checkAnimation();
|
||||
}
|
||||
|
||||
not_null<GameData*> game() {
|
||||
|
@ -1375,7 +1375,7 @@ void Gif::playAnimation(bool autoplay) {
|
||||
stopAnimation();
|
||||
} else if (_dataMedia->canBePlayed()) {
|
||||
if (!autoplayEnabled()) {
|
||||
history()->owner().checkPlayingVideoFiles();
|
||||
history()->owner().checkPlayingAnimations();
|
||||
}
|
||||
createStreamedPlayer();
|
||||
}
|
||||
@ -1432,12 +1432,11 @@ void Gif::checkStreamedIsStarted() const {
|
||||
void Gif::setStreamed(std::unique_ptr<Streamed> value) {
|
||||
const auto removed = (_streamed && !value);
|
||||
const auto set = (!_streamed && value);
|
||||
if (removed) {
|
||||
history()->owner().unregisterPlayingVideoFile(_parent);
|
||||
}
|
||||
_streamed = std::move(value);
|
||||
if (set) {
|
||||
history()->owner().registerPlayingVideoFile(_parent);
|
||||
history()->owner().registerHeavyViewPart(_parent);
|
||||
} else if (removed) {
|
||||
_parent->checkHeavyPart();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1489,14 +1488,10 @@ void Gif::stopAnimation() {
|
||||
}
|
||||
}
|
||||
|
||||
int Gif::checkAnimationCount() {
|
||||
if (!_streamed) {
|
||||
return 0;
|
||||
} else if (autoplayEnabled()) {
|
||||
return 1;
|
||||
void Gif::checkAnimation() {
|
||||
if (_streamed && !autoplayEnabled()) {
|
||||
stopAnimation();
|
||||
}
|
||||
stopAnimation();
|
||||
return 0;
|
||||
}
|
||||
|
||||
float64 Gif::dataProgress() const {
|
||||
|
@ -87,7 +87,7 @@ public:
|
||||
StateRequest request) const override;
|
||||
|
||||
void stopAnimation() override;
|
||||
int checkAnimationCount() override;
|
||||
void checkAnimation() override;
|
||||
|
||||
TextWithEntities getCaption() const override {
|
||||
return _caption.toTextWithEntities();
|
||||
|
@ -58,6 +58,14 @@ Location::~Location() {
|
||||
}
|
||||
}
|
||||
|
||||
void Location::unloadHeavyPart() {
|
||||
_media = nullptr;
|
||||
}
|
||||
|
||||
bool Location::hasHeavyPart() const {
|
||||
return (_media != nullptr);
|
||||
}
|
||||
|
||||
void Location::ensureMediaCreated() const {
|
||||
if (_media) {
|
||||
return;
|
||||
|
@ -58,12 +58,8 @@ public:
|
||||
return isBubbleBottom();
|
||||
}
|
||||
|
||||
void unloadHeavyPart() override {
|
||||
_media = nullptr;
|
||||
}
|
||||
bool hasHeavyPart() const override {
|
||||
return (_media != nullptr);
|
||||
}
|
||||
void unloadHeavyPart() override;
|
||||
bool hasHeavyPart() const override;
|
||||
|
||||
private:
|
||||
void ensureMediaCreated() const;
|
||||
|
@ -141,8 +141,7 @@ public:
|
||||
}
|
||||
virtual void clearStickerLoopPlayed() {
|
||||
}
|
||||
virtual int checkAnimationCount() {
|
||||
return 0;
|
||||
virtual void checkAnimation() {
|
||||
}
|
||||
|
||||
[[nodiscard]] virtual QSize sizeForGrouping() const {
|
||||
|
@ -414,21 +414,19 @@ void GroupedMedia::updateNeedBubbleState() {
|
||||
}
|
||||
|
||||
void GroupedMedia::stopAnimation() {
|
||||
for (auto &part : _parts) {
|
||||
for (const auto &part : _parts) {
|
||||
part.content->stopAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
int GroupedMedia::checkAnimationCount() {
|
||||
auto result = 0;
|
||||
for (auto &part : _parts) {
|
||||
result += part.content->checkAnimationCount();
|
||||
void GroupedMedia::checkAnimation() {
|
||||
for (const auto &part : _parts) {
|
||||
part.content->checkAnimation();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool GroupedMedia::hasHeavyPart() const {
|
||||
for (auto &part : _parts) {
|
||||
for (const auto &part : _parts) {
|
||||
if (part.content->hasHeavyPart()) {
|
||||
return true;
|
||||
}
|
||||
@ -437,7 +435,7 @@ bool GroupedMedia::hasHeavyPart() const {
|
||||
}
|
||||
|
||||
void GroupedMedia::unloadHeavyPart() {
|
||||
for (auto &part : _parts) {
|
||||
for (const auto &part : _parts) {
|
||||
part.content->unloadHeavyPart();
|
||||
}
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ public:
|
||||
}
|
||||
|
||||
void stopAnimation() override;
|
||||
int checkAnimationCount() override;
|
||||
void checkAnimation() override;
|
||||
bool hasHeavyPart() const override;
|
||||
void unloadHeavyPart() override;
|
||||
|
||||
|
@ -63,8 +63,8 @@ public:
|
||||
void stopAnimation() override {
|
||||
if (_attach) _attach->stopAnimation();
|
||||
}
|
||||
int checkAnimationCount() override {
|
||||
return _attach ? _attach->checkAnimationCount() : 0;
|
||||
void checkAnimation() override {
|
||||
if (_attach) _attach->checkAnimation();
|
||||
}
|
||||
|
||||
not_null<WebPageData*> webpage() {
|
||||
|
Loading…
Reference in New Issue
Block a user