Add a simple configuration menu.

This commit is contained in:
Maschell 2018-07-17 15:32:27 +02:00
parent eac6a6c0a6
commit 3febae4867
4 changed files with 54 additions and 6 deletions

View File

@ -1,4 +1,9 @@
#include <map>
#include <string>
#include <wups.h>
#include <wups/confighooks.h>
#include <wups/config/WUPSConfig.h>
#include <wups/config/WUPSConfigItemMultipleValues.h>
#include <utils/logger.h>
#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<int32_t,std::string> 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();

View File

@ -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;

View File

@ -3,6 +3,11 @@
#include <wups.h>
#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_

View File

@ -1,4 +1,5 @@
#include "stream_utils.h"
#include "retain_vars.hpp"
#include "EncodingHelper.h"
#include "MJPEGStreamServer.hpp"
#include <fs/FSUtils.h>
@ -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) {