Add menu and slider options.
ControlOptionsInterfaces for lists and ranges. BUG: 30140438 TEST: unit tests pass Change-Id: I7bcb63777600cff18347c8eae54112025b6556b3
This commit is contained in:
parent
8c13aaf1ac
commit
e2a9a01296
5 changed files with 193 additions and 0 deletions
|
@ -56,9 +56,11 @@ v4l2_test_files := \
|
|||
metadata/fixed_property_test.cpp \
|
||||
metadata/ignored_control_test.cpp \
|
||||
metadata/map_converter_test.cpp \
|
||||
metadata/menu_control_options_test.cpp \
|
||||
metadata/metadata_test.cpp \
|
||||
metadata/optioned_control_test.cpp \
|
||||
metadata/ranged_converter_test.cpp \
|
||||
metadata/slider_control_options_test.cpp \
|
||||
metadata/v4l2_enum_control_test.cpp \
|
||||
|
||||
# V4L2 Camera HAL.
|
||||
|
|
42
modules/camera/3_4/metadata/menu_control_options.h
Normal file
42
modules/camera/3_4/metadata/menu_control_options.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef V4L2_CAMERA_HAL_METADATA_MENU_CONTROL_OPTIONS_H_
|
||||
#define V4L2_CAMERA_HAL_METADATA_MENU_CONTROL_OPTIONS_H_
|
||||
|
||||
#include "control_options_interface.h"
|
||||
|
||||
namespace v4l2_camera_hal {
|
||||
|
||||
// MenuControlOptions offer a fixed list of acceptable values.
|
||||
template <typename T>
|
||||
class MenuControlOptions : public ControlOptionsInterface<T> {
|
||||
public:
|
||||
MenuControlOptions(std::vector<T> options) : options_(options) {}
|
||||
|
||||
virtual std::vector<T> MetadataRepresentation() override { return options_; };
|
||||
virtual bool IsSupported(const T& option) override {
|
||||
return (std::find(options_.begin(), options_.end(), option) !=
|
||||
options_.end());
|
||||
};
|
||||
|
||||
private:
|
||||
std::vector<T> options_;
|
||||
};
|
||||
|
||||
} // namespace v4l2_camera_hal
|
||||
|
||||
#endif // V4L2_CAMERA_HAL_METADATA_MENU_CONTROL_OPTIONS_H_
|
49
modules/camera/3_4/metadata/menu_control_options_test.cpp
Normal file
49
modules/camera/3_4/metadata/menu_control_options_test.cpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "menu_control_options.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using testing::Test;
|
||||
|
||||
namespace v4l2_camera_hal {
|
||||
|
||||
class MenuControlOptionsTest : public Test {
|
||||
protected:
|
||||
virtual void SetUp() { dut_.reset(new MenuControlOptions<int>(options_)); }
|
||||
|
||||
std::unique_ptr<MenuControlOptions<int>> dut_;
|
||||
const std::vector<int> options_{1, 10, 19, 30};
|
||||
};
|
||||
|
||||
TEST_F(MenuControlOptionsTest, MetadataRepresentation) {
|
||||
// Technically order doesn't matter, but this is faster to write,
|
||||
// and still passes.
|
||||
EXPECT_EQ(dut_->MetadataRepresentation(), options_);
|
||||
}
|
||||
|
||||
TEST_F(MenuControlOptionsTest, IsSupported) {
|
||||
for (auto option : options_) {
|
||||
EXPECT_TRUE(dut_->IsSupported(option));
|
||||
}
|
||||
// And at least one unsupported.
|
||||
EXPECT_FALSE(dut_->IsSupported(99));
|
||||
}
|
||||
|
||||
} // namespace v4l2_camera_hal
|
46
modules/camera/3_4/metadata/slider_control_options.h
Normal file
46
modules/camera/3_4/metadata/slider_control_options.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef V4L2_CAMERA_HAL_METADATA_SLIDER_CONTROL_OPTIONS_H_
|
||||
#define V4L2_CAMERA_HAL_METADATA_SLIDER_CONTROL_OPTIONS_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "control_options_interface.h"
|
||||
|
||||
namespace v4l2_camera_hal {
|
||||
|
||||
// SliderControlOptions offer a range of acceptable values, inclusive.
|
||||
template <typename T>
|
||||
class SliderControlOptions : public ControlOptionsInterface<T> {
|
||||
public:
|
||||
SliderControlOptions(T min, T max) : min_(min), max_(max) {}
|
||||
|
||||
virtual std::vector<T> MetadataRepresentation() override {
|
||||
return {min_, max_};
|
||||
};
|
||||
virtual bool IsSupported(const T& option) override {
|
||||
return option >= min_ && option <= max_;
|
||||
};
|
||||
|
||||
private:
|
||||
T min_;
|
||||
T max_;
|
||||
};
|
||||
|
||||
} // namespace v4l2_camera_hal
|
||||
|
||||
#endif // V4L2_CAMERA_HAL_METADATA_SLIDER_CONTROL_OPTIONS_H_
|
54
modules/camera/3_4/metadata/slider_control_options_test.cpp
Normal file
54
modules/camera/3_4/metadata/slider_control_options_test.cpp
Normal file
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "slider_control_options.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using testing::Test;
|
||||
|
||||
namespace v4l2_camera_hal {
|
||||
|
||||
class SliderControlOptionsTest : public Test {
|
||||
protected:
|
||||
virtual void SetUp() {
|
||||
dut_.reset(new SliderControlOptions<int>(min_, max_));
|
||||
}
|
||||
|
||||
std::unique_ptr<SliderControlOptions<int>> dut_;
|
||||
const int min_ = 1;
|
||||
const int max_ = 10;
|
||||
};
|
||||
|
||||
TEST_F(SliderControlOptionsTest, MetadataRepresentation) {
|
||||
// Technically order doesn't matter, but this is faster to write,
|
||||
// and still passes.
|
||||
std::vector<int> expected{min_, max_};
|
||||
EXPECT_EQ(dut_->MetadataRepresentation(), expected);
|
||||
}
|
||||
|
||||
TEST_F(SliderControlOptionsTest, IsSupported) {
|
||||
for (int i = min_; i <= max_; ++i) {
|
||||
EXPECT_TRUE(dut_->IsSupported(i));
|
||||
}
|
||||
// Out of range unsupported.
|
||||
EXPECT_FALSE(dut_->IsSupported(min_ - 1));
|
||||
EXPECT_FALSE(dut_->IsSupported(max_ + 1));
|
||||
}
|
||||
|
||||
} // namespace v4l2_camera_hal
|
Loading…
Reference in a new issue