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 <private/qhwvideobuffer_p.h>
19#include <QtCore/qvariant.h>
20
21#include "qffmpeg_p.h"
22#include "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 virtual std::unique_ptr<QVideoFrameTextures> mapTextures(QRhi *) override;
38 virtual quint64 textureHandle(QRhi *rhi, int plane) const override;
39
40 QVideoFrameFormat::PixelFormat pixelFormat() const;
41 QSize size() const;
42
43 static QVideoFrameFormat::PixelFormat toQtPixelFormat(AVPixelFormat avPixelFormat, bool *needsConversion = nullptr);
44 static AVPixelFormat toAVPixelFormat(QVideoFrameFormat::PixelFormat pixelFormat);
45
46 void convertSWFrame();
47
48 AVFrame *getHWFrame() const { return m_hwFrame.get(); }
49
50 void setTextureConverter(const QFFmpeg::TextureConverter &converter);
51
52 QVideoFrameFormat::ColorSpace colorSpace() const;
53 QVideoFrameFormat::ColorTransfer colorTransfer() const;
54 QVideoFrameFormat::ColorRange colorRange() const;
55
56 float maxNits();
57
58private:
59 QVideoFrameFormat::PixelFormat m_pixelFormat;
60 AVFrame *m_frame = nullptr;
61 AVFrameUPtr m_hwFrame;
62 AVFrameUPtr m_swFrame;
63 QSize m_size;
64 QFFmpeg::TextureConverter m_textureConverter;
65 QVideoFrame::MapMode m_mode = QVideoFrame::NotMapped;
66 std::unique_ptr<QFFmpeg::TextureSet> m_textures;
67};
68
69QT_END_NAMESPACE
70
71#endif
72

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