From 3febae48672c729e7844be68f4133e2fe3864364 Mon Sep 17 00:00:00 2001 From: Maschell Date: Tue, 17 Jul 2018 15:32:27 +0200 Subject: [PATCH] Add a simple configuration menu. --- src/main.cpp | 33 +++++++++++++++++++++++++++++++++ src/retain_vars.cpp | 1 + src/retain_vars.hpp | 5 +++++ src/stream_utils.cpp | 21 +++++++++++++++------ 4 files changed, 54 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 5951330..0630192 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,9 @@ +#include +#include #include +#include +#include +#include #include #include "retain_vars.hpp" #include "EncodingHelper.h" @@ -14,6 +19,34 @@ WUPS_PLUGIN_LICENSE("GPL"); // Something is using "write"... WUPS_FS_ACCESS() +void resolutionChanged(int32_t newResolution) { + DEBUG_FUNCTION_LINE("Resolution changed %d \n",newResolution); + gResolution = newResolution; + + // Restart server. + EncodingHelper::destroyInstance(); + MJPEGStreamServer::destroyInstance(); + + EncodingHelper::getInstance()->StartAsyncThread(); + MJPEGStreamServer::getInstance(); +} + + +WUPS_GET_CONFIG() { + WUPSConfig* config = new WUPSConfig("Streaming Plugin"); + WUPSConfigCategory* catOther = config->addCategory("Main"); + + std::map resolutionValues; + resolutionValues[WUPS_STREAMING_RESOLUTION_240P] = "240p"; + resolutionValues[WUPS_STREAMING_RESOLUTION_360P] = "360p"; + resolutionValues[WUPS_STREAMING_RESOLUTION_480P] = "480p"; + + // item Type config id displayed name default value onChangeCallback. + catOther->addItem(new WUPSConfigItemMultipleValues("resolution", "Streaming resolution", gResolution, resolutionValues, resolutionChanged)); + + return config; +} + // Gets called once the loader exists. INITIALIZE_PLUGIN() { socket_lib_init(); diff --git a/src/retain_vars.cpp b/src/retain_vars.cpp index 28aedc6..ecca1fe 100644 --- a/src/retain_vars.cpp +++ b/src/retain_vars.cpp @@ -1,2 +1,3 @@ #include "retain_vars.hpp" wups_loader_app_status_t gAppStatus __attribute__((section(".data"))) = WUPS_APP_STATUS_UNKNOWN; +int32_t gResolution __attribute__((section(".data"))) = WUPS_STREAMING_RESOLUTION_240P; diff --git a/src/retain_vars.hpp b/src/retain_vars.hpp index cb114c1..4635183 100644 --- a/src/retain_vars.hpp +++ b/src/retain_vars.hpp @@ -3,6 +3,11 @@ #include +#define WUPS_STREAMING_RESOLUTION_240P 1 +#define WUPS_STREAMING_RESOLUTION_360P 2 +#define WUPS_STREAMING_RESOLUTION_480P 3 + extern wups_loader_app_status_t gAppStatus; +extern int32_t gResolution; #endif // _RETAINS_VARS_H_ diff --git a/src/stream_utils.cpp b/src/stream_utils.cpp index 24670b9..87a1f45 100644 --- a/src/stream_utils.cpp +++ b/src/stream_utils.cpp @@ -1,4 +1,5 @@ #include "stream_utils.h" +#include "retain_vars.hpp" #include "EncodingHelper.h" #include "MJPEGStreamServer.hpp" #include @@ -31,6 +32,7 @@ bool copyBuffer(GX2ColorBuffer * sourceBuffer, GX2ColorBuffer * targetBuffer, ui targetBuffer->surface.depth = 1; targetBuffer->surface.mipLevels = 1; targetBuffer->surface.format = GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8; + //targetBuffer->surface.format = GX2_SURFACE_FORMAT_SRGB_R8_G8_B8_A8; targetBuffer->surface.aa = GX2_AA_MODE1X; targetBuffer->surface.tileMode = GX2_TILE_MODE_LINEAR_ALIGNED; targetBuffer->viewMip = 0; @@ -117,12 +119,19 @@ bool streamVideo(GX2ColorBuffer *srcBuffer) { memset(colorBuffer,0,sizeof(GX2ColorBuffer)); // keep dimensions - //uint32_t width = srcBuffer->surface.width; - //uint32_t height = srcBuffer->surface.height; - //uint32_t width = 640; - //uint32_t height = 360; - uint32_t width = 428; - uint32_t height = 240; + + uint32_t width = 640/2; + uint32_t height = 360/2; + + if(gResolution == WUPS_STREAMING_RESOLUTION_480P) { + width = 854; + height = 480; + } else if(gResolution == WUPS_STREAMING_RESOLUTION_360P) { + width = 640; + height = 360; + } else { + + } bool valid = copyBuffer(srcBuffer,colorBuffer,width,height); if(!valid) {