Qt 6.x
The Qt SDK
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
6#include "qvideosink.h"
7
9
10namespace QFFmpeg {
11
13 : Renderer(tc), m_sink(sink)
14{
15}
16
17void VideoRenderer::setOutput(QVideoSink *sink, bool cleanPrevSink)
18{
19 setOutputInternal(m_sink, sink, [cleanPrevSink](QVideoSink *prev) {
20 if (prev && cleanPrevSink)
21 prev->setVideoFrame({});
22 });
23}
24
26{
27 if (!m_sink)
28 return {};
29
30 if (!frame.isValid()) {
31 m_sink->setVideoFrame({});
32 return {};
33 }
34
35 // qCDebug(qLcVideoRenderer) << "RHI:" << accel.isNull() << accel.rhi() << sink->rhi();
36
37#ifdef Q_OS_ANDROID
38 // QTBUG-108446
39 // In general case, just creation of frames context is not correct since
40 // frames may require additional specific data for hw contexts, so
41 // just setting of hw_frames_ctx is not enough.
42 // TODO: investigate the case in order to remove or fix the code.
43 if (frame.codec()->hwAccel() && !frame.avFrame()->hw_frames_ctx) {
44 HWAccel *hwaccel = frame.codec()->hwAccel();
45 AVFrame *avframe = frame.avFrame();
46 if (!hwaccel->hwFramesContext())
47 hwaccel->createFramesContext(AVPixelFormat(avframe->format),
48 { avframe->width, avframe->height });
49
50 if (hwaccel->hwFramesContext())
51 avframe->hw_frames_ctx = av_buffer_ref(hwaccel->hwFramesContextAsBuffer());
52 }
53#endif
54
55 auto buffer = std::make_unique<QFFmpegVideoBuffer>(frame.takeAVFrame());
56 QVideoFrameFormat format(buffer->size(), buffer->pixelFormat());
57 format.setColorSpace(buffer->colorSpace());
58 format.setColorTransfer(buffer->colorTransfer());
59 format.setColorRange(buffer->colorRange());
60 format.setMaxLuminance(buffer->maxNits());
61 QVideoFrame videoFrame(buffer.release(), format);
62 videoFrame.setStartTime(frame.pts());
63 videoFrame.setEndTime(frame.end());
64 m_sink->setVideoFrame(videoFrame);
65
66 return {};
67}
68
69} // namespace QFFmpeg
70
72
73#include "moc_qffmpegvideorenderer_p.cpp"
AVHWFramesContext * hwFramesContext() const
AVBufferRef * hwFramesContextAsBuffer() const
void createFramesContext(AVPixelFormat swFormat, const QSize &size)
void setOutputInternal(QPointer< Output > &actual, Output *desired, ChangeHandler &&changeHandler)
RenderingResult renderInternal(Frame frame) override
VideoRenderer(const TimeController &tc, QVideoSink *sink)
void setOutput(QVideoSink *sink, bool cleanPrevSink=false)
The QVideoFrameFormat class specifies the stream format of a video presentation surface.
The QVideoFrame class represents a frame of video data.
Definition qvideoframe.h:26
void setEndTime(qint64 time)
Sets the presentation time (in microseconds) when a frame should stop being displayed.
void setStartTime(qint64 time)
Sets the presentation time (in microseconds) when the frame should initially be displayed.
The QVideoSink class represents a generic sink for video data.
Definition qvideosink.h:22
void setVideoFrame(const QVideoFrame &frame)
Sets the current video frame.
Combined button and popup list for selecting options.
GLenum GLuint buffer
GLint GLsizei GLsizei GLenum format
const GLfloat * tc
GLsizei GLenum GLboolean sink
QFrame frame
[0]