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 "qffmpegioutils_p.h"
5#include "qiodevice.h"
6#include "qffmpegdefs_p.h"
7
8QT_BEGIN_NAMESPACE
9
10namespace QFFmpeg {
11
12int readQIODevice(void *opaque, uint8_t *buf, int buf_size)
13{
14 auto *dev = static_cast<QIODevice *>(opaque);
15 Q_ASSERT(dev);
16
17 if (dev->atEnd())
18 return AVERROR_EOF;
19 return dev->read(data: reinterpret_cast<char *>(buf), maxlen: buf_size);
20}
21
22int writeQIODevice(void *opaque, AvioWriteBufferType buf, int buf_size)
23{
24 auto dev = static_cast<QIODevice *>(opaque);
25 Q_ASSERT(dev);
26
27 return dev->write(data: reinterpret_cast<const char *>(buf), len: buf_size);
28}
29
30int64_t seekQIODevice(void *opaque, int64_t offset, int whence)
31{
32 QIODevice *dev = static_cast<QIODevice *>(opaque);
33 Q_ASSERT(dev);
34
35 if (dev->isSequential())
36 return AVERROR(EINVAL);
37
38 if (whence & AVSEEK_SIZE)
39 return dev->size();
40
41 whence &= ~AVSEEK_FORCE;
42
43 if (whence == SEEK_CUR)
44 offset += dev->pos();
45 else if (whence == SEEK_END)
46 offset += dev->size();
47
48 if (!dev->seek(pos: offset))
49 return AVERROR(EINVAL);
50 return offset;
51}
52
53} // namespace QFFmpeg
54
55QT_END_NAMESPACE
56

source code of qtmultimedia/src/plugins/multimedia/ffmpeg/qffmpegioutils.cpp