Expose Connection environment variables to the app start (#1430)
Co-authored-by: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com>
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/xml_parser.hpp>
|
||||
#include <string>
|
||||
|
||||
// local includes
|
||||
#include "config.h"
|
||||
@@ -267,12 +268,32 @@ namespace nvhttp {
|
||||
|
||||
launch_session.host_audio = host_audio;
|
||||
launch_session.gcm_key = util::from_hex<crypto::aes_t>(get_arg(args, "rikey"), true);
|
||||
std::stringstream mode = std::stringstream(get_arg(args, "mode"));
|
||||
// Split mode by the char "x", to populate width/height/fps
|
||||
int x = 0;
|
||||
std::string segment;
|
||||
while (std::getline(mode, segment, 'x')) {
|
||||
if (x == 0) launch_session.width = atoi(segment.c_str());
|
||||
if (x == 1) launch_session.height = atoi(segment.c_str());
|
||||
if (x == 2) launch_session.fps = atoi(segment.c_str());
|
||||
x++;
|
||||
}
|
||||
launch_session.unique_id = (get_arg(args, "uniqueid"));
|
||||
launch_session.uuid = (get_arg(args, "uuid"));
|
||||
launch_session.appid = util::from_view(get_arg(args, "appid"));
|
||||
launch_session.enable_sops = util::from_view(get_arg(args, "sops"));
|
||||
launch_session.surround_info = util::from_view(get_arg(args, "surroundAudioInfo"));
|
||||
launch_session.gcmap = util::from_view(get_arg(args, "gcmap"));
|
||||
launch_session.enable_hdr = 0;
|
||||
if (args.find("enableHdr"s) != std::end(args)) {
|
||||
launch_session.enable_hdr = util::from_view(get_arg(args, "enableHdr"));
|
||||
}
|
||||
uint32_t prepend_iv = util::endian::big<uint32_t>(util::from_view(get_arg(args, "rikeyid")));
|
||||
auto prepend_iv_p = (uint8_t *) &prepend_iv;
|
||||
|
||||
auto next = std::copy(prepend_iv_p, prepend_iv_p + sizeof(prepend_iv), std::begin(launch_session.iv));
|
||||
std::fill(next, std::end(launch_session.iv), 0);
|
||||
|
||||
BOOST_LOG(error) << launch_session.width << " h: " << launch_session.height << " fps: " << launch_session.fps;
|
||||
return launch_session;
|
||||
}
|
||||
|
||||
@@ -757,8 +778,11 @@ namespace nvhttp {
|
||||
}
|
||||
}
|
||||
|
||||
host_audio = util::from_view(get_arg(args, "localAudioPlayMode"));
|
||||
auto launch_session = make_launch_session(host_audio, args);
|
||||
|
||||
if (appid > 0) {
|
||||
auto err = proc::proc.execute(appid);
|
||||
auto err = proc::proc.execute(appid, launch_session);
|
||||
if (err) {
|
||||
tree.put("root.<xmlattr>.status_code", err);
|
||||
tree.put("root.<xmlattr>.status_message", "Failed to start the specified application");
|
||||
@@ -768,8 +792,7 @@ namespace nvhttp {
|
||||
}
|
||||
}
|
||||
|
||||
host_audio = util::from_view(get_arg(args, "localAudioPlayMode"));
|
||||
rtsp_stream::launch_session_raise(make_launch_session(host_audio, args));
|
||||
rtsp_stream::launch_session_raise(launch_session);
|
||||
|
||||
tree.put("root.<xmlattr>.status_code", 200);
|
||||
tree.put("root.sessionUrl0", "rtsp://"s + request->local_endpoint().address().to_string() + ':' + std::to_string(map_port(rtsp_stream::RTSP_SETUP_PORT)));
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @file src/process.cpp
|
||||
* @brief todo
|
||||
* @brief Handles the startup and shutdown of the apps started by a streaming Session.
|
||||
*/
|
||||
#define BOOST_BIND_GLOBAL_PLACEHOLDERS
|
||||
|
||||
@@ -101,7 +101,7 @@ namespace proc {
|
||||
}
|
||||
|
||||
int
|
||||
proc_t::execute(int app_id) {
|
||||
proc_t::execute(int app_id, rtsp_stream::launch_session_t launch_session) {
|
||||
// Ensure starting from a clean slate
|
||||
terminate();
|
||||
|
||||
@@ -120,6 +120,29 @@ namespace proc {
|
||||
_app_prep_begin = std::begin(_app.prep_cmds);
|
||||
_app_prep_it = _app_prep_begin;
|
||||
|
||||
// Add Stream-specific environment variables
|
||||
_env["SUNSHINE_APP_ID"] = std::to_string(_app_id);
|
||||
_env["SUNSHINE_APP_NAME"] = _app.name;
|
||||
_env["SUNSHINE_CLIENT_WIDTH"] = std::to_string(launch_session.width);
|
||||
_env["SUNSHINE_CLIENT_HEIGHT"] = std::to_string(launch_session.height);
|
||||
_env["SUNSHINE_CLIENT_FPS"] = std::to_string(launch_session.fps);
|
||||
_env["SUNSHINE_CLIENT_HDR"] = launch_session.enable_hdr ? "true" : "false";
|
||||
_env["SUNSHINE_CLIENT_GCMAP"] = std::to_string(launch_session.gcmap);
|
||||
_env["SUNSHINE_CLIENT_HOST_AUDIO"] = launch_session.host_audio ? "true" : "false";
|
||||
_env["SUNSHINE_CLIENT_ENABLE_SOPS"] = launch_session.enable_sops ? "true" : "false";
|
||||
int channelCount = launch_session.surround_info & (65535);
|
||||
switch (channelCount) {
|
||||
case 2:
|
||||
_env["SUNSHINE_CLIENT_AUDIO_CONFIGURATION"] = "2.0";
|
||||
break;
|
||||
case 6:
|
||||
_env["SUNSHINE_CLIENT_AUDIO_CONFIGURATION"] = "5.1";
|
||||
break;
|
||||
case 8:
|
||||
_env["SUNSHINE_CLIENT_AUDIO_CONFIGURATION"] = "7.1";
|
||||
break;
|
||||
}
|
||||
|
||||
if (!_app.output.empty() && _app.output != "null"sv) {
|
||||
#ifdef _WIN32
|
||||
// fopen() interprets the filename as an ANSI string on Windows, so we must convert it
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "platform/common.h"
|
||||
#include "rtsp.h"
|
||||
#include "utility.h"
|
||||
|
||||
namespace proc {
|
||||
@@ -65,7 +66,7 @@ namespace proc {
|
||||
_apps(std::move(apps)) {}
|
||||
|
||||
int
|
||||
execute(int app_id);
|
||||
execute(int app_id, rtsp_stream::launch_session_t launch_session);
|
||||
|
||||
/**
|
||||
* @return _app_id if a process is running, otherwise returns 0
|
||||
|
||||
10
src/rtsp.h
10
src/rtsp.h
@@ -17,6 +17,16 @@ namespace rtsp_stream {
|
||||
crypto::aes_t iv;
|
||||
|
||||
bool host_audio;
|
||||
std::string unique_id;
|
||||
std::string uuid;
|
||||
int width;
|
||||
int height;
|
||||
int fps;
|
||||
int gcmap;
|
||||
int appid;
|
||||
int surround_info;
|
||||
bool enable_hdr;
|
||||
bool enable_sops;
|
||||
};
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user