2019-02-13 18:10:18 +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
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2019-04-12 09:25:00 +00:00
|
|
|
namespace Storage {
|
|
|
|
class StreamedFileDownloader;
|
|
|
|
} // namespace Storage
|
|
|
|
|
2019-02-13 18:10:18 +00:00
|
|
|
namespace Media {
|
|
|
|
namespace Streaming {
|
|
|
|
|
|
|
|
struct LoadedPart {
|
2022-05-10 14:22:28 +00:00
|
|
|
int64 offset = 0;
|
2019-02-13 18:10:18 +00:00
|
|
|
QByteArray bytes;
|
|
|
|
|
2022-05-10 14:22:28 +00:00
|
|
|
static constexpr auto kFailedOffset = int64(-1);
|
2019-04-11 13:07:48 +00:00
|
|
|
|
2022-05-10 14:22:28 +00:00
|
|
|
[[nodiscard]] bool valid(int64 size) const;
|
2019-02-13 18:10:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Loader {
|
|
|
|
public:
|
|
|
|
static constexpr auto kPartSize = 128 * 1024;
|
|
|
|
|
2020-05-20 12:28:18 +00:00
|
|
|
[[nodiscard]] virtual Storage::Cache::Key baseCacheKey() const = 0;
|
2022-05-10 14:22:28 +00:00
|
|
|
[[nodiscard]] virtual int64 size() const = 0;
|
2019-02-13 18:10:18 +00:00
|
|
|
|
2022-05-10 14:22:28 +00:00
|
|
|
virtual void load(int64 offset) = 0;
|
|
|
|
virtual void cancel(int64 offset) = 0;
|
2019-12-23 10:27:20 +00:00
|
|
|
virtual void resetPriorities() = 0;
|
|
|
|
virtual void setPriority(int priority) = 0;
|
2019-02-13 18:10:18 +00:00
|
|
|
virtual void stop() = 0;
|
|
|
|
|
2019-12-23 11:13:32 +00:00
|
|
|
// Remove from queue if no requests are in progress.
|
|
|
|
virtual void tryRemoveFromQueue() = 0;
|
|
|
|
|
2019-02-13 18:10:18 +00:00
|
|
|
// Parts will be sent from the main thread.
|
|
|
|
[[nodiscard]] virtual rpl::producer<LoadedPart> parts() const = 0;
|
|
|
|
|
2019-04-12 09:25:00 +00:00
|
|
|
virtual void attachDownloader(
|
2019-12-04 06:51:21 +00:00
|
|
|
not_null<Storage::StreamedFileDownloader*> downloader) = 0;
|
2019-04-12 09:25:00 +00:00
|
|
|
virtual void clearAttachedDownloader() = 0;
|
|
|
|
|
2019-02-13 18:10:18 +00:00
|
|
|
virtual ~Loader() = default;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-02-25 17:26:08 +00:00
|
|
|
class PriorityQueue {
|
|
|
|
public:
|
2022-05-10 14:22:28 +00:00
|
|
|
bool add(int64 value);
|
|
|
|
bool remove(int64 value);
|
2019-12-23 10:27:20 +00:00
|
|
|
void resetPriorities();
|
2019-12-04 07:42:55 +00:00
|
|
|
[[nodiscard]] bool empty() const;
|
2022-05-10 14:22:28 +00:00
|
|
|
[[nodiscard]] std::optional<int64> front() const;
|
|
|
|
[[nodiscard]] std::optional<int64> take();
|
|
|
|
[[nodiscard]] base::flat_set<int64> takeInRange(int64 from, int64 till);
|
2019-02-25 17:26:08 +00:00
|
|
|
void clear();
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct Entry {
|
2022-05-10 14:22:28 +00:00
|
|
|
int64 value = 0;
|
2019-02-25 17:26:08 +00:00
|
|
|
int priority = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
friend bool operator<(const Entry &a, const Entry &b);
|
|
|
|
|
|
|
|
base::flat_set<Entry> _data;
|
|
|
|
int _priority = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-02-13 18:10:18 +00:00
|
|
|
} // namespace Streaming
|
|
|
|
} // namespace Media
|