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
qandroidvideoframebuffer_p.h
Go to the documentation of this file.
1// Copyright (C) 2022 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 QANDROIDVIDEOFRAMEBUFFER_P_H
5#define QANDROIDVIDEOFRAMEBUFFER_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 <QAbstractVideoBuffer>
19#include <QByteArray>
20#include <QVideoFrameFormat>
21#include <QJniObject>
22#include <QtCore/qjnitypes.h>
23
24#include <QtCore/qtconfigmacros.h>
25
26#include <QtFFmpegMediaPluginImpl/private/qandroidvideojnitypes_p.h>
27
29
30Q_DECLARE_JNI_CLASS(QtCamera2, "org/qtproject/qt/android/multimedia/QtCamera2")
31Q_DECLARE_JNI_CLASS(Image, "android/media/Image")
32Q_DECLARE_JNI_CLASS(ImageFormat, "android/graphics/ImageFormat")
33Q_DECLARE_JNI_CLASS(ImagePlane, "android/media/Image$Plane")
34Q_DECLARE_JNI_CLASS(ByteBuffer, "java/nio/ByteBuffer")
35
36class QAndroidVideoFrameBuffer : public QAbstractVideoBuffer
37{
38public:
39 class FrameReleaseDelegate {
40 public:
41 virtual ~FrameReleaseDelegate() = default;
42 virtual void onFrameReleased() = 0;
43 };
44 enum class MemoryPolicy {
45 Copy, // Make a copy of frame data
46 Reuse // Reuse frame data
47 };
48
49 // Please note that MemoryPolicy::Reuse can be changed internally to MemoryPolicy::Copy
50 QAndroidVideoFrameBuffer(QJniObject frame,
51 std::shared_ptr<FrameReleaseDelegate> frameReleaseDelegate,
52 MemoryPolicy policy,
53 QtVideo::Rotation rotation = QtVideo::Rotation::None);
54 ~QAndroidVideoFrameBuffer();
55 MapData map(QVideoFrame::MapMode) override { return m_mapData; }
56 QVideoFrameFormat format() const override { return m_videoFrameFormat; }
57 long timestamp() const { return m_timestamp; }
58 bool isParsed() const { return m_parsed; }
59
60private:
61 bool useCopiedData() const;
62 bool parse(const QJniObject &frame);
63 QVideoFrameFormat m_videoFrameFormat;
64 long m_timestamp = 0;
65 MapData m_mapData;
66 // Currently we have maximum 3 planes here
67 // We keep this data in QByteArray for proper cleaning
68 static constexpr int MAX_PLANES = 3;
69 QByteArray dataCleaner[MAX_PLANES];
70 jobject m_nativeFrame = nullptr;
71 std::shared_ptr<FrameReleaseDelegate> m_frameReleaseDelegate;
72 MemoryPolicy m_policy;
73 bool m_parsed = false;
74 QImage m_image;
75
76 enum AndroidImageFormat {
77 // Values taken from Android API ImageFormat, PixelFormat, or HardwareBuffer
78 // (that can be retuned by Image::getFormat() method)
79 // https://developer.android.com/reference/android/media/Image#getFormat()
80 RGBA_8888 = 1,
81 RAW_SENSOR = 32,
82 YUV_420_888 = 35,
83 RAW_PRIVATE = 36,
84 YUV_422_888 = 39,
85 YUV_444_888 = 40,
86 FLEX_RGB_888 = 41,
87 FLEX_RGBA_8888 = 42,
88 YCBCR_P010 = 54,
89 JPEG = 256,
90 HEIC = 1212500294
91 };
92};
93
94QT_END_NAMESPACE
95
96#endif // QANDROIDVIDEOFRAMEBUFFER_P_H
Q_DECLARE_JNI_CLASS(MotionEvent, "android/view/MotionEvent")