@@ -51,7 +51,6 @@ extern int streamPort;
5151extern char httpURL[];
5252extern char streamURL[];
5353extern char default_index[];
54- extern int8_t streamCount;
5554extern unsigned long streamsServed;
5655extern unsigned long imagesServed;
5756extern int myRotation;
@@ -85,9 +84,6 @@ static const char* _STREAM_PART = "Content-Type: image/jpeg\r\nContent-Length: %
8584httpd_handle_t stream_httpd = NULL ;
8685httpd_handle_t camera_httpd = NULL ;
8786
88- // Flag that can be set to kill all active streams
89- bool streamKill;
90-
9187#ifdef __cplusplus
9288extern " C" {
9389#endif
@@ -152,7 +148,7 @@ void serialDump() {
152148 int McuTc = (temprature_sens_read () - 32 ) / 1.8 ; // celsius
153149 int McuTf = temprature_sens_read (); // fahrenheit
154150 Serial.printf (" System up: %" PRId64 " :%02i:%02i:%02i (d:h:m:s)\r\n " , upDays, upHours, upMin, upSec);
155- Serial.printf (" Active streams: %i , Previous streams: %lu, Images captured: %lu\r\n " , streamCount , streamsServed, imagesServed);
151+ Serial.printf (" Active streams: %lu , Previous streams: %lu, Images captured: %lu\r\n " , cam_streamer_get_num_clients (cam_streamer) , streamsServed, imagesServed);
156152 Serial.printf (" CPU Freq: %i MHz, Xclk Freq: %i MHz\r\n " , ESP.getCpuFreqMHz (), xclk);
157153 Serial.printf (" MCU temperature : %i C, %i F (approximate)\r\n " , McuTc, McuTf);
158154 Serial.printf (" Heap: %i, free: %i, min free: %i, max block: %i\r\n " , ESP.getHeapSize (), ESP.getFreeHeap (), ESP.getMinFreeHeap (), ESP.getMaxAllocHeap ());
@@ -232,7 +228,10 @@ static esp_err_t stream_handler(httpd_req_t *req){
232228 printf (" [stream_handler] could not get socket fd!\n " );
233229 return ESP_FAIL;
234230 }
235- cam_streamer_enqueue_client (cam_streamer, fd);
231+
232+ if (cam_streamer_enqueue_client (cam_streamer, fd))
233+ ++streamsServed;
234+
236235 return ESP_OK;
237236}
238237
@@ -307,7 +306,7 @@ static esp_err_t cmd_handler(httpd_req_t *req){
307306 else if (!strcmp (variable, " autolamp" ) && (lampVal != -1 )) {
308307 autoLamp = val;
309308 if (autoLamp) {
310- if (streamCount > 0 ) setLamp (lampVal);
309+ if (cam_streamer_get_num_clients (cam_streamer) > 0 ) setLamp (lampVal);
311310 else setLamp (0 );
312311 } else {
313312 setLamp (lampVal);
@@ -316,7 +315,7 @@ static esp_err_t cmd_handler(httpd_req_t *req){
316315 else if (!strcmp (variable, " lamp" ) && (lampVal != -1 )) {
317316 lampVal = constrain (val,0 ,100 );
318317 if (autoLamp) {
319- if (streamCount > 0 ) setLamp (lampVal);
318+ if (cam_streamer_get_num_clients (cam_streamer) > 0 ) setLamp (lampVal);
320319 else setLamp (0 );
321320 } else {
322321 setLamp (lampVal);
@@ -513,7 +512,7 @@ static esp_err_t dump_handler(httpd_req_t *req){
513512 int McuTf = temprature_sens_read (); // fahrenheit
514513
515514 d+= sprintf (d," Up: %" PRId64 " :%02i:%02i:%02i (d:h:m:s)<br>\n " , upDays, upHours, upMin, upSec);
516- d+= sprintf (d," Active streams: %i, Previous streams: %lu, Images captured: %lu<br>\n " , streamCount , streamsServed, imagesServed);
515+ d+= sprintf (d," Active streams: %i, Previous streams: %lu, Images captured: %lu<br>\n " , cam_streamer_get_num_clients (cam_streamer) , streamsServed, imagesServed);
517516 d+= sprintf (d," CPU Freq: %i MHz, Xclk Freq: %i MHz<br>\n " , ESP.getCpuFreqMHz (), xclk);
518517 d+= sprintf (d," <span title=\" NOTE: Internal temperature sensor readings can be innacurate on the ESP32-c1 chipset, and may vary significantly between devices!\" >" );
519518 d+= sprintf (d," MCU temperature : %i °C, %i °F</span>\n <br>" , McuTc, McuTf);
@@ -550,7 +549,7 @@ static esp_err_t dump_handler(httpd_req_t *req){
550549static esp_err_t stop_handler (httpd_req_t *req){
551550 flashLED (75 );
552551 Serial.println (" \r\n Stream stop requested via Web" );
553- streamKill = true ;
552+ cam_streamer_dequeue_all_clients (cam_streamer) ;
554553 httpd_resp_set_hdr (req, " Access-Control-Allow-Origin" , " *" );
555554 return httpd_resp_send (req, NULL , 0 );
556555}
@@ -794,7 +793,10 @@ void startCameraServer(int hPort, int sPort){
794793 httpd_register_uri_handler (stream_httpd, &info_uri);
795794 httpd_register_uri_handler (stream_httpd, &streamviewer_uri);
796795 cam_streamer=(cam_streamer_t *) malloc (sizeof (cam_streamer_t ));
797- cam_streamer_init (cam_streamer, stream_httpd, 3 );
796+ #ifndef CAM_STREAMER_DESIRED_FPS
797+ #define CAM_STREAMER_DESIRED_FPS 2
798+ #endif
799+ cam_streamer_init (cam_streamer, stream_httpd, CAM_STREAMER_DESIRED_FPS);
798800 cam_streamer_start (cam_streamer);
799801 }
800802 httpd_register_uri_handler (stream_httpd, &favicon_16x16_uri);
0 commit comments