|
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
21 #define INT32 long // jpeg's definition
26 #pragma warning (push)
27 #pragma warning (disable : 4091)
77 struct jpeg_destination_mgr pub;
81 JOCTET cache[1000000];
89 constexpr
size_t hdr_size = 1000;
91 const char *brk =
"\r\n";
92 std::snprintf(hdr, hdr_size,
"Content-Type: image/jpeg%s\
93 Content-Length: %d%s%s", brk, len, brk, brk);
94 Bytes hbuf(hdr,strlen(hdr));
96 Bytes buf((
char *)data,len);
108 std::snprintf(hdr, hdr_size,
"%s--boundarydonotcross%s", brk, brk);
109 Bytes hbuf2(hdr,strlen(hdr));
110 p->os().write(hbuf2);
117 dest->buffer = &(dest->cache[0]);
118 dest->bufsize =
sizeof(dest->cache);
119 dest->pub.next_output_byte = dest->buffer;
120 dest->pub.free_in_buffer = dest->bufsize;
126 send_net_data(dest->buffer,dest->bufsize-dest->pub.free_in_buffer,
128 dest->pub.next_output_byte = dest->buffer;
129 dest->pub.free_in_buffer = dest->bufsize;
136 send_net_data(dest->buffer,dest->bufsize-dest->pub.free_in_buffer,
148 if (cinfo->dest ==
nullptr) {
149 cinfo->dest = (
struct jpeg_destination_mgr *)
150 (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
164 if (img==
nullptr)
return false;
165 int w = img->
width();
170 JSAMPROW row_pointer[1];
172 struct jpeg_compress_struct cinfo;
173 struct jpeg_error_mgr jerr;
174 cinfo.err = jpeg_std_error(&jerr);
175 cinfo.client_data = &proto;
176 jpeg_create_compress(&cinfo);
178 cinfo.image_width = w;
179 cinfo.image_height = h;
182 jpeg_set_defaults(&cinfo);
185 jpeg_start_compress(&cinfo, TRUE);
186 if(!envelope.empty()) {
187 jpeg_write_marker(&cinfo, JPEG_COM,
reinterpret_cast<const JOCTET*
>(envelope.c_str()), envelope.length() + 1);
191 while (cinfo.next_scanline < cinfo.image_height) {
193 row_pointer[0] = data + cinfo.next_scanline * row_stride;
194 jpeg_write_scanlines(&cinfo, row_pointer, 1);
196 jpeg_finish_compress(&cinfo);
197 jpeg_destroy_compress(&cinfo);
210 std::string target =
"GET /?action=stream\n\n";
215 target +=
" HTTP/1.1\n";
223 Bytes b((
char*)target.c_str(),target.length());
229 #ifdef MJPEG_AUTOCOMPRESS
const std::string & getCarrierName() const
Get the carrier type of the route.
#define yCWarning(component,...)
virtual void write(char ch)
Write a single byte to the stream.
bool sendHeader(yarp::os::ConnectionState &proto) override
Write a header appropriate to the carrier to the connection, followed by any carrier-specific data.
bool write(yarp::os::ConnectionState &proto, yarp::os::SizedWriter &writer) override
Write a message.
void send_net_data(JOCTET *data, int len, void *client)
size_t getRowSize() const
Size of the underlying image buffer rows.
size_t width() const
Gets width of image in pixels.
void jpeg_net_dest(j_compress_ptr cinfo)
OutputStream & os()
Shorthand for getOutputStream()
virtual const Route & getRoute() const =0
Get the route associated with this connection.
yarp::sig::FlexImage * checkForImage(yarp::os::SizedWriter &writer)
net_destination_mgr * net_destination_ptr
static const std::map< int, J_COLOR_SPACE > yarpCode2Mjpeg
const yarp::os::LogComponent & MJPEGCARRIER()
Image class with user control of representation details.
struct jpeg_destination_mgr pub
std::string getCarrierModifier(const char *mod, bool *hasModifier=nullptr)
size_t height() const
Gets height of image in pixels.
static void term_net_destination(j_compress_ptr cinfo)
static void init_net_destination(j_compress_ptr cinfo)
Simple abstraction for a YARP port name.
A simple abstraction for a block of bytes.
virtual bool autoCompression() const
bool reply(yarp::os::ConnectionState &proto, yarp::os::SizedWriter &writer) override
The basic state of a connection - route, streams in use, etc.
static boolean empty_net_output_buffer(j_compress_ptr cinfo)
An interface to the operating system, including Port based communication.
const Contact & getToContact() const
Get the destination contact of the route, if available.
#define yCTrace(component,...)
static const std::map< int, int > yarpCode2Channels
Minimal requirements for an efficient Writer.
unsigned char * getRawImage() const
Access to the internal image buffer.
virtual int getPixelCode() const
Gets pixel type identifier.