mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-17 05:09:58 +01:00
Fixed and unified implementation shmdata and video broadcast
This commit is contained in:
@@ -1,3 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of vimix - video live mixer
|
||||||
|
*
|
||||||
|
* **Copyright** (C) 2019-2022 Bruno Herbelin <bruno.herbelin@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
**/
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@@ -14,16 +33,18 @@
|
|||||||
#include "ShmdataBroadcast.h"
|
#include "ShmdataBroadcast.h"
|
||||||
|
|
||||||
// Test command
|
// Test command
|
||||||
// gst-launch-1.0 --gst-plugin-path=/usr/local/lib/gstreamer-1.0/ shmdatasrc socket-path=/tmp/vimix-feed ! videoconvert ! autovideosink
|
// gst-launch-1.0 --gst-plugin-path=/usr/local/lib/gstreamer-1.0/ shmdatasrc socket-path=/tmp/shmdata_vimix0 ! videoconvert ! autovideosink
|
||||||
|
|
||||||
|
std::string ShmdataBroadcast::shmdata_sink_ = "shmdatasink";
|
||||||
|
|
||||||
bool ShmdataBroadcast::available()
|
bool ShmdataBroadcast::available()
|
||||||
{
|
{
|
||||||
static bool _available = false;
|
|
||||||
|
|
||||||
// test for availability once on first run
|
// test for availability once on first run
|
||||||
static bool _tested = false;
|
static bool _available = false, _tested = false;
|
||||||
if (!_tested)
|
if (!_tested) {
|
||||||
_available = GstToolkit::has_feature("shmdatasink");
|
_available = GstToolkit::has_feature(ShmdataBroadcast::shmdata_sink_);
|
||||||
|
_tested = true;
|
||||||
|
}
|
||||||
|
|
||||||
return _available;
|
return _available;
|
||||||
}
|
}
|
||||||
@@ -45,14 +66,10 @@ std::string ShmdataBroadcast::init(GstCaps *caps)
|
|||||||
return std::string("Shmdata Broadcast : Invalid caps");
|
return std::string("Shmdata Broadcast : Invalid caps");
|
||||||
|
|
||||||
// create a gstreamer pipeline
|
// create a gstreamer pipeline
|
||||||
std::string description = "appsrc name=src ! queue ! shmdatasink socket-path=XXXX name=sink";
|
std::string description = "appsrc name=src ! queue ! ";
|
||||||
|
|
||||||
// change the placeholder to include the broadcast port
|
// complement pipeline with sink
|
||||||
std::string::size_type xxxx = description.find("XXXX");
|
description += ShmdataBroadcast::shmdata_sink_ + " name=sink";
|
||||||
if (xxxx != std::string::npos)
|
|
||||||
description.replace(xxxx, 4, socket_path_);
|
|
||||||
else
|
|
||||||
return std::string("Shmdata Broadcast : Failed to configure shared memory socket path.");
|
|
||||||
|
|
||||||
// parse pipeline descriptor
|
// parse pipeline descriptor
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
@@ -63,6 +80,11 @@ std::string ShmdataBroadcast::init(GstCaps *caps)
|
|||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// setup shm sink
|
||||||
|
g_object_set (G_OBJECT (gst_bin_get_by_name (GST_BIN (pipeline_), "sink")),
|
||||||
|
"socket-path", socket_path_.c_str(),
|
||||||
|
NULL);
|
||||||
|
|
||||||
// setup custom app source
|
// setup custom app source
|
||||||
src_ = GST_APP_SRC( gst_bin_get_by_name (GST_BIN (pipeline_), "src") );
|
src_ = GST_APP_SRC( gst_bin_get_by_name (GST_BIN (pipeline_), "src") );
|
||||||
if (src_) {
|
if (src_) {
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ private:
|
|||||||
std::string socket_path_;
|
std::string socket_path_;
|
||||||
std::atomic<bool> stopped_;
|
std::atomic<bool> stopped_;
|
||||||
|
|
||||||
|
static std::string shmdata_sink_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SHMDATABROADCAST_H
|
#endif // SHMDATABROADCAST_H
|
||||||
|
|||||||
@@ -1,3 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of vimix - video live mixer
|
||||||
|
*
|
||||||
|
* **Copyright** (C) 2019-2022 Bruno Herbelin <bruno.herbelin@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
**/
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@@ -21,9 +40,9 @@
|
|||||||
std::string VideoBroadcast::srt_sink_;
|
std::string VideoBroadcast::srt_sink_;
|
||||||
std::string VideoBroadcast::h264_encoder_;
|
std::string VideoBroadcast::h264_encoder_;
|
||||||
|
|
||||||
std::vector< std::pair<std::string, std::string> > pipeline_sink_ {
|
std::vector< std::string > pipeline_sink_ {
|
||||||
{"srtsink", "srtsink uri=srt://:XXXX name=sink"},
|
"srtsink",
|
||||||
{"srtserversink", "srtserversink uri=srt://:XXXX name=sink"}
|
"srtserversink"
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector< std::pair<std::string, std::string> > pipeline_encoder_ {
|
std::vector< std::pair<std::string, std::string> > pipeline_encoder_ {
|
||||||
@@ -42,8 +61,8 @@ bool VideoBroadcast::available()
|
|||||||
|
|
||||||
for (auto config = pipeline_sink_.cbegin();
|
for (auto config = pipeline_sink_.cbegin();
|
||||||
config != pipeline_sink_.cend() && srt_sink_.empty(); ++config) {
|
config != pipeline_sink_.cend() && srt_sink_.empty(); ++config) {
|
||||||
if ( GstToolkit::has_feature(config->first) ) {
|
if ( GstToolkit::has_feature(*config) ) {
|
||||||
srt_sink_ = config->second;
|
srt_sink_ = *config;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,14 +110,7 @@ std::string VideoBroadcast::init(GstCaps *caps)
|
|||||||
description += "video/x-h264, profile=high ! queue ! h264parse config-interval=-1 ! mpegtsmux ! ";
|
description += "video/x-h264, profile=high ! queue ! h264parse config-interval=-1 ! mpegtsmux ! ";
|
||||||
|
|
||||||
// complement pipeline with sink
|
// complement pipeline with sink
|
||||||
description += VideoBroadcast::srt_sink_;
|
description += VideoBroadcast::srt_sink_ + " name=sink";
|
||||||
|
|
||||||
// change the placeholder to include the broadcast port
|
|
||||||
std::string::size_type xxxx = description.find("XXXX");
|
|
||||||
if (xxxx != std::string::npos)
|
|
||||||
description.replace(xxxx, 4, std::to_string(port_));
|
|
||||||
else
|
|
||||||
return std::string("Video Broadcast : Failed to configure broadcast port.");
|
|
||||||
|
|
||||||
// parse pipeline descriptor
|
// parse pipeline descriptor
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
@@ -109,9 +121,10 @@ std::string VideoBroadcast::init(GstCaps *caps)
|
|||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Configure options
|
// setup SRT streaming sink properties (uri, latency)
|
||||||
// setup SRT streaming sink properties (latency)
|
std::string uri = "srt://:" + std::to_string(port_);
|
||||||
g_object_set (G_OBJECT (gst_bin_get_by_name (GST_BIN (pipeline_), "sink")),
|
g_object_set (G_OBJECT (gst_bin_get_by_name (GST_BIN (pipeline_), "sink")),
|
||||||
|
"uri", uri.c_str(),
|
||||||
"latency", 200,
|
"latency", 200,
|
||||||
"wait-for-connection", false,
|
"wait-for-connection", false,
|
||||||
NULL);
|
NULL);
|
||||||
|
|||||||
Reference in New Issue
Block a user