2019-12-28 14:56:06 +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 "base/timer.h"
|
|
|
|
|
2020-07-03 10:48:55 +00:00
|
|
|
class PhotoData;
|
2019-12-28 14:56:06 +00:00
|
|
|
class DocumentData;
|
|
|
|
|
|
|
|
namespace Media {
|
|
|
|
namespace Streaming {
|
|
|
|
class Reader;
|
|
|
|
class Document;
|
|
|
|
} // namespace Streaming
|
|
|
|
} // namespace Media
|
|
|
|
|
|
|
|
namespace Data {
|
|
|
|
|
|
|
|
class Session;
|
|
|
|
struct FileOrigin;
|
|
|
|
|
|
|
|
class Streaming final {
|
|
|
|
public:
|
|
|
|
explicit Streaming(not_null<Session*> owner);
|
|
|
|
Streaming(const Streaming &other) = delete;
|
|
|
|
Streaming &operator=(const Streaming &other) = delete;
|
|
|
|
~Streaming();
|
|
|
|
|
|
|
|
using Reader = ::Media::Streaming::Reader;
|
|
|
|
using Document = ::Media::Streaming::Document;
|
|
|
|
|
|
|
|
[[nodiscard]] std::shared_ptr<Reader> sharedReader(
|
|
|
|
not_null<DocumentData*> document,
|
|
|
|
FileOrigin origin,
|
|
|
|
bool forceRemoteLoader = false);
|
|
|
|
[[nodiscard]] std::shared_ptr<Document> sharedDocument(
|
|
|
|
not_null<DocumentData*> document,
|
|
|
|
FileOrigin origin);
|
|
|
|
|
2020-07-03 10:48:55 +00:00
|
|
|
[[nodiscard]] std::shared_ptr<Reader> sharedReader(
|
|
|
|
not_null<PhotoData*> photo,
|
|
|
|
FileOrigin origin,
|
|
|
|
bool forceRemoteLoader = false);
|
|
|
|
[[nodiscard]] std::shared_ptr<Document> sharedDocument(
|
|
|
|
not_null<PhotoData*> photo,
|
|
|
|
FileOrigin origin);
|
|
|
|
|
2019-12-28 14:56:06 +00:00
|
|
|
void keepAlive(not_null<DocumentData*> document);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void clearKeptAlive();
|
|
|
|
|
2020-07-03 10:48:55 +00:00
|
|
|
template <typename Data>
|
|
|
|
[[nodiscard]] std::shared_ptr<Reader> sharedReader(
|
|
|
|
base::flat_map<not_null<Data*>, std::weak_ptr<Reader>> &readers,
|
|
|
|
not_null<Data*> data,
|
|
|
|
FileOrigin origin,
|
|
|
|
bool forceRemoteLoader = false);
|
|
|
|
|
|
|
|
template <typename Data>
|
|
|
|
[[nodiscard]] std::shared_ptr<Document> sharedDocument(
|
|
|
|
base::flat_map<not_null<Data*>, std::weak_ptr<Document>> &documents,
|
|
|
|
base::flat_map<not_null<Data*>, std::weak_ptr<Reader>> &readers,
|
|
|
|
not_null<Data*> data,
|
|
|
|
FileOrigin origin);
|
|
|
|
|
2019-12-28 14:56:06 +00:00
|
|
|
const not_null<Session*> _owner;
|
|
|
|
|
|
|
|
base::flat_map<
|
|
|
|
not_null<DocumentData*>,
|
2020-07-03 10:48:55 +00:00
|
|
|
std::weak_ptr<Reader>> _fileReaders;
|
|
|
|
base::flat_map<
|
|
|
|
not_null<DocumentData*>,
|
|
|
|
std::weak_ptr<Document>> _fileDocuments;
|
|
|
|
|
|
|
|
base::flat_map<not_null<PhotoData*>, std::weak_ptr<Reader>> _photoReaders;
|
|
|
|
base::flat_map<
|
|
|
|
not_null<PhotoData*>,
|
|
|
|
std::weak_ptr<Document>> _photoDocuments;
|
2019-12-28 14:56:06 +00:00
|
|
|
|
|
|
|
base::flat_map<std::shared_ptr<Document>, crl::time> _keptAlive;
|
|
|
|
base::Timer _keptAliveTimer;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Data
|