diff --git a/Telegram/SourceFiles/calls/calls_call.cpp b/Telegram/SourceFiles/calls/calls_call.cpp index fde79072e..84acf4fe5 100644 --- a/Telegram/SourceFiles/calls/calls_call.cpp +++ b/Telegram/SourceFiles/calls/calls_call.cpp @@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "calls/calls_instance.h" #include "base/openssl_help.h" #include "base/random.h" +#include "base/power_save_blocker.h" #include "mtproto/mtproto_dh_utils.h" #include "mtproto/mtproto_config.h" #include "core/application.h" @@ -162,13 +163,17 @@ Call::Call( , _user(user) , _api(&_user->session().mtp()) , _type(type) +, _discardByTimeoutTimer([=] { hangup(); }) +, _powerSaveBlocker(std::make_unique( + base::PowerSaveBlockType::PreventDisplaySleep, + u"Video call is active"_q)) , _videoIncoming( std::make_unique( StartVideoState(video))) , _videoOutgoing( std::make_unique( StartVideoState(video))) { - _discardByTimeoutTimer.setCallback([=] { hangup(); }); + ; if (_type == Type::Outgoing) { setState(State::Requesting); @@ -1009,6 +1014,7 @@ void Call::setState(State state) { || state == State::Busy) { // Destroy controller before destroying Call Panel, // so that the panel hide animation is smooth. + _powerSaveBlocker = nullptr; destroyController(); } switch (state) { diff --git a/Telegram/SourceFiles/calls/calls_call.h b/Telegram/SourceFiles/calls/calls_call.h index ffc503d1f..750c75be5 100644 --- a/Telegram/SourceFiles/calls/calls_call.h +++ b/Telegram/SourceFiles/calls/calls_call.h @@ -13,6 +13,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mtproto/sender.h" #include "mtproto/mtproto_auth_key.h" +namespace base { +class PowerSaveBlocker; +} // namespace base + namespace Media { namespace Audio { class Track; @@ -269,6 +273,8 @@ private: base::DelayedCallTimer _finishByTimeoutTimer; base::Timer _discardByTimeoutTimer; + std::unique_ptr _powerSaveBlocker; + rpl::variable _muted = false; DhConfig _dhConfig; diff --git a/Telegram/SourceFiles/calls/group/calls_group_call.cpp b/Telegram/SourceFiles/calls/group/calls_group_call.cpp index 2fd9fa8e7..39f551a16 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_call.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_call.cpp @@ -27,6 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_peer_values.h" #include "data/data_session.h" #include "base/global_shortcuts.h" +#include "base/power_save_blocker.h" #include "base/random.h" #include "webrtc/webrtc_video_track.h" #include "webrtc/webrtc_media_devices.h" @@ -567,6 +568,9 @@ GroupCall::GroupCall( , _peer(info.peer) , _history(_peer->owner().history(_peer)) , _api(&_peer->session().mtp()) +, _powerSaveBlocker(std::make_unique( + base::PowerSaveBlockType::PreventDisplaySleep, + u"Video chat is active"_q)) , _joinAs(info.joinAs) , _possibleJoinAs(std::move(info.possibleJoinAs)) , _joinHash(info.joinHash) diff --git a/Telegram/SourceFiles/calls/group/calls_group_call.h b/Telegram/SourceFiles/calls/group/calls_group_call.h index a3fdf9039..0776ee5cc 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_call.h +++ b/Telegram/SourceFiles/calls/group/calls_group_call.h @@ -26,6 +26,7 @@ class VideoCaptureInterface; namespace base { class GlobalShortcutManager; class GlobalShortcutValue; +class PowerSaveBlocker; } // namespace base namespace Webrtc { @@ -564,6 +565,8 @@ private: bool _recordingStoppedByMe = false; bool _requestedVideoChannelsUpdateScheduled = false; + std::unique_ptr _powerSaveBlocker; + MTP::DcId _broadcastDcId = 0; base::flat_map, LoadingPart> _broadcastParts; base::flat_set< diff --git a/Telegram/SourceFiles/media/player/media_player_instance.cpp b/Telegram/SourceFiles/media/player/media_player_instance.cpp index bafd1c258..a4ebcba4a 100644 --- a/Telegram/SourceFiles/media/player/media_player_instance.cpp +++ b/Telegram/SourceFiles/media/player/media_player_instance.cpp @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_streaming.h" #include "data/data_file_click_handler.h" #include "base/random.h" +#include "base/power_save_blocker.h" #include "media/audio/media_audio.h" #include "media/audio/media_audio_capture.h" #include "media/streaming/media_streaming_instance.h" @@ -568,6 +569,26 @@ bool Instance::moveInPlaylist( return false; } +void Instance::updatePowerSaveBlocker( + not_null data, + const TrackState &state) { + const auto block = !IsPausedOrPausing(state.state) + && !IsStoppedOrStopping(state.state); + const auto blockVideo = block + && data->current.audio() + && data->current.audio()->isVideoMessage(); + base::UpdatePowerSaveBlocker( + data->powerSaveBlocker, + block, + base::PowerSaveBlockType::PreventAppSuspension, + "Audio playback is active"); // const char*, not QString-construct. + base::UpdatePowerSaveBlocker( + data->powerSaveBlockerVideo, + blockVideo, + base::PowerSaveBlockType::PreventDisplaySleep, + "Video playback is active"); // const char*, not QString-construct. +} + void Instance::ensureShuffleMove(not_null data, int delta) { const auto raw = data->shuffleData.get(); if (delta < 0) { @@ -1170,6 +1191,8 @@ void Instance::emitUpdate(AudioMsgId::Type type, CheckCallback check) { streamed->progress.updateState(state); } } + updatePowerSaveBlocker(data, state); + auto finished = false; _updatedNotifier.fire_copy({state}); if (data->isPlaying && state.state == State::StoppedAtEnd) { diff --git a/Telegram/SourceFiles/media/player/media_player_instance.h b/Telegram/SourceFiles/media/player/media_player_instance.h index 5155ac69b..f19aa7032 100644 --- a/Telegram/SourceFiles/media/player/media_player_instance.h +++ b/Telegram/SourceFiles/media/player/media_player_instance.h @@ -35,6 +35,10 @@ enum class Error; } // namespace Streaming } // namespace Media +namespace base { +class PowerSaveBlocker; +} // namespace base + namespace Media { namespace Player { @@ -195,6 +199,8 @@ private: bool resumeOnCallEnd = false; std::unique_ptr streamed; std::unique_ptr shuffleData; + std::unique_ptr powerSaveBlocker; + std::unique_ptr powerSaveBlockerVideo; }; struct SeekingChanges { @@ -234,6 +240,9 @@ private: void validateOtherPlaylist(not_null data); void playlistUpdated(not_null data); bool moveInPlaylist(not_null data, int delta, bool autonext); + void updatePowerSaveBlocker( + not_null data, + const TrackState &state); HistoryItem *itemByIndex(not_null data, int index); void stopAndClear(not_null data); diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index b7690782a..2254d0182 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -60,6 +60,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/window_session_controller.h" #include "window/window_controller.h" #include "base/platform/base_platform_info.h" +#include "base/power_save_blocker.h" #include "base/random.h" #include "base/unixtime.h" #include "base/qt_signal_producer.h" @@ -227,6 +228,7 @@ struct OverlayWidget::Streamed { Streaming::Instance instance; PlaybackControls controls; + std::unique_ptr powerSaveBlocker; bool withSound = false; bool pausedBySeek = false; @@ -2791,6 +2793,21 @@ bool OverlayWidget::createStreamingObjects() { return true; } +void OverlayWidget::updatePowerSaveBlocker( + const Player::TrackState &state) { + Expects(_streamed != nullptr); + + const auto block = (_document != nullptr) + && _document->isVideoFile() + && !IsPausedOrPausing(state.state) + && !IsStoppedOrStopping(state.state); + base::UpdatePowerSaveBlocker( + _streamed->powerSaveBlocker, + block, + base::PowerSaveBlockType::PreventDisplaySleep, + "Video playback is active"); // const char*, not QString-construct. +} + QImage OverlayWidget::transformedShownContent() const { return transformShownContent( videoShown() ? currentVideoFrameImage() : _staticContent, @@ -3259,6 +3276,7 @@ void OverlayWidget::updatePlaybackState() { const auto state = _streamed->instance.player().prepareLegacyState(); if (state.position != kTimeUnknown && state.length != kTimeUnknown) { _streamed->controls.updatePlayback(state); + updatePowerSaveBlocker(state); _touchbarTrackState.fire_copy(state); } } diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.h b/Telegram/SourceFiles/media/view/media_view_overlay_widget.h index 40f6edbb6..49ab57655 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.h +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.h @@ -310,6 +310,7 @@ private: [[nodiscard]] bool createStreamingObjects(); void handleStreamingUpdate(Streaming::Update &&update); void handleStreamingError(Streaming::Error &&error); + void updatePowerSaveBlocker(const Player::TrackState &state); void initThemePreview(); void destroyThemePreview(); diff --git a/Telegram/SourceFiles/media/view/media_view_pip.cpp b/Telegram/SourceFiles/media/view/media_view_pip.cpp index ea0534490..76235fe32 100644 --- a/Telegram/SourceFiles/media/view/media_view_pip.cpp +++ b/Telegram/SourceFiles/media/view/media_view_pip.cpp @@ -23,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session.h" #include "core/application.h" #include "base/platform/base_platform_info.h" +#include "base/power_save_blocker.h" #include "ui/platform/ui_platform_utility.h" #include "ui/widgets/buttons.h" #include "ui/wrap/fade_wrap.h" @@ -1512,6 +1513,7 @@ void Pip::updatePlaybackState() { return; } _playbackProgress->updateState(state); + updatePowerSaveBlocker(state); qint64 position = 0; if (Player::IsStoppedAtEnd(state.state)) { @@ -1529,6 +1531,17 @@ void Pip::updatePlaybackState() { } } +void Pip::updatePowerSaveBlocker(const Player::TrackState &state) { + const auto block = _data->isVideoFile() + && !IsPausedOrPausing(state.state) + && !IsStoppedOrStopping(state.state); + base::UpdatePowerSaveBlocker( + _powerSaveBlocker, + block, + base::PowerSaveBlockType::PreventDisplaySleep, + "Video playback is active"); // const char*, not QString-construct. +} + void Pip::updatePlaybackTexts( int64 position, int64 length, diff --git a/Telegram/SourceFiles/media/view/media_view_pip.h b/Telegram/SourceFiles/media/view/media_view_pip.h index 155481549..ec65ed206 100644 --- a/Telegram/SourceFiles/media/view/media_view_pip.h +++ b/Telegram/SourceFiles/media/view/media_view_pip.h @@ -14,6 +14,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include +namespace base { +class PowerSaveBlocker; +} // namespace base + namespace Data { class DocumentMedia; } // namespace Data @@ -187,6 +191,7 @@ private: void saveGeometry(); void updatePlaybackState(); + void updatePowerSaveBlocker(const Player::TrackState &state); void updatePlayPauseResumeState(const Player::TrackState &state); void restartAtSeekPosition(crl::time position); @@ -244,12 +249,13 @@ private: void seekFinish(float64 value); const not_null _delegate; - not_null _data; + const not_null _data; FullMsgId _contextId; Streaming::Instance _instance; bool _opengl = false; PipPanel _panel; QSize _size; + std::unique_ptr _powerSaveBlocker; std::unique_ptr _playbackProgress; std::shared_ptr _dataMedia; diff --git a/Telegram/lib_base b/Telegram/lib_base index 5d99fef79..9efbcbfeb 160000 --- a/Telegram/lib_base +++ b/Telegram/lib_base @@ -1 +1 @@ -Subproject commit 5d99fef79a9a311896199b223a0325c0998f9c9a +Subproject commit 9efbcbfebeba378a269b73bf7040b7a1f8e7ca57