Commit b47ce539 authored by weigua's avatar weigua Committed by Commit Bot

Add a feature list to media perception private API.

Bug: 900873
Change-Id: I684ac77608c8274cc8e221300b310f37bc41e9cf
Reviewed-on: https://chromium-review.googlesource.com/c/1312149
Commit-Queue: Wei Guan <weigua@chromium.org>
Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604865}
parent 7fb2910e
...@@ -87,6 +87,17 @@ message State { ...@@ -87,6 +87,17 @@ message State {
// Corners and aspect ratio of the whiteboard in the image frame. Should only // Corners and aspect ratio of the whiteboard in the image frame. Should only
// be set when setting state to running and configuration to whiteboard. // be set when setting state to running and configuration to whiteboard.
optional Whiteboard whiteboard = 5; optional Whiteboard whiteboard = 5;
enum Feature {
// UNSET is not a real feature value.
FEATURE_UNSET = 0;
FEATURE_AUTOZOOM = 1;
FEATURE_HOTWORD_DETECTION = 2;
FEATURE_OCCUPANCY_DETECTION = 3;
}
// A list of enabled media perception features.
repeated Feature features = 6;
} }
// This is the output of the MediaPerceptionSinkCalculator. // This is the output of the MediaPerceptionSinkCalculator.
......
...@@ -527,6 +527,36 @@ mri::State::Status StateStatusIdlToProto(const State& state) { ...@@ -527,6 +527,36 @@ mri::State::Status StateStatusIdlToProto(const State& state) {
return mri::State::STATUS_UNSPECIFIED; return mri::State::STATUS_UNSPECIFIED;
} }
Feature FeatureProtoToIdl(int feature) {
switch (feature) {
case mri::State::FEATURE_AUTOZOOM:
return FEATURE_AUTOZOOM;
case mri::State::FEATURE_HOTWORD_DETECTION:
return FEATURE_HOTWORD_DETECTION;
case mri::State::FEATURE_OCCUPANCY_DETECTION:
return FEATURE_OCCUPANCY_DETECTION;
case mri::State::FEATURE_UNSET:
return FEATURE_NONE;
}
NOTREACHED() << "Reached feature not in switch.";
return FEATURE_NONE;
}
mri::State::Feature FeatureIdlToProto(const Feature& feature) {
switch (feature) {
case FEATURE_AUTOZOOM:
return mri::State::FEATURE_AUTOZOOM;
case FEATURE_HOTWORD_DETECTION:
return mri::State::FEATURE_HOTWORD_DETECTION;
case FEATURE_OCCUPANCY_DETECTION:
return mri::State::FEATURE_OCCUPANCY_DETECTION;
case FEATURE_NONE:
return mri::State::FEATURE_UNSET;
}
NOTREACHED() << "Reached feature not in switch.";
return mri::State::FEATURE_UNSET;
}
void VideoStreamParamIdlToProto(mri::VideoStreamParam* param_result, void VideoStreamParamIdlToProto(mri::VideoStreamParam* param_result,
const VideoStreamParam& param) { const VideoStreamParam& param) {
if (param_result == nullptr) if (param_result == nullptr)
...@@ -614,7 +644,14 @@ State StateProtoToIdl(const mri::State& state) { ...@@ -614,7 +644,14 @@ State StateProtoToIdl(const mri::State& state) {
} }
if (state.has_whiteboard()) if (state.has_whiteboard())
state_result.whiteboard = WhiteboardProtoToIdl(state.whiteboard()); state_result.whiteboard = WhiteboardProtoToIdl(state.whiteboard());
if (state.features_size() > 0) {
state_result.features = std::make_unique<std::vector<Feature>>();
for (const auto& feature : state.features()) {
const Feature feature_result = FeatureProtoToIdl(feature);
if (feature_result != FEATURE_NONE)
state_result.features->emplace_back(feature_result);
}
}
return state_result; return state_result;
} }
...@@ -639,6 +676,11 @@ mri::State StateIdlToProto(const State& state) { ...@@ -639,6 +676,11 @@ mri::State StateIdlToProto(const State& state) {
if (state.whiteboard) if (state.whiteboard)
WhiteboardIdlToProto(*state.whiteboard, state_result.mutable_whiteboard()); WhiteboardIdlToProto(*state.whiteboard, state_result.mutable_whiteboard());
if (state.features && state.features.get() != nullptr) {
for (size_t i = 0; i < state.features.get()->size(); ++i)
state_result.add_features(FeatureIdlToProto(state.features.get()->at(i)));
}
return state_result; return state_result;
} }
......
...@@ -515,6 +515,11 @@ TEST(MediaPerceptionConversionUtilsTest, StateProtoToIdl) { ...@@ -515,6 +515,11 @@ TEST(MediaPerceptionConversionUtilsTest, StateProtoToIdl) {
kWhiteboardBottomRightY); kWhiteboardBottomRightY);
state.mutable_whiteboard()->set_aspect_ratio(kWhiteboardAspectRatio); state.mutable_whiteboard()->set_aspect_ratio(kWhiteboardAspectRatio);
state.add_features(mri::State::FEATURE_AUTOZOOM);
state.add_features(mri::State::FEATURE_HOTWORD_DETECTION);
state.add_features(mri::State::FEATURE_OCCUPANCY_DETECTION);
state.add_features(mri::State::FEATURE_UNSET);
media_perception::State state_result = media_perception::State state_result =
media_perception::StateProtoToIdl(state); media_perception::StateProtoToIdl(state);
EXPECT_EQ(state_result.status, media_perception::STATUS_RUNNING); EXPECT_EQ(state_result.status, media_perception::STATUS_RUNNING);
...@@ -533,6 +538,16 @@ TEST(MediaPerceptionConversionUtilsTest, StateProtoToIdl) { ...@@ -533,6 +538,16 @@ TEST(MediaPerceptionConversionUtilsTest, StateProtoToIdl) {
ASSERT_TRUE(state_result.whiteboard->aspect_ratio); ASSERT_TRUE(state_result.whiteboard->aspect_ratio);
EXPECT_EQ(*state_result.whiteboard->aspect_ratio, kWhiteboardAspectRatio); EXPECT_EQ(*state_result.whiteboard->aspect_ratio, kWhiteboardAspectRatio);
ASSERT_TRUE(state_result.features);
ASSERT_TRUE(state_result.features.get());
ASSERT_EQ(state_result.features.get()->size(), 3u);
EXPECT_EQ(state_result.features.get()->at(0),
media_perception::FEATURE_AUTOZOOM);
EXPECT_EQ(state_result.features.get()->at(1),
media_perception::FEATURE_HOTWORD_DETECTION);
EXPECT_EQ(state_result.features.get()->at(2),
media_perception::FEATURE_OCCUPANCY_DETECTION);
state.set_status(mri::State::STARTED); state.set_status(mri::State::STARTED);
state.set_device_context(kTestDeviceContext); state.set_device_context(kTestDeviceContext);
state_result = media_perception::StateProtoToIdl(state); state_result = media_perception::StateProtoToIdl(state);
...@@ -569,6 +584,14 @@ TEST(MediaPerceptionConversionUtilsTest, StateIdlToProto) { ...@@ -569,6 +584,14 @@ TEST(MediaPerceptionConversionUtilsTest, StateIdlToProto) {
MakePointIdl(kWhiteboardBottomRightX, kWhiteboardBottomRightY); MakePointIdl(kWhiteboardBottomRightX, kWhiteboardBottomRightY);
state.whiteboard->aspect_ratio = state.whiteboard->aspect_ratio =
std::make_unique<double>(kWhiteboardAspectRatio); std::make_unique<double>(kWhiteboardAspectRatio);
state.features =
std::make_unique<std::vector<media_perception::Feature>>();
state.features->emplace_back(media_perception::FEATURE_AUTOZOOM);
state.features->emplace_back(media_perception::FEATURE_HOTWORD_DETECTION);
state.features->emplace_back(media_perception::FEATURE_OCCUPANCY_DETECTION);
state.features->emplace_back(media_perception::FEATURE_NONE);
state_proto = StateIdlToProto(state); state_proto = StateIdlToProto(state);
EXPECT_EQ(state_proto.status(), mri::State::RUNNING); EXPECT_EQ(state_proto.status(), mri::State::RUNNING);
ASSERT_TRUE(state_proto.has_configuration()); ASSERT_TRUE(state_proto.has_configuration());
...@@ -589,6 +612,12 @@ TEST(MediaPerceptionConversionUtilsTest, StateIdlToProto) { ...@@ -589,6 +612,12 @@ TEST(MediaPerceptionConversionUtilsTest, StateIdlToProto) {
ASSERT_TRUE(state_proto.whiteboard().has_aspect_ratio()); ASSERT_TRUE(state_proto.whiteboard().has_aspect_ratio());
EXPECT_EQ(state_proto.whiteboard().aspect_ratio(), kWhiteboardAspectRatio); EXPECT_EQ(state_proto.whiteboard().aspect_ratio(), kWhiteboardAspectRatio);
ASSERT_EQ(state_proto.features_size(), 4);
EXPECT_EQ(state_proto.features(0), mri::State::FEATURE_AUTOZOOM);
EXPECT_EQ(state_proto.features(1), mri::State::FEATURE_HOTWORD_DETECTION);
EXPECT_EQ(state_proto.features(2), mri::State::FEATURE_OCCUPANCY_DETECTION);
EXPECT_EQ(state_proto.features(3), mri::State::FEATURE_UNSET);
state.status = media_perception::STATUS_SUSPENDED; state.status = media_perception::STATUS_SUSPENDED;
state.device_context = std::make_unique<std::string>(kTestDeviceContext); state.device_context = std::make_unique<std::string>(kTestDeviceContext);
state_proto = StateIdlToProto(state); state_proto = StateIdlToProto(state);
......
...@@ -63,6 +63,12 @@ namespace mediaPerceptionPrivate { ...@@ -63,6 +63,12 @@ namespace mediaPerceptionPrivate {
MOJO_CONNECTION_FAILURE MOJO_CONNECTION_FAILURE
}; };
enum Feature {
AUTOZOOM,
HOTWORD_DETECTION,
OCCUPANCY_DETECTION
};
enum ComponentType { enum ComponentType {
// The smaller component with limited functionality (smaller size and // The smaller component with limited functionality (smaller size and
// limited models). // limited models).
...@@ -198,6 +204,9 @@ namespace mediaPerceptionPrivate { ...@@ -198,6 +204,9 @@ namespace mediaPerceptionPrivate {
// only be set when setting state to <code>RUNNING</code> and configuration // only be set when setting state to <code>RUNNING</code> and configuration
// to whiteboard. // to whiteboard.
Whiteboard? whiteboard; Whiteboard? whiteboard;
// A list of enabled media perception features.
Feature[]? features;
}; };
dictionary BoundingBox { dictionary BoundingBox {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment