YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
MjpegStream.h
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#ifndef MJPEGSTREAM_INC
7#define MJPEGSTREAM_INC
8
15#include <yarp/sig/Image.h>
17
18#include "MjpegDecompression.h"
19
22public:
26
27 void init(int len) {
28 // state that the following data is a list containing 1 blob
30 listLen = 1;
31 blobLen = len;
32 }
33
34};
36
41{
42private:
43 yarp::os::TwoWayStream *delegate;
48 BlobNetworkHeader blobHeader;
50 MjpegDecompression decompression;
51 int phase;
52 char *cursor;
53 int remaining;
54 bool autocompress;
55 yarp::os::Bytes envelope;
56public:
57 MjpegStream(TwoWayStream *delegate, bool autocompress) :
58 delegate(delegate),
59 blobHeader(BlobNetworkHeader{0,0,0}),
60 phase(0),
61 cursor(NULL),
62 remaining(0),
63 autocompress(autocompress)
64 {}
65
66 virtual ~MjpegStream() {
67 delete delegate;
68 }
69
70 yarp::os::InputStream& getInputStream() override { return *this; }
71 yarp::os::OutputStream& getOutputStream() override { return *this; }
72
73
74 const yarp::os::Contact& getLocalAddress() const override {
75 return delegate->getLocalAddress();
76 }
77
78 const yarp::os::Contact& getRemoteAddress() const override {
79 return delegate->getRemoteAddress();
80 }
81
82 bool isOk() const override {
83 return delegate->isOk();
84 }
85
86 void reset() override {
87 delegate->reset();
88 }
89
90 void close() override {
91 delegate->close();
92 }
93
94 void beginPacket() override {
95 delegate->beginPacket();
96 }
97
98 void endPacket() override {
99 delegate->endPacket();
100 }
101
103 void write(const yarp::os::Bytes& b) override;
104
107
108 void interrupt() override {
109 delegate->getInputStream().interrupt();
110 }
111
113 if (!autocompress) {
114 return false;
115 }
116 return decompression.setReadEnvelopeCallback(callback, data);
117 }
118};
119
120#endif
#define BOTTLE_TAG_BLOB
Definition Bottle.h:27
#define BOTTLE_TAG_LIST
Definition Bottle.h:28
yarp::os::NetInt32 blobLen
Definition MjpegStream.h:25
yarp::os::NetInt32 listTag
Definition MjpegStream.h:23
yarp::os::NetInt32 listLen
Definition MjpegStream.h:24
void init(int len)
Definition MjpegStream.h:27
bool setReadEnvelopeCallback(yarp::os::InputStream::readEnvelopeCallbackType callback, void *data)
void write(const yarp::os::Bytes &b) override
Write a block of bytes to the stream.
yarp::os::InputStream & getInputStream() override
Get an InputStream to read from.
Definition MjpegStream.h:70
bool isOk() const override
Check if the stream is ok or in an error state.
Definition MjpegStream.h:82
void endPacket() override
Mark the end of a logical packet (see beginPacket).
Definition MjpegStream.h:98
virtual ~MjpegStream()
Definition MjpegStream.h:66
MjpegStream(TwoWayStream *delegate, bool autocompress)
Definition MjpegStream.h:57
yarp::os::OutputStream & getOutputStream() override
Get an OutputStream to write to.
Definition MjpegStream.h:71
bool setReadEnvelopeCallback(yarp::os::InputStream::readEnvelopeCallbackType callback, void *data) override
Install a callback that the InputStream will have to call when the envelope is read from a message in...
const yarp::os::Contact & getRemoteAddress() const override
Get the address of the remote side of the stream.
Definition MjpegStream.h:78
void close() override
Terminate the stream.
Definition MjpegStream.h:90
void beginPacket() override
Mark the beginning of a logical packet.
Definition MjpegStream.h:94
void reset() override
Reset the stream.
Definition MjpegStream.h:86
void interrupt() override
Interrupt the stream.
const yarp::os::Contact & getLocalAddress() const override
Get the address of the local side of the stream.
Definition MjpegStream.h:74
void interrupt() override
Interrupt any current reads or writes attached to the port.
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.
void(* readEnvelopeCallbackType)(void *, const yarp::os::Bytes &envelope)
Callback type for setting the envelope from a message in carriers that cannot be escaped.
An abstraction for a block of bytes, with optional responsibility for allocating/destroying that bloc...
Simple specification of the minimum functions needed from output streams.
virtual void write(char ch)
Write a single byte to the stream.
An InputStream that reads from a string.
An OutputStream that produces a string.
A stream which can be asked to perform bidirectional communication.
virtual InputStream & getInputStream()=0
Get an InputStream to read from.
virtual const Contact & getRemoteAddress() const =0
Get the address of the remote side of the stream.
virtual void endPacket()=0
Mark the end of a logical packet (see beginPacket).
virtual void close()=0
Terminate the stream.
virtual void reset()=0
Reset the stream.
virtual void beginPacket()=0
Mark the beginning of a logical packet.
virtual bool isOk() const =0
Check if the stream is ok or in an error state.
virtual const Contact & getLocalAddress() const =0
Get the address of the local side of the stream.
Image class with user control of representation details.
Definition Image.h:363
Byte order in image header for network transmission.
::ssize_t ssize_t
Definition numeric.h:86
std::int32_t NetInt32
Definition of the NetInt32 type.
Definition NetInt32.h:29
#define YARP_END_PACK
Ends 1 byte packing for structs/classes.
Definition system.h:193
#define YARP_BEGIN_PACK
Starts 1 byte packing for structs/classes.
Definition system.h:192