23 #pragma warning (push)
24 #pragma warning (disable : 4091)
74 struct jpeg_destination_mgr pub;
78 JOCTET cache[1000000];
86 constexpr
size_t hdr_size = 1000;
88 const char *brk =
"\r\n";
89 std::snprintf(hdr, hdr_size,
"Content-Type: image/jpeg%s\
90 Content-Length: %d%s%s", brk, len, brk, brk);
91 Bytes hbuf(hdr,strlen(hdr));
93 Bytes buf((
char *)data,len);
105 std::snprintf(hdr, hdr_size,
"%s--boundarydonotcross%s", brk, brk);
106 Bytes hbuf2(hdr,strlen(hdr));
107 p->os().write(hbuf2);
114 dest->buffer = &(dest->cache[0]);
115 dest->bufsize =
sizeof(dest->cache);
116 dest->pub.next_output_byte = dest->buffer;
117 dest->pub.free_in_buffer = dest->bufsize;
123 send_net_data(dest->buffer,dest->bufsize-dest->pub.free_in_buffer,
125 dest->pub.next_output_byte = dest->buffer;
126 dest->pub.free_in_buffer = dest->bufsize;
133 send_net_data(dest->buffer,dest->bufsize-dest->pub.free_in_buffer,
145 if (cinfo->dest ==
nullptr) {
146 cinfo->dest = (
struct jpeg_destination_mgr *)
147 (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
161 if (img ==
nullptr) {
164 int w = img->
width();
169 JSAMPROW row_pointer[1];
171 struct jpeg_compress_struct cinfo;
172 struct jpeg_error_mgr jerr;
173 cinfo.err = jpeg_std_error(&jerr);
174 cinfo.client_data = &proto;
175 jpeg_create_compress(&cinfo);
177 cinfo.image_width = w;
178 cinfo.image_height = h;
181 jpeg_set_defaults(&cinfo);
184 jpeg_start_compress(&cinfo, TRUE);
185 if(!envelope.empty()) {
186 jpeg_write_marker(&cinfo, JPEG_COM,
reinterpret_cast<const JOCTET*
>(envelope.c_str()), envelope.length() + 1);
190 while (cinfo.next_scanline < cinfo.image_height) {
192 row_pointer[0] = data + cinfo.next_scanline * row_stride;
193 jpeg_write_scanlines(&cinfo, row_pointer, 1);
195 jpeg_finish_compress(&cinfo);
196 jpeg_destroy_compress(&cinfo);
209 std::string target =
"GET /?action=stream\n\n";
214 target +=
" HTTP/1.1\n";
222 Bytes b((
char*)target.c_str(),target.length());
228 #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.
virtual const Route & getRoute() const =0
Get the route associated with this connection.
OutputStream & os()
Shorthand for getOutputStream()
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