mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-21 14:03:11 -07:00
Add QtAV Output
This commit is contained in:
parent
d0aaacb600
commit
26b2d57fcb
6 changed files with 190 additions and 6 deletions
|
@ -20,6 +20,80 @@
|
|||
|
||||
#include <QMainWindow>
|
||||
|
||||
namespace QtAV
|
||||
{
|
||||
class VideoOutput;
|
||||
class AVPlayer;
|
||||
}
|
||||
|
||||
#include <QBuffer>
|
||||
#include <QMutex>
|
||||
#include <QThread>
|
||||
#include <QFile>
|
||||
|
||||
class StreamRelayIODevice : public QIODevice
|
||||
{
|
||||
private:
|
||||
QMutex *mutex;
|
||||
QByteArray buffer;
|
||||
|
||||
public:
|
||||
explicit StreamRelayIODevice(QObject *parent = nullptr)
|
||||
: QIODevice(parent),
|
||||
mutex(new QMutex(QMutex::Recursive))
|
||||
{
|
||||
setOpenMode(OpenModeFlag::ReadOnly);
|
||||
}
|
||||
|
||||
~StreamRelayIODevice() override = default;
|
||||
|
||||
void PushSample(uint8_t *buf, size_t size)
|
||||
{
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
printf("push sample %zu\n", size);
|
||||
buffer.append(reinterpret_cast<const char *>(buf), static_cast<int>(size));
|
||||
}
|
||||
emit readyRead();
|
||||
}
|
||||
|
||||
|
||||
qint64 pos() const override { return 0; }
|
||||
bool open(QIODevice::OpenMode mode) override { return true; }
|
||||
bool isSequential() const override { return true; }
|
||||
|
||||
qint64 bytesAvailable() const override
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
return buffer.size() + QIODevice::bytesAvailable();
|
||||
}
|
||||
|
||||
protected:
|
||||
qint64 readData(char *data, qint64 maxSize)
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
{
|
||||
QMutexLocker locker(mutex);
|
||||
if(buffer.size() >= maxSize)
|
||||
{
|
||||
printf("read %lld\n", maxSize);
|
||||
memcpy(data, buffer.constData(), maxSize);
|
||||
buffer.remove(0, maxSize);
|
||||
return maxSize;
|
||||
}
|
||||
}
|
||||
QThread::msleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
qint64 writeData(const char *data, qint64 maxSize)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class StreamWindow: public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -27,6 +101,15 @@ class StreamWindow: public QMainWindow
|
|||
public:
|
||||
explicit StreamWindow(QWidget *parent = nullptr);
|
||||
~StreamWindow();
|
||||
|
||||
StreamRelayIODevice *GetIODevice() { return io_device; }
|
||||
|
||||
private:
|
||||
QtAV::VideoOutput *video_output;
|
||||
QtAV::AVPlayer *av_player;
|
||||
|
||||
StreamRelayIODevice *io_device;
|
||||
|
||||
};
|
||||
|
||||
#endif // CHIAKI_GUI_STREAMWINDOW_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue