Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qffmpegvideorenderer.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
7
8#include <QtMultimedia/qvideosink.h>
9#include <QtMultimedia/private/qvideoframe_p.h>
10
12
13namespace QFFmpeg {
14
15VideoRenderer::VideoRenderer(const PlaybackEngineObjectID &id, const TimeController &tc,
16 QVideoSink *sink, const VideoTransformation &transform)
17 : Renderer(id, tc), m_sink(sink), m_transform(transform)
18{
19}
20
21void VideoRenderer::setOutput(QVideoSink *sink, bool cleanPrevSink)
22{
23 setOutputInternal(m_sink, sink, [=](QVideoSink *prev) {
24 if (!prev)
25 return;
26
27 if (sink)
28 sink->setVideoFrame(prev->videoFrame());
29
30 if (cleanPrevSink)
31 prev->setVideoFrame({});
32 });
33}
34
36{
37 if (!m_sink)
38 return {};
39
40 if (!frame.isValid()) {
41 m_sink->setVideoFrame({});
42 return {};
43 }
44
45 // qCDebug(qLcVideoRenderer) << "RHI:" << accel.isNull() << accel.rhi() << sink->rhi();
46
47 const auto codecContext = frame.codecContext();
48 Q_ASSERT(codecContext);
49
50#ifdef Q_OS_ANDROID
51 // QTBUG-108446
52 // In general case, just creation of frames context is not correct since
53 // frames may require additional specific data for hw contexts, so
54 // just setting of hw_frames_ctx is not enough.
55 // TODO: investigate the case in order to remove or fix the code.
56 if (codecContext->hwAccel() && !frame.avFrame()->hw_frames_ctx) {
57 HWAccel *hwaccel = codecContext->hwAccel();
58 AVFrame *avframe = frame.avFrame();
59 if (!hwaccel->hwFramesContext())
60 hwaccel->createFramesContext(AVPixelFormat(avframe->format),
61 { avframe->width, avframe->height });
62
63 if (hwaccel->hwFramesContext())
64 avframe->hw_frames_ctx = av_buffer_ref(hwaccel->hwFramesContextAsBuffer());
65 }
66#endif
67
68 const auto pixelAspectRatio = codecContext->pixelAspectRatio(frame.avFrame());
69 auto buffer = std::make_unique<QFFmpegVideoBuffer>(frame.takeAVFrame(), pixelAspectRatio);
70 QVideoFrameFormat format(buffer->size(), buffer->pixelFormat());
71 format.setColorSpace(buffer->colorSpace());
72 format.setColorTransfer(buffer->colorTransfer());
73 format.setColorRange(buffer->colorRange());
74 format.setMaxLuminance(buffer->maxNits());
75 format.setRotation(m_transform.rotation);
76 format.setMirrored(m_transform.mirroredHorizontallyAfterRotation);
77 QVideoFrame videoFrame = QVideoFramePrivate::createFrame(std::move(buffer), format);
78 videoFrame.setStartTime(frame.startTime().get());
79 videoFrame.setEndTime(frame.endTime().get());
80 m_sink->setVideoFrame(videoFrame);
81
82 return {};
83}
84
85} // namespace QFFmpeg
86
87QT_END_NAMESPACE
88
89#include "moc_qffmpegvideorenderer_p.cpp"
RenderingResult renderInternal(Frame frame) override
void setOutput(QVideoSink *sink, bool cleanPrevSink=false)
QT_MANGLE_NAMESPACE(QMacScreenCaptureStreamDelegate) QMacScreenCaptureStreamDelegate
Combined button and popup list for selecting options.