mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-14 18:57:07 -07:00
Add QtAV Output
This commit is contained in:
parent
d0aaacb600
commit
26b2d57fcb
6 changed files with 190 additions and 6 deletions
|
@ -3,7 +3,9 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
|||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
find_package(Qt5 REQUIRED COMPONENTS Core Widgets Gui Multimedia)
|
||||
find_package(Qt5 REQUIRED COMPONENTS Core Widgets Gui Multimedia OpenGL)
|
||||
|
||||
find_package(QtAV REQUIRED)
|
||||
|
||||
add_executable(chiaki
|
||||
src/main.cpp
|
||||
|
@ -13,4 +15,7 @@ target_include_directories(chiaki PRIVATE include)
|
|||
|
||||
target_link_libraries(chiaki chiaki-lib)
|
||||
|
||||
target_link_libraries(chiaki Qt5::Core Qt5::Widgets Qt5::Gui Qt5::Multimedia)
|
||||
target_link_libraries(chiaki Qt5::Core Qt5::Widgets Qt5::Gui Qt5::OpenGL Qt5::Multimedia)
|
||||
|
||||
target_include_directories(chiaki PRIVATE ${QTAV_INCLUDE_DIRS} ${QTAVWIDGETS_INCLUDE_DIRS})
|
||||
target_link_libraries(chiaki ${QTAV_LIBRARIES} ${QTAVWIDGETS_LIBRARIES})
|
|
@ -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
|
||||
|
|
|
@ -21,6 +21,13 @@ void audio_frame_cb(int16_t *buf, size_t samples_count, void *user)
|
|||
audio_io->write((const char *)buf, static_cast<qint64>(samples_count * 2 * 2));
|
||||
}
|
||||
|
||||
void video_sample_cb(uint8_t *buf, size_t buf_size, void *user)
|
||||
{
|
||||
//StreamRelayIODevice *io_device = reinterpret_cast<StreamRelayIODevice *>(user);
|
||||
//io_device->PushSample(buf, buf_size);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if(argc != 7)
|
||||
|
@ -64,8 +71,6 @@ int main(int argc, char *argv[])
|
|||
window.resize(640, 360);
|
||||
window.show();
|
||||
|
||||
return app.exec();
|
||||
|
||||
|
||||
QAudioFormat audio_format;
|
||||
audio_format.setSampleRate(48000);
|
||||
|
@ -87,11 +92,15 @@ int main(int argc, char *argv[])
|
|||
ChiakiSession session;
|
||||
chiaki_session_init(&session, &connect_info);
|
||||
chiaki_session_set_audio_frame_cb(&session, audio_frame_cb, NULL);
|
||||
chiaki_session_set_video_sample_cb(&session, video_sample_cb, window.GetIODevice());
|
||||
chiaki_session_start(&session);
|
||||
|
||||
int ret = app.exec();
|
||||
|
||||
chiaki_session_join(&session);
|
||||
chiaki_session_fini(&session);
|
||||
|
||||
delete audio_out;
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
|
@ -17,9 +17,40 @@
|
|||
|
||||
#include <streamwindow.h>
|
||||
|
||||
#include <QtAV>
|
||||
#include <QtAVWidgets>
|
||||
|
||||
#include <QProcessEnvironment>
|
||||
|
||||
|
||||
StreamWindow::StreamWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
{
|
||||
video_output = new QtAV::VideoOutput(QtAV::VideoRendererId_GLWidget2, this);
|
||||
setCentralWidget(video_output->widget());
|
||||
|
||||
av_player = new QtAV::AVPlayer(this);
|
||||
|
||||
connect(av_player, &QtAV::AVPlayer::stateChanged, this, [](QtAV::AVPlayer::State state){
|
||||
printf("state changed to %d\n", state);
|
||||
});
|
||||
|
||||
av_player->setRenderer(video_output);
|
||||
|
||||
io_device = new StreamRelayIODevice(this);
|
||||
io_device->open(QIODevice::ReadOnly);
|
||||
|
||||
QString test_filename = QProcessEnvironment::systemEnvironment().value("CHIAKI_TEST_VIDEO");
|
||||
if(!test_filename.isEmpty())
|
||||
{
|
||||
QFile *test_file = new QFile(test_filename, this);
|
||||
test_file->open(QIODevice::OpenModeFlag::ReadOnly);
|
||||
QByteArray sample = test_file->readAll();
|
||||
io_device->PushSample((uint8_t *)sample.constData(), (size_t)sample.size());
|
||||
test_file->close();
|
||||
av_player->setIODevice(io_device);
|
||||
av_player->play();
|
||||
}
|
||||
}
|
||||
|
||||
StreamWindow::~StreamWindow()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue