YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
GstreamerStream.h
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#ifndef YARP_GSTREAMERTREAM_H
7#define YARP_GSTREAMERTREAM_H
8
9#include <yarp/os/Contact.h>
12#include "GstreamerDecoder.h"
13
14#include <yarp/sig/Image.h>
16
17#include <cstdlib>
18#include <mutex>
19
24{
25private:
26 GstYarpDecoder* m_decoder = nullptr;
27
28public:
30 m_closed(false),
31 m_interrupting(false),
32 m_mutex()
33 {
34 }
35
36 virtual bool open(const std::string& pipeline_string, const yarp::os::Contact& remote);
37
38 virtual bool open(const std::string& pipeline_string, const yarp::os::Contact& local, const yarp::os::Contact& remote);
39
40 virtual ~GstreamerStream();
41
43 {
44 return *this;
45 }
46
47 OutputStream& getOutputStream() override
48 {
49 return *this;
50 }
51
52 const yarp::os::Contact& getLocalAddress() const override
53 {
54 return m_localAddress;
55 }
56
57 const yarp::os::Contact& getRemoteAddress() const override
58 {
59 return m_remoteAddress;
60 }
61
63 void prepareNextFrame();
64
65 void interrupt() override;
66
67 void close() override
68 {
69 closeMain();
70 }
71
72 virtual void closeMain();
73
74 bool isOk() const override;
75
78
80 void write(const yarp::os::Bytes& b) override;
81
82 void reset() override;
83
84 void beginPacket() override;
85
86 void endPacket() override;
87
88private:
89 bool m_closed, m_interrupting;
90
91 yarp::sig::ImageOf<yarp::sig::PixelRgb>* m_pointer_last_frame=nullptr;
93 enum class enum_phases
94 {
95 PHASE_0_GET_IMG = 0,
96 PHASE_1_PREPARE_HEADER = 1,
97 PHASE_2_SEND_HEADER = 2,
98 PHASE_3_SEND_IMAGE = 3
99 } m_enum_phases = enum_phases::PHASE_0_GET_IMG;
100
101 bool m_debug_test_image_generation = false;
102
103 yarp::os::Contact m_localAddress, m_remoteAddress;
104 std::mutex m_mutex;
105 yarp::os::Semaphore m_sema;
106
107 char* m_cursor = nullptr;
108 size_t m_remaining = 0;
109
110};
111
112#endif
void reset() override
Reset the stream.
void close() override
Terminate the stream.
void interrupt() override
Interrupt the stream.
void beginPacket() override
Mark the beginning of a logical packet.
yarp::sig::ImageOf< yarp::sig::PixelRgb > * getFrame()
bool isOk() const override
Check if the stream is ok or in an error state.
virtual ~GstreamerStream()
const yarp::os::Contact & getLocalAddress() const override
Get the address of the local side of the stream.
virtual bool open(const std::string &pipeline_string, const yarp::os::Contact &remote)
virtual void closeMain()
void endPacket() override
Mark the end of a logical packet (see beginPacket).
OutputStream & getOutputStream() override
Get an OutputStream to write to.
InputStream & getInputStream() override
Get an InputStream to read from.
const yarp::os::Contact & getRemoteAddress() const override
Get the address of the remote side of the stream.
void write(const yarp::os::Bytes &b) override
Write a block of bytes to the stream.
A simple abstraction for a block of bytes.
Definition Bytes.h:24
Represents how to reach a part of a YARP network.
Definition Contact.h:33
Simple specification of the minimum functions needed from input streams.
Definition InputStream.h:25
virtual int read()
Read and return a single byte.
InputStream()
Constructor.
Simple specification of the minimum functions needed from output streams.
virtual void write(char ch)
Write a single byte to the stream.
A class for thread synchronization and mutual exclusion.
Definition Semaphore.h:25
A stream which can be asked to perform bidirectional communication.
Byte order in image header for network transmission.
Typed image class.
Definition Image.h:605
::ssize_t ssize_t
Definition numeric.h:86