diff --git a/Connection.cpp b/Connection.cpp index 9ff377d..3ad847b 100644 --- a/Connection.cpp +++ b/Connection.cpp @@ -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(); diff --git a/NetworkSource.cpp b/NetworkSource.cpp index 8579291..2613d9b 100644 --- a/NetworkSource.cpp +++ b/NetworkSource.cpp @@ -253,7 +253,6 @@ void NetworkStream::update() } else { Log::Info("Connection rejected."); -// failed_ = true; } } } diff --git a/NetworkToolkit.cpp b/NetworkToolkit.cpp index c7d3824..6f8f1a0 100644 --- a/NetworkToolkit.cpp +++ b/NetworkToolkit.cpp @@ -77,8 +77,8 @@ const std::vector NetworkToolkit::protocol_send_pipeline { const std::vector 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" }; diff --git a/Settings.cpp b/Settings.cpp index da9174b..881c474 100644 --- a/Settings.cpp +++ b/Settings.cpp @@ -107,6 +107,21 @@ void Settings::Save() SourceConfNode->SetAttribute("res", application.source.res); pRoot->InsertEndChild(SourceConfNode); + // bloc connections + { + XMLElement *connectionsNode = xmlDoc.NewElement( "Connections" ); + + map::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"); diff --git a/Settings.h b/Settings.h index 2fee106..5e63a16 100644 --- a/Settings.h +++ b/Settings.h @@ -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 instance_names; // Settings of widgets WidgetsConfig widget; diff --git a/Streamer.cpp b/Streamer.cpp index 3ef14b2..643c89a 100644 --- a/Streamer.cpp +++ b/Streamer.cpp @@ -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]; diff --git a/UserInterfaceManager.cpp b/UserInterfaceManager.cpp index 9bc4af4..5979839 100644 --- a/UserInterfaceManager.cpp +++ b/UserInterfaceManager.cpp @@ -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 ls = Streaming::manager().listStreams(); - for (auto it = ls.begin(); it != ls.end(); it++) - ImGui::Text("%s", (*it).c_str() ); + if (ls.size()>0) { + ImGui::Separator(); + for (auto it = ls.begin(); it != ls.end(); it++) + ImGui::Text(" %s", (*it).c_str() ); + } } ImGui::EndMenu(); diff --git a/main.cpp b/main.cpp index 5a0cad2..8f34da0 100644 --- a/main.cpp +++ b/main.cpp @@ -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; }