YARP
Yet Another Robot Platform
H264Carrier.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#include "H264Carrier.h"
7#include "H264Stream.h"
8#include "H264LogComponent.h"
9#include <yarp/os/Contact.h>
11#include <yarp/os/Name.h>
13#include <cstdio>
14
15
16using namespace yarp::os;
17using namespace yarp::sig;
18
19
20
21std::string H264Carrier::getName() const
22{
23 return "h264";
24}
25
27{
28 return true;
29}
30
32{
33 return true;
34}
35
37{
38 return true;
39}
40
42{
43 return false;
44}
45
47{
48 return false;
49}
50
51void H264Carrier::handleEnvelope(const std::string& envelope)
52{
53 this->envelope = envelope;
54}
55
57{
58 return false;
59}
60
62{
63 return false;
64}
65
67{
68 return false;
69}
70
71// this is important - flips expected flow of messages
73{
74 return false;
75}
76
77std::string H264Carrier::toString() const
78{
79 return "h264_carrier";
80}
81
82void H264Carrier::getHeader(Bytes& header) const
83{
84}
85
87{
88 return true;
89}
90
92{
93 // no parameters - no carrier variants
94 yCTrace(H264CARRIER, "setParameters");
95}
96
97
98static int getIntParam(Name &n, const char *param)
99{
100 bool hasField;
101 std::string strValue = n.getCarrierModifier(param, &hasField);
102 Value *v = Value::makeValue(strValue);
103 int intvalue = 0;
104 if((hasField) && v->isInt32())
105 {
106 intvalue = v->asInt32();
107 }
108
109 delete v;
110 return intvalue;
111}
112
113// Now, the initial hand-shaking
115{
116 //get all parameters of this carrier
117 Name n(proto.getRoute().getCarrierName() + "://test");
118
119 cfgParams.crop.left = getIntParam(n, "cropLeft");
120 cfgParams.crop.right = getIntParam(n, "cropRight");
121 cfgParams.crop.top = getIntParam(n, "cropTop");
122 cfgParams.crop.bottom = getIntParam(n, "cropBottom");
123 cfgParams.fps_max = getIntParam(n, "max_fps");
124 cfgParams.removeJitter = (getIntParam(n, "removeJitter") > 0) ? true : false;
125 return true;
126}
127
129{
130 yCTrace(H264CARRIER, "sendHeader");
131 return true;
132}
133
135{
136 yCTrace(H264CARRIER, "expectSenderSpecifier");
137 return true;
138}
139
141{
142 yCTrace(H264CARRIER, "expectExtraHeader");
143 return true;
144}
145
147{
148 yCTrace(H264CARRIER, "respondToHeader");
149 return true;
150}
151
153{
154 // I'm the receiver...
155
156 cfgParams.remotePort = proto.getRoute().getToContact().getPort();
157
158 auto* stream = new H264Stream(cfgParams);
159 if (stream==nullptr) { return false; }
160
162 bool ok = stream->open(remote);
163
164 //std::cout << "Remote contact info: host=" << proto.getRoute().getToContact().getHost() << " port= " << proto.getRoute().getToContact().getPort() <<std::endl;
165 if (!ok)
166 {
167 delete stream;
168 return false;
169 }
170 stream->start();
171
172 proto.takeStreams(stream);
173 return true;
174}
175
177{
178 return true;
179}
180
182{
183 //I should not be here: the carried doesn't perform writing
184 return false;
185}
186
188{
189 return false;
190}
191
193{
194 return true;
195}
196
198{
199 return true;
200}
201
203{
204 return true;
205}
206
208{
209 return true;
210}
211
213{
214 return {};
215}
216
218{
219 return new yarp::os::impl::FakeFace();
220}
static int getIntParam(Name &n, const char *param)
Definition: H264Carrier.cpp:98
const yarp::os::LogComponent & H264CARRIER()
bool respondToHeader(yarp::os::ConnectionState &proto) override
Respond to the header.
bool canEscape() const override
Check if carrier can encode administrative messages, as opposed to just user data.
Definition: H264Carrier.cpp:46
std::string getName() const override
Get the name of this connection type ("tcp", "mcast", "shmem", ...)
Definition: H264Carrier.cpp:21
bool write(yarp::os::ConnectionState &proto, yarp::os::SizedWriter &writer) override
Write a message.
bool expectSenderSpecifier(yarp::os::ConnectionState &proto) override
Expect the name of the sending port.
void handleEnvelope(const std::string &envelope) override
Carriers that do not distinguish data from administrative headers (i.e.
Definition: H264Carrier.cpp:51
bool isPush() const override
Check if carrier is "push" or "pull" style.
Definition: H264Carrier.cpp:72
bool expectIndex(yarp::os::ConnectionState &proto) override
Expect a message header, if there is one for this carrier.
virtual bool sendIndex(yarp::os::ConnectionState &proto, yarp::os::SizedWriter &writer)
bool isConnectionless() const override
Check if this carrier is connectionless (like udp, mcast) or connection based (like tcp).
Definition: H264Carrier.cpp:26
bool expectExtraHeader(yarp::os::ConnectionState &proto) override
Receive any carrier-specific header.
bool isTextMode() const override
Check if carrier is textual in nature.
Definition: H264Carrier.cpp:41
bool supportReply() const override
This flag is used by YARP to determine whether the connection can carry RPC traffic,...
Definition: H264Carrier.cpp:61
std::string toString() const override
Get name of carrier.
Definition: H264Carrier.cpp:77
void setParameters(const yarp::os::Bytes &header) override
Configure this carrier based on the first 8 bytes of the connection.
Definition: H264Carrier.cpp:91
bool prepareSend(yarp::os::ConnectionState &proto) override
Perform any initialization needed before writing on a connection.
bool isLocal() const override
Check if carrier operates within a single process.
Definition: H264Carrier.cpp:66
bool isActive() const override
Check if carrier is alive and error free.
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...
Definition: H264Carrier.cpp:82
bool reply(yarp::os::ConnectionState &proto, yarp::os::SizedWriter &writer) override
bool canOffer() const override
Check if writing is implemented for this carrier.
Definition: H264Carrier.cpp:36
std::string getBootstrapCarrierName() const override
Get the name of the carrier that should be used prior to handshaking, if a port is registered with th...
bool sendHeader(yarp::os::ConnectionState &proto) override
Write a header appropriate to the carrier to the connection, followed by any carrier-specific data.
bool requireAck() const override
Check if carrier has flow control, requiring sent messages to be acknowledged by recipient.
Definition: H264Carrier.cpp:56
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...
Definition: H264Carrier.cpp:86
bool expectReplyToHeader(yarp::os::ConnectionState &proto) override
Process reply to header, if one is expected for this carrier.
bool canAccept() const override
Check if reading is implemented for this carrier.
Definition: H264Carrier.cpp:31
bool sendAck(yarp::os::ConnectionState &proto) override
Send an acknowledgement, if needed for this carrier.
bool expectAck(yarp::os::ConnectionState &proto) override
Receive an acknowledgement, if expected for this carrier.
yarp::os::Face * createFace() const override
Create new Face object that the carrier needs.
A simple abstraction for a block of bytes.
Definition: Bytes.h:24
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
int getPort() const
Get the port number associated with this Contact for socket communication.
Definition: Contact.cpp:239
The initial point-of-contact with a port.
Definition: Face.h:20
Simple abstraction for a YARP port name.
Definition: Name.h:18
std::string getCarrierModifier(const char *mod, bool *hasModifier=nullptr)
Definition: Name.cpp:44
const std::string & getCarrierName() const
Get the carrier type of the route.
Definition: Route.cpp:123
const Contact & getToContact() const
Get the destination contact of the route, if available.
Definition: Route.cpp:113
Minimal requirements for an efficient Writer.
Definition: SizedWriter.h:32
virtual const Contact & getRemoteAddress() const =0
Get the address of the remote side of the stream.
A single value (typically within a Bottle).
Definition: Value.h:43
virtual std::int32_t asInt32() const
Get 32-bit integer value.
Definition: Value.cpp:204
virtual bool isInt32() const
Checks if value is a 32-bit integer.
Definition: Value.cpp:132
A dummy Face for testing purposes.
Definition: FakeFace.h:19
#define yCTrace(component,...)
Definition: LogComponent.h:84
An interface to the operating system, including Port based communication.
struct h264Decoder_cfgParamters::@91 crop