mirror of https://github.com/procxx/kepka.git
Restore download priorities without streaming.
This commit is contained in:
parent
85545dba64
commit
8a3506af89
|
@ -328,6 +328,11 @@ void File::Context::handleEndOfFile() {
|
|||
if (error) {
|
||||
logFatal(qstr("av_seek_frame"));
|
||||
}
|
||||
|
||||
// If we loaded a file till the end then we think it is fully cached,
|
||||
// assume we finished loading and don't want to keep all other
|
||||
// download tasks throttled because of an active streaming.
|
||||
_reader->tryRemoveLoaderAsync();
|
||||
} else {
|
||||
_readTillEnd = true;
|
||||
}
|
||||
|
@ -374,12 +379,10 @@ bool File::Context::finished() const {
|
|||
return unroll() || _readTillEnd;
|
||||
}
|
||||
|
||||
void File::Context::waitTillInterrupted() {
|
||||
while (!interrupted()) {
|
||||
_reader->startSleep(&_semaphore);
|
||||
_semaphore.acquire();
|
||||
}
|
||||
_reader->stopSleep();
|
||||
void File::Context::stopStreamingAsync() {
|
||||
// If we finished loading we don't want to keep all other
|
||||
// download tasks throttled because of an active streaming.
|
||||
_reader->stopStreamingAsync();
|
||||
}
|
||||
|
||||
File::File(
|
||||
|
@ -398,7 +401,9 @@ void File::start(not_null<FileDelegate*> delegate, crl::time position) {
|
|||
while (!context->finished()) {
|
||||
context->readNextPacket();
|
||||
}
|
||||
context->waitTillInterrupted();
|
||||
if (!context->interrupted()) {
|
||||
context->stopStreamingAsync();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ private:
|
|||
[[nodiscard]] bool failed() const;
|
||||
[[nodiscard]] bool finished() const;
|
||||
|
||||
void waitTillInterrupted();
|
||||
void stopStreamingAsync();
|
||||
|
||||
private:
|
||||
enum class SleepPolicy {
|
||||
|
|
|
@ -37,6 +37,9 @@ public:
|
|||
virtual void setPriority(int priority) = 0;
|
||||
virtual void stop() = 0;
|
||||
|
||||
// Remove from queue if no requests are in progress.
|
||||
virtual void tryRemoveFromQueue() = 0;
|
||||
|
||||
// Parts will be sent from the main thread.
|
||||
[[nodiscard]] virtual rpl::producer<LoadedPart> parts() const = 0;
|
||||
|
||||
|
|
|
@ -77,6 +77,9 @@ void LoaderLocal::setPriority(int priority) {
|
|||
void LoaderLocal::stop() {
|
||||
}
|
||||
|
||||
void LoaderLocal::tryRemoveFromQueue() {
|
||||
}
|
||||
|
||||
rpl::producer<LoadedPart> LoaderLocal::parts() const {
|
||||
return _parts.events();
|
||||
}
|
||||
|
|
|
@ -30,6 +30,8 @@ public:
|
|||
void setPriority(int priority) override;
|
||||
void stop() override;
|
||||
|
||||
void tryRemoveFromQueue() override;
|
||||
|
||||
// Parts will be sent from the main thread.
|
||||
[[nodiscard]] rpl::producer<LoadedPart> parts() const override;
|
||||
|
||||
|
|
|
@ -68,6 +68,14 @@ void LoaderMtproto::stop() {
|
|||
});
|
||||
}
|
||||
|
||||
void LoaderMtproto::tryRemoveFromQueue() {
|
||||
crl::on_main(this, [=] {
|
||||
if (_requested.empty() && !haveSentRequests()) {
|
||||
removeFromQueue();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void LoaderMtproto::cancel(int offset) {
|
||||
crl::on_main(this, [=] {
|
||||
cancelForOffset(offset);
|
||||
|
|
|
@ -33,6 +33,8 @@ public:
|
|||
void setPriority(int priority) override;
|
||||
void stop() override;
|
||||
|
||||
void tryRemoveFromQueue() override;
|
||||
|
||||
// Parts will be sent from the main thread.
|
||||
[[nodiscard]] rpl::producer<LoadedPart> parts() const override;
|
||||
|
||||
|
|
|
@ -886,6 +886,19 @@ void Reader::stopSleep() {
|
|||
_sleeping.store(nullptr, std::memory_order_release);
|
||||
}
|
||||
|
||||
void Reader::stopStreamingAsync() {
|
||||
_stopStreamingAsync = true;
|
||||
crl::on_main(this, [=] {
|
||||
if (_stopStreamingAsync) {
|
||||
stopStreaming(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void Reader::tryRemoveLoaderAsync() {
|
||||
_loader->tryRemoveFromQueue();
|
||||
}
|
||||
|
||||
void Reader::startStreaming() {
|
||||
_streamingActive = true;
|
||||
refreshLoaderPriority();
|
||||
|
@ -894,6 +907,7 @@ void Reader::startStreaming() {
|
|||
void Reader::stopStreaming(bool stillActive) {
|
||||
Expects(_sleeping == nullptr);
|
||||
|
||||
_stopStreamingAsync = false;
|
||||
_waiting.store(nullptr, std::memory_order_release);
|
||||
if (!stillActive) {
|
||||
_streamingActive = false;
|
||||
|
|
|
@ -57,6 +57,8 @@ public:
|
|||
void startSleep(not_null<crl::semaphore*> wake);
|
||||
void wakeFromSleep();
|
||||
void stopSleep();
|
||||
void stopStreamingAsync();
|
||||
void tryRemoveLoaderAsync();
|
||||
|
||||
// Main thread.
|
||||
void startStreaming();
|
||||
|
@ -233,6 +235,7 @@ private:
|
|||
base::thread_safe_queue<LoadedPart, std::vector> _loadedParts;
|
||||
std::atomic<crl::semaphore*> _waiting = nullptr;
|
||||
std::atomic<crl::semaphore*> _sleeping = nullptr;
|
||||
std::atomic<bool> _stopStreamingAsync = false;
|
||||
PriorityQueue _loadingOffsets;
|
||||
|
||||
Slices _slices;
|
||||
|
|
Loading…
Reference in New Issue