From 079772a399b830050a4e1e789d3f235af85181f8 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 20 Jan 2022 18:12:30 +0300 Subject: [PATCH] Correctly preserve first frame alpha in video streaming. --- .../media/streaming/media_streaming_video_track.cpp | 10 ++++++++-- .../media/streaming/media_streaming_video_track.h | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Telegram/SourceFiles/media/streaming/media_streaming_video_track.cpp b/Telegram/SourceFiles/media/streaming/media_streaming_video_track.cpp index f510b31e0..13647a89e 100644 --- a/Telegram/SourceFiles/media/streaming/media_streaming_video_track.cpp +++ b/Telegram/SourceFiles/media/streaming/media_streaming_video_track.cpp @@ -611,6 +611,8 @@ bool VideoTrackObject::processFirstFrame() { if (_stream.frame->width * _stream.frame->height > kMaxFrameArea) { return false; } + const auto alpha = (_stream.frame->format == AV_PIX_FMT_BGRA) + || (_stream.frame->format == AV_PIX_FMT_YUVA420P); auto frame = ConvertFrame( _stream, _stream.frame.get(), @@ -619,7 +621,7 @@ bool VideoTrackObject::processFirstFrame() { if (frame.isNull()) { return false; } - _shared->init(std::move(frame), _syncTimePoint.trackTime); + _shared->init(std::move(frame), alpha, _syncTimePoint.trackTime); callReady(); queueReadFrames(); return true; @@ -702,12 +704,16 @@ void VideoTrackObject::fail(Error error) { _error(error); } -void VideoTrack::Shared::init(QImage &&cover, crl::time position) { +void VideoTrack::Shared::init( + QImage &&cover, + bool hasAlpha, + crl::time position) { Expects(!initialized()); _frames[0].original = std::move(cover); _frames[0].position = position; _frames[0].format = FrameFormat::ARGB32; + _frames[0].alpha = hasAlpha; // Usually main thread sets displayed time before _counter increment. // But in this case we update _counter, so we set a fake displayed time. diff --git a/Telegram/SourceFiles/media/streaming/media_streaming_video_track.h b/Telegram/SourceFiles/media/streaming/media_streaming_video_track.h index 707ff297d..484b4a24a 100644 --- a/Telegram/SourceFiles/media/streaming/media_streaming_video_track.h +++ b/Telegram/SourceFiles/media/streaming/media_streaming_video_track.h @@ -110,7 +110,7 @@ private: }; // Called from the wrapped object queue. - void init(QImage &&cover, crl::time position); + void init(QImage &&cover, bool hasAlpha, crl::time position); [[nodiscard]] bool initialized() const; [[nodiscard]] PrepareState prepareState(