media_streaming_document.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 "media/streaming/media_streaming_player.h"
  9. #include "ui/effects/radial_animation.h"
  10. #include "ui/effects/animations.h"
  11. #include "base/timer.h"
  12. class DocumentData;
  13. namespace Media::Streaming {
  14. class Instance;
  15. class Loader;
  16. struct QualityDescriptor {
  17. uint32 sizeInBytes = 0;
  18. uint32 height = 0;
  19. };
  20. class Document {
  21. public:
  22. Document(
  23. not_null<DocumentData*> document,
  24. std::shared_ptr<Reader> reader,
  25. std::vector<QualityDescriptor> otherQualities = {});
  26. Document(
  27. not_null<PhotoData*> photo,
  28. std::shared_ptr<Reader> reader,
  29. std::vector<QualityDescriptor> otherQualities = {});
  30. explicit Document(std::unique_ptr<Loader> loader);
  31. void play(const PlaybackOptions &options);
  32. void saveFrameToCover();
  33. [[nodiscard]] Player &player();
  34. [[nodiscard]] const Player &player() const;
  35. [[nodiscard]] const Information &info() const;
  36. [[nodiscard]] bool waitingShown() const;
  37. [[nodiscard]] float64 waitingOpacity() const;
  38. [[nodiscard]] Ui::RadialState waitingState() const;
  39. void setOtherQualities(std::vector<QualityDescriptor> value);
  40. [[nodiscard]] rpl::producer<int> switchQualityRequests() const;
  41. private:
  42. Document(
  43. std::shared_ptr<Reader> reader,
  44. DocumentData *document,
  45. PhotoData *photo,
  46. std::vector<QualityDescriptor> otherQualities);
  47. friend class Instance;
  48. void registerInstance(not_null<Instance*> instance);
  49. void unregisterInstance(not_null<Instance*> instance);
  50. void refreshPlayerPriority();
  51. void waitingCallback();
  52. void checkForQualitySwitch(SpeedEstimate estimate);
  53. bool checkSwitchToHigherQuality();
  54. bool checkSwitchToLowerQuality();
  55. void handleUpdate(Update &&update);
  56. void handleError(Error &&error);
  57. void ready(Information &&info);
  58. void waitingChange(bool waiting);
  59. void validateGoodThumbnail();
  60. void resubscribe();
  61. DocumentData *_document = nullptr;
  62. PhotoData *_photo = nullptr;
  63. Player _player;
  64. Information _info;
  65. rpl::lifetime _subscription;
  66. mutable Ui::InfiniteRadialAnimation _radial;
  67. Ui::Animations::Simple _fading;
  68. base::Timer _timer;
  69. base::flat_set<not_null<Instance*>> _instances;
  70. std::vector<QualityDescriptor> _otherQualities;
  71. rpl::event_stream<int> _switchQualityRequests;
  72. SpeedEstimate _lastSpeedEstimate;
  73. bool _waiting = false;
  74. };
  75. } // namespace Media::Streaming