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