media_clip_implementation.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 <QtCore/QBuffer>
  9. #include <QtCore/QFile>
  10. namespace Core {
  11. class FileLocation;
  12. } // namespace Core
  13. namespace Media {
  14. namespace Clip {
  15. namespace internal {
  16. class ReaderImplementation {
  17. public:
  18. ReaderImplementation(Core::FileLocation *location, QByteArray *data)
  19. : _location(location)
  20. , _data(data) {
  21. }
  22. enum class Mode {
  23. Silent,
  24. Inspecting, // Not playing video, but reading data.
  25. };
  26. enum class ReadResult {
  27. Success,
  28. Error,
  29. EndOfFile,
  30. };
  31. // Read frames till current frame will have presentation time > frameMs, systemMs = crl::now().
  32. virtual ReadResult readFramesTill(crl::time frameMs, crl::time systemMs) = 0;
  33. // Get current frame real and presentation time.
  34. virtual crl::time frameRealTime() const = 0;
  35. virtual crl::time framePresentationTime() const = 0;
  36. // Render current frame to an image with specific size.
  37. virtual bool renderFrame(
  38. QImage &to,
  39. bool &hasAlpha,
  40. int &index,
  41. const QSize &size) = 0;
  42. virtual crl::time durationMs() const = 0;
  43. virtual bool start(Mode mode, crl::time &positionMs) = 0;
  44. virtual ~ReaderImplementation() {
  45. }
  46. int64 dataSize() const {
  47. return _dataSize;
  48. }
  49. protected:
  50. Core::FileLocation *_location = nullptr;
  51. QByteArray *_data = nullptr;
  52. QFile _file;
  53. QBuffer _buffer;
  54. QIODevice *_device = nullptr;
  55. int64 _dataSize = 0;
  56. void initDevice();
  57. };
  58. } // namespace internal
  59. } // namespace Clip
  60. } // namespace Media