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
qmultimedia_dmabuf_support.cpp
Go to the documentation of this file.
1// Copyright (C) 2026 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/qdmabufallocator_p.h>
7#include <QtMultimedia/private/qmultimediautils_p.h>
8#include <QtMultimedia/private/qtmm_alignment_support_p.h>
9#include <QtCore/qloggingcategory.h>
10
11#if QT_CONFIG(linux_dmabuf)
12# include <QtCore/qscopeguard.h>
13# include <linux/dma-buf.h>
14# include <sys/ioctl.h>
15# include <sys/mman.h>
16# include <unistd.h>
17#endif
18
19#include <cerrno>
20
21QT_BEGIN_NAMESPACE
22
23namespace QtMultimediaPrivate {
24
25#if QT_CONFIG(linux_dmabuf)
26
27Q_STATIC_LOGGING_CATEGORY(qLcDmaBufSupport, "qt.multimedia.dmabufsupport");
28
30{
31 const uint64_t startOrEnd =
33
36 };
38 qCDebug(qLcDmaBufSupport) << "DMA_BUF_IOCTL_SYNC failed" << qt_error_string(errno);
39}
40
42{
43 if (offset < 0 || size_t(offset) > bufferSize || size > bufferSize - size_t(offset)) {
44 qCWarning(qLcDmaBufSupport) << "DMA-BUF range lies outside its buffer";
45 return std::nullopt;
46 }
47
48 if (size == 0)
49 return QByteArray{};
50
51 // The mapping must start on a page boundary, so map from the page holding offset.
53 if (Q_UNLIKELY(sysconfPageSize < 0)) {
54 qCWarning(qLcDmaBufSupport) << "cannot determine system page size:" << qt_error_string(errno);
55 return std::nullopt;
56 }
60
62 if (mapping == MAP_FAILED) {
63 qCWarning(qLcDmaBufSupport) << "mapping DMA-BUF failed:" << qt_error_string(errno);
64 return std::nullopt;
65 }
66 auto unmap = qScopeGuard([&] {
68 });
69
71 auto syncEnd = qScopeGuard([&] {
73 });
74
75 return QByteArray(static_cast<const char *>(mapping) + pageOffset, qsizetype(size));
76}
77
79{
80 const off_t bufferSize = lseek(fd, 0, SEEK_END);
81 if (bufferSize < 0) {
82 qCWarning(qLcDmaBufSupport) << "cannot determine DMA-BUF size:" << qt_error_string(errno);
83 return std::nullopt;
84 }
85
87}
88
90{
91 return copyDmaBufData(buf.fd(), offset, size, buf.size());
92}
93
94#endif // QT_CONFIG(linux_dmabuf)
95
96} // namespace QtMultimediaPrivate
97
98QT_END_NAMESPACE