media_audio_local_cache.h 993 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. namespace Media::Audio {
  9. struct LocalSound {
  10. DocumentId id = 0;
  11. QByteArray wav;
  12. explicit operator bool() const {
  13. return !wav.isEmpty();
  14. }
  15. };
  16. class LocalCache final {
  17. public:
  18. [[nodiscard]] LocalSound sound(
  19. DocumentId id,
  20. Fn<QByteArray()> resolveOriginalBytes,
  21. Fn<QByteArray()> fallbackOriginalBytes);
  22. private:
  23. base::flat_map<DocumentId, QByteArray> _cache;
  24. };
  25. class LocalDiskCache final {
  26. public:
  27. explicit LocalDiskCache(const QString &folder);
  28. [[nodiscard]] QString name(const LocalSound &sound);
  29. [[nodiscard]] QString path(const LocalSound &sound);
  30. private:
  31. const QString _base;
  32. base::flat_map<DocumentId, QString> _paths;
  33. };
  34. } // namespace Media::Audio