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
qandroidvideoframefactory.cpp
Go to the documentation of this file.
1// Copyright (C) 2024 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#include <QtFFmpegMediaPluginImpl/private/qandroidvideoframefactory_p.h>
5
6#include <QtMultimedia/qvideoframe.h>
7
8QT_BEGIN_NAMESPACE
9namespace {
10// This is due to a limitation of ImageReader. When limit is reached, we cannot acquire more frames
11// until we close any of the previous image. That is why, When the limit is reached, we will do
12// a copy of the frame data and immediately close the image.
13constexpr int NATIVE_FRAME_LIMIT = 10;
14}
15
16
17QVideoFrame QAndroidVideoFrameFactory::createVideoFrame(QtJniTypes::Image frame,
18 QtVideo::Rotation rotation)
19{
20 const int currentCounter = m_framesCounter.fetch_add(1, std::memory_order_relaxed) + 1;
21
22 auto frameAdapter = std::make_unique<QAndroidVideoFrameBuffer>(
23 frame,
24 shared_from_this(),
25 currentCounter > NATIVE_FRAME_LIMIT ?
26 QAndroidVideoFrameBuffer::MemoryPolicy::Copy
27 : QAndroidVideoFrameBuffer::MemoryPolicy::Reuse,
28 rotation);
29
30 if (!frameAdapter->isParsed())
31 return QVideoFrame{};
32
33 const qint64 currentTimeStamp = frameAdapter->timestamp();
34 QVideoFrame videoFrame(std::move(frameAdapter));
35
36 if (m_lastTimestamp == 0)
37 m_lastTimestamp = currentTimeStamp;
38
39 videoFrame.setStartTime(m_lastTimestamp);
40 videoFrame.setEndTime(currentTimeStamp);
41
42 m_lastTimestamp = currentTimeStamp;
43
44 return videoFrame;
45}
46
47void QAndroidVideoFrameFactory::onFrameReleased()
48{
49 const int currentCounter = m_framesCounter.fetch_sub(1, std::memory_order_relaxed);
50 Q_ASSERT(currentCounter >= 0);
51}