Skip to content

Commit

Permalink
0.3.0 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisAJS committed Jan 5, 2023
1 parent 6b3c1d6 commit 72597d0
Show file tree
Hide file tree
Showing 14 changed files with 149 additions and 143 deletions.
4 changes: 2 additions & 2 deletions src/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ IF (CMAKE_SYSTEM MATCHES Windows)
message("Building Windows executable")
add_executable(lgx2userspace WIN32 ${SOURCES} appicon.rc)
target_include_directories(lgx2userspace PRIVATE liblgx)
target_link_libraries(lgx2userspace PRIVATE mingw32 liblgx)
target_link_libraries(lgx2userspace PRIVATE mingw32 liblgx -static)

add_executable(lgx2userspace-glfw WIN32 ${GLFW_SOURCES} appicon.rc)
target_include_directories(lgx2userspace-glfw PRIVATE liblgx)
target_link_libraries(lgx2userspace-glfw PRIVATE mingw32 liblgx)
target_link_libraries(lgx2userspace-glfw PRIVATE mingw32 liblgx -static)
else()
add_executable(lgx2userspace ${SOURCES})
target_include_directories(lgx2userspace PRIVATE liblgx)
Expand Down
5 changes: 3 additions & 2 deletions src/cli/OptionParser.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <getopt.h>
#include <iostream>
#include "OptionParser.h"
#include <liblgx.h>

lgx2::VideoOutput *app::OptionParser::videoOutput() {
return _videoOutput;
Expand Down Expand Up @@ -68,11 +67,13 @@ bool app::OptionParser::process(int argc, char **argv) {
" usage:\n"
"\t-v\tPrint diagnostics information summary at end of execution, useful when submitting bugs\n"
"\t-V\tPrint diagnostic information during execution\n"
#ifndef __MINGW32__
"\t-d V4L2LoopbackDevice\tSpecify the V4L2Loopback device to output video to (e.g. /dev/video99)\n\n"
"\t-a Pulseaudio sink\tOutput audio to a Pulseaudio sink (useful when outputting video to V4L2Loopback)\n"
#endif
#ifdef GC550_SUPPORT
"\t-x Use LGX (GC550) device specifically\n"
#endif
"\t-a Pulseaudio sink\tOutput audio to a Pulseaudio sink (useful when outputting video to V4L2Loopback)\n"
"\t-s Output only sound\n"
"\t-g Output video only\n"
"\t-f Use a fake USB stream containing unprocessed frames from a dump.bin file\n";
Expand Down
12 changes: 4 additions & 8 deletions src/cli/glfwmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
#include <liblgx.h>
#include "OptionParser.h"
#include "../version.h"
#include <GLFW/glfw3.h>

bool do_exit = false;

int main(int argc, char **argv) {
std::cout << "lgx2userspace v0.2.0 ("<< GIT_BRANCH << "-" << GIT_REV << ")" << std::endl;
std::cout << "lgx2userspace-glfw " << APP_VERSION << " ("<< GIT_BRANCH << "-" << GIT_REV << " - " << GIT_TAG << ")" << std::endl;

app::OptionParser optionParser{};

Expand All @@ -20,25 +19,22 @@ int main(int argc, char **argv) {
lgx2::Logger *logger{optionParser.logger()};
lgx2::VideoOutput *videoOutput{optionParser.videoOutput()};
lgx2::AudioOutput *audioOutput{optionParser.audioOutput()};

lgx2::Stream *stream{optionParser.stream()};
glfw::GlfwFrameOutput frameOutput{};
NOOPLogger noopLogger{};

if (stream == nullptr) {
stream = new libusb::UsbStream();
}

if (videoOutput == nullptr) {
videoOutput = &frameOutput;
videoOutput = new glfw::GlfwVideoOutput{};
}

if (audioOutput == nullptr) {
audioOutput = &frameOutput;
audioOutput = new sdl::SdlAudioOutput{};
}

if (logger == nullptr) {
logger = &noopLogger;
logger = new NOOPLogger{};
}

lgx2::Device device{stream, videoOutput, audioOutput, logger};
Expand Down
17 changes: 7 additions & 10 deletions src/cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
bool do_exit = false;

int main(int argc, char **argv) {
std::cout << "lgx2userspace v0.2.0 ("<< GIT_BRANCH << "-" << GIT_REV << ")" << std::endl;
std::cout << "lgx2userspace-sdl " << APP_VERSION << " ("<< GIT_BRANCH << "-" << GIT_REV << " - " << GIT_TAG << ")" << std::endl;

app::OptionParser optionParser{};

Expand All @@ -19,25 +19,22 @@ int main(int argc, char **argv) {
lgx2::Logger *logger{optionParser.logger()};
lgx2::VideoOutput *videoOutput{optionParser.videoOutput()};
lgx2::AudioOutput *audioOutput{optionParser.audioOutput()};

lgx2::Stream *stream{optionParser.stream()};
sdl::SdlFrameOutput sdlOutput{};
NOOPLogger noopLogger{};

if (stream == nullptr) {
stream = new libusb::UsbStream();
stream = new libusb::UsbStream{};
}

if (videoOutput == nullptr) {
videoOutput = &sdlOutput;
videoOutput = new sdl::SdlVideoOutput{};
}

if (audioOutput == nullptr) {
audioOutput = &sdlOutput;
audioOutput = new sdl::SdlAudioOutput{};
}

if (logger == nullptr) {
logger = &noopLogger;
logger = new NOOPLogger{};
}

lgx2::Device device{stream, videoOutput, audioOutput, logger};
Expand All @@ -50,12 +47,12 @@ int main(int argc, char **argv) {

device.initialise(targetDevice);

SDL_Event event;

signal(SIGTERM, [](int) {
do_exit = true;
});

SDL_Event event;

while (!do_exit) {

while (SDL_PollEvent(&event)) {
Expand Down
11 changes: 7 additions & 4 deletions src/liblgx/liblgx-common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ set(BOOTSTRAP_SOURCES
src/bootstrap/commanddata_lgx2.h)

set(SDLOUTPUT_SOURCES
src/sdl/SdlFrameOutput.cpp
src/sdl/SdlFrameOutput.h)
src/sdl/SdlVideoOutput.cpp
src/sdl/SdlVideoOutput.h
src/sdl/SdlAudioOutput.cpp
src/sdl/SdlAudioOutput.h
)

set(GLFWOUTPUT_SOURCES
src/glfw/GlfwFrameOutput.cpp
src/glfw/GlfwFrameOutput.h)
src/glfw/GlfwVideoOutput.cpp
src/glfw/GlfwVideoOutput.h)

set(NULL_SOURCES
src/NullVideoOutput.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
#include "GlfwFrameOutput.h"
// Based on the work done by MasterAler (https://github.com/MasterAler/SampleYUVRenderer). Original shader code and OGL code lovingly adapted.

#include "GlfwVideoOutput.h"

#include <stdexcept>
#include <GLFW/glfw3.h>
#include <GL/gl.h>
#include <vector>

//Vertex matrix
static const GLfloat vertexVertices[] = {
-1.0f, -1.0f,
1.0f, -1.0f,
-1.0f, 1.0f,
1.0f, 1.0f,
};

//Texture matrix
static const GLfloat textureVertices[] = {
0.0f, 1.0f,
1.0f, 1.0f,
Expand Down Expand Up @@ -54,13 +52,13 @@ static const char* fragment_shader_text =
"}";

namespace glfw {
GlfwFrameOutput::GlfwFrameOutput() {
GlfwVideoOutput::GlfwVideoOutput() {
if (!glfwInit()) {
throw std::runtime_error("Failed to initialise GLFW3");
}
}

void GlfwFrameOutput::initialiseVideo() {
void GlfwVideoOutput::initialiseVideo() {
window = glfwCreateWindow(1920, 1080, "lgx2userspace", nullptr, nullptr);
if (!window) {
throw std::runtime_error("Failed to create GLFW3 window");
Expand All @@ -86,17 +84,21 @@ namespace glfw {
int vertexMaxLength = 4096;
GLchar vertexErrorLog[4096]{0};
glGetShaderInfoLog(vertexShader, vertexMaxLength, &vertexMaxLength, &vertexErrorLog[0]);
printf("ERRORLOG: %s\n", vertexErrorLog);

if (vertexMaxLength > 0) {
fprintf(stderr, "Vertex shader error: %s\n", vertexErrorLog);
throw std::runtime_error("Failed to compile vertex shader.");
}

GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragmentShader, 1, &fragment_shader_text, nullptr);
glCompileShader(fragmentShader);
int maxLength = 4096;
GLchar errorLog[4096]{0};
glGetShaderInfoLog(fragmentShader, maxLength, &maxLength, &errorLog[0]);
printf("ERRORLOG: %s\n", errorLog);

if (maxLength > 0) {
fprintf(stderr, "Fragment shader error: %s\n", errorLog);
throw std::runtime_error("Failed to compile fragment shader.");
}

GLuint shaderProgram = glCreateProgram();
glAttachShader(shaderProgram, fragmentShader);
Expand All @@ -118,7 +120,7 @@ namespace glfw {
glGenTextures(3, textures);
}

void GlfwFrameOutput::videoFrameAvailable(uint32_t *image) {
void GlfwVideoOutput::videoFrameAvailable(uint32_t *image) {
uint8_t *rawImage = reinterpret_cast<uint8_t *>(image);
uint8_t y[1920*1080];
uint8_t u[1920*1080];
Expand Down Expand Up @@ -179,7 +181,7 @@ namespace glfw {
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}

void GlfwFrameOutput::display() {
void GlfwVideoOutput::display() {
glfwPollEvents();

glfwSwapBuffers(window);
Expand All @@ -189,23 +191,7 @@ namespace glfw {
}
}

void GlfwFrameOutput::shutdownVideo() {

}

void GlfwFrameOutput::initialiseAudio() {

}

void GlfwFrameOutput::audioFrameAvailable(uint32_t *audio) {

}

void GlfwFrameOutput::render() {

}

void GlfwFrameOutput::shutdownAudio() {
void GlfwVideoOutput::shutdownVideo() {

}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#ifndef LGX2USERSPACE_GLFWFRAMEOUTPUT_H
#define LGX2USERSPACE_GLFWFRAMEOUTPUT_H
#ifndef LGX2USERSPACE_GLFWVIDEOOUTPUT_H
#define LGX2USERSPACE_GLFWVIDEOOUTPUT_H

#include "lgxdevice.h"
#include <glad/glad.h>
#include <GLFW/glfw3.h>

namespace glfw {

class GlfwFrameOutput : public lgx2::VideoOutput, public lgx2::AudioOutput {
class GlfwVideoOutput : public lgx2::VideoOutput {
public:
GlfwFrameOutput();
GlfwVideoOutput();

void initialiseVideo() override;

Expand All @@ -19,14 +19,6 @@ namespace glfw {

void shutdownVideo() override;

void initialiseAudio() override;

void audioFrameAvailable(uint32_t *audio) override;

void render() override;

void shutdownAudio() override;

private:
GLFWwindow *window{nullptr};

Expand All @@ -39,4 +31,4 @@ namespace glfw {

}

#endif //LGX2USERSPACE_GLFWFRAMEOUTPUT_H
#endif //LGX2USERSPACE_GLFWVIDEOOUTPUT_H
5 changes: 3 additions & 2 deletions src/liblgx/liblgx-common/src/lgxcommon.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "sdl/SdlFrameOutput.h"
#include "glfw/GlfwFrameOutput.h"
#include "sdl/SdlVideoOutput.h"
#include "sdl/SdlAudioOutput.h"
#include "glfw/GlfwVideoOutput.h"
#include "usb/UsbStream.h"
#include "NullAudioOutput.h"
#include "NullVideoOutput.h"
Expand Down
38 changes: 38 additions & 0 deletions src/liblgx/liblgx-common/src/sdl/SdlAudioOutput.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <stdexcept>
#include "SdlAudioOutput.h"

namespace sdl {

SdlAudioOutput::SdlAudioOutput() {

if (SDL_AudioInit(nullptr) != 0) {
throw std::runtime_error(SDL_GetError());
}
}

void SdlAudioOutput::initialiseAudio() {
SDL_AudioSpec want, have;

SDL_memset(&want, 0, sizeof(want));
want.freq = 48000;
want.format = AUDIO_S16LSB;
want.channels = 2;
want.samples = 1024;
want.callback = nullptr;
_audio = SDL_OpenAudioDevice(nullptr, 0, &want, &have, SDL_AUDIO_ALLOW_FORMAT_CHANGE);
SDL_PauseAudioDevice(_audio, 0);
}

void SdlAudioOutput::audioFrameAvailable(uint32_t *audio) {
SDL_QueueAudio(_audio, audio, 800 * 4);
}

void SdlAudioOutput::render() {
// Should be where audio data is written to the audio pipe
}

void SdlAudioOutput::shutdownAudio() {
SDL_PauseAudioDevice(_audio, 1);
SDL_CloseAudioDevice(_audio);
}
}
25 changes: 25 additions & 0 deletions src/liblgx/liblgx-common/src/sdl/SdlAudioOutput.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef LGX2USERSPACE_SDLAUDIOOUTPUT_H
#define LGX2USERSPACE_SDLAUDIOOUTPUT_H

#include "lgxdevice.h"
#include <SDL2/SDL.h>

namespace sdl {
class SdlAudioOutput : public lgx2::AudioOutput {
public:
SdlAudioOutput();

void initialiseAudio() override;

void audioFrameAvailable(uint32_t *audio) override;

void render() override;

void shutdownAudio() override;
private:
SDL_AudioDeviceID _audio{};
};
}


#endif //LGX2USERSPACE_SDLAUDIOOUTPUT_H
Loading

0 comments on commit 72597d0

Please sign in to comment.