Fixed issue with killed mjpeg_stream

pull/2514/head
AlexeyAB 6 years ago
parent ec1b66ace2
commit 50956447f8
  1. 8
      src/demo.c
  2. 46
      src/http_stream.cpp
  3. 2
      src/image.c

@ -129,7 +129,7 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int
demo_ext_output = ext_output; demo_ext_output = ext_output;
demo_json_port = json_port; demo_json_port = json_port;
printf("Demo\n"); printf("Demo\n");
net = parse_network_cfg_custom(cfgfile, 1, 0); // set batch=1 net = parse_network_cfg_custom(cfgfile, 1, 1); // set batch=1
if(weightfile){ if(weightfile){
load_weights(&net, weightfile); load_weights(&net, weightfile);
} }
@ -237,7 +237,7 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int
++frame_id; ++frame_id;
if (demo_json_port > 0) { if (demo_json_port > 0) {
int timeout = 200; int timeout = 400000;
send_json(local_dets, local_nboxes, l.classes, demo_names, frame_id, demo_json_port, timeout); send_json(local_dets, local_nboxes, l.classes, demo_names, frame_id, demo_json_port, timeout);
} }
@ -268,8 +268,8 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int
// if you run it with param -mjpeg_port 8090 then open URL in your web-browser: http://localhost:8090 // if you run it with param -mjpeg_port 8090 then open URL in your web-browser: http://localhost:8090
if (mjpeg_port > 0 && show_img) { if (mjpeg_port > 0 && show_img) {
int port = mjpeg_port; int port = mjpeg_port;
int timeout = 200; int timeout = 400000;
int jpeg_quality = 30; // 1 - 100 int jpeg_quality = 40; // 1 - 100
send_mjpeg(show_img, port, timeout, jpeg_quality); send_mjpeg(show_img, port, timeout, jpeg_quality);
} }

@ -115,7 +115,7 @@ class MJPG_sender
public: public:
MJPG_sender(int port = 0, int _timeout = 200000, int _quality = 30) MJPG_sender(int port = 0, int _timeout = 400000, int _quality = 30)
: sock(INVALID_SOCKET) : sock(INVALID_SOCKET)
, timeout(_timeout) , timeout(_timeout)
, quality(_quality) , quality(_quality)
@ -230,17 +230,17 @@ public:
} }
maxfd = (maxfd>client ? maxfd : client); maxfd = (maxfd>client ? maxfd : client);
FD_SET(client, &master); FD_SET(client, &master);
_write(client, "HTTP/1.0 200 OK\n", 0); _write(client, "HTTP/1.0 200 OK\r\n", 0);
_write(client, _write(client,
"Server: Mozarella/2.2\n" "Server: Mozarella/2.2\r\n"
"Accept-Range: bytes\n" "Accept-Range: bytes\r\n"
"Connection: close\n" "Connection: close\r\n"
"Max-Age: 0\n" "Max-Age: 0\r\n"
"Expires: 0\n" "Expires: 0\r\n"
"Cache-Control: no-cache, private\n" "Cache-Control: no-cache, private\r\n"
"Pragma: no-cache\n" "Pragma: no-cache\r\n"
"Content-Type: multipart/x-mixed-replace; boundary=mjpegstream\n" "Content-Type: multipart/x-mixed-replace; boundary=mjpegstream\r\n"
"\n", 0); "\r\n", 0);
cerr << "MJPG_sender: new client " << client << endl; cerr << "MJPG_sender: new client " << client << endl;
} }
else // existing client, just stream pix else // existing client, just stream pix
@ -252,7 +252,7 @@ public:
} }
char head[400]; char head[400];
sprintf(head, "--mjpegstream\nContent-Type: image/jpeg\nContent-Length: %zu\n\n", outlen); sprintf(head, "--mjpegstream\r\nContent-Type: image/jpeg\r\nContent-Length: %zu\r\n\r\n", outlen);
_write(s, head, 0); _write(s, head, 0);
int n = _write(s, (char*)(&outbuf[0]), outlen); int n = _write(s, (char*)(&outbuf[0]), outlen);
//cerr << "known client " << s << " " << n << endl; //cerr << "known client " << s << " " << n << endl;
@ -303,7 +303,7 @@ class JSON_sender
public: public:
JSON_sender(int port = 0, int _timeout = 200000) JSON_sender(int port = 0, int _timeout = 400000)
: sock(INVALID_SOCKET) : sock(INVALID_SOCKET)
, timeout(_timeout) , timeout(_timeout)
{ {
@ -409,18 +409,18 @@ public:
} }
maxfd = (maxfd>client ? maxfd : client); maxfd = (maxfd>client ? maxfd : client);
FD_SET(client, &master); FD_SET(client, &master);
_write(client, "HTTP/1.0 200 OK\n", 0); _write(client, "HTTP/1.0 200 OK\r\n", 0);
_write(client, _write(client,
"Server: Mozarella/2.2\n" "Server: Mozarella/2.2\r\n"
"Accept-Range: bytes\n" "Accept-Range: bytes\r\n"
"Connection: close\n" "Connection: close\r\n"
"Max-Age: 0\n" "Max-Age: 0\r\n"
"Expires: 0\n" "Expires: 0\r\n"
"Cache-Control: no-cache, private\n" "Cache-Control: no-cache, private\r\n"
"Pragma: no-cache\n" "Pragma: no-cache\r\n"
"Content-Type: application/json\n" "Content-Type: application/json\r\n"
//"Content-Type: multipart/x-mixed-replace; boundary=boundary\r\n" //"Content-Type: multipart/x-mixed-replace; boundary=boundary\r\n"
"\n", 0); "\r\n", 0);
_write(client, "[\n", 0); // open JSON array _write(client, "[\n", 0); // open JSON array
int n = _write(client, outputbuf, outlen); int n = _write(client, outputbuf, outlen);
cerr << "JSON_sender: new client " << client << endl; cerr << "JSON_sender: new client " << client << endl;

@ -829,7 +829,7 @@ void draw_train_loss(IplImage* img, int img_size, float avg_loss, float max_img_
else else
cvPutText(img, "- Saved", cvPoint(250, img_size - 10), &font, CV_RGB(255, 255, 255)); cvPutText(img, "- Saved", cvPoint(250, img_size - 10), &font, CV_RGB(255, 255, 255));
if (mjpeg_port > 0) send_mjpeg(img, mjpeg_port, 200000, 80); if (mjpeg_port > 0) send_mjpeg(img, mjpeg_port, 500000, 100);
} }
#endif // OPENCV #endif // OPENCV

Loading…
Cancel
Save