-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathiodevice.h
58 lines (52 loc) · 1.45 KB
/
iodevice.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* Copyright (C) 2018-2019 Wang Bin - wbsecg1 at gmail.com
* https://github.com/wang-bin/qtmultimedia-plugins-mdk
* MIT License
*/
#pragma once
// qio: qrc: etc
#include "mdk/global.h"
#ifdef MDK_ABI
#include "mdk/MediaIO.h"
#include <QIODevice>
using namespace MDK_NS;
class QMediaIO final : public MediaIO
{
public:
static void registerOnce();
QMediaIO(QIODevice* io = nullptr);
const char* name() const override { return "QIODevice";}
const std::set<std::string>& protocols() const override {
static const std::set<std::string> s{"qio", "qrc"};
return s;
}
bool isSeekable() const override { return io_ && !io_->isSequential(); }
bool isWritable() const override { return io_ && io_->isWritable(); }
int64_t read(uint8_t *data, int64_t maxSize) override {
if (!io_)
return 0;
return io_->read((char*)data, maxSize);
}
int64_t write(const uint8_t *data, int64_t maxSize) override {
if (!io_)
return 0;
return io_->write((const char*)data, maxSize);
}
bool seek(int64_t offset, int from) override;
int64_t position() const override {
if (!io_)
return 0;
return io_->pos();
}
int64_t size() const override {
if (!io_)
return 0;
return io_->size();
}
protected:
bool onUrlChanged() override;
private:
bool owns_io_ = true;
QIODevice* io_ = nullptr;
};
#endif //MDK_ABI