2
* Copyright (C) 2015 Canonical, Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 3, as published
6
* by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License along
14
* with this program. If not, see <http://www.gnu.org/licenses/>.
23
#include "testsourcemediamanager.h"
27
#include "mcs/video/videoformat.h"
30
std::shared_ptr<TestSourceMediaManager> TestSourceMediaManager::create(const std::string &remote_address) {
31
return std::shared_ptr<TestSourceMediaManager>{new TestSourceMediaManager{remote_address}};
34
TestSourceMediaManager::TestSourceMediaManager(const std::string &remote_address) :
35
remote_address_(remote_address) {
38
TestSourceMediaManager::~TestSourceMediaManager() {
41
SharedGObject<GstElement> TestSourceMediaManager::ConstructPipeline(const wds::H264VideoFormat &format) {
42
auto profile = mcs::video::ExtractH264Profile(format);
43
auto rr = mcs::video::ExtractRateAndResolution(format);
47
ss << Utils::Sprintf("videotestsrc ! video/x-raw,format=I420,framerate=%d/1,width=%d,height=%d,pixel-aspect-ratio=1/1 ! ", rr.framerate, rr.width, rr.height);
48
ss << "x264enc tune=zerolatency byte-stream=true ! ";
49
ss << Utils::Sprintf("video/x-h264,profile=%s ! ", profile.c_str());
50
ss << "mpegtsmux ! rtpmp2tpay ! ";
51
ss << Utils::Sprintf("udpsink name=sink host=%s port=%d", remote_address_.c_str(), sink_port1_);
55
ss << Utils::Sprintf("videoconvert ! video/x-raw,format=I420,framerate=%d/1,pixel-aspect-ratio=1/1 ! ", rr.framerate);
56
ss << Utils::Sprintf("videoscale ! video/x-raw,width=%d,height=%d ! ", rr.width, rr.height);
58
ss << "x264enc byte-stream=true tune=zerolatency interlaced=false ! ";
59
ss << Utils::Sprintf("video/x-h264,profile=%s !", profile.c_str());
60
ss << "mpegtsmux ! rtpmp2tpay ! ";
61
ss << Utils::Sprintf("udpsink name=sink host=%s port=%d", remote_address_.c_str(), sink_port1_);
64
DEBUG("pipeline: %s", ss.str());
66
GError *error = nullptr;
67
GstElement *pipeline = gst_parse_launch(ss.str().c_str(), &error);
69
ERROR("Failed to setup GStreamer pipeline: %s", error->message);
74
return make_shared_gobject(pipeline);