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