mirror of
https://github.com/telegramdesktop/tdesktop
synced 2024-12-15 02:44:45 +00:00
Create PowerSaveBlocker-s on calls / video / audio.
This commit is contained in:
parent
c7b6db00ca
commit
9c01295521
@ -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::PowerSaveBlocker>(
|
||||
base::PowerSaveBlockType::PreventDisplaySleep,
|
||||
u"Video call is active"_q))
|
||||
, _videoIncoming(
|
||||
std::make_unique<Webrtc::VideoTrack>(
|
||||
StartVideoState(video)))
|
||||
, _videoOutgoing(
|
||||
std::make_unique<Webrtc::VideoTrack>(
|
||||
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) {
|
||||
|
@ -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<base::PowerSaveBlocker> _powerSaveBlocker;
|
||||
|
||||
rpl::variable<bool> _muted = false;
|
||||
|
||||
DhConfig _dhConfig;
|
||||
|
@ -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::PowerSaveBlocker>(
|
||||
base::PowerSaveBlockType::PreventDisplaySleep,
|
||||
u"Video chat is active"_q))
|
||||
, _joinAs(info.joinAs)
|
||||
, _possibleJoinAs(std::move(info.possibleJoinAs))
|
||||
, _joinHash(info.joinHash)
|
||||
|
@ -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<base::PowerSaveBlocker> _powerSaveBlocker;
|
||||
|
||||
MTP::DcId _broadcastDcId = 0;
|
||||
base::flat_map<not_null<LoadPartTask*>, LoadingPart> _broadcastParts;
|
||||
base::flat_set<
|
||||
|
@ -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*> 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*> 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) {
|
||||
|
@ -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> streamed;
|
||||
std::unique_ptr<ShuffleData> shuffleData;
|
||||
std::unique_ptr<base::PowerSaveBlocker> powerSaveBlocker;
|
||||
std::unique_ptr<base::PowerSaveBlocker> powerSaveBlockerVideo;
|
||||
};
|
||||
|
||||
struct SeekingChanges {
|
||||
@ -234,6 +240,9 @@ private:
|
||||
void validateOtherPlaylist(not_null<Data*> data);
|
||||
void playlistUpdated(not_null<Data*> data);
|
||||
bool moveInPlaylist(not_null<Data*> data, int delta, bool autonext);
|
||||
void updatePowerSaveBlocker(
|
||||
not_null<Data*> data,
|
||||
const TrackState &state);
|
||||
HistoryItem *itemByIndex(not_null<Data*> data, int index);
|
||||
void stopAndClear(not_null<Data*> data);
|
||||
|
||||
|
@ -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<base::PowerSaveBlocker> 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);
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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,
|
||||
|
@ -14,6 +14,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
|
||||
#include <QtCore/QPointer>
|
||||
|
||||
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*> _delegate;
|
||||
not_null<DocumentData*> _data;
|
||||
const not_null<DocumentData*> _data;
|
||||
FullMsgId _contextId;
|
||||
Streaming::Instance _instance;
|
||||
bool _opengl = false;
|
||||
PipPanel _panel;
|
||||
QSize _size;
|
||||
std::unique_ptr<base::PowerSaveBlocker> _powerSaveBlocker;
|
||||
std::unique_ptr<PlaybackProgress> _playbackProgress;
|
||||
std::shared_ptr<Data::DocumentMedia> _dataMedia;
|
||||
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 5d99fef79a9a311896199b223a0325c0998f9c9a
|
||||
Subproject commit 9efbcbfebeba378a269b73bf7040b7a1f8e7ca57
|
Loading…
Reference in New Issue
Block a user