ClassControllCamera.cpp 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210
  1. #include "ClassControllCamera.h"
  2. #include "ClassLogFile.h"
  3. #include <stdio.h>
  4. #include "driver/gpio.h"
  5. #include "esp_timer.h"
  6. #include "esp_log.h"
  7. #include "Helper.h"
  8. #include "statusled.h"
  9. #include "CImageBasis.h"
  10. #include "server_ota.h"
  11. #include "server_GPIO.h"
  12. #include "../../include/defines.h"
  13. #include <esp_event.h>
  14. #include <esp_log.h>
  15. #include <esp_system.h>
  16. #include <nvs_flash.h>
  17. #include <sys/param.h>
  18. #include <string.h>
  19. #include <sys/stat.h>
  20. #include "freertos/FreeRTOS.h"
  21. #include "freertos/task.h"
  22. #include "esp_camera.h"
  23. #include "driver/ledc.h"
  24. #include "MainFlowControl.h"
  25. #include "ov2640_sharpness.h"
  26. #if (ESP_IDF_VERSION_MAJOR >= 5)
  27. #include "soc/periph_defs.h"
  28. #include "esp_private/periph_ctrl.h"
  29. #include "soc/gpio_sig_map.h"
  30. #include "soc/gpio_periph.h"
  31. #include "soc/io_mux_reg.h"
  32. #include "esp_rom_gpio.h"
  33. #define gpio_pad_select_gpio esp_rom_gpio_pad_select_gpio
  34. #define gpio_matrix_in(a, b, c) esp_rom_gpio_connect_in_signal(a, b, c)
  35. #define gpio_matrix_out(a, b, c, d) esp_rom_gpio_connect_out_signal(a, b, c, d)
  36. #define ets_delay_us(a) esp_rom_delay_us(a)
  37. #endif
  38. CCamera Camera;
  39. camera_controll_config_temp_t CCstatus;
  40. static const char *TAG = "CAM";
  41. /* Camera live stream */
  42. #define PART_BOUNDARY "123456789000000000000987654321"
  43. static const char *_STREAM_CONTENT_TYPE = "multipart/x-mixed-replace;boundary=" PART_BOUNDARY;
  44. static const char *_STREAM_BOUNDARY = "\r\n--" PART_BOUNDARY "\r\n";
  45. static const char *_STREAM_PART = "Content-Type: image/jpeg\r\nContent-Length: %u\r\n\r\n";
  46. uint8_t *demoImage = NULL; // Buffer holding the demo image in bytes
  47. #define DEMO_IMAGE_SIZE 30000 // Max size of demo image in bytes
  48. // Camera module bus communications frequency.
  49. // Originally: config.xclk_freq_mhz = 20000000, but this lead to visual artifacts on many modules.
  50. // See https://github.com/espressif/esp32-camera/issues/150#issuecomment-726473652 et al.
  51. #if !defined(XCLK_FREQ_MHZ)
  52. // int xclk = 8;
  53. int xclk = 20; // Orginal value
  54. #else
  55. int xclk = XCLK_FREQ_MHZ;
  56. #endif
  57. static camera_config_t camera_config = {
  58. .pin_pwdn = CAM_PIN_PWDN,
  59. .pin_reset = CAM_PIN_RESET,
  60. .pin_xclk = CAM_PIN_XCLK,
  61. .pin_sscb_sda = CAM_PIN_SIOD,
  62. .pin_sscb_scl = CAM_PIN_SIOC,
  63. .pin_d7 = CAM_PIN_D7,
  64. .pin_d6 = CAM_PIN_D6,
  65. .pin_d5 = CAM_PIN_D5,
  66. .pin_d4 = CAM_PIN_D4,
  67. .pin_d3 = CAM_PIN_D3,
  68. .pin_d2 = CAM_PIN_D2,
  69. .pin_d1 = CAM_PIN_D1,
  70. .pin_d0 = CAM_PIN_D0,
  71. .pin_vsync = CAM_PIN_VSYNC,
  72. .pin_href = CAM_PIN_HREF,
  73. .pin_pclk = CAM_PIN_PCLK,
  74. .xclk_freq_hz = (xclk * 1000000),
  75. .ledc_timer = LEDC_TIMER_0, // LEDC timer to be used for generating XCLK
  76. .ledc_channel = LEDC_CHANNEL_0, // LEDC channel to be used for generating XCLK
  77. .pixel_format = PIXFORMAT_JPEG, // YUV422,GRAYSCALE,RGB565,JPEG
  78. .frame_size = FRAMESIZE_VGA, // QQVGA-UXGA Do not use sizes above QVGA when not JPEG
  79. // .frame_size = FRAMESIZE_UXGA, //QQVGA-UXGA Do not use sizes above QVGA when not JPEG
  80. .jpeg_quality = 6, // 0-63 lower number means higher quality
  81. .fb_count = 1, // if more than one, i2s runs in continuous mode. Use only with JPEG
  82. .fb_location = CAMERA_FB_IN_PSRAM, /*!< The location where the frame buffer will be allocated */
  83. .grab_mode = CAMERA_GRAB_LATEST, // only from new esp32cam version
  84. };
  85. typedef struct
  86. {
  87. httpd_req_t *req;
  88. size_t len;
  89. } jpg_chunking_t;
  90. CCamera::CCamera(void)
  91. {
  92. #ifdef DEBUG_DETAIL_ON
  93. ESP_LOGD(TAG, "CreateClassCamera");
  94. #endif
  95. CCstatus.WaitBeforePicture = 2;
  96. ledc_init();
  97. }
  98. esp_err_t CCamera::InitCam(void)
  99. {
  100. ESP_LOGD(TAG, "Init Camera");
  101. TickType_t cam_xDelay = 100 / portTICK_PERIOD_MS;
  102. CCstatus.ImageQuality = camera_config.jpeg_quality;
  103. CCstatus.ImageFrameSize = camera_config.frame_size;
  104. // De-init in case it was already initialized
  105. esp_camera_deinit();
  106. vTaskDelay(cam_xDelay);
  107. // initialize the camera
  108. esp_err_t err = esp_camera_init(&camera_config);
  109. vTaskDelay(cam_xDelay);
  110. if (err != ESP_OK)
  111. {
  112. ESP_LOGE(TAG, "Camera Init Failed");
  113. return err;
  114. }
  115. CCstatus.CameraInitSuccessful = true;
  116. // Get a reference to the sensor
  117. sensor_t *s = esp_camera_sensor_get();
  118. if (s != NULL)
  119. {
  120. CCstatus.CamSensor_id = s->id.PID;
  121. // Dump camera module, warn for unsupported modules.
  122. switch (CCstatus.CamSensor_id)
  123. {
  124. case OV2640_PID:
  125. ESP_LOGI(TAG, "OV2640 camera module detected");
  126. break;
  127. case OV3660_PID:
  128. ESP_LOGI(TAG, "OV3660 camera module detected");
  129. break;
  130. case OV5640_PID:
  131. ESP_LOGI(TAG, "OV5640 camera module detected");
  132. break;
  133. default:
  134. ESP_LOGE(TAG, "Camera module is unknown and not properly supported!");
  135. CCstatus.CameraInitSuccessful = false;
  136. }
  137. }
  138. if (CCstatus.CameraInitSuccessful)
  139. {
  140. return ESP_OK;
  141. }
  142. else
  143. {
  144. return ESP_FAIL;
  145. }
  146. }
  147. bool CCamera::testCamera(void)
  148. {
  149. bool success;
  150. camera_fb_t *fb = esp_camera_fb_get();
  151. if (fb)
  152. {
  153. success = true;
  154. }
  155. else
  156. {
  157. success = false;
  158. }
  159. esp_camera_fb_return(fb);
  160. return success;
  161. }
  162. void CCamera::ledc_init(void)
  163. {
  164. #ifdef USE_PWM_LEDFLASH
  165. // Prepare and then apply the LEDC PWM timer configuration
  166. ledc_timer_config_t ledc_timer = {};
  167. ledc_timer.speed_mode = LEDC_MODE;
  168. ledc_timer.timer_num = LEDC_TIMER;
  169. ledc_timer.duty_resolution = LEDC_DUTY_RES;
  170. ledc_timer.freq_hz = LEDC_FREQUENCY; // Set output frequency at 5 kHz
  171. ledc_timer.clk_cfg = LEDC_AUTO_CLK;
  172. ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer));
  173. // Prepare and then apply the LEDC PWM channel configuration
  174. ledc_channel_config_t ledc_channel = {};
  175. ledc_channel.speed_mode = LEDC_MODE;
  176. ledc_channel.channel = LEDC_CHANNEL;
  177. ledc_channel.timer_sel = LEDC_TIMER;
  178. ledc_channel.intr_type = LEDC_INTR_DISABLE;
  179. ledc_channel.gpio_num = LEDC_OUTPUT_IO;
  180. ledc_channel.duty = 0; // Set duty to 0%
  181. ledc_channel.hpoint = 0;
  182. // ledc_channel.flags.output_invert = LEDC_OUTPUT_INVERT;
  183. ESP_ERROR_CHECK(ledc_channel_config(&ledc_channel));
  184. #endif
  185. }
  186. void CCamera::SetLEDIntensity(float _intrel)
  187. {
  188. _intrel = min(_intrel, (float)100);
  189. _intrel = max(_intrel, (float)0);
  190. _intrel = _intrel / 100;
  191. CCstatus.ImageLedIntensity = (int)(_intrel * 8191);
  192. ESP_LOGD(TAG, "Set led_intensity to %d of 8191", CCstatus.ImageLedIntensity);
  193. }
  194. bool CCamera::getCameraInitSuccessful(void)
  195. {
  196. return CCstatus.CameraInitSuccessful;
  197. }
  198. esp_err_t CCamera::setSensorDatenFromCCstatus(void)
  199. {
  200. sensor_t *s = esp_camera_sensor_get();
  201. if (s != NULL)
  202. {
  203. s->set_framesize(s, CCstatus.ImageFrameSize);
  204. s->set_quality(s, CCstatus.ImageQuality); // 0 - 63
  205. s->set_brightness(s, CCstatus.ImageBrightness); // -2 to 2
  206. s->set_contrast(s, CCstatus.ImageContrast); // -2 to 2
  207. s->set_saturation(s, CCstatus.ImageSaturation); // -2 to 2
  208. // s->set_sharpness(s, CCstatus.ImageSharpness); // auto-sharpness is not officially supported, default to 0
  209. SetCamSharpness(CCstatus.ImageAutoSharpness, CCstatus.ImageSharpness);
  210. s->set_denoise(s, CCstatus.ImageDenoiseLevel); // The OV2640 does not support it, OV3660 and OV5640 (0 to 8)
  211. s->set_special_effect(s, CCstatus.ImageSpecialEffect); // 0 to 6 (0 - No Effect, 1 - Negative, 2 - Grayscale, 3 - Red Tint, 4 - Green Tint, 5 - Blue Tint, 6 - Sepia)
  212. s->set_wb_mode(s, CCstatus.ImageWbMode); // 0 to 4 - if awb_gain enabled (0 - Auto, 1 - Sunny, 2 - Cloudy, 3 - Office, 4 - Home)
  213. s->set_ae_level(s, CCstatus.ImageAeLevel); // -2 to 2
  214. s->set_aec_value(s, CCstatus.ImageAecValue); // 0 to 1200
  215. s->set_agc_gain(s, CCstatus.ImageAgcGain); // 0 to 30
  216. // s->set_gainceiling(s, CCstatus.ImageGainceiling); // Image gain (GAINCEILING_x2, x4, x8, x16, x32, x64 or x128)
  217. ov5640_set_gainceiling(s, CCstatus.ImageGainceiling);
  218. s->set_lenc(s, CCstatus.ImageLenc); // 0 = disable , 1 = enable
  219. s->set_gain_ctrl(s, CCstatus.ImageAgc); // 0 = disable , 1 = enable
  220. s->set_exposure_ctrl(s, CCstatus.ImageAec); // 0 = disable , 1 = enable
  221. s->set_hmirror(s, CCstatus.ImageHmirror); // 0 = disable , 1 = enable
  222. s->set_vflip(s, CCstatus.ImageVflip); // 0 = disable , 1 = enable
  223. s->set_aec2(s, CCstatus.ImageAec2); // 0 = disable , 1 = enable
  224. s->set_bpc(s, CCstatus.ImageBpc); // 0 = disable , 1 = enable
  225. s->set_wpc(s, CCstatus.ImageWpc); // 0 = disable , 1 = enable
  226. s->set_raw_gma(s, CCstatus.ImageRawGma); // 0 = disable , 1 = enable
  227. s->set_awb_gain(s, CCstatus.ImageAwbGain); // 0 = disable , 1 = enable
  228. s->set_whitebal(s, CCstatus.ImageAwb); // 0 = disable , 1 = enable
  229. s->set_dcw(s, CCstatus.ImageDcw); // 0 = disable , 1 = enable
  230. TickType_t cam_xDelay = 100 / portTICK_PERIOD_MS;
  231. vTaskDelay(cam_xDelay);
  232. return ESP_OK;
  233. }
  234. else
  235. {
  236. return ESP_FAIL;
  237. }
  238. }
  239. esp_err_t CCamera::getSensorDatenToCCstatus(void)
  240. {
  241. sensor_t *s = esp_camera_sensor_get();
  242. if (s != NULL)
  243. {
  244. CCstatus.CamSensor_id = s->id.PID;
  245. CCstatus.ImageFrameSize = (framesize_t)s->status.framesize;
  246. CCstatus.ImageGainceiling = (gainceiling_t)s->status.gainceiling;
  247. CCstatus.ImageQuality = s->status.quality;
  248. CCstatus.ImageBrightness = s->status.brightness;
  249. CCstatus.ImageContrast = s->status.contrast;
  250. CCstatus.ImageSaturation = s->status.saturation;
  251. // CCstatus.ImageSharpness = s->status.sharpness; // gibt -1 zurück, da es nicht unterstützt wird
  252. CCstatus.ImageWbMode = s->status.wb_mode;
  253. CCstatus.ImageAwb = s->status.awb;
  254. CCstatus.ImageAwbGain = s->status.awb_gain;
  255. CCstatus.ImageAec = s->status.aec;
  256. CCstatus.ImageAec2 = s->status.aec2;
  257. CCstatus.ImageAeLevel = s->status.ae_level;
  258. CCstatus.ImageAecValue = s->status.aec_value;
  259. CCstatus.ImageAgc = s->status.agc;
  260. CCstatus.ImageAgcGain = s->status.agc_gain;
  261. CCstatus.ImageBpc = s->status.bpc;
  262. CCstatus.ImageWpc = s->status.wpc;
  263. CCstatus.ImageRawGma = s->status.raw_gma;
  264. CCstatus.ImageLenc = s->status.lenc;
  265. CCstatus.ImageSpecialEffect = s->status.special_effect;
  266. CCstatus.ImageHmirror = s->status.hmirror;
  267. CCstatus.ImageVflip = s->status.vflip;
  268. CCstatus.ImageDcw = s->status.dcw;
  269. CCstatus.ImageDenoiseLevel = s->status.denoise;
  270. return ESP_OK;
  271. }
  272. else
  273. {
  274. return ESP_FAIL;
  275. }
  276. }
  277. // on the OV5640, gainceiling must be set with the real value (x2>>>level = 2, .... x128>>>level = 128)
  278. int CCamera::ov5640_set_gainceiling(sensor_t *s, gainceiling_t level)
  279. {
  280. int ret = 0;
  281. if (CCstatus.CamSensor_id == OV2640_PID)
  282. {
  283. ret = s->set_gainceiling(s, CCstatus.ImageGainceiling); // Image gain (GAINCEILING_x2, x4, x8, x16, x32, x64 or x128)
  284. }
  285. else
  286. {
  287. int _level = (1 << ((int)level + 1));
  288. ret = s->set_reg(s, 0x3A18, 0xFF, (_level >> 8) & 3) || s->set_reg(s, 0x3A19, 0xFF, _level & 0xFF);
  289. if (ret == 0)
  290. {
  291. // ESP_LOGD(TAG, "Set gainceiling to: %d", level);
  292. s->status.gainceiling = level;
  293. }
  294. }
  295. return ret;
  296. }
  297. // - It always zooms to the image center when offsets are zero
  298. // - if imageSize = 0 then the image is not zoomed
  299. // - if imageSize = max value, then the image is fully zoomed in
  300. // - a zoom step is >>> Width + 32 px / Height + 24 px
  301. void CCamera::SanitizeZoomParams(int imageSize, int frameSizeX, int frameSizeY, int &imageWidth, int &imageHeight, int &zoomOffsetX, int &zoomOffsetY)
  302. {
  303. // for OV2640, This works only if the aspect ratio of 4:3 is preserved in the window size.
  304. // use only values divisible by 8 without remainder
  305. imageWidth = CCstatus.ImageWidth + (imageSize * 4 * 8);
  306. imageHeight = CCstatus.ImageHeight + (imageSize * 3 * 8);
  307. int _maxX = frameSizeX - imageWidth;
  308. int _maxY = frameSizeY - imageHeight;
  309. if ((abs(zoomOffsetX) * 2) > _maxX)
  310. {
  311. if (zoomOffsetX > 0)
  312. {
  313. zoomOffsetX = _maxX;
  314. }
  315. else
  316. {
  317. zoomOffsetX = 0;
  318. }
  319. }
  320. else
  321. {
  322. if (zoomOffsetX > 0)
  323. {
  324. zoomOffsetX = ((_maxX / 2) + zoomOffsetX);
  325. }
  326. else
  327. {
  328. zoomOffsetX = ((_maxX / 2) + zoomOffsetX);
  329. }
  330. }
  331. if ((abs(zoomOffsetY) * 2) > _maxY)
  332. {
  333. if (zoomOffsetY > 0)
  334. {
  335. zoomOffsetY = _maxY;
  336. }
  337. else
  338. {
  339. zoomOffsetY = 0;
  340. }
  341. }
  342. else
  343. {
  344. if (zoomOffsetY > 0)
  345. {
  346. zoomOffsetY = ((_maxY / 2) + zoomOffsetY);
  347. }
  348. else
  349. {
  350. zoomOffsetY = ((_maxY / 2) + zoomOffsetY);
  351. }
  352. }
  353. }
  354. void CCamera::SetZoomSize(bool zoomEnabled, int zoomOffsetX, int zoomOffsetY, int imageSize, int imageVflip)
  355. {
  356. sensor_t *s = esp_camera_sensor_get();
  357. if (s != NULL)
  358. {
  359. if (zoomEnabled)
  360. {
  361. int _imageSize_temp = 0;
  362. int _imageWidth = CCstatus.ImageWidth;
  363. int _imageHeight = CCstatus.ImageHeight;
  364. int _offsetx = zoomOffsetX;
  365. int _offsety = zoomOffsetY;
  366. int frameSizeX;
  367. int frameSizeY;
  368. switch (CCstatus.CamSensor_id)
  369. {
  370. case OV5640_PID:
  371. frameSizeX = 2592;
  372. frameSizeY = 1944;
  373. // max imageSize = ((frameSizeX - CCstatus.ImageWidth) / 8 / 4) - 1
  374. // 59 = ((2560 - 640) / 8 / 4) - 1
  375. if (imageSize < 59)
  376. {
  377. _imageSize_temp = (59 - imageSize);
  378. }
  379. SanitizeZoomParams(_imageSize_temp, frameSizeX, frameSizeY, _imageWidth, _imageHeight, _offsetx, _offsety);
  380. SetCamWindow(s, frameSizeX, frameSizeY, _offsetx, _offsety, _imageWidth, _imageHeight, CCstatus.ImageWidth, CCstatus.ImageHeight, imageVflip);
  381. break;
  382. case OV3660_PID:
  383. frameSizeX = 2048;
  384. frameSizeY = 1536;
  385. // max imageSize = ((frameSizeX - CCstatus.ImageWidth) / 8 / 4) -1
  386. // 43 = ((2048 - 640) / 8 / 4) - 1
  387. if (imageSize < 43)
  388. {
  389. _imageSize_temp = (43 - imageSize);
  390. }
  391. SanitizeZoomParams(_imageSize_temp, frameSizeX, frameSizeY, _imageWidth, _imageHeight, _offsetx, _offsety);
  392. SetCamWindow(s, frameSizeX, frameSizeY, _offsetx, _offsety, _imageWidth, _imageHeight, CCstatus.ImageWidth, CCstatus.ImageHeight, imageVflip);
  393. break;
  394. case OV2640_PID:
  395. frameSizeX = 1600;
  396. frameSizeY = 1200;
  397. // max imageSize = ((frameSizeX - CCstatus.ImageWidth) / 8 / 4) -1
  398. // 29 = ((1600 - 640) / 8 / 4) - 1
  399. if (imageSize < 29)
  400. {
  401. _imageSize_temp = (29 - imageSize);
  402. }
  403. SanitizeZoomParams(_imageSize_temp, frameSizeX, frameSizeY, _imageWidth, _imageHeight, _offsetx, _offsety);
  404. SetCamWindow(s, frameSizeX, frameSizeY, _offsetx, _offsety, _imageWidth, _imageHeight, CCstatus.ImageWidth, CCstatus.ImageHeight, imageVflip);
  405. break;
  406. default:
  407. // do nothing
  408. break;
  409. }
  410. }
  411. else
  412. {
  413. s->set_framesize(s, CCstatus.ImageFrameSize);
  414. }
  415. }
  416. }
  417. void CCamera::SetQualityZoomSize(int qual, framesize_t resol, bool zoomEnabled, int zoomOffsetX, int zoomOffsetY, int imageSize, int imageVflip)
  418. {
  419. sensor_t *s = esp_camera_sensor_get();
  420. // OV2640 has no lower limit on jpeg quality
  421. if (CCstatus.CamSensor_id == OV5640_PID)
  422. {
  423. qual = min(63, max(8, qual));
  424. }
  425. SetImageWidthHeightFromResolution(resol);
  426. if (s != NULL)
  427. {
  428. s->set_quality(s, qual);
  429. SetZoomSize(zoomEnabled, zoomOffsetX, zoomOffsetY, imageSize, imageVflip);
  430. }
  431. else
  432. {
  433. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "SetQualityZoomSize, Failed to get Cam control structure");
  434. }
  435. }
  436. void CCamera::SetCamSharpness(bool _autoSharpnessEnabled, int _sharpnessLevel)
  437. {
  438. sensor_t *s = esp_camera_sensor_get();
  439. if (s != NULL)
  440. {
  441. if (CCstatus.CamSensor_id == OV2640_PID)
  442. {
  443. _sharpnessLevel = min(2, max(-2, _sharpnessLevel));
  444. // The OV2640 does not officially support sharpness, so the detour is made with the ov2640_sharpness.cpp.
  445. if (_autoSharpnessEnabled)
  446. {
  447. ov2640_enable_auto_sharpness(s);
  448. }
  449. else
  450. {
  451. ov2640_set_sharpness(s, _sharpnessLevel);
  452. }
  453. }
  454. else
  455. {
  456. _sharpnessLevel = min(3, max(-3, _sharpnessLevel));
  457. // for CAMERA_OV5640 and CAMERA_OV3660
  458. if (_autoSharpnessEnabled)
  459. {
  460. // autoSharpness is not supported, default to zero
  461. s->set_sharpness(s, 0);
  462. }
  463. else
  464. {
  465. s->set_sharpness(s, _sharpnessLevel);
  466. }
  467. }
  468. }
  469. else
  470. {
  471. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "SetCamSharpness, Failed to get Cam control structure");
  472. }
  473. }
  474. void CCamera::SetCamWindow(sensor_t *s, int frameSizeX, int frameSizeY, int xOffset, int yOffset, int xTotal, int yTotal, int xOutput, int yOutput, int imageVflip)
  475. {
  476. if (CCstatus.CamSensor_id == OV2640_PID)
  477. {
  478. s->set_res_raw(s, 0, 0, 0, 0, xOffset, yOffset, xTotal, yTotal, xOutput, yOutput, false, false);
  479. }
  480. else
  481. {
  482. // for CAMERA_OV5640 and CAMERA_OV3660
  483. bool scale = !(xOutput == xTotal && yOutput == yTotal);
  484. bool binning = (xTotal >= (frameSizeX >> 1));
  485. if (imageVflip == true)
  486. {
  487. s->set_res_raw(s, xOffset, yOffset, xOffset + xTotal - 1, yOffset + yTotal - 1, 0, 0, frameSizeX, frameSizeY, xOutput, yOutput, scale, binning);
  488. }
  489. else
  490. {
  491. s->set_res_raw(s, xOffset, yOffset, xOffset + xTotal, yOffset + yTotal, 0, 0, frameSizeX, frameSizeY, xOutput, yOutput, scale, binning);
  492. }
  493. }
  494. }
  495. static size_t jpg_encode_stream(void *arg, size_t index, const void *data, size_t len)
  496. {
  497. jpg_chunking_t *j = (jpg_chunking_t *)arg;
  498. if (!index)
  499. {
  500. j->len = 0;
  501. }
  502. if (httpd_resp_send_chunk(j->req, (const char *)data, len) != ESP_OK)
  503. {
  504. return 0;
  505. }
  506. j->len += len;
  507. return len;
  508. }
  509. esp_err_t CCamera::CaptureToBasisImage(CImageBasis *_Image, int delay)
  510. {
  511. #ifdef DEBUG_DETAIL_ON
  512. LogFile.WriteHeapInfo("CaptureToBasisImage - Start");
  513. #endif
  514. _Image->EmptyImage(); // Delete previous stored raw image -> black image
  515. LEDOnOff(true); // Status-LED on
  516. if (delay > 0)
  517. {
  518. LightOnOff(true); // Flash-LED on
  519. const TickType_t xDelay = delay / portTICK_PERIOD_MS;
  520. vTaskDelay(xDelay);
  521. }
  522. #ifdef DEBUG_DETAIL_ON
  523. LogFile.WriteHeapInfo("CaptureToBasisImage - After LightOn");
  524. #endif
  525. camera_fb_t *fb = esp_camera_fb_get();
  526. esp_camera_fb_return(fb);
  527. fb = esp_camera_fb_get();
  528. if (!fb)
  529. {
  530. LEDOnOff(false); // Status-LED off
  531. LightOnOff(false); // Flash-LED off
  532. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "is not working anymore (CaptureToBasisImage) - most probably caused "
  533. "by a hardware problem (instablility, ...). System will reboot.");
  534. doReboot();
  535. return ESP_FAIL;
  536. }
  537. if (CCstatus.DemoMode)
  538. {
  539. // Use images stored on SD-Card instead of camera image
  540. /* Replace Framebuffer with image from SD-Card */
  541. loadNextDemoImage(fb);
  542. }
  543. CImageBasis *_zwImage = new CImageBasis("zwImage");
  544. if (_zwImage)
  545. {
  546. _zwImage->LoadFromMemory(fb->buf, fb->len);
  547. }
  548. else
  549. {
  550. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "CaptureToBasisImage: Can't allocate _zwImage");
  551. }
  552. esp_camera_fb_return(fb);
  553. #ifdef DEBUG_DETAIL_ON
  554. LogFile.WriteHeapInfo("CaptureToBasisImage - After fb_get");
  555. #endif
  556. LEDOnOff(false); // Status-LED off
  557. if (delay > 0)
  558. {
  559. LightOnOff(false); // Flash-LED off
  560. }
  561. // TickType_t xDelay = 1000 / portTICK_PERIOD_MS;
  562. // vTaskDelay( xDelay ); // wait for power to recover
  563. #ifdef DEBUG_DETAIL_ON
  564. LogFile.WriteHeapInfo("CaptureToBasisImage - After LoadFromMemory");
  565. #endif
  566. if (_zwImage == NULL)
  567. {
  568. return ESP_OK;
  569. }
  570. stbi_uc *p_target;
  571. stbi_uc *p_source;
  572. int channels = 3;
  573. int width = CCstatus.ImageWidth;
  574. int height = CCstatus.ImageHeight;
  575. #ifdef DEBUG_DETAIL_ON
  576. std::string _zw = "Targetimage: " + std::to_string((int)_Image->rgb_image) + " Size: " + std::to_string(_Image->width) + ", " + std::to_string(_Image->height);
  577. _zw = _zw + " _zwImage: " + std::to_string((int)_zwImage->rgb_image) + " Size: " + std::to_string(_zwImage->width) + ", " + std::to_string(_zwImage->height);
  578. LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, _zw);
  579. #endif
  580. for (int x = 0; x < width; ++x)
  581. {
  582. for (int y = 0; y < height; ++y)
  583. {
  584. p_target = _Image->rgb_image + (channels * (y * width + x));
  585. p_source = _zwImage->rgb_image + (channels * (y * width + x));
  586. for (int c = 0; c < channels; c++)
  587. {
  588. p_target[c] = p_source[c];
  589. }
  590. }
  591. }
  592. delete _zwImage;
  593. #ifdef DEBUG_DETAIL_ON
  594. LogFile.WriteHeapInfo("CaptureToBasisImage - Done");
  595. #endif
  596. return ESP_OK;
  597. }
  598. esp_err_t CCamera::CaptureToFile(std::string nm, int delay)
  599. {
  600. string ftype;
  601. LEDOnOff(true); // Status-LED on
  602. if (delay > 0)
  603. {
  604. LightOnOff(true); // Flash-LED on
  605. const TickType_t xDelay = delay / portTICK_PERIOD_MS;
  606. vTaskDelay(xDelay);
  607. }
  608. camera_fb_t *fb = esp_camera_fb_get();
  609. esp_camera_fb_return(fb);
  610. fb = esp_camera_fb_get();
  611. if (!fb)
  612. {
  613. LEDOnOff(false); // Status-LED off
  614. LightOnOff(false); // Flash-LED off
  615. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "CaptureToFile: Capture Failed. "
  616. "Check camera module and/or proper electrical connection");
  617. // doReboot();
  618. return ESP_FAIL;
  619. }
  620. LEDOnOff(false); // Status-LED off
  621. #ifdef DEBUG_DETAIL_ON
  622. ESP_LOGD(TAG, "w %d, h %d, size %d", fb->width, fb->height, fb->len);
  623. #endif
  624. nm = FormatFileName(nm);
  625. #ifdef DEBUG_DETAIL_ON
  626. ESP_LOGD(TAG, "Save Camera to: %s", nm.c_str());
  627. #endif
  628. ftype = toUpper(getFileType(nm));
  629. #ifdef DEBUG_DETAIL_ON
  630. ESP_LOGD(TAG, "Filetype: %s", ftype.c_str());
  631. #endif
  632. uint8_t *buf = NULL;
  633. size_t buf_len = 0;
  634. bool converted = false;
  635. if (ftype.compare("BMP") == 0)
  636. {
  637. frame2bmp(fb, &buf, &buf_len);
  638. converted = true;
  639. }
  640. if (ftype.compare("JPG") == 0)
  641. {
  642. if (fb->format != PIXFORMAT_JPEG)
  643. {
  644. bool jpeg_converted = frame2jpg(fb, CCstatus.ImageQuality, &buf, &buf_len);
  645. converted = true;
  646. if (!jpeg_converted)
  647. {
  648. ESP_LOGE(TAG, "JPEG compression failed");
  649. }
  650. }
  651. else
  652. {
  653. buf_len = fb->len;
  654. buf = fb->buf;
  655. }
  656. }
  657. FILE *fp = fopen(nm.c_str(), "wb");
  658. if (fp == NULL)
  659. {
  660. // If an error occurs during the file creation
  661. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "CaptureToFile: Failed to open file " + nm);
  662. }
  663. else
  664. {
  665. fwrite(buf, sizeof(uint8_t), buf_len, fp);
  666. fclose(fp);
  667. }
  668. if (converted)
  669. {
  670. free(buf);
  671. }
  672. esp_camera_fb_return(fb);
  673. if (delay > 0)
  674. {
  675. LightOnOff(false); // Flash-LED off
  676. }
  677. return ESP_OK;
  678. }
  679. esp_err_t CCamera::CaptureToHTTP(httpd_req_t *req, int delay)
  680. {
  681. esp_err_t res = ESP_OK;
  682. size_t fb_len = 0;
  683. int64_t fr_start = esp_timer_get_time();
  684. LEDOnOff(true); // Status-LED on
  685. if (delay > 0)
  686. {
  687. LightOnOff(true); // Flash-LED on
  688. const TickType_t xDelay = delay / portTICK_PERIOD_MS;
  689. vTaskDelay(xDelay);
  690. }
  691. camera_fb_t *fb = esp_camera_fb_get();
  692. esp_camera_fb_return(fb);
  693. fb = esp_camera_fb_get();
  694. if (!fb)
  695. {
  696. LEDOnOff(false); // Status-LED off
  697. LightOnOff(false); // Flash-LED off
  698. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "CaptureToFile: Capture Failed. "
  699. "Check camera module and/or proper electrical connection");
  700. httpd_resp_send_500(req);
  701. // doReboot();
  702. return ESP_FAIL;
  703. }
  704. LEDOnOff(false); // Status-LED off
  705. res = httpd_resp_set_type(req, "image/jpeg");
  706. if (res == ESP_OK)
  707. {
  708. res = httpd_resp_set_hdr(req, "Content-Disposition", "inline; filename=raw.jpg");
  709. }
  710. if (res == ESP_OK)
  711. {
  712. if (CCstatus.DemoMode)
  713. {
  714. // Use images stored on SD-Card instead of camera image
  715. LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Using Demo image!");
  716. /* Replace Framebuffer with image from SD-Card */
  717. loadNextDemoImage(fb);
  718. res = httpd_resp_send(req, (const char *)fb->buf, fb->len);
  719. }
  720. else
  721. {
  722. if (fb->format == PIXFORMAT_JPEG)
  723. {
  724. fb_len = fb->len;
  725. res = httpd_resp_send(req, (const char *)fb->buf, fb->len);
  726. }
  727. else
  728. {
  729. jpg_chunking_t jchunk = {req, 0};
  730. res = frame2jpg_cb(fb, 80, jpg_encode_stream, &jchunk) ? ESP_OK : ESP_FAIL;
  731. httpd_resp_send_chunk(req, NULL, 0);
  732. fb_len = jchunk.len;
  733. }
  734. }
  735. }
  736. esp_camera_fb_return(fb);
  737. int64_t fr_end = esp_timer_get_time();
  738. ESP_LOGI(TAG, "JPG: %dKB %dms", (int)(fb_len / 1024), (int)((fr_end - fr_start) / 1000));
  739. if (delay > 0)
  740. {
  741. LightOnOff(false); // Flash-LED off
  742. }
  743. return res;
  744. }
  745. esp_err_t CCamera::CaptureToStream(httpd_req_t *req, bool FlashlightOn)
  746. {
  747. esp_err_t res = ESP_OK;
  748. size_t fb_len = 0;
  749. int64_t fr_start;
  750. char *part_buf[64];
  751. // wenn die Kameraeinstellungen durch Erstellen eines neuen Referenzbildes verändert wurden, müssen sie neu gesetzt werden
  752. if (CFstatus.changedCameraSettings)
  753. {
  754. Camera.setSensorDatenFromCCstatus(); // CCstatus >>> Kamera
  755. Camera.SetQualityZoomSize(CCstatus.ImageQuality, CCstatus.ImageFrameSize, CCstatus.ImageZoomEnabled, CCstatus.ImageZoomOffsetX, CCstatus.ImageZoomOffsetY, CCstatus.ImageZoomSize, CCstatus.ImageVflip);
  756. CFstatus.changedCameraSettings = false;
  757. }
  758. LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Live stream started");
  759. if (FlashlightOn)
  760. {
  761. LEDOnOff(true); // Status-LED on
  762. LightOnOff(true); // Flash-LED on
  763. }
  764. // httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); //stream is blocking web interface, only serving to local
  765. httpd_resp_set_type(req, _STREAM_CONTENT_TYPE);
  766. httpd_resp_send_chunk(req, _STREAM_BOUNDARY, strlen(_STREAM_BOUNDARY));
  767. while (1)
  768. {
  769. fr_start = esp_timer_get_time();
  770. camera_fb_t *fb = esp_camera_fb_get();
  771. esp_camera_fb_return(fb);
  772. fb = esp_camera_fb_get();
  773. if (!fb)
  774. {
  775. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "CaptureToStream: Camera framebuffer not available");
  776. break;
  777. }
  778. fb_len = fb->len;
  779. if (res == ESP_OK)
  780. {
  781. size_t hlen = snprintf((char *)part_buf, sizeof(part_buf), _STREAM_PART, fb_len);
  782. res = httpd_resp_send_chunk(req, (const char *)part_buf, hlen);
  783. }
  784. if (res == ESP_OK)
  785. {
  786. res = httpd_resp_send_chunk(req, (const char *)fb->buf, fb_len);
  787. }
  788. if (res == ESP_OK)
  789. {
  790. res = httpd_resp_send_chunk(req, _STREAM_BOUNDARY, strlen(_STREAM_BOUNDARY));
  791. }
  792. esp_camera_fb_return(fb);
  793. int64_t fr_end = esp_timer_get_time();
  794. ESP_LOGD(TAG, "JPG: %dKB %dms", (int)(fb_len / 1024), (int)((fr_end - fr_start) / 1000));
  795. if (res != ESP_OK)
  796. {
  797. // Exit loop, e.g. also when closing the webpage
  798. break;
  799. }
  800. int64_t fr_delta_ms = (fr_end - fr_start) / 1000;
  801. if (CAM_LIVESTREAM_REFRESHRATE > fr_delta_ms)
  802. {
  803. const TickType_t xDelay = (CAM_LIVESTREAM_REFRESHRATE - fr_delta_ms) / portTICK_PERIOD_MS;
  804. ESP_LOGD(TAG, "Stream: sleep for: %ldms", (long)xDelay * 10);
  805. vTaskDelay(xDelay);
  806. }
  807. }
  808. LEDOnOff(false); // Status-LED off
  809. LightOnOff(false); // Flash-LED off
  810. LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Live stream stopped");
  811. return res;
  812. }
  813. void CCamera::LightOnOff(bool status)
  814. {
  815. GpioHandler *gpioHandler = gpio_handler_get();
  816. if ((gpioHandler != NULL) && (gpioHandler->isEnabled()))
  817. {
  818. ESP_LOGD(TAG, "Use gpioHandler to trigger flashlight");
  819. gpioHandler->flashLightEnable(status);
  820. }
  821. else
  822. {
  823. #ifdef USE_PWM_LEDFLASH
  824. if (status)
  825. {
  826. ESP_LOGD(TAG, "Internal Flash-LED turn on with PWM %d", CCstatus.ImageLedIntensity);
  827. ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, CCstatus.ImageLedIntensity));
  828. // Update duty to apply the new value
  829. ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));
  830. }
  831. else
  832. {
  833. ESP_LOGD(TAG, "Internal Flash-LED turn off PWM");
  834. ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, 0));
  835. ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));
  836. }
  837. #else
  838. // Init the GPIO
  839. gpio_pad_select_gpio(FLASH_GPIO);
  840. // Set the GPIO as a push/pull output
  841. gpio_set_direction(FLASH_GPIO, GPIO_MODE_OUTPUT);
  842. if (status)
  843. {
  844. gpio_set_level(FLASH_GPIO, 1);
  845. }
  846. else
  847. {
  848. gpio_set_level(FLASH_GPIO, 0);
  849. }
  850. #endif
  851. }
  852. }
  853. void CCamera::LEDOnOff(bool status)
  854. {
  855. if (xHandle_task_StatusLED == NULL)
  856. {
  857. // Init the GPIO
  858. gpio_pad_select_gpio(BLINK_GPIO);
  859. /* Set the GPIO as a push/pull output */
  860. gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
  861. if (!status)
  862. {
  863. gpio_set_level(BLINK_GPIO, 1);
  864. }
  865. else
  866. {
  867. gpio_set_level(BLINK_GPIO, 0);
  868. }
  869. }
  870. }
  871. void CCamera::SetImageWidthHeightFromResolution(framesize_t resol)
  872. {
  873. if (resol == FRAMESIZE_QVGA)
  874. {
  875. CCstatus.ImageHeight = 240;
  876. CCstatus.ImageWidth = 320;
  877. }
  878. else if (resol == FRAMESIZE_VGA)
  879. {
  880. CCstatus.ImageHeight = 480;
  881. CCstatus.ImageWidth = 640;
  882. }
  883. else if (resol == FRAMESIZE_SVGA)
  884. {
  885. CCstatus.ImageHeight = 600;
  886. CCstatus.ImageWidth = 800;
  887. }
  888. else if (resol == FRAMESIZE_XGA)
  889. {
  890. CCstatus.ImageHeight = 768;
  891. CCstatus.ImageWidth = 1024;
  892. }
  893. else if (resol == FRAMESIZE_HD)
  894. {
  895. CCstatus.ImageHeight = 720;
  896. CCstatus.ImageWidth = 1280;
  897. }
  898. else if (resol == FRAMESIZE_SXGA)
  899. {
  900. CCstatus.ImageHeight = 1024;
  901. CCstatus.ImageWidth = 1280;
  902. }
  903. else if (resol == FRAMESIZE_UXGA)
  904. {
  905. CCstatus.ImageHeight = 1200;
  906. CCstatus.ImageWidth = 1600;
  907. }
  908. }
  909. framesize_t CCamera::TextToFramesize(const char *_size)
  910. {
  911. if (strcmp(_size, "QVGA") == 0)
  912. {
  913. return FRAMESIZE_QVGA; // 320x240
  914. }
  915. else if (strcmp(_size, "VGA") == 0)
  916. {
  917. return FRAMESIZE_VGA; // 640x480
  918. }
  919. else if (strcmp(_size, "SVGA") == 0)
  920. {
  921. return FRAMESIZE_SVGA; // 800x600
  922. }
  923. else if (strcmp(_size, "XGA") == 0)
  924. {
  925. return FRAMESIZE_XGA; // 1024x768
  926. }
  927. else if (strcmp(_size, "SXGA") == 0)
  928. {
  929. return FRAMESIZE_SXGA; // 1280x1024
  930. }
  931. else if (strcmp(_size, "UXGA") == 0)
  932. {
  933. return FRAMESIZE_UXGA; // 1600x1200
  934. }
  935. return CCstatus.ImageFrameSize;
  936. }
  937. std::vector<std::string> demoFiles;
  938. void CCamera::useDemoMode(void)
  939. {
  940. char line[50];
  941. FILE *fd = fopen("/sdcard/demo/files.txt", "r");
  942. if (!fd)
  943. {
  944. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Can not start Demo mode, the folder '/sdcard/demo/' does not contain the needed files!");
  945. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "See Details on https://jomjol.github.io/AI-on-the-edge-device-docs/Demo-Mode!");
  946. return;
  947. }
  948. demoImage = (uint8_t *)malloc(DEMO_IMAGE_SIZE);
  949. if (demoImage == NULL)
  950. {
  951. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Unable to acquire required memory for demo image!");
  952. return;
  953. }
  954. while (fgets(line, sizeof(line), fd) != NULL)
  955. {
  956. line[strlen(line) - 1] = '\0';
  957. demoFiles.push_back(line);
  958. }
  959. fclose(fd);
  960. LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Using Demo mode (" + std::to_string(demoFiles.size()) + " files) instead of real camera image!");
  961. for (auto file : demoFiles)
  962. {
  963. LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, file);
  964. }
  965. CCstatus.DemoMode = true;
  966. }
  967. bool CCamera::loadNextDemoImage(camera_fb_t *fb)
  968. {
  969. char filename[50];
  970. int readBytes;
  971. long fileSize;
  972. snprintf(filename, sizeof(filename), "/sdcard/demo/%s", demoFiles[getCountFlowRounds() % demoFiles.size()].c_str());
  973. LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Using " + std::string(filename) + " as demo image");
  974. /* Inject saved image */
  975. FILE *fp = fopen(filename, "rb");
  976. if (!fp)
  977. {
  978. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to read file: " + std::string(filename) + "!");
  979. return false;
  980. }
  981. fileSize = GetFileSize(filename);
  982. if (fileSize > DEMO_IMAGE_SIZE)
  983. {
  984. char buf[100];
  985. snprintf(buf, sizeof(buf), "Demo Image (%d bytes) is larger than provided buffer (%d bytes)!", (int)fileSize, DEMO_IMAGE_SIZE);
  986. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, std::string(buf));
  987. return false;
  988. }
  989. readBytes = fread(demoImage, 1, DEMO_IMAGE_SIZE, fp);
  990. LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "read " + std::to_string(readBytes) + " bytes");
  991. fclose(fp);
  992. fb->buf = demoImage; // Update pointer
  993. fb->len = readBytes;
  994. // ToDo do we also need to set height, width, format and timestamp?
  995. return true;
  996. }
  997. long CCamera::GetFileSize(std::string filename)
  998. {
  999. struct stat stat_buf;
  1000. long rc = stat(filename.c_str(), &stat_buf);
  1001. return rc == 0 ? stat_buf.st_size : -1;
  1002. }