Skip to content

Commit

Permalink
Merge branch 'merge_attempt4' into 2.6-evo
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelscholle authored Dec 29, 2024
2 parents d5b66cc + 8444c40 commit 7b31859
Show file tree
Hide file tree
Showing 15 changed files with 236 additions and 234 deletions.
8 changes: 7 additions & 1 deletion 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
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
131 changes: 44 additions & 87 deletions app/videostreaming/gstreamer/gst_video.pri
Original file line number Diff line number Diff line change
@@ -1,100 +1,57 @@
DEFINES += QOPENHD_ENABLE_GSTREAMER_QMLGLSINK
INCLUDEPATH += $$PWD
INCLUDEPATH += C:/ffmpeg/include

#DEFINES += QOPENHD_GSTREAMER_PRIMARY_VIDEO
DEFINES += QOPENHD_GSTREAMER_SECONDARY_VIDEO
LIBS += -LC:/ffmpeg/lib -lavcodec -lavutil -lavformat
# TODO dirty
LIBS += -lGLESv2 -lEGL

SOURCES += \
$$PWD/gstqmlglsinkstream.cpp \
$$PWD/gstrtpaudioplayer.cpp \
$$PWD/gstrtpreceiver.cpp
win32 {
INCLUDEPATH += $$PWD/../../../build-libs-windows/ffmpeg/include
LIBS += -L$$PWD/../../../build-libs-windows/ffmpeg/lib -lavcodec -lavutil -lavformat

HEADERS += \
$$PWD/gst_helper.hpp \
$$PWD/gstqmlglsinkstream.h \
$$PWD/gstrtpaudioplayer.h \
$$PWD/gstrtpreceiver.h
INCLUDEPATH += $$PWD/../../../build-libs-windows/angle-x64/include
LIBS += -L$$PWD/../../../build-libs-windows/angle-x64/bin -lGLESv2 -lEGL

android{
message("gst android")
# More or less taken from QGroundControl.
# this is already the "least dirty" solution I could come up with :/
#DOWNLOADED_GST_FOLDER= /home/hyperion/gstreamer-1.0-android-universal-1.20.5
#DOWNLOADED_GST_FOLDER= /home/consti10/Downloads/gstreamer-1.0-android-universal-1.20.5
#DOWNLOADED_GST_FOLDER= $$PWD/../../../lib/gstreamer_prebuilts/gstreamer-1.0-android-universal-1.20.5
DOWNLOADED_GST_FOLDER= $$PWD/../../../lib/gstreamer_prebuilts/gstreamer-1.0-android-universal
DEFINES += EGL_EGLEXT_PROTOTYPES
DEFINES += GL_GLEXT_PROTOTYPES
# LIBS += -lOpengl32
}

# Set the right folder for the compile arch
GSTREAMER_ARCH_FOLDER = armv7
contains(ANDROID_TARGET_ARCH, armeabi-v7a) {
GSTREAMER_ARCH_FOLDER = armv7
} else:contains(ANDROID_TARGET_ARCH, arm64-v8a) {
GSTREAMER_ARCH_FOLDER = arm64
} else:contains(ANDROID_TARGET_ARCH, x86_64) {
GSTREAMER_ARCH_FOLDER = x86_64
} else {
message(Unknown ANDROID_TARGET_ARCH $$ANDROID_TARGET_ARCH)
GSTREAMER_ARCH_FOLDER = armv7
}
# just using the something something webrtc from stephen was the easiest solution.
#include(../../lib/h264/h264.pri)

#GSTREAMER_ARCH_FOLDER = arm64
SOURCES += \
$$PWD/QSGVideoTextureItem.cpp \
$$PWD/gl/gl_shaders.cpp \
$$PWD/gl/gl_videorenderer.cpp \
$$PWD/texturerenderer.cpp \
$$PWD/avcodec_decoder.cpp \

GSTREAMER_ROOT_ANDROID = $$DOWNLOADED_GST_FOLDER/$$GSTREAMER_ARCH_FOLDER
message(gstreamer root android:)
message($$GSTREAMER_ROOT_ANDROID)
HEADERS += \
$$PWD/QSGVideoTextureItem.h \
$$PWD/gl/gl_shaders.h \
$$PWD/gl/gl_videorenderer.h \
$$PWD/texturerenderer.h \
$$PWD/avcodec_decoder.h \

GST_ROOT = $$GSTREAMER_ROOT_ANDROID
exists($$GST_ROOT) {
message(Doing QGC gstreamer stuff)
message($$GST_ROOT)
QMAKE_CXXFLAGS += -pthread
CONFIG += VideoEnabled

LIBS += -L$$GST_ROOT/lib/gstreamer-1.0 \
-lgstvideo-1.0 \
-lgstcoreelements \
-lgstplayback \
-lgstudp \
-lgstrtp \
-lgstrtsp \
-lgstx264 \
-lgstlibav \
-lgstsdpelem \
-lgstvideoparsersbad \
-lgstrtpmanager \
-lgstisomp4 \
-lgstmatroska \
-lgstmpegtsdemux \
-lgstandroidmedia \
-lgstopengl \
-lgsttcp \
-lgstapp \
-lgstalaw \
-lgstautodetect

# experimental
#INCLUDEPATH += /usr/local/include/uvgrtp
#LIBS += -L/usr/local/lib -luvgrtp

# Rest of GStreamer dependencies
LIBS += -L$$GST_ROOT/lib \
-lgraphene-1.0 -ljpeg -lpng16 \
-lgstfft-1.0 -lm \
-lgstnet-1.0 -lgio-2.0 \
-lgstphotography-1.0 -lgstgl-1.0 -lEGL \
-lgstaudio-1.0 -lgstcodecparsers-1.0 -lgstbase-1.0 \
-lgstreamer-1.0 -lgstrtp-1.0 -lgstpbutils-1.0 -lgstrtsp-1.0 -lgsttag-1.0 \
-lgstvideo-1.0 -lavformat -lavcodec -lavutil -lx264 -lavfilter -lswresample \
-lgstriff-1.0 -lgstcontroller-1.0 -lgstapp-1.0 \
-lgstsdp-1.0 -lbz2 -lgobject-2.0 -lgstmpegts-1.0 \
-Wl,--export-dynamic -lgmodule-2.0 -pthread -lglib-2.0 -lorc-0.4 -liconv -lffi -lintl \
# dirty way to check if we are on rpi and therefore should use the external decode service
CONFIG += link_pkgconfig
packagesExist(mmal) {
DEFINES += IS_PLATFORM_RPI
}

INCLUDEPATH += \
$$GST_ROOT/include/gstreamer-1.0 \
$$GST_ROOT/lib/gstreamer-1.0/include \
$$GST_ROOT/include/glib-2.0 \
$$GST_ROOT/lib/glib-2.0/include
}else {
message(Gstreamer prebuilt directory does not exist)
}
}else {
message(gst linux)
CONFIG += link_pkgconfig
PKGCONFIG += gstreamer-1.0 gstreamer-video-1.0 gstreamer-gl-1.0 gstreamer-app-1.0 #gstreamer1.0-plugins-good
exists(/usr/local/share/openhd/platform/rock/) {
message(This is a Rock)
DEFINES += IS_PLATFORM_ROCK
} else {
message(This is not a Rock)
}

# can be used in c++, also set to be exposed in qml
DEFINES += QOPENHD_ENABLE_VIDEO_VIA_AVCODEC
Loading

0 comments on commit 7b31859

Please sign in to comment.