Skip to content

Commit

Permalink
finally merging everyting together, thanks @buldo for your windows wo…
Browse files Browse the repository at this point in the history
…rk (#732)

* Using geodesic.h from repo

* make linux work again ;)

* revert windows gstreamer until it works

* revert more windows stuff for now

* Update MavlinkChoiceElement2.qml

* Update MavlinkChoiceElement.qml

* Scheduling hotfix

* windows build

* How to

* Update QOpenHD.pro

* Update gst_video.pri

* Update UDPReceiver.cpp

* Revert "Update UDPReceiver.cpp"

This reverts commit dc7e3e9.

* Update UDPReceiver.cpp

* Update UDPReceiver.cpp

* Update UDPReceiver.cpp

* Update UDPReceiver.cpp

* Update UDPReceiver.cpp

* Update texturerenderer.cpp

* Update avcodec_video.pri

* Update avcodec_video.pri

* Update avcodec_video.pri

* Update avcodec_video.pri

* Update avcodec_video.pri

* Update gst_video.pri

---------

Co-authored-by: Roman Buldygin <[email protected]>
  • Loading branch information
raphaelscholle and buldo authored Dec 29, 2024
1 parent 2da1b76 commit a1da3cb
Show file tree
Hide file tree
Showing 17 changed files with 273 additions and 244 deletions.
19 changes: 7 additions & 12 deletions QOpenHD.pro
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ CONFIG(debug, debug|release) {
} else:CONFIG(release, debug|release) {
DEFINES += QT_NO_DEBUG
CONFIG += installer
CONFIG += force_debug_info
DESTDIR = $${OUT_PWD}/release
DEFINES += QMLJSDEBUGGER
}
Expand Down Expand Up @@ -103,6 +102,12 @@ LinuxBuild {
include(app/videostreaming/gstreamer/gst_video.pri)
}

# gst Qt plugins in windows is hard
WindowsBuild {
# In future is better to use windows decoding and rendering api
include(app/videostreaming/avcodec/avcodec_video.pri)
}

# All Generic files / files that literally have 0!! dependencies other than qt
SOURCES += \
app/adsb/adsbvehicle.cpp \
Expand All @@ -125,6 +130,7 @@ HEADERS += \
app/common/util_fs.h \
app/common/StringHelper.hpp \
app/common/TimeHelper.hpp \
app/common/SchedulingHelper.hpp \
app/logging/hudlogmessagesmodel.h \
app/logging/loghelper.h \
app/logging/logmessagesmodel.h \
Expand Down Expand Up @@ -234,17 +240,6 @@ JetsonBuild {
WindowsBuild {
# This aparently makes qt use absolute paths, otherwise we get compile issues ?
QMAKE_PROJECT_DEPTH = 0
#include(app/videostreaming/gstreamer/gst_video.pri)
#include(app/videostreaming/avcodec/avcodec_video.pri)
# Path to FFmpeg headers
# INCLUDEPATH += C:/ffmpeg
#INCLUDEPATH += C:/ffmpeg/libavutil/

# Path to FFmpeg libraries
#LIBS += -LC:/ffmpeg/lib

# Link against the required FFmpeg libraries
#LIBS += -lavcodec -lavformat -lavutil -lswscale -lswresample
}

AndroidBuild {
Expand Down
10 changes: 10 additions & 0 deletions README.windows.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
How to:
1. Create folder `build-libs-windows` in repository root
2. Download and extract `ffmpeg-release-full-shared.7z` into `build-libs-windows` ( from https://www.gyan.dev/ffmpeg/builds/ )
Maybe it will be good idea to fix version and put this version in download script
3. Rename extracted folder to `ffmpeg`. Chech that `ffmpeg` folder contains `bin`, `include`, etc. folders.
4. Trying to use prebuild angle from https://github.com/mmozeiko/build-angle
Download latest release and extract to `build-libs-windows`.
Maybe it better to clone/adjust this build pipeline

5. After build you need to copy `bin` folders content to folder with `.exe`
28 changes: 8 additions & 20 deletions app/common/SchedulingHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,29 @@
#define WIFIBROADCAST_SCHEDULINGHELPER_H

#include <pthread.h>
#include <sys/resource.h>
#include <unistd.h>
#include <string>
#include <iostream>
#include <qdebug.h>
#ifdef __windows__
#include <windows.h>
#endif

namespace SchedulingHelper {

static void printCurrentThreadPriority(const std::string& name) {
int which = PRIO_PROCESS;
id_t pid = (id_t) getpid();
int priority = getpriority(which, pid);
//wifibroadcast::log::get_default()->debug("{} has priority {}",name,priority);
}

static void printCurrentThreadSchedulingPolicy(const std::string& name) {
auto self = pthread_self();
int policy;
sched_param param{};
auto result = pthread_getschedparam(self, &policy, &param);
if (result != 0) {
qDebug()<<"Cannot get thread scheduling policy";
}
//wifibroadcast::log::get_default()->debug("{} has policy {} and priority {}",name,policy,param.sched_priority);
}

// this thread should run as close to realtime as possible
static void setThreadParamsMaxRealtime(pthread_t target) {
int policy = SCHED_FIFO;

// TODO: windows.h contains THREAD_PRIORITY_TIME_CRITICAL but not working
#ifndef __windows__
int policy = SCHED_FIFO;
sched_param param{};
param.sched_priority = sched_get_priority_max(policy);
auto result = pthread_setschedparam(target, policy, &param);
if (result != 0) {
qDebug()<<"cannot set ThreadParamsMaxRealtime";
}
#endif
}

static void setThreadParamsMaxRealtime() {
Expand Down
4 changes: 4 additions & 0 deletions app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ static void android_check_permissions(){

int main(int argc, char *argv[]) {

#if defined(__windows__)
QCoreApplication::setAttribute(Qt::AA_UseOpenGLES);
#endif

QCoreApplication::setOrganizationName("OpenHD");
QCoreApplication::setOrganizationDomain("openhd");
QCoreApplication::setApplicationName("QOpenHD");
Expand Down
2 changes: 1 addition & 1 deletion app/telemetry/tutil/geodesi_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <QtGlobal>

extern "C" {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) || defined(Q_OS_WIN)
#include "lib/geographiclib-c-2.0/src/geodesic.h"
#else
#include "geodesic.h"
Expand Down
3 changes: 1 addition & 2 deletions app/videostreaming/avcodec/avcodec_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ extern "C" {
#include <libavutil/imgutils.h>
#include <libavutil/buffer.h>
#include <libavutil/frame.h>
//
#include "libavutil/frame.h"
#include <libavutil/mem.h>
#include "libavutil/hwcontext.h"
#include "libavutil/hwcontext_drm.h"
#include "libavutil/pixdesc.h"
Expand Down
12 changes: 12 additions & 0 deletions app/videostreaming/avcodec/avcodec_video.pri
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ LIBS += -LC:/ffmpeg/lib -lavcodec -lavutil -lavformat
# TODO dirty
LIBS += -lGLESv2 -lEGL

win32 {
INCLUDEPATH += $$PWD/../../../build-libs-windows/ffmpeg/include
LIBS += -L$$PWD/../../../build-libs-windows/ffmpeg/lib -lavcodec -lavutil -lavformat

INCLUDEPATH += $$PWD/../../../build-libs-windows/angle-x64/include
LIBS += -L$$PWD/../../../build-libs-windows/angle-x64/bin -lGLESv2 -lEGL

DEFINES += EGL_EGLEXT_PROTOTYPES
DEFINES += GL_GLEXT_PROTOTYPES
# LIBS += -lOpengl32
}

# just using the something something webrtc from stephen was the easiest solution.
#include(../../lib/h264/h264.pri)

Expand Down
22 changes: 14 additions & 8 deletions app/videostreaming/avcodec/color_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@
#include <cstdint>

static uint32_t create_pixel_rgba(uint8_t r,uint8_t g,uint8_t b,uint8_t a){
uint8_t rgba[4];
rgba[0]=r;
rgba[1]=g;
rgba[2]=b;
rgba[3]=a;
uint32_t ret;
memcpy(&ret,rgba,4);
return ret;
#ifdef __windows__
return ((uint32_t)a << 24) | ((uint32_t)b << 16) | ((uint32_t)g << 8) | (uint32_t)r;
#else
uint8_t rgba[4];
rgba[0]=r;
rgba[1]=g;
rgba[2]=b;
rgba[3]=a;
uint32_t ret;
memcpy(&ret,rgba,4);
return ret;
#endif


}

// --------------------------------------------------- from drm-howto ---------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions app/videostreaming/avcodec/gl/gl_shaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ static const GLchar* fragment_shader_source_NV12 =
" texture2D(s_texture_uv,v_texCoord).xy\n"
" );"
" mat3 colorMatrix = mat3(\n"
" 1.1644f, 1.1644f, 1.1644f,\n"
" 0.0f, -0.3917f, 2.0172f,\n"
" 1.5960f, -0.8129f, 0.0f"
" 1.1644, 1.1644, 1.1644,\n"
" 0.0, -0.3917, 2.0172,\n"
" 1.5960, -0.8129, 0.0"
" );\n"
" gl_FragColor = vec4(clamp(YCbCr*colorMatrix,0.0,1.0), 1.0);\n"
"}\n";
Expand Down
12 changes: 9 additions & 3 deletions app/videostreaming/avcodec/gl/gl_videorenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
#include "gl_videorenderer.h"
#include "../color_helper.h"
#include <GL/gl.h>
#include <EGL/eglext.h>
#include <GLES2/gl2ext.h>
#include <chrono>
#include "../avcodec_helper.hpp"
#include <libavutil/error.h>
#include <vector>

static EGLint texgen_attrs[] = {
EGL_DMA_BUF_PLANE0_FD_EXT,
Expand Down Expand Up @@ -34,9 +39,10 @@ static void create_rgba_texture(GLuint& tex_id,uint32_t color_rgba){
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
const int width=1280;
const int height=720;
uint8_t pixels[4*width*height];
fillFrame(pixels,width,height,width*4, color_rgba);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
std::vector<uint8_t> pixels(4*width*height);

fillFrame(pixels.data(), width, height, width*4, color_rgba);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
glBindTexture(GL_TEXTURE_2D,0);
}

Expand Down
7 changes: 6 additions & 1 deletion app/videostreaming/avcodec/gl/glhelp.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef GLHELP_H
#define GLHELP_H

extern "C" {
#include <EGL/egl.h>
#include <EGL/eglext.h>
// Crude hack for QT on the rpi. Fucking hell, how annyoing this QT crap with redefining opengl is !
Expand All @@ -11,12 +12,14 @@

//#include <GLES3/gl32.h>
//#include <GLES3/gl3ext.h>

}
#include <cassert>

/// Some gl extensions that don't seem to be part of raspberry gl.
/// I think you could get these from other places like GLAD or libepoxy.
///

#ifndef __windows__
EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list) __attribute__((weak)); // May not be in libEGL symbol table, resolve manually :(
EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list)
{
Expand Down Expand Up @@ -61,6 +64,8 @@ void glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image)
}
imageTargetTexture2DOES(target, image);
}

#endif
/// END Gl Extensions --------------------------------------------------


Expand Down
Loading

0 comments on commit a1da3cb

Please sign in to comment.