24#pragma warning (disable : 4091)
60#ifdef LIBJPEG_TURBO_VERSION
78 struct jpeg_destination_mgr
pub;
90 constexpr size_t hdr_size = 1000;
92 const char *brk =
"\r\n";
93 std::snprintf(hdr, hdr_size,
"Content-Type: image/jpeg%s\
94Content-Length: %d%s%s", brk, len, brk, brk);
95 Bytes hbuf(hdr,strlen(hdr));
97 Bytes buf((
char *)data,len);
109 std::snprintf(hdr, hdr_size,
"%s--boundarydonotcross%s", brk, brk);
110 Bytes hbuf2(hdr,strlen(hdr));
111 p->os().write(hbuf2);
118 dest->buffer = &(dest->cache[0]);
119 dest->bufsize =
sizeof(dest->cache);
120 dest->pub.next_output_byte = dest->buffer;
121 dest->pub.free_in_buffer = dest->bufsize;
127 send_net_data(dest->buffer,dest->bufsize-dest->pub.free_in_buffer,
129 dest->pub.next_output_byte = dest->buffer;
130 dest->pub.free_in_buffer = dest->bufsize;
137 send_net_data(dest->buffer,dest->bufsize-dest->pub.free_in_buffer,
149 if (cinfo->dest ==
nullptr) {
150 cinfo->dest = (
struct jpeg_destination_mgr *)
151 (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
165 if (img ==
nullptr) {
168 int w = img->
width();
173 JSAMPROW row_pointer[1];
175 struct jpeg_compress_struct cinfo;
176 struct jpeg_error_mgr jerr;
177 cinfo.err = jpeg_std_error(&jerr);
178 cinfo.client_data = &proto;
179 jpeg_create_compress(&cinfo);
181 cinfo.image_width = w;
182 cinfo.image_height = h;
183#ifndef LIBJPEG_TURBO_VERSION
187 yCTrace(
MJPEGCARRIER,
"Pixel format not supported, please compile YARP with libjpeg-turbo to support it.");
193 jpeg_set_defaults(&cinfo);
196 jpeg_start_compress(&cinfo, TRUE);
197 if(!envelope.empty()) {
198 jpeg_write_marker(&cinfo, JPEG_COM,
reinterpret_cast<const JOCTET*
>(envelope.c_str()), envelope.length() + 1);
202 while (cinfo.next_scanline < cinfo.image_height) {
204 row_pointer[0] = data + cinfo.next_scanline * row_stride;
205 jpeg_write_scanlines(&cinfo, row_pointer, 1);
207 jpeg_finish_compress(&cinfo);
208 jpeg_destroy_compress(&cinfo);
221 std::string target =
"GET /?action=stream\n\n";
226 target +=
" HTTP/1.1\n";
234 Bytes b((
char*)target.c_str(),target.length());
240#ifdef MJPEG_AUTOCOMPRESS
static const std::map< int, int > yarpCode2Channels
static boolean empty_net_output_buffer(j_compress_ptr cinfo)
static const std::map< int, J_COLOR_SPACE > yarpCode2Mjpeg
void jpeg_net_dest(j_compress_ptr cinfo)
net_destination_mgr * net_destination_ptr
static void init_net_destination(j_compress_ptr cinfo)
void send_net_data(JOCTET *data, int len, void *client)
static void term_net_destination(j_compress_ptr cinfo)
const yarp::os::LogComponent & MJPEGCARRIER()
virtual bool autoCompression() const
bool reply(yarp::os::ConnectionState &proto, yarp::os::SizedWriter &writer) override
bool write(yarp::os::ConnectionState &proto, yarp::os::SizedWriter &writer) override
Write a message.
bool sendHeader(yarp::os::ConnectionState &proto) override
Write a header appropriate to the carrier to the connection, followed by any carrier-specific data.
A simple abstraction for a block of bytes.
The basic state of a connection - route, streams in use, etc.
OutputStream & os()
Shorthand for getOutputStream()
virtual const Route & getRoute() const =0
Get the route associated with this connection.
Simple abstraction for a YARP port name.
std::string getCarrierModifier(const char *mod, bool *hasModifier=nullptr)
virtual void write(char ch)
Write a single byte to the stream.
const std::string & getCarrierName() const
Get the carrier type of the route.
const Contact & getToContact() const
Get the destination contact of the route, if available.
Minimal requirements for an efficient Writer.
Image class with user control of representation details.
size_t width() const
Gets width of image in pixels.
size_t getRowSize() const
Size of the underlying image buffer rows.
unsigned char * getRawImage() const
Access to the internal image buffer.
size_t height() const
Gets height of image in pixels.
virtual int getPixelCode() const
Gets pixel type identifier.
yarp::sig::FlexImage * checkForImage(yarp::os::SizedWriter &writer)
#define yCTrace(component,...)
#define yCWarning(component,...)
An interface to the operating system, including Port based communication.
struct jpeg_destination_mgr pub