media_streaming_utility.h 2.6 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_common.h"
  9. #include "ffmpeg/ffmpeg_utility.h"
  10. namespace Media {
  11. namespace Streaming {
  12. struct TimePoint {
  13. crl::time trackTime = kTimeUnknown;
  14. crl::time worldTime = kTimeUnknown;
  15. bool valid() const {
  16. return (trackTime != kTimeUnknown) && (worldTime != kTimeUnknown);
  17. }
  18. explicit operator bool() const {
  19. return valid();
  20. }
  21. };
  22. struct Stream {
  23. int index = -1;
  24. crl::time duration = kTimeUnknown;
  25. AVRational timeBase = FFmpeg::kUniversalTimeBase;
  26. FFmpeg::CodecPointer codec;
  27. FFmpeg::FramePointer decodedFrame;
  28. FFmpeg::FramePointer transferredFrame;
  29. std::deque<FFmpeg::Packet> queue;
  30. int invalidDataPackets = 0;
  31. // Audio only.
  32. int frequency = 0;
  33. // Video only.
  34. int rotation = 0;
  35. AVRational aspect = FFmpeg::kNormalAspect;
  36. FFmpeg::SwscalePointer swscale;
  37. };
  38. [[nodiscard]] crl::time FramePosition(const Stream &stream);
  39. [[nodiscard]] FFmpeg::AvErrorWrap ProcessPacket(
  40. Stream &stream,
  41. FFmpeg::Packet &&packet);
  42. [[nodiscard]] FFmpeg::AvErrorWrap ReadNextFrame(Stream &stream);
  43. [[nodiscard]] bool GoodForRequest(
  44. const QImage &image,
  45. bool hasAlpha,
  46. int rotation,
  47. const FrameRequest &request);
  48. [[nodiscard]] bool TransferFrame(
  49. Stream &stream,
  50. not_null<AVFrame*> decodedFrame,
  51. not_null<AVFrame*> transferredFrame);
  52. [[nodiscard]] QImage ConvertFrame(
  53. Stream &stream,
  54. not_null<AVFrame*> frame,
  55. QSize resize,
  56. QImage storage);
  57. [[nodiscard]] FrameYUV ExtractYUV(Stream &stream, AVFrame *frame);
  58. struct ExpandDecision {
  59. QSize result;
  60. bool expanding = false;
  61. };
  62. [[nodiscard]] ExpandDecision DecideFrameResize(
  63. QSize outer,
  64. QSize original,
  65. int minVisibleNominator = 3, // If we cut out no more than 0.25 of
  66. int minVisibleDenominator = 4); // the original, let's expand.
  67. [[nodiscard]] bool FrameResizeMayExpand(
  68. QSize outer,
  69. QSize original,
  70. int minVisibleNominator = 3,
  71. int minVisibleDenominator = 4);
  72. [[nodiscard]] ExpandDecision DecideVideoFrameResize(
  73. QSize outer,
  74. QSize original);
  75. [[nodiscard]] QSize CalculateResizeFromOuter(QSize outer, QSize original);
  76. [[nodiscard]] QImage PrepareBlurredBackground(QSize outer, QImage frame);
  77. void FillBlurredBackground(QPainter &p, QSize outer, QImage bg);
  78. [[nodiscard]] QImage PrepareByRequest(
  79. const QImage &original,
  80. bool hasAlpha,
  81. const AVRational &aspect,
  82. int rotation,
  83. const FrameRequest &request,
  84. QImage storage);
  85. } // namespace Streaming
  86. } // namespace Media