YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
GstreamerCarrier.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2024-2024 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#include "GstreamerCarrier.h"
7#include "GstreamerStream.h"
8
10#include <yarp/os/Log.h>
11#include <yarp/os/LogStream.h>
12#include <yarp/os/Name.h>
13#include <yarp/os/Route.h>
15
16#include <string>
17
18using namespace yarp::os;
19
21 "yarp.carrier.gstreamer.gstreamerCarrier",
25 nullptr)
26
28
29yarp::os::Carrier* GstreamerCarrier::create() const
30{
31 return new GstreamerCarrier();
32}
33
34std::string GstreamerCarrier::getName() const
35{
36 return "gstreamer";
37}
38
40{
41 return true;
42}
43
45{
46}
47
49{
50 YARP_UNUSED(header);
51}
52
54{
55 return true;
56}
57
58
60{
61 auto* stream = new GstreamerStream();
62 yAssert(stream != nullptr);
63
64 Contact remote = proto.getStreams().getRemoteAddress();
65 bool ok = stream->open(this->pipeline_string,remote);
66 if (!ok) {
67 delete stream;
68 return false;
69 }
70
71 int myPort = stream->getLocalAddress().getPort();
72 proto.takeStreams(stream);
73
74 return true;
75}
76
78{
79 auto* stream = new GstreamerStream();
80 if (stream == nullptr) {
81 return false;
82 }
83
84 yarp::os::Contact remote = proto.getStreams().getRemoteAddress();
85 bool ok = stream->open(this->pipeline_string,remote);
86
87 // std::cout << "Remote contact info: host=" << proto.getRoute().getToContact().getHost() << " port= " << proto.getRoute().getToContact().getPort() <<std::endl;
88 if (!ok) {
89 delete stream;
90 return false;
91 }
92
93 proto.takeStreams(stream);
94 return true;
95}
96
99{
100 // get all parameters of this carrier
101 yarp::os::Name n(proto.getRoute().getCarrierName() + "://test");
102
103 // default pipeline
104 pipeline_string = "udpsrc port = 15001 caps = \"application/x-rtp, media = (string)video, encoding-name = (string)H264, payload = (int)96 \" ! rtph264depay ! h264parse ! avdec_h264 ";
105
106 bool has_pipeline_field = false;
107 bool has_pipeline_env = false;
108
109 //check for pipelineCmd option
110 //BEWARE: The following code is not usable, since yarp connect does not currently support
111 //spaces in the command line. Maybe in the future...
112 {
113 std::string tmp_pipeline_string = n.getCarrierModifier("pipelineCmd", &has_pipeline_field);
114
116 {
117 pipeline_string = tmp_pipeline_string;
118 yCDebug(GSTREAMER_CARRIER, "Using pipeline from command line: %s", pipeline_string.c_str());
119 }
120 }
121
122 //check for pipelineEnv option
123 {
124 std::string tmp_pipeline_env_string = n.getCarrierModifier("pipelineEnv", &has_pipeline_env);
125
126 if (has_pipeline_env) {
127 const char* env_p = std::getenv(tmp_pipeline_env_string.c_str());
128 if (env_p!=nullptr)
129 {
130 pipeline_string = env_p;
131 yCDebug(GSTREAMER_CARRIER, "Using pipeline from env: %s", pipeline_string.c_str());
132 }
133 }
134 }
135
136 if (has_pipeline_field == false &&
137 has_pipeline_env == false)
138 {
139 yCWarning(GSTREAMER_CARRIER, "pipeline parameter not found! Using default test string");
140 }
141
142 return true;
143}
144
146{
147 return true;
148}
149
151{
152 return true;
153}
154
156{
157 return true;
158}
159
164
166{
167 return true;
168}
169
171{
172 return false;
173}
174
175std::string GstreamerCarrier::toString() const
176{
177 return "gstreamer_carrier";
178}
179
181{
182 return true;
183}
184
186{
187 return true;
188}
189
191{
192 return false;
193}
const yarp::os::LogComponent & GSTREAMER_CARRIER()
#define yAssert(x)
Definition Log.h:388
GstreamerCarrier.
bool sendAck(yarp::os::ConnectionState &proto) override
Send an acknowledgement, if needed for this carrier.
std::string getName() const override
Get the name of this connection type ("tcp", "mcast", "shmem", ...)
bool expectIndex(yarp::os::ConnectionState &proto) override
Expect a message header, if there is one for this carrier.
bool isConnectionless() const override
Check if this carrier is connectionless (like udp, mcast) or connection based (like tcp).
bool prepareSend(yarp::os::ConnectionState &proto) override
Perform any initialization needed before writing on a connection.
bool expectReplyToHeader(yarp::os::ConnectionState &proto) override
Process reply to header, if one is expected for this carrier.
bool sendHeader(yarp::os::ConnectionState &proto) override
Write a header appropriate to the carrier to the connection, followed by any carrier-specific data.
bool reply(yarp::os::ConnectionState &proto, yarp::os::SizedWriter &writer) override
bool expectExtraHeader(yarp::os::ConnectionState &proto) override
Receive any carrier-specific header.
bool respondToHeader(yarp::os::ConnectionState &proto) override
Respond to the header.
yarp::os::Face * createFace() const override
Create new Face object that the carrier needs.
bool expectAck(yarp::os::ConnectionState &proto) override
Receive an acknowledgement, if expected for this carrier.
bool checkHeader(const yarp::os::Bytes &header) override
Given the first 8 bytes received on a connection, decide if this is the right carrier type to use for...
void setParameters(const yarp::os::Bytes &header) override
Configure this carrier based on the first 8 bytes of the connection.
void getHeader(yarp::os::Bytes &header) const override
Provide 8 bytes describing this connection sufficiently to allow the other side of a connection to se...
bool expectSenderSpecifier(yarp::os::ConnectionState &proto) override
Expect the name of the sending port.
std::string toString() const override
Get name of carrier.
bool write(yarp::os::ConnectionState &proto, yarp::os::SizedWriter &writer) override
Write a message.
A mini-server for performing network communication in the background.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
A simple abstraction for a block of bytes.
Definition Bytes.h:24
A base class for connection types (tcp, mcast, shmem, ...) which are called carriers in YARP.
Definition Carrier.h:44
The basic state of a connection - route, streams in use, etc.
virtual const Route & getRoute() const =0
Get the route associated with this connection.
virtual void takeStreams(TwoWayStream *streams)=0
Provide streams to be used with the connection.
virtual TwoWayStream & getStreams()=0
Access the streams associated with the connection.
Represents how to reach a part of a YARP network.
Definition Contact.h:33
The initial point-of-contact with a port.
Definition Face.h:20
static LogCallback printCallback()
Get current print callback.
Definition Log.cpp:873
static LogType minimumPrintLevel()
Get current minimum print level.
Definition Log.cpp:833
@ LogTypeReserved
Definition Log.h:98
Simple abstraction for a YARP port name.
Definition Name.h:18
Minimal requirements for an efficient Writer.
Definition SizedWriter.h:32
A dummy Face for testing purposes.
Definition FakeFace.h:19
#define yCWarning(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
An interface to the operating system, including Port based communication.
The main, catch-all namespace for YARP.
Definition dirs.h:16
#define YARP_UNUSED(var)
Definition api.h:162