fix(uvc osx): check the video format and throw warning

This commit is contained in:
Tiny 2018-12-27 17:13:22 +08:00
parent 20b6026789
commit a52c5f510d
3 changed files with 35 additions and 2419 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) 2014 Vidvox, LLC
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -141,10 +141,15 @@ struct device : public AVfoundationCamera{
volatile bool pause_ = false; volatile bool pause_ = false;
volatile bool stop = false; volatile bool stop = false;
unsigned char *cameraBuffer = NULL; unsigned char *camera_buffer = NULL;
unsigned char *cameraWriteBuffer = NULL; unsigned char *camera_write_buffer = NULL;
std::mutex _devices_mutex; std::mutex _devices_mutex;
CameraConfig get_camera_config() const {
return _config;
}
device(std::shared_ptr<context> parent, const CameraConfig &config) device(std::shared_ptr<context> parent, const CameraConfig &config)
: AVfoundationCamera(& const_cast<CameraConfig&>(config)), : AVfoundationCamera(& const_cast<CameraConfig&>(config)),
parent(parent), _config(config) { parent(parent), _config(config) {
@ -216,10 +221,10 @@ struct device : public AVfoundationCamera{
void poll() { void poll() {
if (is_capturing) { if (is_capturing) {
cameraBuffer = getFrame(); camera_buffer = getFrame();
if (cameraBuffer != NULL) { if (camera_buffer != NULL) {
if (callback) { if (callback) {
callback(cameraBuffer, [this]() mutable { callback(camera_buffer, [this]() mutable {
// todo // todo
}); });
} }
@ -263,13 +268,6 @@ struct device : public AVfoundationCamera{
stopCamera(); stopCamera();
closeCamera(); closeCamera();
} }
// void reset_options_to_default() {
// setCameraSetting(BRIGHTNESS, 120);
// setCameraSetting(CONTRAST, 127);
// setCameraSetting(GAIN, 24);
// setCameraSetting(SATURATION, 192);
// }
}; };
std::vector <struct device*> device::s_devices; std::vector <struct device*> device::s_devices;
@ -281,6 +279,7 @@ MYNTEYE_API std::shared_ptr<context> create_context() {
MYNTEYE_API std::vector<std::shared_ptr<device>> query_devices( MYNTEYE_API std::vector<std::shared_ptr<device>> query_devices(
std::shared_ptr<context> context) { std::shared_ptr<context> context) {
std::vector<std::shared_ptr<device>> devices; std::vector<std::shared_ptr<device>> devices;
auto camerasConfig = findDevicesConfig(); auto camerasConfig = findDevicesConfig();
printConfig(camerasConfig); printConfig(camerasConfig);
@ -379,7 +378,7 @@ MYNTEYE_API bool pu_control_query(
return true; return true;
} }
// Access XU (Extension Unit) controls // Access XU (Extension Unit) controls , Not supported on osx
MYNTEYE_API bool xu_control_range( MYNTEYE_API bool xu_control_range(
const device &/*device*/, const xu &/*xu*/, const device &/*device*/, const xu &/*xu*/,
uint8_t /*selector*/, uint8_t /*id*/, uint8_t /*selector*/, uint8_t /*id*/,
@ -398,10 +397,30 @@ MYNTEYE_API bool xu_control_query( // XU_QUERY_SET, XU_QUERY_GET
} }
MYNTEYE_API void set_device_mode( 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) { video_channel_callback callback) {
MYNTEYE_UNUSED(fourcc); if (width != device.get_camera_config().cam_width ||
MYNTEYE_UNUSED(fps); height != device.get_camera_config().cam_height) {
LOG(ERROR) << __func__
<< width << "x" << height << "|"
<< device.get_camera_config().cam_width << "x"
<< device.get_camera_config().cam_height << std::endl
<< " failed: the different size can't be set to get frame.";
return;
}
if (fps < device.getFps()) {
LOG(WARNING) << __func__
<< " The fps requied is less than the sdk support.";
} else if (fps > device.getFps()) {
LOG(WARNING) << __func__
<< " The fps requied is more than the"
<< " sdk max support, use the max fps instead.";
}
if (fourcc != static_cast<int>(Format::YUYV)) {
LOG(WARNING) << __func__
<< " sdk max just support yuyv video mode.";
}
device.callback = callback; device.callback = callback;
} }
MYNTEYE_API void start_streaming(device &device, int num_transfer_bufs) { // NOLINT MYNTEYE_API void start_streaming(device &device, int num_transfer_bufs) { // NOLINT