streamed_file_downloader.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. #include "storage/file_download.h"
  9. #include "storage/cache/storage_cache_types.h"
  10. #include "data/data_file_origin.h"
  11. namespace Media {
  12. namespace Streaming {
  13. class Reader;
  14. struct LoadedPart;
  15. } // namespace Streaming
  16. } // namespace Media
  17. namespace Storage {
  18. class StreamedFileDownloader final : public FileLoader {
  19. public:
  20. StreamedFileDownloader(
  21. not_null<Main::Session*> session,
  22. uint64 objectId,
  23. MTP::DcId dcId,
  24. Data::FileOrigin origin,
  25. Cache::Key cacheKey,
  26. MediaKey fileLocationKey,
  27. std::shared_ptr<Media::Streaming::Reader> reader,
  28. // For FileLoader
  29. const QString &toFile,
  30. int64 size,
  31. LocationType locationType,
  32. LoadToCacheSetting toCache,
  33. LoadFromCloudSetting fromCloud,
  34. bool autoLoading,
  35. uint8 cacheTag);
  36. ~StreamedFileDownloader();
  37. uint64 objId() const override;
  38. Data::FileOrigin fileOrigin() const override;
  39. QByteArray readLoadedPart(int64 offset);
  40. private:
  41. void startLoading() override;
  42. Cache::Key cacheKey() const override;
  43. std::optional<MediaKey> fileLocationKey() const override;
  44. void cancelHook() override;
  45. void requestParts();
  46. void requestPart();
  47. void savePart(const Media::Streaming::LoadedPart &part);
  48. uint64 _objectId = 0;
  49. Data::FileOrigin _origin;
  50. Cache::Key _cacheKey;
  51. MediaKey _fileLocationKey;
  52. std::shared_ptr<Media::Streaming::Reader> _reader;
  53. std::vector<bool> _partIsSaved; // vector<bool> :D
  54. mutable int _nextPartIndex = 0;
  55. int _partsCount = 0;
  56. int _partsRequested = 0;
  57. int _partsSaved = 0;
  58. rpl::lifetime _lifetime;
  59. };
  60. } // namespace Storage