Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
testvideosink.cpp
Go to the documentation of this file.
1
// Copyright (C) 2024 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4
#
include
"testvideosink_p.h"
5
6
#
include
<
qsignalspy
.
h
>
7
#
include
<
qtestsystem
.
h
>
8
9
QT_BEGIN_NAMESPACE
10
11
TestVideoSink::TestVideoSink(
bool
storeFrames) : m_storeFrames(storeFrames)
12
{
13
connect(
this
, &QVideoSink::videoFrameChanged,
this
, &TestVideoSink::addVideoFrame);
14
connect(
this
, &QVideoSink::videoFrameChanged,
this
, &TestVideoSink::videoFrameChangedSync);
15
}
16
17
QVideoFrame TestVideoSink::waitForFrame()
18
{
19
QSignalSpy
spy(
this
, &TestVideoSink::videoFrameChangedSync);
20
return
spy
.
wait
() ? spy.at(0).at(0).value<QVideoFrame>() : QVideoFrame{};
21
}
22
23
void
TestVideoSink::addVideoFrame(
const
QVideoFrame &frame)
24
{
25
m_elapsedTimer.start();
26
27
if
(m_storeFrames)
28
m_frameList.append(frame);
29
30
if
(frame.isValid())
31
m_frameTimes.emplace_back(std::chrono::microseconds(frame.startTime()));
32
33
++m_totalFrames;
34
}
35
36
void
TestVideoSink::setStoreImagesEnabled(
bool
storeImages)
37
{
38
if
(storeImages)
39
connect(
this
, &QVideoSink::videoFrameChanged,
this
, &TestVideoSink::storeImage,
40
Qt::UniqueConnection);
41
else
42
disconnect(
this
, &QVideoSink::videoFrameChanged,
this
, &TestVideoSink::storeImage);
43
}
44
45
void
TestVideoSink::storeImage(
const
QVideoFrame &frame)
46
{
47
QImage
image = frame.toImage();
48
image.detach();
49
m_images.push_back(std::move(image));
50
}
51
52
std
::chrono::milliseconds TestVideoSink::durationBetweenFrames(qsizetype frameCount)
53
{
54
Q_ASSERT(frameCount > 0);
55
56
QElapsedTimer
timer;
57
qsizetype framesReceived = 0;
58
59
QObject context;
60
connect(
this
, &QVideoSink::videoFrameChanged, &context, [&] {
61
if
(framesReceived++ == 0)
62
timer.start();
63
});
64
65
auto
allFramesAreReceived = [&]() {
66
return
framesReceived > frameCount;
67
};
68
69
using
namespace
std
::chrono;
70
return
QTest::qWaitFor(allFramesAreReceived, seconds(10))
71
? milliseconds(timer.elapsed() / frameCount)
72
: milliseconds(0);
73
}
74
75
QT_END_NAMESPACE
76
77
#
include
"moc_testvideosink_p.cpp"
QElapsedTimer
\inmodule QtCore
Definition
qelapsedtimer.h:16
QImage
\inmodule QtGui
Definition
qimage.h:38
QSignalSpy
\inmodule QtTest
Definition
qsignalspy.h:22
QSignalSpy::wait
bool wait(int timeout)
Definition
qsignalspy.h:47
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
qtmultimedia
src
multimediatestlib
testvideosink.cpp
Generated on
for Qt by
1.18.0