Minor improvements in connection and IPC (multiple instances not fully

supported yet)
This commit is contained in:
brunoherbelin
2020-10-25 23:14:47 +01:00
parent 7fba62bc49
commit cb6a0aefa4
8 changed files with 69 additions and 18 deletions

View File

@@ -61,6 +61,14 @@ bool Connection::init()
std::thread(listen).detach();
// regularly check for available streaming hosts
std::thread(ask).detach();
// inform the application settings of our id
Settings::application.instance_id = connections_[0].port_handshake - HANDSHAKE_PORT;
// use or replace instance name from settings
if (Settings::application.instance_names.count(Settings::application.instance_id))
connections_[0].name = Settings::application.instance_names[Settings::application.instance_id];
else
Settings::application.instance_names[Settings::application.instance_id] = connections_[0].name;
// restore state of Streamer
Streaming::manager().enable( Settings::application.accept_connections );
@@ -78,8 +86,6 @@ void Connection::terminate()
Streaming::manager().enable( false );
}
int Connection::numHosts () const
{
return connections_.size();
@@ -253,6 +259,10 @@ void ConnectionRequestListener::ProcessMessage( const osc::ReceivedMessage& m,
if ( i < 0) {
// a new connection! Add to list
Connection::manager().connections_.push_back(info);
// replace instance name in settings
int id = info.port_handshake - HANDSHAKE_PORT;
Settings::application.instance_names[id] = info.name;
#ifdef CONNECTION_DEBUG
Log::Info("List of connection updated:");
Connection::manager().print();

View File

@@ -253,7 +253,6 @@ void NetworkStream::update()
}
else {
Log::Info("Connection rejected.");
// failed_ = true;
}
}
}

View File

@@ -77,8 +77,8 @@ const std::vector<std::string> NetworkToolkit::protocol_send_pipeline {
const std::vector<std::string> NetworkToolkit::protocol_receive_pipeline {
"shmsrc socket-path=XXXX ! video/x-raw, format=RGB, framerate=30/1 ! queue max-size-buffers=3",
"udpsrc buffer-size=200000 port=XXXX ! application/x-rtp,encoding-name=JPEG,payload=26 ! queue max-size-buffers=3 ! rtpjpegdepay ! jpegdec",
"udpsrc buffer-size=200000 port=XXXX ! application/x-rtp,media=video,encoding-name=H264,payload=96,clock-rate=90000 ! queue max-size-buffers=3 ! rtph264depay ! avdec_h264",
"udpsrc buffer-size=200000 timeout=200000 port=XXXX ! application/x-rtp,encoding-name=JPEG,payload=26 ! queue max-size-buffers=3 ! rtpjitterbuffer ! rtpjpegdepay ! jpegdec",
"udpsrc buffer-size=200000 timeout=200000 port=XXXX ! application/x-rtp,encoding-name=H264,payload=96,clock-rate=90000 ! queue max-size-buffers=3 ! rtph264depay ! avdec_h264",
"tcpclientsrc timeout=1 port=XXXX ! queue max-size-buffers=3 ! application/x-rtp-stream,media=video,encoding-name=JPEG,payload=26 ! rtpstreamdepay ! rtpjpegdepay ! jpegdec",
"tcpclientsrc timeout=1 port=XXXX ! queue max-size-buffers=3 ! application/x-rtp-stream,media=video,encoding-name=H264,payload=96,clock-rate=90000 ! rtpstreamdepay ! rtph264depay ! avdec_h264"
};

View File

@@ -107,6 +107,21 @@ void Settings::Save()
SourceConfNode->SetAttribute("res", application.source.res);
pRoot->InsertEndChild(SourceConfNode);
// bloc connections
{
XMLElement *connectionsNode = xmlDoc.NewElement( "Connections" );
map<int, std::string>::iterator iter;
for (iter=application.instance_names.begin(); iter != application.instance_names.end(); iter++)
{
XMLElement *connection = xmlDoc.NewElement( "Instance" );
connection->SetAttribute("name", iter->second.c_str());
connection->SetAttribute("id", iter->first);
connectionsNode->InsertEndChild(connection);
}
pRoot->InsertEndChild(connectionsNode);
}
// bloc views
{
XMLElement *viewsNode = xmlDoc.NewElement( "Views" );
@@ -326,6 +341,22 @@ void Settings::Load()
}
// bloc Connections
{
XMLElement * pElement = pRoot->FirstChildElement("Connections");
if (pElement)
{
XMLElement* connectionNode = pElement->FirstChildElement("Instance");
for( ; connectionNode ; connectionNode=connectionNode->NextSiblingElement())
{
int id = 0;
connectionNode->QueryIntAttribute("id", &id);
application.instance_names[id] = connectionNode->Attribute("name");
}
}
}
// bloc history of recent
{
XMLElement * pElement = pRoot->FirstChildElement("Recent");

View File

@@ -163,6 +163,7 @@ struct Application
{
// instance check
bool fresh_start;
int instance_id;
// Verification
std::string name;
@@ -175,7 +176,10 @@ struct Application
bool smooth_transition;
bool smooth_cursor;
bool action_history_follow_view;
// connection settings
bool accept_connections;
std::map<int, std::string> instance_names;
// Settings of widgets
WidgetsConfig widget;

View File

@@ -231,7 +231,7 @@ void Streaming::addStream(const std::string &sender, int reply_to, const std::st
else {
conf.protocol = NetworkToolkit::UDP_JPEG;
}
// conf.protocol = NetworkToolkit::UDP_JPEG; // force udp for testing
conf.protocol = NetworkToolkit::UDP_JPEG; // force udp for testing
// build OSC message
char buffer[IP_MTU_SIZE];

View File

@@ -1213,13 +1213,15 @@ void UserInterface::RenderPreview()
{
static char dummy_str[512];
sprintf(dummy_str, "%s", Connection::manager().info().name.c_str());
ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN);
// ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN);
ImGui::InputText("Name", dummy_str, IM_ARRAYSIZE(dummy_str), ImGuiInputTextFlags_ReadOnly);
ImGui::Separator();
std::vector<std::string> ls = Streaming::manager().listStreams();
if (ls.size()>0) {
ImGui::Separator();
for (auto it = ls.begin(); it != ls.end(); it++)
ImGui::Text(" %s", (*it).c_str() );
}
}
ImGui::EndMenu();

View File

@@ -53,6 +53,12 @@ int main(int argc, char *argv[])
/// lock to inform an instance is running
Settings::Lock();
///
/// CONNECTION INIT
///
if ( !Connection::manager().init() )
return 1;
///
/// RENDERING INIT
///
@@ -65,10 +71,6 @@ int main(int argc, char *argv[])
if ( !UserInterface::manager().Init() )
return 1;
if ( !Connection::manager().init() )
return 1;
///
/// GStreamer
///
@@ -99,8 +101,6 @@ int main(int argc, char *argv[])
Rendering::manager().draw();
}
Connection::manager().terminate();
///
/// UI TERMINATE
///
@@ -112,13 +112,18 @@ int main(int argc, char *argv[])
Rendering::manager().terminate();
///
/// Settings
/// CONNECTION TERMINATE
///
Settings::Save();
Connection::manager().terminate();
/// unlock on clean exit
Settings::Unlock();
///
/// Settings
///
Settings::Save();
/// ok
return 0;
}