2019-12-11 12:09:21 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#include "media/streaming/media_streaming_instance.h"
|
|
|
|
|
|
|
|
#include "media/streaming/media_streaming_document.h"
|
|
|
|
#include "data/data_file_origin.h"
|
2020-07-03 10:48:55 +00:00
|
|
|
#include "data/data_photo.h"
|
2019-12-11 12:09:21 +00:00
|
|
|
#include "data/data_document.h"
|
|
|
|
#include "data/data_session.h"
|
2019-12-28 14:56:06 +00:00
|
|
|
#include "data/data_streaming.h"
|
2019-12-11 12:09:21 +00:00
|
|
|
|
|
|
|
namespace Media {
|
|
|
|
namespace Streaming {
|
|
|
|
|
|
|
|
Instance::Instance(
|
|
|
|
std::shared_ptr<Document> shared,
|
|
|
|
Fn<void()> waitingCallback)
|
|
|
|
: _shared(std::move(shared))
|
|
|
|
, _waitingCallback(std::move(waitingCallback)) {
|
|
|
|
if (_shared) {
|
|
|
|
_shared->registerInstance(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Instance::Instance(
|
|
|
|
not_null<DocumentData*> document,
|
|
|
|
Data::FileOrigin origin,
|
|
|
|
Fn<void()> waitingCallback)
|
|
|
|
: Instance(
|
2019-12-28 14:56:06 +00:00
|
|
|
document->owner().streaming().sharedDocument(document, origin),
|
2019-12-11 12:09:21 +00:00
|
|
|
std::move(waitingCallback)) {
|
|
|
|
}
|
|
|
|
|
2020-07-03 10:48:55 +00:00
|
|
|
Instance::Instance(
|
|
|
|
not_null<PhotoData*> photo,
|
|
|
|
Data::FileOrigin origin,
|
|
|
|
Fn<void()> waitingCallback)
|
|
|
|
: Instance(
|
|
|
|
photo->owner().streaming().sharedDocument(photo, origin),
|
|
|
|
std::move(waitingCallback)) {
|
|
|
|
}
|
|
|
|
|
2019-12-11 12:09:21 +00:00
|
|
|
Instance::~Instance() {
|
|
|
|
if (_shared) {
|
2019-12-17 14:30:14 +00:00
|
|
|
unlockPlayer();
|
2019-12-11 12:09:21 +00:00
|
|
|
_shared->unregisterInstance(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-18 18:26:17 +00:00
|
|
|
bool Instance::valid() const {
|
|
|
|
return (_shared != nullptr);
|
|
|
|
}
|
|
|
|
|
2020-01-03 11:18:38 +00:00
|
|
|
std::shared_ptr<Document> Instance::shared() const {
|
|
|
|
return _shared;
|
|
|
|
}
|
|
|
|
|
2019-12-11 12:09:21 +00:00
|
|
|
const Player &Instance::player() const {
|
|
|
|
Expects(_shared != nullptr);
|
|
|
|
|
|
|
|
return _shared->player();
|
|
|
|
}
|
|
|
|
|
|
|
|
const Information &Instance::info() const {
|
|
|
|
Expects(_shared != nullptr);
|
|
|
|
|
|
|
|
return _shared->info();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Instance::play(const PlaybackOptions &options) {
|
|
|
|
Expects(_shared != nullptr);
|
|
|
|
|
|
|
|
_shared->play(options);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Instance::pause() {
|
|
|
|
Expects(_shared != nullptr);
|
|
|
|
|
|
|
|
_shared->player().pause();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Instance::resume() {
|
|
|
|
Expects(_shared != nullptr);
|
|
|
|
|
|
|
|
_shared->player().resume();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Instance::stop() {
|
|
|
|
Expects(_shared != nullptr);
|
|
|
|
|
|
|
|
_shared->player().stop();
|
|
|
|
}
|
|
|
|
|
2019-12-18 18:26:17 +00:00
|
|
|
void Instance::stopAudio() {
|
|
|
|
Expects(_shared != nullptr);
|
|
|
|
|
|
|
|
_shared->player().stopAudio();
|
|
|
|
}
|
|
|
|
|
2019-12-11 12:09:21 +00:00
|
|
|
void Instance::saveFrameToCover() {
|
|
|
|
Expects(_shared != nullptr);
|
|
|
|
|
|
|
|
_shared->saveFrameToCover();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Instance::active() const {
|
|
|
|
Expects(_shared != nullptr);
|
|
|
|
|
|
|
|
return _shared->player().active();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Instance::ready() const {
|
|
|
|
Expects(_shared != nullptr);
|
|
|
|
|
|
|
|
return _shared->player().ready();
|
|
|
|
}
|
|
|
|
|
2019-12-12 13:26:53 +00:00
|
|
|
std::optional<Error> Instance::failed() const {
|
|
|
|
Expects(_shared != nullptr);
|
|
|
|
|
|
|
|
return _shared->player().failed();
|
|
|
|
}
|
|
|
|
|
2019-12-11 12:09:21 +00:00
|
|
|
bool Instance::paused() const {
|
|
|
|
Expects(_shared != nullptr);
|
|
|
|
|
|
|
|
return _shared->player().paused();
|
|
|
|
}
|
|
|
|
|
|
|
|
float64 Instance::speed() const {
|
|
|
|
Expects(_shared != nullptr);
|
|
|
|
|
|
|
|
return _shared->player().speed();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Instance::setSpeed(float64 speed) {
|
|
|
|
Expects(_shared != nullptr);
|
|
|
|
|
|
|
|
_shared->player().setSpeed(speed);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Instance::waitingShown() const {
|
|
|
|
Expects(_shared != nullptr);
|
|
|
|
|
|
|
|
return _shared->waitingShown();
|
|
|
|
}
|
|
|
|
|
|
|
|
float64 Instance::waitingOpacity() const {
|
|
|
|
Expects(_shared != nullptr);
|
|
|
|
|
|
|
|
return _shared->waitingOpacity();
|
|
|
|
}
|
|
|
|
|
|
|
|
Ui::RadialState Instance::waitingState() const {
|
|
|
|
Expects(_shared != nullptr);
|
|
|
|
|
|
|
|
return _shared->waitingState();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Instance::callWaitingCallback() {
|
|
|
|
if (_waitingCallback) {
|
|
|
|
_waitingCallback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage Instance::frame(const FrameRequest &request) const {
|
2019-12-12 06:56:08 +00:00
|
|
|
return player().frame(request, this);
|
2019-12-11 12:09:21 +00:00
|
|
|
}
|
|
|
|
|
2019-12-11 14:01:11 +00:00
|
|
|
bool Instance::markFrameShown() {
|
2019-12-17 14:30:14 +00:00
|
|
|
Expects(_shared != nullptr);
|
|
|
|
|
2019-12-11 14:01:11 +00:00
|
|
|
return _shared->player().markFrameShown();
|
|
|
|
}
|
|
|
|
|
2019-12-17 14:30:14 +00:00
|
|
|
void Instance::lockPlayer() {
|
|
|
|
Expects(_shared != nullptr);
|
|
|
|
|
|
|
|
if (!_playerLocked) {
|
|
|
|
_playerLocked = true;
|
|
|
|
_shared->player().lock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Instance::unlockPlayer() {
|
|
|
|
Expects(_shared != nullptr);
|
|
|
|
|
|
|
|
if (_playerLocked) {
|
|
|
|
_playerLocked = false;
|
|
|
|
_shared->player().unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Instance::playerLocked() const {
|
|
|
|
Expects(_shared != nullptr);
|
|
|
|
|
|
|
|
return _shared->player().locked();
|
|
|
|
}
|
|
|
|
|
2019-12-23 10:27:20 +00:00
|
|
|
void Instance::setPriority(int priority) {
|
|
|
|
Expects(_shared != nullptr);
|
|
|
|
|
|
|
|
if (_priority == priority) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_priority = priority;
|
|
|
|
_shared->refreshPlayerPriority();
|
|
|
|
}
|
|
|
|
|
|
|
|
int Instance::priority() const {
|
|
|
|
return _priority;
|
|
|
|
}
|
|
|
|
|
2019-12-11 12:09:21 +00:00
|
|
|
rpl::lifetime &Instance::lifetime() {
|
|
|
|
return _lifetime;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Streaming
|
|
|
|
} // namespace Media
|