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
This commit is contained in:
parent
c423162322
commit
8765444e20
4 changed files with 26 additions and 4 deletions
|
@ -787,7 +787,8 @@ void ExternalCameraDevice::trimSupportedFormats(
|
|||
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 @@ 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<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();
|
||||
|
|
|
@ -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};
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -96,7 +96,8 @@ protected:
|
|||
// 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);
|
||||
|
|
|
@ -77,6 +77,9 @@ struct ExternalCameraConfig {
|
|||
};
|
||||
std::vector<FpsLimitation> fpsLimits;
|
||||
|
||||
// Minimum output stream size
|
||||
Size minStreamSize;
|
||||
|
||||
private:
|
||||
ExternalCameraConfig();
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue