Skip to content

Commit

Permalink
WIP: refactoring viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
rectalogic committed Oct 1, 2023
1 parent f0e517c commit 945d78d
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 146 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ endif()
add_subdirectory(vfxpipe)
add_subdirectory(webvfx)

# add_subdirectory(viewer)
add_subdirectory(viewer)
add_subdirectory(tools/driver)
add_subdirectory(plugins/mlt)
add_subdirectory(plugins/frei0r)
add_subdirectory(doc)

# add_dependencies(webvfx_viewer webvfx)
add_dependencies(webvfx_viewer vfxpipe)
add_dependencies(webvfx vfxpipe)

if(MLT_FOUND)
Expand Down
12 changes: 3 additions & 9 deletions viewer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,20 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

find_package(Qt6 REQUIRED QUIET COMPONENTS Widgets Quick OPTIONAL_COMPONENTS WebEngineQuick)
find_package(Qt6 REQUIRED QUIET COMPONENTS Widgets)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)

qt_add_executable(webvfx_viewer MACOSX_BUNDLE
main.cpp
image_color.cpp
content_pipe.cpp
viewer.cpp
viewer.ui
)

list(APPEND ViewerLibraries Qt6::Widgets Qt6::Quick webvfx)

if(${Qt6WebEngineQuick_FOUND})
list(APPEND ViewerLibraries Qt6::WebEngineQuick)
add_definitions(-DWEBENGINEQUICK)
endif()

target_link_libraries(webvfx_viewer PRIVATE ${ViewerLibraries})
target_link_libraries(webvfx_viewer PRIVATE Qt6::Widgets vfxpipe)

if(APPLE)
set_target_properties(webvfx_viewer PROPERTIES OUTPUT_NAME "WebVfx Viewer")
Expand Down
81 changes: 81 additions & 0 deletions viewer/content_pipe.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright (c) 2023 Andrew Wason. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content_pipe.h"
#include <QImage>
#include <QtDebug>
#include <QtGlobal>
#include <stdio.h>
#include <vfxpipe.h>

ContentPipe::ContentPipe(const QUrl& url, QObject* parent)
: QObject(parent)
, url(url)
, pid(0)
, pipeWrite(-1)
, pipeRead(-1)
{
}

ContentPipe::~ContentPipe()
{
if (pipeRead != -1)
close(pipeRead);
if (pipeWrite != -1)
close(pipeWrite);
}

bool ContentPipe::renderContent(
double time,
const QList<QImage> sourceImages,
QImage& outputImage)
{
Q_ASSERT(outputImage.format() == QImage::Format_RGBA8888);

if (!pid) {
auto spawnErrorHandler = [](std::string msg) {
qCritical() << __FUNCTION__ << ": " << msg;
};
pid = VfxPipe::spawnProcess(&pipeRead, &pipeWrite, url.toString().toStdString(), spawnErrorHandler);
}
if (pid == -1) {
qCritical() << __FUNCTION__ << ": vfxpipe failed to spawn process";
return false;
}

auto ioErrorHandler = [this](int n, std::string msg = "") {
if (!msg.empty())
qCritical() << __FUNCTION__ << ": " << msg;
close(pipeRead);
pipeRead = -1;
close(pipeWrite);
pipeWrite = -1;
};

if (!VfxPipe::dataIO(pipeWrite, reinterpret_cast<std::byte*>(&time), sizeof(time), write, ioErrorHandler)) {
return false;
}

// Output format
VfxPipe::VideoFrame vfxOutputFrame(VfxPipe::VideoFrameFormat::PixelFormat::RGBA32, outputImage.width(), outputImage.height());
if (!VfxPipe::writeVideoFrame(pipeWrite, &vfxOutputFrame, ioErrorHandler)) {
return false;
}

uint32_t frameCount = sourceImages.size();
if (!VfxPipe::dataIO(pipeWrite, reinterpret_cast<const std::byte*>(&frameCount), sizeof(frameCount), write, ioErrorHandler)) {
return false;
}
for (const auto& sourceImage : sourceImages) {
Q_ASSERT(sourceImage.format() == QImage::Format_RGBA8888);
VfxPipe::VideoFrame vfxFrame(VfxPipe::VideoFrameFormat::PixelFormat::RGBA32, sourceImage.width(), sourceImage.height(), reinterpret_cast<const std::byte*>(sourceImage.constBits()));
if (!VfxPipe::writeVideoFrame(pipeWrite, &vfxFrame, ioErrorHandler)) {
return false;
}
}

if (!VfxPipe::dataIO(pipeRead, reinterpret_cast<std::byte*>(outputImage.bits()), vfxOutputFrame.format.dataSize(), read, ioErrorHandler)) {
return false;
}
}
24 changes: 24 additions & 0 deletions viewer/content_pipe.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) 2023 Andrew Wason. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#pragma once

#include <QObject>
#include <QUrl>

class ContentPipe : public QObject {
public:
ContentPipe(const QUrl& url, QObject* parent = nullptr);
~ContentPipe();
bool renderContent(
double time,
const QList<QImage> sourceImages,
QImage& outputImage);

private:
QUrl url;
int pid;
int pipeWrite;
int pipeRead;
};
11 changes: 1 addition & 10 deletions viewer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,12 @@
#include <QApplication>
#include <QScopedPointer>
#include <QtGlobal>
#ifdef WEBENGINEQUICK
#include <QtWebEngineQuick>
#endif

int main(int argc, char* argv[])
{
#ifdef WEBENGINEQUICK
// https://doc.qt.io/qt-6/qml-qtwebengine-webengineview.html#rendering-to-opengl-surface
// https://doc.qt.io/qt-6/qtwebengine-overview.html#embedding-web-content-into-qt-quick-applications
QtWebEngineQuick::initialize();
#endif

QApplication app(argc, argv);

app.setOrganizationDomain("webvfx.org");
app.setOrganizationDomain("webvfx.stream");
app.setOrganizationName("WebVfx");
app.setApplicationName("WebVfx Viewer");

Expand Down
Loading

0 comments on commit 945d78d

Please sign in to comment.