feat: add rudimentary usb cdc video streaming impl

This commit is contained in:
Sebastian Fitt 2023-04-07 21:08:55 +02:00
parent 86162720a5
commit 35f48f87b1
2 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,51 @@
#include "etvr_eye_tracker_usb.hpp"
#include <Arduino.h>
#include <USBCDC.h>
#include <esp_camera.h>
void etvr_eye_tracker_usb_init() {
Serial.begin(3000000);
Serial.flush();
}
void etvr_eye_tracker_usb_loop() {
int64_t last_frame = 0;
if (!last_frame)
last_frame = esp_timer_get_time();
long last_request_time = 0;
camera_fb_t* fb = NULL;
esp_err_t err = ESP_OK;
size_t len = 0;
uint8_t* buf = NULL;
while (true) {
fb = esp_camera_fb_get();
if (fb) {
len = fb->len;
buf = fb->buf;
} else {
log_e("Camera capture failed with response: %s", esp_err_to_name(err));
err = ESP_FAIL;
}
if (err == ESP_OK)
Serial.write((const char*)buf, len);
if (fb) {
esp_camera_fb_return(fb);
fb = NULL;
buf = NULL;
} else if (buf) {
free(buf);
buf = NULL;
}
if (err != ESP_OK)
break;
long request_end = millis();
long latency = request_end - last_request_time;
last_request_time = request_end;
log_d("Size: %uKB, Time: %ums (%ifps)\n", len / 1024, latency,
1000 / latency);
}
}

View File

@ -0,0 +1,7 @@
#ifndef INCLUDED_ETVR_EYE_TRACKER_USB_HPP
#define INCLUDED_ETVR_EYE_TRACKER_USB_HPP
void etvr_eye_tracker_usb_init();
void etvr_eye_tracker_usb_loop();
#endif // INCLUDED_ETVR_EYE_TRACKER_USB_HPP