style(uvc osx): code style improve.
This commit is contained in:
parent
6b93ceecee
commit
50571a4a40
|
@ -59,31 +59,37 @@ void printConfig(std::vector<CameraConfig> cfg_list) {
|
|||
int format = -1;
|
||||
int frame_mode = -1;
|
||||
|
||||
for (int i=0;i<(int)cfg_list.size();i++) {
|
||||
for (unsigned int i=0; i < cfg_list.size(); i++) {
|
||||
if (cfg_list[i].device != device) {
|
||||
if (device >= 0) printf("\b fps\n");
|
||||
device = cfg_list[i].device;
|
||||
if(strncmp(cfg_list[i].name, MYNT_DEV_NAME, strlen(MYNT_DEV_NAME)) == 0) {
|
||||
if (strncmp(cfg_list[i].name,
|
||||
MYNT_DEV_NAME, strlen(MYNT_DEV_NAME)) == 0) {
|
||||
printf("*");
|
||||
} else {
|
||||
printf(" ");
|
||||
}
|
||||
|
||||
printf(" %d: %s\n", cfg_list[i].device, cfg_list[i].name);
|
||||
format = -1;
|
||||
}
|
||||
|
||||
if ((cfg_list[i].cam_format != format) || (cfg_list[i].frame_mode != frame_mode)) {
|
||||
if ((cfg_list[i].cam_format != format) ||
|
||||
(cfg_list[i].frame_mode != frame_mode)) {
|
||||
if (format >= 0) printf("\b fps\n");
|
||||
format = cfg_list[i].cam_format;
|
||||
if(cfg_list[i].frame_mode<0) printf(" format: %s",fstr[cfg_list[i].cam_format]);
|
||||
else printf(" format7_%d: %s",cfg_list[i].frame_mode,fstr[cfg_list[i].cam_format]);
|
||||
if (cfg_list[i].frame_mode < 0) {
|
||||
printf(" format: %s", fstr[cfg_list[i].cam_format]);
|
||||
} else {
|
||||
printf(" format7_%d: %s", cfg_list[i].frame_mode,
|
||||
fstr[cfg_list[i].cam_format]);
|
||||
}
|
||||
// if(cfg_list[i].compress) printf(" (default)");
|
||||
width = height = fps = -1;
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
if ((cfg_list[i].cam_width != width) || (cfg_list[i].cam_height != height)) {
|
||||
if ((cfg_list[i].cam_width != width) ||
|
||||
(cfg_list[i].cam_height != height)) {
|
||||
if (width > 0) printf("\b fps\n");
|
||||
printf(" %dx%d ", cfg_list[i].cam_width, cfg_list[i].cam_height);
|
||||
width = cfg_list[i].cam_width;
|
||||
|
@ -91,11 +97,14 @@ void printConfig(std::vector<CameraConfig> cfg_list) {
|
|||
fps = INT_MAX;
|
||||
}
|
||||
|
||||
if (cfg_list[i].frame_mode>=0) printf("max|");
|
||||
else if (cfg_list[i].cam_fps != fps) {
|
||||
if(int(cfg_list[i].cam_fps)==cfg_list[i].cam_fps)
|
||||
printf("%d|",int(cfg_list[i].cam_fps));
|
||||
else printf("%.1f|",cfg_list[i].cam_fps);
|
||||
if (cfg_list[i].frame_mode >= 0) {
|
||||
printf("max|");
|
||||
} else if (cfg_list[i].cam_fps != fps) {
|
||||
if (static_cast<int>(cfg_list[i].cam_fps) == cfg_list[i].cam_fps) {
|
||||
printf("%d|", static_cast<int>(cfg_list[i].cam_fps));
|
||||
} else {
|
||||
printf("%.1f|", cfg_list[i].cam_fps);
|
||||
}
|
||||
fps = cfg_list[i].cam_fps;
|
||||
}
|
||||
}
|
||||
|
@ -189,8 +198,9 @@ struct device : public AVfoundationCamera{
|
|||
unsigned char *cameraWriteBuffer = NULL;
|
||||
|
||||
std::mutex _devices_mutex;
|
||||
device(std::shared_ptr<context> parent, CameraConfig &config)
|
||||
: AVfoundationCamera(&config), parent(parent), _config(config){
|
||||
device(std::shared_ptr<context> parent, const CameraConfig &config)
|
||||
: AVfoundationCamera(& const_cast<CameraConfig&>(config)),
|
||||
parent(parent), _config(config) {
|
||||
VLOG(2) << __func__;
|
||||
if (strncmp(config.name, MYNT_DEV_NAME, strlen(MYNT_DEV_NAME)) == 0) {
|
||||
_vendor_id = MYNTEYE_VID; // 0x04B4
|
||||
|
@ -205,7 +215,7 @@ struct device : public AVfoundationCamera{
|
|||
~device() {
|
||||
VLOG(2) << __func__;
|
||||
std::lock_guard<std::mutex> lock(_devices_mutex);
|
||||
for(unsigned long i = 0 ; i < s_devices.size() ; i++) {
|
||||
for (unsigned int i = 0 ; i < s_devices.size() ; i++) {
|
||||
if (this == s_devices[i]) {
|
||||
s_devices.erase(s_devices.begin()+i);
|
||||
}
|
||||
|
@ -217,25 +227,6 @@ struct device : public AVfoundationCamera{
|
|||
setup_camera();
|
||||
}
|
||||
|
||||
// void set_format(
|
||||
// int width, int height, int format, int fps,
|
||||
// video_channel_callback callback) {
|
||||
// this->width = width;
|
||||
// this->height = height;
|
||||
// this->format = format;
|
||||
// this->fps = fps;
|
||||
// this->callback = callback;
|
||||
// }
|
||||
|
||||
// static void uvc_frame_callback (struct uvc_frame *frame, void *user_ptr)
|
||||
// {
|
||||
// for(unsigned long i = 0 ; i < s_devices.size() ; i++) {
|
||||
// if(user_ptr == (void*)s_devices[i]) {
|
||||
// printf("bingo\n");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
void start_capture() {
|
||||
if (is_capturing) {
|
||||
LOG(WARNING) << "Start capture failed, is capturing already";
|
||||
|
@ -268,7 +259,7 @@ struct device : public AVfoundationCamera{
|
|||
if (initCamera()) {
|
||||
printInfo();
|
||||
} else {
|
||||
printf("could not initialize selected camera\n");
|
||||
LOG(ERROR) << "could not initialize selected camera";
|
||||
closeCamera();
|
||||
return;
|
||||
}
|
||||
|
@ -284,8 +275,8 @@ struct device : public AVfoundationCamera{
|
|||
// memcpy(cameraWriteBuffer,cameraBuffer,engine->ringBuffer->size());
|
||||
// engine->framenumber_++;
|
||||
// engine->ringBuffer->writeFinished();
|
||||
// //long driver_time = VisionEngine::currentMicroSeconds() - start_time;
|
||||
// //std::cout << "camera latency: " << driver_time/1000.0f << "ms" << std::endl;
|
||||
// long driver_time = VisionEngine::currentMicroSeconds() - start_time;
|
||||
// std::cout << "camera latency: " << driver_time/1000.0f << "ms" << std::endl;
|
||||
// }
|
||||
if (callback) {
|
||||
callback(cameraBuffer, [this]() mutable {
|
||||
|
@ -295,10 +286,10 @@ struct device : public AVfoundationCamera{
|
|||
pv_sleep();
|
||||
} else {
|
||||
if ((is_capturing) && (!stillRunning())) {
|
||||
printf("error!\n");
|
||||
} else pv_sleep();
|
||||
LOG(ERROR) << "error status in camera running.";
|
||||
} else { pv_sleep(); }
|
||||
}
|
||||
} else pv_sleep(5);
|
||||
} else { pv_sleep(5); }
|
||||
}
|
||||
|
||||
void pause(bool pause) {
|
||||
|
@ -310,9 +301,7 @@ struct device : public AVfoundationCamera{
|
|||
LOG(WARNING) << __func__ << " failed: video_channel_callback is empty";
|
||||
return;
|
||||
}
|
||||
|
||||
start_capture();
|
||||
|
||||
thread = std::thread([this]() {
|
||||
while (!stop)
|
||||
poll();
|
||||
|
@ -367,34 +356,46 @@ MYNTEYE_API std::string get_video_name(const device &device) {
|
|||
MYNTEYE_API bool pu_control_range(
|
||||
const device &device, Option option, int32_t *min, int32_t *max,
|
||||
int32_t *def) {
|
||||
// todo
|
||||
MYNTEYE_UNUSED(device);
|
||||
MYNTEYE_UNUSED(option);
|
||||
MYNTEYE_UNUSED(min);
|
||||
MYNTEYE_UNUSED(max);
|
||||
}
|
||||
MYNTEYE_API bool pu_control_query(
|
||||
const device &device, Option option, pu_query query, int32_t *value) {
|
||||
// todo
|
||||
MYNTEYE_UNUSED(device);
|
||||
MYNTEYE_UNUSED(option);
|
||||
MYNTEYE_UNUSED(query);
|
||||
MYNTEYE_UNUSED(value);
|
||||
}
|
||||
|
||||
// Access XU (Extension Unit) controls
|
||||
MYNTEYE_API bool xu_control_range(
|
||||
const device &device, const xu &xu, uint8_t selector, uint8_t id,
|
||||
int32_t *min, int32_t *max, int32_t *def) {
|
||||
const device &/*device*/, const xu &/*xu*/,
|
||||
uint8_t /*selector*/, uint8_t /*id*/,
|
||||
int32_t * /*min*/, int32_t * /*max*/, int32_t * /*def*/) {
|
||||
// not supported on osx
|
||||
LOG(WARNING) << __func__ << " failed: this API is not supported on osx";
|
||||
}
|
||||
MYNTEYE_API bool xu_control_query( // XU_QUERY_SET, XU_QUERY_GET
|
||||
const device &device, const xu &xu, uint8_t selector, xu_query query,
|
||||
uint16_t size, uint8_t *data) {
|
||||
const device &/*device*/, const xu &/*xu*/,
|
||||
uint8_t /*selector*/, xu_query /*query*/,
|
||||
uint16_t /*size*/, uint8_t * /*data*/) {
|
||||
// not supported on osx
|
||||
LOG(WARNING) << __func__ << " failed: this API is not supported on osx";
|
||||
}
|
||||
|
||||
MYNTEYE_API void set_device_mode(
|
||||
device &device, int width, int height, int fourcc, int fps, // NOLINT
|
||||
device &device, int /*width*/, int /*height*/, int fourcc, int fps, // NOLINT
|
||||
video_channel_callback callback) {
|
||||
MYNTEYE_UNUSED(fourcc);
|
||||
MYNTEYE_UNUSED(fps);
|
||||
device.callback = callback;
|
||||
}
|
||||
MYNTEYE_API void start_streaming(device &device, int num_transfer_bufs) {
|
||||
MYNTEYE_API void start_streaming(device &device, int num_transfer_bufs) { // NOLINT
|
||||
device.start_streaming();
|
||||
}
|
||||
MYNTEYE_API void stop_streaming(device &device) {
|
||||
MYNTEYE_API void stop_streaming(device &device) { // NOLINT
|
||||
device.stop_streaming();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user