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
qv4l2filedescriptor.cpp
Go to the documentation of this file.
1// Copyright (C) 2023 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
5
6#include <QtMultimedia/private/qmultimediautils_p.h>
7#include <QtCore/private/qcore_unix_p.h>
8
10
11namespace QtV4L2 {
12
13QV4L2FileDescriptor::QV4L2FileDescriptor(QUniqueFileDescriptorHandle descriptor)
15{
16 Q_ASSERT(isValid());
17}
18
19q23::expected<int, std::error_code> QV4L2FileDescriptor::call(int request, void *arg) const
20{
21 const int result = QtMultimediaPrivate::qt_safe_ioctl(get(), request, arg);
22 if (result < 0)
23 return q23::unexpected(std::error_code{ errno, std::system_category() });
24
25 return result;
26}
27
29 uint32_t bufferCount) const
30{
31 v4l2_requestbuffers req = {};
32 req.count = bufferCount;
33 req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
34 req.memory = memoryType;
35
36 auto callResult = call(VIDIOC_REQBUFS, &req);
37 if (!callResult)
38 return q23::unexpected(callResult.error());
39
40 return int(req.count);
41}
42
44{
45 auto status = requestBuffers(type, 0);
46 if (!status)
47 return q23::unexpected(status.error());
48 return {};
49}
50
52{
53 int type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
54 if (!call(VIDIOC_STREAMON, &type))
55 return false;
56
57 m_streamStarted = true;
58 return true;
59}
60
62{
63 int type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
64 const auto result = call(VIDIOC_STREAMOFF, &type);
65 m_streamStarted = false;
66 return bool(result);
67}
68
69} // namespace QtV4L2
70
71QT_END_NAMESPACE
q23::expected< int, std::error_code > requestBuffers(v4l2_memory memoryType, uint32_t bufferCount) const
q23::expected< void, std::error_code > releaseAllBuffers(v4l2_memory) const
QV4L2FileDescriptor(QUniqueFileDescriptorHandle descriptor)
Combined button and popup list for selecting options.