mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-04-01 23:00:58 +00:00
Set higher streaming priority in media overlay.
This commit is contained in:
parent
fa4d8f2fbd
commit
85545dba64
Telegram/SourceFiles/media
streaming
media_streaming_document.cppmedia_streaming_document.hmedia_streaming_file.cppmedia_streaming_file.hmedia_streaming_instance.cppmedia_streaming_instance.hmedia_streaming_loader.cppmedia_streaming_loader.hmedia_streaming_loader_local.cppmedia_streaming_loader_local.hmedia_streaming_loader_mtproto.cppmedia_streaming_loader_mtproto.hmedia_streaming_player.cppmedia_streaming_player.hmedia_streaming_reader.cppmedia_streaming_reader.h
view
@ -85,6 +85,18 @@ void Document::registerInstance(not_null<Instance*> instance) {
|
||||
void Document::unregisterInstance(not_null<Instance*> instance) {
|
||||
_instances.remove(instance);
|
||||
_player.unregisterInstance(instance);
|
||||
refreshPlayerPriority();
|
||||
}
|
||||
|
||||
void Document::refreshPlayerPriority() {
|
||||
if (_instances.empty()) {
|
||||
return;
|
||||
}
|
||||
const auto max = ranges::max_element(
|
||||
_instances,
|
||||
ranges::less(),
|
||||
&Instance::priority);
|
||||
_player.setLoaderPriority((*max)->priority());
|
||||
}
|
||||
|
||||
bool Document::waitingShown() const {
|
||||
|
@ -41,6 +41,7 @@ private:
|
||||
|
||||
void registerInstance(not_null<Instance*> instance);
|
||||
void unregisterInstance(not_null<Instance*> instance);
|
||||
void refreshPlayerPriority();
|
||||
|
||||
void waitingCallback();
|
||||
|
||||
|
@ -421,6 +421,10 @@ bool File::isRemoteLoader() const {
|
||||
return _reader->isRemoteLoader();
|
||||
}
|
||||
|
||||
void File::setLoaderPriority(int priority) {
|
||||
_reader->setLoaderPriority(priority);
|
||||
}
|
||||
|
||||
File::~File() {
|
||||
stop();
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ public:
|
||||
void stop(bool stillActive = false);
|
||||
|
||||
[[nodiscard]] bool isRemoteLoader() const;
|
||||
void setLoaderPriority(int priority);
|
||||
|
||||
~File();
|
||||
|
||||
|
@ -187,6 +187,20 @@ bool Instance::playerLocked() const {
|
||||
return _shared->player().locked();
|
||||
}
|
||||
|
||||
void Instance::setPriority(int priority) {
|
||||
Expects(_shared != nullptr);
|
||||
|
||||
if (_priority == priority) {
|
||||
return;
|
||||
}
|
||||
_priority = priority;
|
||||
_shared->refreshPlayerPriority();
|
||||
}
|
||||
|
||||
int Instance::priority() const {
|
||||
return _priority;
|
||||
}
|
||||
|
||||
rpl::lifetime &Instance::lifetime() {
|
||||
return _lifetime;
|
||||
}
|
||||
|
@ -70,11 +70,15 @@ public:
|
||||
void unlockPlayer();
|
||||
[[nodiscard]] bool playerLocked() const;
|
||||
|
||||
void setPriority(int priority);
|
||||
[[nodiscard]] int priority() const;
|
||||
|
||||
[[nodiscard]] rpl::lifetime &lifetime();
|
||||
|
||||
private:
|
||||
const std::shared_ptr<Document> _shared;
|
||||
Fn<void()> _waitingCallback;
|
||||
int _priority = 1;
|
||||
bool _playerLocked = false;
|
||||
rpl::lifetime _lifetime;
|
||||
|
||||
|
@ -86,7 +86,7 @@ void PriorityQueue::clear() {
|
||||
_data.clear();
|
||||
}
|
||||
|
||||
void PriorityQueue::increasePriority() {
|
||||
void PriorityQueue::resetPriorities() {
|
||||
++_priority;
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,8 @@ public:
|
||||
|
||||
virtual void load(int offset) = 0;
|
||||
virtual void cancel(int offset) = 0;
|
||||
virtual void increasePriority() = 0;
|
||||
virtual void resetPriorities() = 0;
|
||||
virtual void setPriority(int priority) = 0;
|
||||
virtual void stop() = 0;
|
||||
|
||||
// Parts will be sent from the main thread.
|
||||
@ -51,7 +52,7 @@ class PriorityQueue {
|
||||
public:
|
||||
bool add(int value);
|
||||
bool remove(int value);
|
||||
void increasePriority();
|
||||
void resetPriorities();
|
||||
[[nodiscard]] bool empty() const;
|
||||
[[nodiscard]] std::optional<int> front() const;
|
||||
[[nodiscard]] std::optional<int> take();
|
||||
|
@ -68,7 +68,10 @@ void LoaderLocal::fail() {
|
||||
void LoaderLocal::cancel(int offset) {
|
||||
}
|
||||
|
||||
void LoaderLocal::increasePriority() {
|
||||
void LoaderLocal::resetPriorities() {
|
||||
}
|
||||
|
||||
void LoaderLocal::setPriority(int priority) {
|
||||
}
|
||||
|
||||
void LoaderLocal::stop() {
|
||||
|
@ -26,7 +26,8 @@ public:
|
||||
|
||||
void load(int offset) override;
|
||||
void cancel(int offset) override;
|
||||
void increasePriority() override;
|
||||
void resetPriorities() override;
|
||||
void setPriority(int priority) override;
|
||||
void stop() override;
|
||||
|
||||
// Parts will be sent from the main thread.
|
||||
|
@ -57,9 +57,7 @@ void LoaderMtproto::load(int offset) {
|
||||
}
|
||||
|
||||
void LoaderMtproto::addToQueueWithPriority() {
|
||||
addToQueue([&] {
|
||||
return 1;
|
||||
}());
|
||||
addToQueue(_priority);
|
||||
}
|
||||
|
||||
void LoaderMtproto::stop() {
|
||||
@ -79,7 +77,9 @@ void LoaderMtproto::cancel(int offset) {
|
||||
void LoaderMtproto::cancelForOffset(int offset) {
|
||||
if (haveSentRequestForOffset(offset)) {
|
||||
cancelRequestForOffset(offset);
|
||||
addToQueueWithPriority();
|
||||
if (!_requested.empty()) {
|
||||
addToQueueWithPriority();
|
||||
}
|
||||
} else {
|
||||
_requested.remove(offset);
|
||||
}
|
||||
@ -94,12 +94,22 @@ void LoaderMtproto::clearAttachedDownloader() {
|
||||
_downloader = nullptr;
|
||||
}
|
||||
|
||||
void LoaderMtproto::increasePriority() {
|
||||
void LoaderMtproto::resetPriorities() {
|
||||
crl::on_main(this, [=] {
|
||||
_requested.increasePriority();
|
||||
_requested.resetPriorities();
|
||||
});
|
||||
}
|
||||
|
||||
void LoaderMtproto::setPriority(int priority) {
|
||||
if (_priority == priority) {
|
||||
return;
|
||||
}
|
||||
_priority = priority;
|
||||
if (haveSentRequests()) {
|
||||
addToQueueWithPriority();
|
||||
}
|
||||
}
|
||||
|
||||
bool LoaderMtproto::readyToRequest() const {
|
||||
return !_requested.empty();
|
||||
}
|
||||
|
@ -29,7 +29,8 @@ public:
|
||||
|
||||
void load(int offset) override;
|
||||
void cancel(int offset) override;
|
||||
void increasePriority() override;
|
||||
void resetPriorities() override;
|
||||
void setPriority(int priority) override;
|
||||
void stop() override;
|
||||
|
||||
// Parts will be sent from the main thread.
|
||||
@ -49,6 +50,7 @@ private:
|
||||
void addToQueueWithPriority();
|
||||
|
||||
const int _size = 0;
|
||||
int _priority = 0;
|
||||
|
||||
MTP::Sender _api;
|
||||
|
||||
|
@ -143,6 +143,10 @@ bool Player::markFrameShown() {
|
||||
return _video->markFrameShown();
|
||||
}
|
||||
|
||||
void Player::setLoaderPriority(int priority) {
|
||||
_file->setLoaderPriority(priority);
|
||||
}
|
||||
|
||||
template <typename Track>
|
||||
void Player::trackReceivedTill(
|
||||
const Track &track,
|
||||
|
@ -71,6 +71,8 @@ public:
|
||||
void unregisterInstance(not_null<const Instance*> instance);
|
||||
bool markFrameShown();
|
||||
|
||||
void setLoaderPriority(int priority);
|
||||
|
||||
[[nodiscard]] Media::Player::TrackState prepareLegacyState() const;
|
||||
|
||||
void lock();
|
||||
|
@ -888,6 +888,7 @@ void Reader::stopSleep() {
|
||||
|
||||
void Reader::startStreaming() {
|
||||
_streamingActive = true;
|
||||
refreshLoaderPriority();
|
||||
}
|
||||
|
||||
void Reader::stopStreaming(bool stillActive) {
|
||||
@ -896,6 +897,7 @@ void Reader::stopStreaming(bool stillActive) {
|
||||
_waiting.store(nullptr, std::memory_order_release);
|
||||
if (!stillActive) {
|
||||
_streamingActive = false;
|
||||
refreshLoaderPriority();
|
||||
_loadingOffsets.clear();
|
||||
processDownloaderRequests();
|
||||
}
|
||||
@ -1080,6 +1082,18 @@ void Reader::checkCacheResultsForDownloader() {
|
||||
processDownloaderRequests();
|
||||
}
|
||||
|
||||
void Reader::setLoaderPriority(int priority) {
|
||||
if (_realPriority == priority) {
|
||||
return;
|
||||
}
|
||||
_realPriority = priority;
|
||||
refreshLoaderPriority();
|
||||
}
|
||||
|
||||
void Reader::refreshLoaderPriority() {
|
||||
_loader->setPriority(_streamingActive ? _realPriority : 0);
|
||||
}
|
||||
|
||||
bool Reader::isRemoteLoader() const {
|
||||
return _loader->baseCacheKey().has_value();
|
||||
}
|
||||
@ -1269,8 +1283,8 @@ void Reader::cancelLoadInRange(int from, int till) {
|
||||
|
||||
void Reader::checkLoadWillBeFirst(int offset) {
|
||||
if (_loadingOffsets.front().value_or(offset) != offset) {
|
||||
_loadingOffsets.increasePriority();
|
||||
_loader->increasePriority();
|
||||
_loadingOffsets.resetPriorities();
|
||||
_loader->resetPriorities();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,6 +37,8 @@ public:
|
||||
not_null<Storage::Cache::Database*> cache,
|
||||
std::unique_ptr<Loader> loader);
|
||||
|
||||
void setLoaderPriority(int priority);
|
||||
|
||||
// Any thread.
|
||||
[[nodiscard]] int size() const;
|
||||
[[nodiscard]] bool isRemoteLoader() const;
|
||||
@ -219,6 +221,8 @@ private:
|
||||
void checkForDownloaderChange(int checkItemsCount);
|
||||
void checkForDownloaderReadyOffsets();
|
||||
|
||||
void refreshLoaderPriority();
|
||||
|
||||
static std::shared_ptr<CacheHelper> InitCacheHelper(
|
||||
std::optional<Storage::Cache::Key> baseKey);
|
||||
|
||||
@ -242,6 +246,7 @@ private:
|
||||
// Main thread.
|
||||
Storage::StreamedFileDownloader *_attachedDownloader = nullptr;
|
||||
rpl::event_stream<LoadedPart> _partsForDownloader;
|
||||
int _realPriority = 1;
|
||||
bool _streamingActive = false;
|
||||
|
||||
// Streaming thread.
|
||||
|
@ -68,6 +68,8 @@ namespace {
|
||||
|
||||
constexpr auto kPreloadCount = 4;
|
||||
|
||||
constexpr auto kOverlayLoaderPriority = 2;
|
||||
|
||||
// macOS OpenGL renderer fails to render larger texture
|
||||
// even though it reports that max texture size is 16384.
|
||||
constexpr auto kMaxDisplayImageSize = 4096;
|
||||
@ -2081,6 +2083,7 @@ bool OverlayWidget::createStreamingObjects() {
|
||||
_streamed = nullptr;
|
||||
return false;
|
||||
}
|
||||
_streamed->instance.setPriority(kOverlayLoaderPriority);
|
||||
_streamed->instance.lockPlayer();
|
||||
_streamed->withSound = _doc->isAudioFile()
|
||||
|| _doc->isVideoFile()
|
||||
|
Loading…
Reference in New Issue
Block a user