Very dirty Video Display

This commit is contained in:
Florian Märkl 2019-06-10 20:55:42 +02:00
commit 76a3d67f5e
No known key found for this signature in database
GPG key ID: 125BC8A5A6A1E857
8 changed files with 391 additions and 179 deletions

View file

@ -20,79 +20,7 @@
#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 QLabel;
class StreamWindow: public QMainWindow
{
@ -102,14 +30,10 @@ class StreamWindow: public QMainWindow
explicit StreamWindow(QWidget *parent = nullptr);
~StreamWindow();
StreamRelayIODevice *GetIODevice() { return io_device; }
void SetImage(const QImage &image);
private:
QtAV::VideoOutput *video_output;
QtAV::AVPlayer *av_player;
StreamRelayIODevice *io_device;
QLabel *imageLabel;
};
#endif // CHIAKI_GUI_STREAMWINDOW_H

View file

@ -0,0 +1,52 @@
/*
* This file is part of Chiaki.
*
* Chiaki is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Chiaki is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef CHIAKI_VIDEODECODER_H
#define CHIAKI_VIDEODECODER_H
#include <QMutex>
#include <QObject>
extern "C"
{
#include <libavcodec/avcodec.h>
};
#include <cstdint>
class VideoDecoder: public QObject
{
Q_OBJECT
public:
VideoDecoder();
~VideoDecoder();
void PutFrame(uint8_t *buf, size_t buf_size);
QImage PullFrame();
signals:
void FramesAvailable();
private:
QMutex mutex;
AVCodec *codec;
AVCodecContext *codec_context;
};
#endif // CHIAKI_VIDEODECODER_H