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
4#ifndef QFFMPEGVIDEOBUFFER_P_H
5#define QFFMPEGVIDEOBUFFER_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtMultimedia/private/qhwvideobuffer_p.h>
19#include <QtCore/qvariant.h>
20
21#include <QtFFmpegMediaPluginImpl/private/qffmpeg_p.h>
22#include <QtFFmpegMediaPluginImpl/private/qffmpeghwaccel_p.h>
23
24QT_BEGIN_NAMESPACE
25
26class QFFmpegVideoBuffer : public QHwVideoBuffer
27{
28public:
29 using AVFrameUPtr = QFFmpeg::AVFrameUPtr;
30
31 QFFmpegVideoBuffer(AVFrameUPtr frame, AVRational pixelAspectRatio = { .num: 1, .den: 1 });
32 ~QFFmpegVideoBuffer() override;
33
34 MapData map(QVideoFrame::MapMode mode) override;
35 void unmap() override;
36
37 QVideoFrameTexturesUPtr mapTextures(QRhi &, QVideoFrameTexturesUPtr& oldTextures) override;
38
39 QVideoFrameFormat::PixelFormat pixelFormat() const;
40 QSize size() const;
41
42 static QVideoFrameFormat::PixelFormat toQtPixelFormat(AVPixelFormat avPixelFormat, bool *needsConversion = nullptr);
43 static AVPixelFormat toAVPixelFormat(QVideoFrameFormat::PixelFormat pixelFormat);
44
45 void convertSWFrame();
46
47 AVFrame *getHWFrame() const { return m_hwFrame.get(); }
48
49 void initTextureConverter(QRhi &rhi) override;
50
51 QRhi *rhi() const override;
52
53 QVideoFrameFormat::ColorSpace colorSpace() const;
54 QVideoFrameFormat::ColorTransfer colorTransfer() const;
55 QVideoFrameFormat::ColorRange colorRange() const;
56
57 float maxNits();
58
59private:
60 // The result texture converter must be accessed from the rhi's thread
61 QFFmpeg::TextureConverter &ensureTextureConverter(QRhi &rhi);
62
63 QVideoFrameTexturesUPtr createTexturesFromHwFrame(QRhi &, QVideoFrameTexturesUPtr& oldTextures);
64
65private:
66 QVideoFrameFormat::PixelFormat m_pixelFormat;
67 AVFrame *m_frame = nullptr;
68 AVFrameUPtr m_hwFrame;
69 AVFrameUPtr m_swFrame;
70 QSize m_size;
71 QVideoFrame::MapMode m_mode = QVideoFrame::NotMapped;
72};
73
74QT_END_NAMESPACE
75
76#endif
77

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of qtmultimedia/src/plugins/multimedia/ffmpeg/qffmpegvideobuffer_p.h