2019-04-10 11:26:15 +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 "storage/file_download.h"
|
|
|
|
#include "storage/cache/storage_cache_types.h"
|
2019-12-05 08:32:33 +00:00
|
|
|
#include "data/data_file_origin.h"
|
2019-04-10 11:26:15 +00:00
|
|
|
|
|
|
|
namespace Media {
|
|
|
|
namespace Streaming {
|
|
|
|
class Reader;
|
2019-04-11 07:59:18 +00:00
|
|
|
struct LoadedPart;
|
2019-04-10 11:26:15 +00:00
|
|
|
} // namespace Streaming
|
|
|
|
} // namespace Media
|
|
|
|
|
|
|
|
namespace Storage {
|
|
|
|
|
|
|
|
class StreamedFileDownloader final : public FileLoader {
|
|
|
|
public:
|
|
|
|
StreamedFileDownloader(
|
2020-06-08 15:17:33 +00:00
|
|
|
not_null<Main::Session*> session,
|
|
|
|
|
2019-04-10 11:26:15 +00:00
|
|
|
uint64 objectId,
|
2019-04-11 07:59:18 +00:00
|
|
|
MTP::DcId dcId,
|
2019-04-10 11:26:15 +00:00
|
|
|
Data::FileOrigin origin,
|
2019-04-12 07:34:39 +00:00
|
|
|
Cache::Key cacheKey,
|
|
|
|
MediaKey fileLocationKey,
|
2019-04-10 11:26:15 +00:00
|
|
|
std::shared_ptr<Media::Streaming::Reader> reader,
|
|
|
|
|
|
|
|
// For FileLoader
|
|
|
|
const QString &toFile,
|
|
|
|
int32 size,
|
|
|
|
LocationType locationType,
|
|
|
|
LoadToCacheSetting toCache,
|
|
|
|
LoadFromCloudSetting fromCloud,
|
|
|
|
bool autoLoading,
|
|
|
|
uint8 cacheTag);
|
|
|
|
~StreamedFileDownloader();
|
|
|
|
|
|
|
|
uint64 objId() const override;
|
|
|
|
Data::FileOrigin fileOrigin() const override;
|
|
|
|
|
2019-04-12 09:25:00 +00:00
|
|
|
QByteArray readLoadedPart(int offset);
|
|
|
|
|
2019-04-10 11:26:15 +00:00
|
|
|
private:
|
2019-12-04 12:15:58 +00:00
|
|
|
void startLoading() override;
|
2019-04-12 07:34:39 +00:00
|
|
|
Cache::Key cacheKey() const override;
|
2019-04-11 07:59:18 +00:00
|
|
|
std::optional<MediaKey> fileLocationKey() const override;
|
2019-12-05 08:32:33 +00:00
|
|
|
void cancelHook() override;
|
2019-12-04 07:42:55 +00:00
|
|
|
void requestParts();
|
|
|
|
void requestPart();
|
2019-04-10 11:26:15 +00:00
|
|
|
|
2019-04-11 07:59:18 +00:00
|
|
|
void savePart(const Media::Streaming::LoadedPart &part);
|
|
|
|
|
2019-04-10 11:26:15 +00:00
|
|
|
uint64 _objectId = 0;
|
|
|
|
Data::FileOrigin _origin;
|
2019-04-12 07:34:39 +00:00
|
|
|
Cache::Key _cacheKey;
|
|
|
|
MediaKey _fileLocationKey;
|
2019-04-10 11:26:15 +00:00
|
|
|
std::shared_ptr<Media::Streaming::Reader> _reader;
|
|
|
|
|
|
|
|
std::vector<bool> _partIsSaved; // vector<bool> :D
|
2019-12-02 07:28:33 +00:00
|
|
|
mutable int _nextPartIndex = 0;
|
2019-04-12 08:00:06 +00:00
|
|
|
int _partsCount = 0;
|
|
|
|
int _partsRequested = 0;
|
|
|
|
int _partsSaved = 0;
|
2019-04-10 11:26:15 +00:00
|
|
|
|
2019-04-11 07:59:18 +00:00
|
|
|
rpl::lifetime _lifetime;
|
|
|
|
|
2019-04-10 11:26:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Storage
|