Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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), m_rotation(rotation)
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 const auto codec = frame.codec();
39
40#ifdef Q_OS_ANDROID
41 // QTBUG-108446
42 // In general case, just creation of frames context is not correct since
43 // frames may require additional specific data for hw contexts, so
44 // just setting of hw_frames_ctx is not enough.
45 // TODO: investigate the case in order to remove or fix the code.
46 if (codec->hwAccel() && !frame.avFrame()->hw_frames_ctx) {
47 HWAccel *hwaccel = codec->hwAccel();
48 AVFrame *avframe = frame.avFrame();
49 if (!hwaccel->hwFramesContext())
50 hwaccel->createFramesContext(AVPixelFormat(avframe->format),
51 { avframe->width, avframe->height });
52
53 if (hwaccel->hwFramesContext())
54 avframe->hw_frames_ctx = av_buffer_ref(hwaccel->hwFramesContextAsBuffer());
55 }
56#endif
57
58 const auto pixelAspectRatio = codec->pixelAspectRatio(frame.avFrame());
59 auto buffer = std::make_unique<QFFmpegVideoBuffer>(frame.takeAVFrame(), pixelAspectRatio);
60 QVideoFrameFormat format(buffer->size(), buffer->pixelFormat());
61 format.setColorSpace(buffer->colorSpace());
62 format.setColorTransfer(buffer->colorTransfer());
63 format.setColorRange(buffer->colorRange());
64 format.setMaxLuminance(buffer->maxNits());
65 format.setRotation(m_rotation);
66 QVideoFrame videoFrame(buffer.release(), format);
67 videoFrame.setStartTime(frame.pts());
68 videoFrame.setEndTime(frame.end());
69 m_sink->setVideoFrame(videoFrame);
70
71 return {};
72}
73
74} // namespace QFFmpeg
75
77
78#include "moc_qffmpegvideorenderer_p.cpp"
void setOutputInternal(QPointer< Output > &actual, Output *desired, ChangeHandler &&changeHandler)
RenderingResult renderInternal(Frame frame) override
VideoRenderer(const TimeController &tc, QVideoSink *sink, QtVideo::Rotation rotation)
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:27
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.
QMediaFormat::AudioCodec codec
GLenum GLuint buffer
GLint GLsizei GLsizei GLenum format
const GLfloat * tc
GLsizei GLenum GLboolean sink
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QFrame frame
[0]