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
|
|
|
|
|
|
|
|
namespace Media {
|
|
|
|
namespace Streaming {
|
|
|
|
|
|
|
|
struct LoadedPart {
|
|
|
|
int offset = 0;
|
|
|
|
QByteArray bytes;
|
|
|
|
|
|
|
|
static constexpr auto kFailedOffset = -1;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Loader {
|
|
|
|
public:
|
|
|
|
static constexpr auto kPartSize = 128 * 1024;
|
|
|
|
|
2019-02-25 17:26:08 +00:00
|
|
|
[[nodiscard]] virtual auto baseCacheKey() const
|
|
|
|
-> std::optional<Storage::Cache::Key> = 0;
|
2019-02-13 18:10:18 +00:00
|
|
|
[[nodiscard]] virtual int size() const = 0;
|
|
|
|
|
2019-02-25 17:26:08 +00:00
|
|
|
virtual void load(int offset) = 0;
|
|
|
|
virtual void cancel(int offset) = 0;
|
|
|
|
virtual void increasePriority() = 0;
|
2019-02-13 18:10:18 +00:00
|
|
|
virtual void stop() = 0;
|
|
|
|
|
|
|
|
// Parts will be sent from the main thread.
|
|
|
|
[[nodiscard]] virtual rpl::producer<LoadedPart> parts() const = 0;
|
|
|
|
|
|
|
|
virtual ~Loader() = default;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-02-25 17:26:08 +00:00
|
|
|
class PriorityQueue {
|
|
|
|
public:
|
|
|
|
bool add(int value);
|
|
|
|
bool remove(int value);
|
|
|
|
void increasePriority();
|
|
|
|
std::optional<int> front() const;
|
|
|
|
std::optional<int> take();
|
|
|
|
base::flat_set<int> takeInRange(int from, int till);
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct Entry {
|
|
|
|
int value = 0;
|
|
|
|
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
|