diff --git a/camera/device/3.4/default/ExternalCameraDevice.cpp b/camera/device/3.4/default/ExternalCameraDevice.cpp index ee7ffaa8d6..167b62378b 100644 --- a/camera/device/3.4/default/ExternalCameraDevice.cpp +++ b/camera/device/3.4/default/ExternalCameraDevice.cpp @@ -787,7 +787,8 @@ void ExternalCameraDevice::trimSupportedFormats( std::vector ExternalCameraDevice::getCandidateSupportedFormatsLocked( int fd, CroppingType cropType, - const std::vector& fpsLimits) { + const std::vector& fpsLimits, + const Size& minStreamSize) { std::vector outFmts; struct v4l2_fmtdesc fmtdesc { .index = 0, @@ -822,6 +823,11 @@ ExternalCameraDevice::getCandidateSupportedFormatsLocked( if (frameSize.discrete.height > frameSize.discrete.width) { continue; } + // Discard all formats which is smaller than minStreamSize + if (frameSize.discrete.width < minStreamSize.width + || frameSize.discrete.height < minStreamSize.height) { + continue; + } SupportedV4L2Format format { .width = frameSize.discrete.width, .height = frameSize.discrete.height, @@ -864,9 +870,9 @@ ExternalCameraDevice::getCandidateSupportedFormatsLocked( void ExternalCameraDevice::initSupportedFormatsLocked(int fd) { std::vector horizontalFmts = - getCandidateSupportedFormatsLocked(fd, HORIZONTAL, mCfg.fpsLimits); + getCandidateSupportedFormatsLocked(fd, HORIZONTAL, mCfg.fpsLimits, mCfg.minStreamSize); std::vector verticalFmts = - getCandidateSupportedFormatsLocked(fd, VERTICAL, mCfg.fpsLimits); + getCandidateSupportedFormatsLocked(fd, VERTICAL, mCfg.fpsLimits, mCfg.minStreamSize); size_t horiSize = horizontalFmts.size(); size_t vertSize = verticalFmts.size(); diff --git a/camera/device/3.4/default/ExternalCameraUtils.cpp b/camera/device/3.4/default/ExternalCameraUtils.cpp index 2e2f73b362..680c95ad3b 100644 --- a/camera/device/3.4/default/ExternalCameraUtils.cpp +++ b/camera/device/3.4/default/ExternalCameraUtils.cpp @@ -267,6 +267,15 @@ ExternalCameraConfig ExternalCameraConfig::loadFromCfg(const char* cfgPath) { ret.fpsLimits = limits; } + XMLElement *minStreamSize = deviceCfg->FirstChildElement("MinimumStreamSize"); + if (minStreamSize == nullptr) { + ALOGI("%s: no minimum stream size specified", __FUNCTION__); + } else { + ret.minStreamSize = { + minStreamSize->UnsignedAttribute("width", /*Default*/0), + minStreamSize->UnsignedAttribute("height", /*Default*/0)}; + } + ALOGI("%s: external camera cfg loaded: maxJpgBufSize %d," " num video buffers %d, num still buffers %d", __FUNCTION__, ret.maxJpegBufSize, @@ -275,6 +284,8 @@ ExternalCameraConfig ExternalCameraConfig::loadFromCfg(const char* cfgPath) { ALOGI("%s: fpsLimitList: %dx%d@%f", __FUNCTION__, limit.size.width, limit.size.height, limit.fpsUpperBound); } + ALOGI("%s: minStreamSize: %dx%d" , __FUNCTION__, + ret.minStreamSize.width, ret.minStreamSize.height); return ret; } @@ -285,6 +296,7 @@ ExternalCameraConfig::ExternalCameraConfig() : fpsLimits.push_back({/*Size*/{ 640, 480}, /*FPS upper bound*/30.0}); fpsLimits.push_back({/*Size*/{1280, 720}, /*FPS upper bound*/7.5}); fpsLimits.push_back({/*Size*/{1920, 1080}, /*FPS upper bound*/5.0}); + minStreamSize = {0, 0}; } diff --git a/camera/device/3.4/default/include/ext_device_v3_4_impl/ExternalCameraDevice_3_4.h b/camera/device/3.4/default/include/ext_device_v3_4_impl/ExternalCameraDevice_3_4.h index a52f0e4ccb..ff0cfb301e 100644 --- a/camera/device/3.4/default/include/ext_device_v3_4_impl/ExternalCameraDevice_3_4.h +++ b/camera/device/3.4/default/include/ext_device_v3_4_impl/ExternalCameraDevice_3_4.h @@ -96,7 +96,8 @@ protected: // Get candidate supported formats list of input cropping type. static std::vector getCandidateSupportedFormatsLocked( int fd, CroppingType cropType, - const std::vector& fpsLimits); + const std::vector& fpsLimits, + const Size& minStreamSize); // Trim supported format list by the cropping type. Also sort output formats by width/height static void trimSupportedFormats(CroppingType cropType, /*inout*/std::vector* pFmts); diff --git a/camera/device/3.4/default/include/ext_device_v3_4_impl/ExternalCameraUtils.h b/camera/device/3.4/default/include/ext_device_v3_4_impl/ExternalCameraUtils.h index 37e7cfb32e..5754ccbec3 100644 --- a/camera/device/3.4/default/include/ext_device_v3_4_impl/ExternalCameraUtils.h +++ b/camera/device/3.4/default/include/ext_device_v3_4_impl/ExternalCameraUtils.h @@ -77,6 +77,9 @@ struct ExternalCameraConfig { }; std::vector fpsLimits; + // Minimum output stream size + Size minStreamSize; + private: ExternalCameraConfig(); };