YARP
Yet Another Robot Platform
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
19
20#include "MjpegDecompression.h"
21
26{
27private:
28 yarp::os::TwoWayStream *delegate;
35 MjpegDecompression decompression;
36 int phase;
37 char *cursor;
38 int remaining;
39 bool autocompress;
40 yarp::os::Bytes envelope;
41public:
42 MjpegStream(TwoWayStream *delegate, bool autocompress) :
43 delegate(delegate),
44 blobHeader(yarp::wire_rep_utils::BlobNetworkHeader{0,0,0}),
45 phase(0),
46 cursor(NULL),
47 remaining(0),
48 autocompress(autocompress)
49 {}
50
51 virtual ~MjpegStream() {
52 delete delegate;
53 }
54
55 yarp::os::InputStream& getInputStream() override { return *this; }
56 yarp::os::OutputStream& getOutputStream() override { return *this; }
57
58
59 const yarp::os::Contact& getLocalAddress() const override {
60 return delegate->getLocalAddress();
61 }
62
63 const yarp::os::Contact& getRemoteAddress() const override {
64 return delegate->getRemoteAddress();
65 }
66
67 bool isOk() const override {
68 return delegate->isOk();
69 }
70
71 void reset() override {
72 delegate->reset();
73 }
74
75 void close() override {
76 delegate->close();
77 }
78
79 void beginPacket() override {
80 delegate->beginPacket();
81 }
82
83 void endPacket() override {
84 delegate->endPacket();
85 }
86
88 void write(const yarp::os::Bytes& b) override;
89
92
93 void interrupt() override {
94 delegate->getInputStream().interrupt();
95 }
96
98 if (!autocompress) {
99 return false;
100 }
101 return decompression.setReadEnvelopeCallback(callback, data);
102 }
103};
104
105#endif
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:55
bool isOk() const override
Check if the stream is ok or in an error state.
Definition: MjpegStream.h:67
void endPacket() override
Mark the end of a logical packet (see beginPacket).
Definition: MjpegStream.h:83
virtual ~MjpegStream()
Definition: MjpegStream.h:51
MjpegStream(TwoWayStream *delegate, bool autocompress)
Definition: MjpegStream.h:42
yarp::os::OutputStream & getOutputStream() override
Get an OutputStream to write to.
Definition: MjpegStream.h:56
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...
Definition: MjpegStream.h:97
const yarp::os::Contact & getRemoteAddress() const override
Get the address of the remote side of the stream.
Definition: MjpegStream.h:63
void close() override
Terminate the stream.
Definition: MjpegStream.h:75
void beginPacket() override
Mark the beginning of a logical packet.
Definition: MjpegStream.h:79
void reset() override
Reset the stream.
Definition: MjpegStream.h:71
void interrupt() override
Interrupt the stream.
Definition: MjpegStream.h:93
const yarp::os::Contact & getLocalAddress() const override
Get the address of the local side of the stream.
Definition: MjpegStream.h:59
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.
Definition: InputStream.cpp:20
void(* readEnvelopeCallbackType)(void *, const yarp::os::Bytes &envelope)
Callback type for setting the envelope from a message in carriers that cannot be escaped.
Definition: InputStream.h:124
virtual void interrupt()
Interrupt the stream.
Definition: InputStream.cpp:42
An abstraction for a block of bytes, with optional responsibility for allocating/destroying that bloc...
Definition: ManagedBytes.h:21
Simple specification of the minimum functions needed from output streams.
Definition: OutputStream.h:21
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.
Definition: TwoWayStream.h:25
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:411
Byte order in image header for network transmission.
::ssize_t ssize_t
Definition: numeric.h:86
The main, catch-all namespace for YARP.
Definition: dirs.h:16