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
|
|
|
|
|
|
|
|
#include "media/streaming/media_streaming_loader.h"
|
|
|
|
#include "mtproto/sender.h"
|
|
|
|
#include "data/data_file_origin.h"
|
2019-12-05 08:32:33 +00:00
|
|
|
#include "storage/download_manager_mtproto.h"
|
2019-02-13 18:10:18 +00:00
|
|
|
|
|
|
|
namespace Media {
|
|
|
|
namespace Streaming {
|
|
|
|
|
2019-12-05 08:32:33 +00:00
|
|
|
class LoaderMtproto : public Loader, public Storage::DownloadMtprotoTask {
|
2019-02-13 18:10:18 +00:00
|
|
|
public:
|
|
|
|
LoaderMtproto(
|
2019-12-05 08:32:33 +00:00
|
|
|
not_null<Storage::DownloadManagerMtproto*> owner,
|
2019-03-25 09:17:47 +00:00
|
|
|
const StorageFileLocation &location,
|
2019-02-13 18:10:18 +00:00
|
|
|
int size,
|
|
|
|
Data::FileOrigin origin);
|
|
|
|
|
2020-05-20 12:28:18 +00:00
|
|
|
[[nodiscard]] Storage::Cache::Key baseCacheKey() const override;
|
2019-02-13 18:10:18 +00:00
|
|
|
[[nodiscard]] int size() const override;
|
|
|
|
|
2019-02-25 17:26:08 +00:00
|
|
|
void load(int offset) override;
|
|
|
|
void cancel(int offset) override;
|
2019-12-23 10:27:20 +00:00
|
|
|
void resetPriorities() override;
|
|
|
|
void setPriority(int priority) override;
|
2019-02-13 18:10:18 +00:00
|
|
|
void stop() override;
|
|
|
|
|
2019-12-23 11:13:32 +00:00
|
|
|
void tryRemoveFromQueue() override;
|
|
|
|
|
2019-02-13 18:10:18 +00:00
|
|
|
// Parts will be sent from the main thread.
|
|
|
|
[[nodiscard]] rpl::producer<LoadedPart> parts() const override;
|
|
|
|
|
2019-04-12 09:25:00 +00:00
|
|
|
void attachDownloader(
|
2019-12-04 06:51:21 +00:00
|
|
|
not_null<Storage::StreamedFileDownloader*> downloader) override;
|
2019-04-12 09:25:00 +00:00
|
|
|
void clearAttachedDownloader() override;
|
|
|
|
|
2019-02-13 18:10:18 +00:00
|
|
|
private:
|
2019-12-04 07:42:55 +00:00
|
|
|
bool readyToRequest() const override;
|
2019-12-05 08:32:33 +00:00
|
|
|
int takeNextRequestOffset() override;
|
|
|
|
bool feedPart(int offset, const QByteArray &bytes) override;
|
|
|
|
void cancelOnFail() override;
|
2019-03-01 12:22:47 +00:00
|
|
|
|
2019-12-05 08:32:33 +00:00
|
|
|
void cancelForOffset(int offset);
|
2019-12-23 09:37:03 +00:00
|
|
|
void addToQueueWithPriority();
|
2019-03-01 12:22:47 +00:00
|
|
|
|
2019-02-13 18:10:18 +00:00
|
|
|
const int _size = 0;
|
2019-12-23 10:27:20 +00:00
|
|
|
int _priority = 0;
|
2019-02-13 18:10:18 +00:00
|
|
|
|
2019-11-27 08:02:56 +00:00
|
|
|
MTP::Sender _api;
|
2019-02-13 18:10:18 +00:00
|
|
|
|
2019-02-25 17:26:08 +00:00
|
|
|
PriorityQueue _requested;
|
2019-02-13 18:10:18 +00:00
|
|
|
rpl::event_stream<LoadedPart> _parts;
|
|
|
|
|
2019-04-12 09:25:00 +00:00
|
|
|
Storage::StreamedFileDownloader *_downloader = nullptr;
|
|
|
|
|
2019-02-13 18:10:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Streaming
|
|
|
|
} // namespace Media
|