mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-13 03:09:57 +01:00
Fixing Streamer and NetworkSource dialog
This commit is contained in:
@@ -65,10 +65,10 @@ bool Connection::init()
|
|||||||
// inform the application settings of our id
|
// inform the application settings of our id
|
||||||
Settings::application.instance_id = connections_[0].port_handshake - HANDSHAKE_PORT;
|
Settings::application.instance_id = connections_[0].port_handshake - HANDSHAKE_PORT;
|
||||||
// use or replace instance name from settings
|
// use or replace instance name from settings
|
||||||
if (Settings::application.instance_names.count(Settings::application.instance_id))
|
// if (Settings::application.instance_names.count(Settings::application.instance_id))
|
||||||
connections_[0].name = Settings::application.instance_names[Settings::application.instance_id];
|
// connections_[0].name = Settings::application.instance_names[Settings::application.instance_id];
|
||||||
else
|
// else
|
||||||
Settings::application.instance_names[Settings::application.instance_id] = connections_[0].name;
|
// Settings::application.instance_names[Settings::application.instance_id] = connections_[0].name;
|
||||||
// restore state of Streamer
|
// restore state of Streamer
|
||||||
Streaming::manager().enable( Settings::application.accept_connections );
|
Streaming::manager().enable( Settings::application.accept_connections );
|
||||||
|
|
||||||
@@ -176,11 +176,12 @@ void Connection::ask()
|
|||||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||||
|
|
||||||
// check the list of connections for non responding (disconnected)
|
// check the list of connections for non responding (disconnected)
|
||||||
for(auto it=Connection::manager().connections_.begin(); it!=Connection::manager().connections_.end(); ) {
|
std::vector< ConnectionInfo >::iterator it = Connection::manager().connections_.begin();
|
||||||
|
for(it++; it!=Connection::manager().connections_.end(); ) {
|
||||||
// decrease life score
|
// decrease life score
|
||||||
(*it).alive--;
|
(*it).alive--;
|
||||||
// erase connection if its life score is negative (not responding too many times)
|
// erase connection if its life score is negative (not responding too many times)
|
||||||
if ( it!=Connection::manager().connections_.begin() && (*it).alive < 0 ) {
|
if ( (*it).alive < 0 ) {
|
||||||
// inform streamer to cancel streaming to this client
|
// inform streamer to cancel streaming to this client
|
||||||
Streaming::manager().removeStreams( (*it).name );
|
Streaming::manager().removeStreams( (*it).name );
|
||||||
// remove from list
|
// remove from list
|
||||||
@@ -258,8 +259,8 @@ void ConnectionRequestListener::ProcessMessage( const osc::ReceivedMessage& m,
|
|||||||
// a new connection! Add to list
|
// a new connection! Add to list
|
||||||
Connection::manager().connections_.push_back(info);
|
Connection::manager().connections_.push_back(info);
|
||||||
// replace instance name in settings
|
// replace instance name in settings
|
||||||
int id = info.port_handshake - HANDSHAKE_PORT;
|
// int id = info.port_handshake - HANDSHAKE_PORT;
|
||||||
Settings::application.instance_names[id] = info.name;
|
// Settings::application.instance_names[id] = info.name;
|
||||||
|
|
||||||
#ifdef CONNECTION_DEBUG
|
#ifdef CONNECTION_DEBUG
|
||||||
Log::Info("List of connection updated:");
|
Log::Info("List of connection updated:");
|
||||||
|
|||||||
@@ -35,6 +35,9 @@ void StreamerResponseListener::ProcessMessage( const osc::ReceivedMessage& m,
|
|||||||
try{
|
try{
|
||||||
if( std::strcmp( m.AddressPattern(), OSC_PREFIX OSC_STREAM_OFFER ) == 0 ){
|
if( std::strcmp( m.AddressPattern(), OSC_PREFIX OSC_STREAM_OFFER ) == 0 ){
|
||||||
|
|
||||||
|
#ifdef NETWORK_DEBUG
|
||||||
|
Log::Info("Received stream info from %s", sender);
|
||||||
|
#endif
|
||||||
NetworkToolkit::StreamConfig conf;
|
NetworkToolkit::StreamConfig conf;
|
||||||
|
|
||||||
// someone is offering a stream
|
// someone is offering a stream
|
||||||
@@ -49,17 +52,14 @@ void StreamerResponseListener::ProcessMessage( const osc::ReceivedMessage& m,
|
|||||||
parent_->connected_ = true;
|
parent_->connected_ = true;
|
||||||
parent_->received_config_ = true;
|
parent_->received_config_ = true;
|
||||||
|
|
||||||
#ifdef NETWORK_DEBUG
|
|
||||||
Log::Info("Received stream info from %s", sender);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else if( std::strcmp( m.AddressPattern(), OSC_PREFIX OSC_STREAM_REJECT ) == 0 ){
|
else if( std::strcmp( m.AddressPattern(), OSC_PREFIX OSC_STREAM_REJECT ) == 0 ){
|
||||||
|
|
||||||
parent_->connected_ = false;
|
|
||||||
parent_->received_config_ = true;
|
|
||||||
#ifdef NETWORK_DEBUG
|
#ifdef NETWORK_DEBUG
|
||||||
Log::Info("Received rejection from %s", sender);
|
Log::Info("Received rejection from %s", sender);
|
||||||
#endif
|
#endif
|
||||||
|
parent_->connected_ = false;
|
||||||
|
parent_->received_config_ = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch( osc::Exception& e ){
|
catch( osc::Exception& e ){
|
||||||
@@ -113,6 +113,10 @@ void NetworkStream::connect(const std::string &nameconnection)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ok, we want to ask to this connected streamer to send us a stream
|
||||||
|
streamer_ = Connection::manager().info(streamer_index);
|
||||||
|
std::string listener_address = NetworkToolkit::closest_host_ip(streamer_.address);
|
||||||
|
|
||||||
// prepare listener to receive stream config from remote streaming manager
|
// prepare listener to receive stream config from remote streaming manager
|
||||||
listener_.setParent(this);
|
listener_.setParent(this);
|
||||||
|
|
||||||
@@ -123,7 +127,7 @@ void NetworkStream::connect(const std::string &nameconnection)
|
|||||||
// invent a port which would be available
|
// invent a port which would be available
|
||||||
listener_port_ = 72000 + rand()%1000;
|
listener_port_ = 72000 + rand()%1000;
|
||||||
// try to create receiver (through exception on fail)
|
// try to create receiver (through exception on fail)
|
||||||
receiver_ = new UdpListeningReceiveSocket(IpEndpointName(Connection::manager().info().address.c_str(), listener_port_), &listener_);
|
receiver_ = new UdpListeningReceiveSocket(IpEndpointName(listener_address.c_str(), listener_port_), &listener_);
|
||||||
}
|
}
|
||||||
catch (const std::runtime_error&) {
|
catch (const std::runtime_error&) {
|
||||||
receiver_ = nullptr;
|
receiver_ = nullptr;
|
||||||
@@ -135,12 +139,6 @@ void NetworkStream::connect(const std::string &nameconnection)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ok, we can ask to this connected streamer to send us a stream
|
|
||||||
ConnectionInfo streamer = Connection::manager().info(streamer_index);
|
|
||||||
IpEndpointName a( streamer.address.c_str(), streamer.port_stream_request );
|
|
||||||
streamer_address_ = a.address;
|
|
||||||
streamer_address_ = a.port;
|
|
||||||
|
|
||||||
// build OSC message
|
// build OSC message
|
||||||
char buffer[IP_MTU_SIZE];
|
char buffer[IP_MTU_SIZE];
|
||||||
osc::OutboundPacketStream p( buffer, IP_MTU_SIZE );
|
osc::OutboundPacketStream p( buffer, IP_MTU_SIZE );
|
||||||
@@ -152,14 +150,14 @@ void NetworkStream::connect(const std::string &nameconnection)
|
|||||||
p << osc::EndMessage;
|
p << osc::EndMessage;
|
||||||
|
|
||||||
// send OSC message to streamer
|
// send OSC message to streamer
|
||||||
UdpTransmitSocket socket( streamer_address_ );
|
UdpTransmitSocket socket( IpEndpointName(streamer_.address.c_str(), streamer_.port_stream_request) );
|
||||||
socket.Send( p.Data(), p.Size() );
|
socket.Send( p.Data(), p.Size() );
|
||||||
|
|
||||||
// Now we wait for the offer from the streamer
|
// Now we wait for the offer from the streamer
|
||||||
std::thread(wait_for_stream_, receiver_).detach();
|
std::thread(wait_for_stream_, receiver_).detach();
|
||||||
|
|
||||||
#ifdef NETWORK_DEBUG
|
#ifdef NETWORK_DEBUG
|
||||||
Log::Info("Asking %s:%d for a stream", streamer.address.c_str(), streamer.port_stream_request);
|
Log::Info("Asking %s:%d for a stream", streamer_.address.c_str(), streamer_.port_stream_request);
|
||||||
Log::Info("Waiting for response at %s:%d", Connection::manager().info().address.c_str(), listener_port_);
|
Log::Info("Waiting for response at %s:%d", Connection::manager().info().address.c_str(), listener_port_);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -181,7 +179,7 @@ void NetworkStream::disconnect()
|
|||||||
p << osc::EndMessage;
|
p << osc::EndMessage;
|
||||||
|
|
||||||
// send OSC message to streamer
|
// send OSC message to streamer
|
||||||
UdpTransmitSocket socket( streamer_address_ );
|
UdpTransmitSocket socket( IpEndpointName(streamer_.address.c_str(), streamer_.port_stream_request) );
|
||||||
socket.Send( p.Data(), p.Size() );
|
socket.Send( p.Data(), p.Size() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "ip/UdpSocket.h"
|
#include "ip/UdpSocket.h"
|
||||||
|
|
||||||
#include "NetworkToolkit.h"
|
#include "NetworkToolkit.h"
|
||||||
|
#include "Connection.h"
|
||||||
#include "StreamSource.h"
|
#include "StreamSource.h"
|
||||||
|
|
||||||
class NetworkStream;
|
class NetworkStream;
|
||||||
@@ -42,7 +43,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// connection information
|
// connection information
|
||||||
IpEndpointName streamer_address_;
|
ConnectionInfo streamer_;
|
||||||
StreamerResponseListener listener_;
|
StreamerResponseListener listener_;
|
||||||
UdpListeningReceiveSocket *receiver_;
|
UdpListeningReceiveSocket *receiver_;
|
||||||
std::atomic<bool> received_config_;
|
std::atomic<bool> received_config_;
|
||||||
|
|||||||
30
Settings.cpp
30
Settings.cpp
@@ -111,14 +111,14 @@ void Settings::Save()
|
|||||||
{
|
{
|
||||||
XMLElement *connectionsNode = xmlDoc.NewElement( "Connections" );
|
XMLElement *connectionsNode = xmlDoc.NewElement( "Connections" );
|
||||||
|
|
||||||
map<int, std::string>::iterator iter;
|
// map<int, std::string>::iterator iter;
|
||||||
for (iter=application.instance_names.begin(); iter != application.instance_names.end(); iter++)
|
// for (iter=application.instance_names.begin(); iter != application.instance_names.end(); iter++)
|
||||||
{
|
// {
|
||||||
XMLElement *connection = xmlDoc.NewElement( "Instance" );
|
// XMLElement *connection = xmlDoc.NewElement( "Instance" );
|
||||||
connection->SetAttribute("name", iter->second.c_str());
|
// connection->SetAttribute("name", iter->second.c_str());
|
||||||
connection->SetAttribute("id", iter->first);
|
// connection->SetAttribute("id", iter->first);
|
||||||
connectionsNode->InsertEndChild(connection);
|
// connectionsNode->InsertEndChild(connection);
|
||||||
}
|
// }
|
||||||
pRoot->InsertEndChild(connectionsNode);
|
pRoot->InsertEndChild(connectionsNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -346,13 +346,13 @@ void Settings::Load()
|
|||||||
XMLElement * pElement = pRoot->FirstChildElement("Connections");
|
XMLElement * pElement = pRoot->FirstChildElement("Connections");
|
||||||
if (pElement)
|
if (pElement)
|
||||||
{
|
{
|
||||||
XMLElement* connectionNode = pElement->FirstChildElement("Instance");
|
// XMLElement* connectionNode = pElement->FirstChildElement("Instance");
|
||||||
for( ; connectionNode ; connectionNode=connectionNode->NextSiblingElement())
|
// for( ; connectionNode ; connectionNode=connectionNode->NextSiblingElement())
|
||||||
{
|
// {
|
||||||
int id = 0;
|
// int id = 0;
|
||||||
connectionNode->QueryIntAttribute("id", &id);
|
// connectionNode->QueryIntAttribute("id", &id);
|
||||||
application.instance_names[id] = connectionNode->Attribute("name");
|
// application.instance_names[id] = connectionNode->Attribute("name");
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ struct Application
|
|||||||
|
|
||||||
// connection settings
|
// connection settings
|
||||||
bool accept_connections;
|
bool accept_connections;
|
||||||
std::map<int, std::string> instance_names;
|
// std::map<int, std::string> instance_names;
|
||||||
|
|
||||||
// Settings of widgets
|
// Settings of widgets
|
||||||
WidgetsConfig widget;
|
WidgetsConfig widget;
|
||||||
|
|||||||
15
Streamer.cpp
15
Streamer.cpp
@@ -44,6 +44,9 @@ void StreamingRequestListener::ProcessMessage( const osc::ReceivedMessage& m,
|
|||||||
|
|
||||||
if( std::strcmp( m.AddressPattern(), OSC_PREFIX OSC_STREAM_REQUEST) == 0 ){
|
if( std::strcmp( m.AddressPattern(), OSC_PREFIX OSC_STREAM_REQUEST) == 0 ){
|
||||||
|
|
||||||
|
#ifdef STREAMER_DEBUG
|
||||||
|
Log::Info("%s wants a stream.", sender);
|
||||||
|
#endif
|
||||||
osc::ReceivedMessage::const_iterator arg = m.ArgumentsBegin();
|
osc::ReceivedMessage::const_iterator arg = m.ArgumentsBegin();
|
||||||
int reply_to_port = (arg++)->AsInt32();
|
int reply_to_port = (arg++)->AsInt32();
|
||||||
const char *client_name = (arg++)->AsString();
|
const char *client_name = (arg++)->AsString();
|
||||||
@@ -51,19 +54,16 @@ void StreamingRequestListener::ProcessMessage( const osc::ReceivedMessage& m,
|
|||||||
Streaming::manager().addStream(sender, reply_to_port, client_name);
|
Streaming::manager().addStream(sender, reply_to_port, client_name);
|
||||||
else
|
else
|
||||||
Streaming::manager().refuseStream(sender, reply_to_port);
|
Streaming::manager().refuseStream(sender, reply_to_port);
|
||||||
#ifdef STREAMER_DEBUG
|
|
||||||
Log::Info("%s wants a stream.", sender);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else if( std::strcmp( m.AddressPattern(), OSC_PREFIX OSC_STREAM_DISCONNECT) == 0 ){
|
else if( std::strcmp( m.AddressPattern(), OSC_PREFIX OSC_STREAM_DISCONNECT) == 0 ){
|
||||||
|
|
||||||
osc::ReceivedMessage::const_iterator arg = m.ArgumentsBegin();
|
|
||||||
int port = (arg++)->AsInt32();
|
|
||||||
Streaming::manager().removeStream(sender, port);
|
|
||||||
|
|
||||||
#ifdef STREAMER_DEBUG
|
#ifdef STREAMER_DEBUG
|
||||||
Log::Info("%s does not need streaming anymore.", sender);
|
Log::Info("%s does not need streaming anymore.", sender);
|
||||||
#endif
|
#endif
|
||||||
|
osc::ReceivedMessage::const_iterator arg = m.ArgumentsBegin();
|
||||||
|
int port = (arg++)->AsInt32();
|
||||||
|
Streaming::manager().removeStream(sender, port);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch( osc::Exception& e ){
|
catch( osc::Exception& e ){
|
||||||
@@ -247,6 +247,7 @@ void Streaming::addStream(const std::string &sender, int reply_to, const std::st
|
|||||||
socket.Send( p.Data(), p.Size() );
|
socket.Send( p.Data(), p.Size() );
|
||||||
|
|
||||||
#ifdef STREAMER_DEBUG
|
#ifdef STREAMER_DEBUG
|
||||||
|
Log::Info("Replying to %s:%d", sender_ip.c_str(), reply_to);
|
||||||
Log::Info("Starting streaming to %s:%d", sender_ip.c_str(), conf.port);
|
Log::Info("Starting streaming to %s:%d", sender_ip.c_str(), conf.port);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user