Camera: allow to configure minimum stream size.
HW video encoder usually has limitation to encode very small
stream. Camera should avoid to return such streams to avoid
video encoding failure.
BUG: 110654511
Test: CTS android.hardware.camera2.cts.RecordingTest#testSupportedVideoSizes
Change-Id: I6104f2d4efcf7831d1dc6d305c82309e2fd1999d
diff --git a/camera/device/3.4/default/ExternalCameraDevice.cpp b/camera/device/3.4/default/ExternalCameraDevice.cpp
index ee7ffaa..167b623 100644
--- a/camera/device/3.4/default/ExternalCameraDevice.cpp
+++ b/camera/device/3.4/default/ExternalCameraDevice.cpp
@@ -787,7 +787,8 @@
std::vector<SupportedV4L2Format>
ExternalCameraDevice::getCandidateSupportedFormatsLocked(
int fd, CroppingType cropType,
- const std::vector<ExternalCameraConfig::FpsLimitation>& fpsLimits) {
+ const std::vector<ExternalCameraConfig::FpsLimitation>& fpsLimits,
+ const Size& minStreamSize) {
std::vector<SupportedV4L2Format> outFmts;
struct v4l2_fmtdesc fmtdesc {
.index = 0,
@@ -822,6 +823,11 @@
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 @@
void ExternalCameraDevice::initSupportedFormatsLocked(int fd) {
std::vector<SupportedV4L2Format> horizontalFmts =
- getCandidateSupportedFormatsLocked(fd, HORIZONTAL, mCfg.fpsLimits);
+ getCandidateSupportedFormatsLocked(fd, HORIZONTAL, mCfg.fpsLimits, mCfg.minStreamSize);
std::vector<SupportedV4L2Format> 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 2e2f73b..680c95a 100644
--- a/camera/device/3.4/default/ExternalCameraUtils.cpp
+++ b/camera/device/3.4/default/ExternalCameraUtils.cpp
@@ -267,6 +267,15 @@
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 @@
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 @@
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 a52f0e4..ff0cfb3 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 @@
// Get candidate supported formats list of input cropping type.
static std::vector<SupportedV4L2Format> getCandidateSupportedFormatsLocked(
int fd, CroppingType cropType,
- const std::vector<ExternalCameraConfig::FpsLimitation>& fpsLimits);
+ const std::vector<ExternalCameraConfig::FpsLimitation>& 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<SupportedV4L2Format>* 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 37e7cfb..5754ccb 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 @@
};
std::vector<FpsLimitation> fpsLimits;
+ // Minimum output stream size
+ Size minStreamSize;
+
private:
ExternalCameraConfig();
};