mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-12 02:40:00 +01:00
Finalizing NetworkSource (Visitors)
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
#include "SessionSource.h"
|
#include "SessionSource.h"
|
||||||
#include "PatternSource.h"
|
#include "PatternSource.h"
|
||||||
#include "DeviceSource.h"
|
#include "DeviceSource.h"
|
||||||
|
#include "NetworkSource.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "Mixer.h"
|
#include "Mixer.h"
|
||||||
#include "ActionManager.h"
|
#include "ActionManager.h"
|
||||||
@@ -532,3 +533,13 @@ void ImGuiVisitor::visit (DeviceSource& s)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ImGuiVisitor::visit (NetworkSource& s)
|
||||||
|
{
|
||||||
|
ImGuiToolkit::Icon(s.icon().x, s.icon().y);
|
||||||
|
ImGui::SameLine(0, 10);
|
||||||
|
ImGui::Text("Network connection");
|
||||||
|
|
||||||
|
ImGui::Text("Connected to %s", s.connection().c_str());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ public:
|
|||||||
void visit (CloneSource& s) override;
|
void visit (CloneSource& s) override;
|
||||||
void visit (PatternSource& s) override;
|
void visit (PatternSource& s) override;
|
||||||
void visit (DeviceSource& s) override;
|
void visit (DeviceSource& s) override;
|
||||||
|
void visit (NetworkSource& s) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // IMGUIVISITOR_H
|
#endif // IMGUIVISITOR_H
|
||||||
|
|||||||
@@ -172,32 +172,32 @@ void NetworkStream::update()
|
|||||||
receiver_->AsynchronousBreak();
|
receiver_->AsynchronousBreak();
|
||||||
|
|
||||||
#ifdef NETWORK_DEBUG
|
#ifdef NETWORK_DEBUG
|
||||||
Log::Info("Creating Network Stream %d %d x %d", config_.port, config_.width, config_.height);
|
Log::Info("Creating Network Stream %d (%d x %d)", config_.port, config_.width, config_.height);
|
||||||
#endif
|
#endif
|
||||||
// build the pipeline depending on stream info
|
// build the pipeline depending on stream info
|
||||||
std::ostringstream pipeline;
|
std::ostringstream pipeline;
|
||||||
if (config_.protocol == NetworkToolkit::UDP_JPEG || config_.protocol == NetworkToolkit::UDP_H264) {
|
|
||||||
|
|
||||||
pipeline << "udpsrc port=" << config_.port;
|
|
||||||
}
|
|
||||||
else if (config_.protocol == NetworkToolkit::TCP_JPEG || config_.protocol == NetworkToolkit::TCP_H264) {
|
|
||||||
|
|
||||||
pipeline << "tcpclientsrc timeout=1 port=" << config_.port;
|
|
||||||
}
|
|
||||||
else if (config_.protocol == NetworkToolkit::SHM_RAW) {
|
|
||||||
|
|
||||||
|
// get generic pipeline string
|
||||||
|
std::string pipelinestring = NetworkToolkit::protocol_receive_pipeline[config_.protocol];
|
||||||
|
// find placeholder for PORT
|
||||||
|
int xxxx = pipelinestring.find("XXXX");
|
||||||
|
// keep beginning of pipeline
|
||||||
|
pipeline << pipelinestring.substr(0, xxxx);
|
||||||
|
// Replace 'XXXX'
|
||||||
|
if (config_.protocol == NetworkToolkit::SHM_RAW) {
|
||||||
std::string path = SystemToolkit::full_filename(SystemToolkit::settings_path(), "shm");
|
std::string path = SystemToolkit::full_filename(SystemToolkit::settings_path(), "shm");
|
||||||
path += std::to_string(config_.port);
|
path += std::to_string(config_.port);
|
||||||
pipeline << "shmsrc is-live=true socket-path=" << path;
|
pipeline << path;
|
||||||
// TODO rename SHM socket "shm_PORT"
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
pipeline << NetworkToolkit::protocol_receive_pipeline[config_.protocol];
|
pipeline << config_.port;
|
||||||
|
// keep ending of pipeline
|
||||||
|
pipeline << pipelinestring.substr(xxxx + 4);
|
||||||
|
// add a videoconverter
|
||||||
pipeline << " ! videoconvert";
|
pipeline << " ! videoconvert";
|
||||||
|
|
||||||
// open the pipeline with generic stream class
|
// open the pipeline with generic stream class
|
||||||
Stream::open(pipeline.str(), config_.width, config_.height);
|
Stream::open(pipeline.str(), config_.width, config_.height);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,45 +1,20 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <algorithm>
|
||||||
#include <cstring>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <algorithm> // std::count
|
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <linux/netdevice.h>
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
//#include <netdb.h>
|
|
||||||
|
|
||||||
|
// TODO OSX implementation
|
||||||
|
#include <linux/netdevice.h>
|
||||||
|
|
||||||
|
// OSC IP gethostbyname
|
||||||
#include "ip/NetworkingUtils.h"
|
#include "ip/NetworkingUtils.h"
|
||||||
|
|
||||||
#include "NetworkToolkit.h"
|
#include "NetworkToolkit.h"
|
||||||
|
|
||||||
|
|
||||||
const char* NetworkToolkit::protocol_name[NetworkToolkit::DEFAULT] = {
|
|
||||||
"TCP Broadcast JPEG",
|
|
||||||
"TCP Broadcast H264",
|
|
||||||
"Shared Memory"
|
|
||||||
};
|
|
||||||
|
|
||||||
const std::vector<std::string> NetworkToolkit::protocol_send_pipeline {
|
|
||||||
|
|
||||||
"video/x-raw, format=I420, framerate=30/1 ! queue max-size-buffers=3 ! jpegenc ! rtpjpegpay ! udpsink name=sink",
|
|
||||||
"video/x-raw, format=I420, framerate=30/1 ! queue max-size-buffers=3 ! x264enc tune=\"zerolatency\" threads=2 ! rtph264pay ! udpsink name=sink",
|
|
||||||
"video/x-raw, format=RGB, framerate=30/1 ! queue max-size-buffers=3 ! shmsink buffer-time=100000 name=sink",
|
|
||||||
"video/x-raw, format=I420 ! queue max-size-buffers=3 ! jpegenc ! rtpjpegpay ! rtpstreampay ! tcpserversink name=sink",
|
|
||||||
"video/x-raw, format=I420 ! queue max-size-buffers=3 ! x264enc tune=\"zerolatency\" threads=2 ! rtph264pay ! rtpstreampay ! tcpserversink name=sink",
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
const std::vector<std::string> NetworkToolkit::protocol_receive_pipeline {
|
|
||||||
|
|
||||||
" ! application/x-rtp,encoding-name=JPEG,payload=26 ! rtpjpegdepay ! jpegdec",
|
|
||||||
" ! application/x-rtp,media=video,encoding-name=H264,payload=96,clock-rate=90000 ! rtph264depay ! avdec_h264",
|
|
||||||
" ! video/x-raw, format=RGB, framerate=30/1",
|
|
||||||
" ! application/x-rtp-stream,media=video,encoding-name=JPEG,payload=26 ! rtpstreamdepay ! rtpjpegdepay ! jpegdec",
|
|
||||||
" ! application/x-rtp-stream,media=video,encoding-name=H264,payload=96,clock-rate=90000 ! rtpstreamdepay ! rtph264depay ! avdec_h264",
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
*
|
*
|
||||||
* TCP Server JPEG : broadcast
|
* TCP Server JPEG : broadcast
|
||||||
@@ -82,6 +57,32 @@ const std::vector<std::string> NetworkToolkit::protocol_receive_pipeline {
|
|||||||
*
|
*
|
||||||
* */
|
* */
|
||||||
|
|
||||||
|
const char* NetworkToolkit::protocol_name[NetworkToolkit::DEFAULT] = {
|
||||||
|
"Shared Memory",
|
||||||
|
"UDP Broadcast JPEG",
|
||||||
|
"UDP Broadcast H264",
|
||||||
|
"TCP Broadcast JPEG",
|
||||||
|
"TCP Broadcast H264"
|
||||||
|
};
|
||||||
|
|
||||||
|
const std::vector<std::string> NetworkToolkit::protocol_send_pipeline {
|
||||||
|
|
||||||
|
"video/x-raw, format=RGB, framerate=30/1 ! queue max-size-buffers=3 ! shmsink buffer-time=100000 name=sink",
|
||||||
|
"video/x-raw, format=I420, framerate=30/1 ! queue max-size-buffers=3 ! jpegenc ! rtpjpegpay ! udpsink name=sink",
|
||||||
|
"video/x-raw, format=I420, framerate=30/1 ! queue max-size-buffers=3 ! x264enc tune=\"zerolatency\" threads=2 ! rtph264pay ! udpsink name=sink",
|
||||||
|
"video/x-raw, format=I420 ! queue max-size-buffers=3 ! jpegenc ! rtpjpegpay ! rtpstreampay ! tcpserversink name=sink",
|
||||||
|
"video/x-raw, format=I420 ! queue max-size-buffers=3 ! x264enc tune=\"zerolatency\" threads=2 ! rtph264pay ! rtpstreampay ! tcpserversink name=sink"
|
||||||
|
};
|
||||||
|
|
||||||
|
const std::vector<std::string> NetworkToolkit::protocol_receive_pipeline {
|
||||||
|
|
||||||
|
"shmsrc is-live=true socket-path=XXXX ! queue max-size-buffers=3 ! video/x-raw, format=RGB, framerate=30/1",
|
||||||
|
"udpsrc port=XXXX ! queue max-size-buffers=3 ! application/x-rtp,encoding-name=JPEG,payload=26 ! rtpjpegdepay ! jpegdec",
|
||||||
|
"udpsrc port=XXXX ! queue max-size-buffers=3 ! application/x-rtp,media=video,encoding-name=H264,payload=96,clock-rate=90000 ! 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"
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
std::vector<std::string> ipstrings;
|
std::vector<std::string> ipstrings;
|
||||||
std::vector<unsigned long> iplongs;
|
std::vector<unsigned long> iplongs;
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ namespace NetworkToolkit
|
|||||||
{
|
{
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
UDP_JPEG = 0,
|
SHM_RAW = 0,
|
||||||
|
UDP_JPEG,
|
||||||
UDP_H264,
|
UDP_H264,
|
||||||
SHM_RAW,
|
|
||||||
TCP_JPEG,
|
TCP_JPEG,
|
||||||
TCP_H264,
|
TCP_H264,
|
||||||
DEFAULT
|
DEFAULT
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "StreamSource.h"
|
#include "StreamSource.h"
|
||||||
#include "PatternSource.h"
|
#include "PatternSource.h"
|
||||||
#include "DeviceSource.h"
|
#include "DeviceSource.h"
|
||||||
|
#include "NetworkSource.h"
|
||||||
#include "Session.h"
|
#include "Session.h"
|
||||||
#include "ImageShader.h"
|
#include "ImageShader.h"
|
||||||
#include "ImageProcessingShader.h"
|
#include "ImageProcessingShader.h"
|
||||||
@@ -527,4 +528,14 @@ void SessionLoader::visit (DeviceSource& s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SessionLoader::visit (NetworkSource& s)
|
||||||
|
{
|
||||||
|
std::string connect = std::string ( xmlCurrent_->Attribute("connection") );
|
||||||
|
|
||||||
|
// change only if different device
|
||||||
|
if ( connect != s.connection() )
|
||||||
|
s.setConnection(connect);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ public:
|
|||||||
void visit (SessionSource& s) override;
|
void visit (SessionSource& s) override;
|
||||||
void visit (PatternSource& s) override;
|
void visit (PatternSource& s) override;
|
||||||
void visit (DeviceSource& s) override;
|
void visit (DeviceSource& s) override;
|
||||||
|
void visit (NetworkSource& s) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
tinyxml2::XMLElement *xmlCurrent_;
|
tinyxml2::XMLElement *xmlCurrent_;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "SessionSource.h"
|
#include "SessionSource.h"
|
||||||
#include "PatternSource.h"
|
#include "PatternSource.h"
|
||||||
#include "DeviceSource.h"
|
#include "DeviceSource.h"
|
||||||
|
#include "NetworkSource.h"
|
||||||
#include "ImageShader.h"
|
#include "ImageShader.h"
|
||||||
#include "ImageProcessingShader.h"
|
#include "ImageProcessingShader.h"
|
||||||
#include "MediaPlayer.h"
|
#include "MediaPlayer.h"
|
||||||
@@ -402,3 +403,9 @@ void SessionVisitor::visit (DeviceSource& s)
|
|||||||
xmlCurrent_->SetAttribute("type", "DeviceSource");
|
xmlCurrent_->SetAttribute("type", "DeviceSource");
|
||||||
xmlCurrent_->SetAttribute("device", s.device().c_str() );
|
xmlCurrent_->SetAttribute("device", s.device().c_str() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SessionVisitor::visit (NetworkSource& s)
|
||||||
|
{
|
||||||
|
xmlCurrent_->SetAttribute("type", "NetworkSource");
|
||||||
|
xmlCurrent_->SetAttribute("connection", s.connection().c_str() );
|
||||||
|
}
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ public:
|
|||||||
void visit (CloneSource& s) override;
|
void visit (CloneSource& s) override;
|
||||||
void visit (PatternSource& s) override;
|
void visit (PatternSource& s) override;
|
||||||
void visit (DeviceSource& s) override;
|
void visit (DeviceSource& s) override;
|
||||||
|
void visit (NetworkSource& s) override;
|
||||||
|
|
||||||
static tinyxml2::XMLElement *NodeToXML(Node &n, tinyxml2::XMLDocument *doc);
|
static tinyxml2::XMLElement *NodeToXML(Node &n, tinyxml2::XMLDocument *doc);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ void Streaming::addStream(const std::string &sender, int reply_to)
|
|||||||
else {
|
else {
|
||||||
conf.protocol = NetworkToolkit::UDP_JPEG;
|
conf.protocol = NetworkToolkit::UDP_JPEG;
|
||||||
}
|
}
|
||||||
// conf.protocol = NetworkToolkit::UDP_JPEG;
|
conf.protocol = NetworkToolkit::UDP_JPEG;
|
||||||
|
|
||||||
// build OSC message
|
// build OSC message
|
||||||
char buffer[IP_MTU_SIZE];
|
char buffer[IP_MTU_SIZE];
|
||||||
@@ -269,11 +269,12 @@ void VideoStreamer::addFrame (FrameBuffer *frame_buffer, float dt)
|
|||||||
glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo_[0]);
|
glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo_[0]);
|
||||||
glBufferData(GL_PIXEL_PACK_BUFFER, size_, NULL, GL_STREAM_READ);
|
glBufferData(GL_PIXEL_PACK_BUFFER, size_, NULL, GL_STREAM_READ);
|
||||||
|
|
||||||
// create a gstreamer pipeline
|
// prevent eroneous protocol values
|
||||||
std::string description = "appsrc name=src ! videoconvert ! ";
|
|
||||||
|
|
||||||
if (config_.protocol < 0 || config_.protocol >= NetworkToolkit::DEFAULT)
|
if (config_.protocol < 0 || config_.protocol >= NetworkToolkit::DEFAULT)
|
||||||
config_.protocol = NetworkToolkit::UDP_JPEG;
|
config_.protocol = NetworkToolkit::UDP_JPEG;
|
||||||
|
|
||||||
|
// create a gstreamer pipeline
|
||||||
|
std::string description = "appsrc name=src ! videoconvert ! ";
|
||||||
description += NetworkToolkit::protocol_send_pipeline[config_.protocol];
|
description += NetworkToolkit::protocol_send_pipeline[config_.protocol];
|
||||||
|
|
||||||
// parse pipeline descriptor
|
// parse pipeline descriptor
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ class GenericStreamSource;
|
|||||||
class SessionSource;
|
class SessionSource;
|
||||||
class RenderSource;
|
class RenderSource;
|
||||||
class CloneSource;
|
class CloneSource;
|
||||||
|
class NetworkSource;
|
||||||
|
|
||||||
// Declares the interface for the visitors
|
// Declares the interface for the visitors
|
||||||
class Visitor {
|
class Visitor {
|
||||||
@@ -66,6 +67,7 @@ public:
|
|||||||
// utility
|
// utility
|
||||||
virtual void visit (Source&) {}
|
virtual void visit (Source&) {}
|
||||||
virtual void visit (MediaSource&) {}
|
virtual void visit (MediaSource&) {}
|
||||||
|
virtual void visit (NetworkSource&) {}
|
||||||
virtual void visit (GenericStreamSource&) {}
|
virtual void visit (GenericStreamSource&) {}
|
||||||
virtual void visit (DeviceSource&) {}
|
virtual void visit (DeviceSource&) {}
|
||||||
virtual void visit (PatternSource&) {}
|
virtual void visit (PatternSource&) {}
|
||||||
|
|||||||
Reference in New Issue
Block a user