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 auto result = call(VIDIOC_STREAMON, &type);
55 if (!result)
56 return q23::unexpected(result.error());
57
58 m_streamStarted = true;
59 return {};
60}
61
63{
64 int type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
65 auto result = call(VIDIOC_STREAMOFF, &type);
66 m_streamStarted = false;
67 if (!result)
68 return q23::unexpected(result.error());
69 return {};
70}
71
73{
74 v4l2_queryctrl queryControl{};
75 queryControl.id = id;
76 auto result = call(VIDIOC_QUERYCTRL, &queryControl);
77 if (!result)
78 return q23::unexpected(result.error());
79 return queryControl;
80}
81
82} // namespace QtV4L2
83
84QT_END_NAMESPACE
q23::expected< int, std::error_code > requestBuffers(v4l2_memory memoryType, uint32_t bufferCount) const
q23::expected< void, std::error_code > stopStream()
q23::expected< void, std::error_code > releaseAllBuffers(v4l2_memory) const
q23::expected< void, std::error_code > startStream()
QV4L2FileDescriptor(QUniqueFileDescriptorHandle descriptor)
q23::expected< v4l2_queryctrl, std::error_code > queryControl(uint32_t id) const
Combined button and popup list for selecting options.