Commit 7936295b authored by Wei Guan's avatar Wei Guan Committed by Commit Bot

Add video stream parameters to media perception private API.

BUG=789375

Change-Id: I752b5eb006f43df0949374acac464793db92115d
Reviewed-on: https://chromium-review.googlesource.com/795550
Commit-Queue: Wei Guan <weigua@chromium.org>
Reviewed-by: default avatarToni Barzic <tbarzic@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#520836}
parent e11d4028
......@@ -28,6 +28,20 @@ message Diagnostics {
repeated PerceptionSample perception_sample = 1;
}
message VideoStreamParam {
// Identifies the video stream described by these parameters.
optional string id = 1;
// Frame width in pixels.
optional int32 width = 2;
// Frame height in pixels.
optional int32 height = 3;
// The frame rate at which this video stream would be processed.
optional float frame_rate = 4;
}
message State {
enum Status {
STATUS_UNSPECIFIED = 0; // Unused required default value for Proto enums.
......@@ -46,6 +60,9 @@ message State {
// Device context so that the media analytics process can better select the
// right video device to open.
optional string device_context = 2;
// A list of video streams processed by the analytics process.
repeated VideoStreamParam video_stream_param = 3;
}
// This is the output of the MediaPerceptionSinkCalculator.
......
......@@ -257,6 +257,24 @@ mri::State::Status StateStatusIdlToProto(const State& state) {
return mri::State::STATUS_UNSPECIFIED;
}
void VideoStreamParamIdlToProto(mri::VideoStreamParam* param_result,
const VideoStreamParam& param) {
if (param_result == nullptr)
return;
if (param.id)
param_result->set_id(*param.id);
if (param.width)
param_result->set_width(*param.width);
if (param.height)
param_result->set_height(*param.height);
if (param.frame_rate)
param_result->set_frame_rate(*param.frame_rate);
}
} // namespace
State StateProtoToIdl(const mri::State& state) {
......@@ -277,6 +295,15 @@ mri::State StateIdlToProto(const State& state) {
if (state.device_context)
state_result.set_device_context(*state.device_context);
if (state.video_stream_param && state.video_stream_param.get() != nullptr) {
for (size_t i = 0; i < state.video_stream_param.get()->size(); ++i) {
mri::VideoStreamParam* video_stream_param_result =
state_result.add_video_stream_param();
VideoStreamParamIdlToProto(video_stream_param_result,
state.video_stream_param.get()->at(i));
}
}
return state_result;
}
......
......@@ -18,6 +18,26 @@ const char kTestDeviceContext[] = "Video camera";
const char kFakePacketLabel1[] = "Packet1";
const char kFakePacketLabel3[] = "Packet3";
const char kFakeEntityLabel3[] = "Region3";
const char kVideoStreamIdForFaceDetection[] = "FaceDetection";
const char kVideoStreamIdForVideoCapture[] = "VideoCapture";
const int kVideoStreamWidthForFaceDetection = 1280;
const int kVideoStreamHeightForFaceDetection = 720;
const int kVideoStreamFrameRateForFaceDetection = 30;
const int kVideoStreamWidthForVideoCapture = 640;
const int kVideoStreamHeightForVideoCapture = 360;
const int kVideoStreamFrameRateForVideoCapture = 5;
void InitializeVideoStreamParam(media_perception::VideoStreamParam& param,
const std::string& id,
int width,
int height,
int frame_rate) {
param.id = std::make_unique<std::string>(id);
param.width = std::make_unique<int>(width);
param.height = std::make_unique<int>(height);
param.frame_rate = std::make_unique<int>(frame_rate);
}
void InitializeFakeFramePerception(const int index,
mri::FramePerception* frame_perception) {
......@@ -280,4 +300,41 @@ TEST(MediaPerceptionConversionUtilsTest, StateIdlToProto) {
EXPECT_EQ(mri::State::STOPPED, state_proto.status());
}
TEST(MediaPerceptionConversionUtilsTest, StateIdlToProtoWithVideoStreamParam) {
media_perception::State state;
state.status = media_perception::STATUS_RUNNING;
state.video_stream_param.reset(
new std::vector<media_perception::VideoStreamParam>(2));
InitializeVideoStreamParam(
state.video_stream_param.get()->at(0), kVideoStreamIdForFaceDetection,
kVideoStreamWidthForFaceDetection, kVideoStreamHeightForFaceDetection,
kVideoStreamFrameRateForFaceDetection);
InitializeVideoStreamParam(
state.video_stream_param.get()->at(1), kVideoStreamIdForVideoCapture,
kVideoStreamWidthForVideoCapture, kVideoStreamHeightForVideoCapture,
kVideoStreamFrameRateForVideoCapture);
mri::State state_proto = StateIdlToProto(state);
EXPECT_EQ(state_proto.status(), mri::State::RUNNING);
EXPECT_EQ(kVideoStreamIdForFaceDetection,
state_proto.video_stream_param(0).id());
EXPECT_EQ(kVideoStreamWidthForFaceDetection,
state_proto.video_stream_param(0).width());
EXPECT_EQ(kVideoStreamHeightForFaceDetection,
state_proto.video_stream_param(0).height());
EXPECT_EQ(kVideoStreamFrameRateForFaceDetection,
state_proto.video_stream_param(0).frame_rate());
EXPECT_EQ(kVideoStreamIdForVideoCapture,
state_proto.video_stream_param(1).id());
EXPECT_EQ(kVideoStreamWidthForVideoCapture,
state_proto.video_stream_param(1).width());
EXPECT_EQ(kVideoStreamHeightForVideoCapture,
state_proto.video_stream_param(1).height());
EXPECT_EQ(kVideoStreamFrameRateForVideoCapture,
state_proto.video_stream_param(1).frame_rate());
}
} // namespace extensions
......@@ -54,6 +54,14 @@ MediaPerceptionPrivateSetStateFunction::Run() {
return RespondNow(
Error("Only provide deviceContext with SetState RUNNING."));
}
// Check that video stream parameters are only provided with SetState RUNNING.
if (params->state.status != media_perception::STATUS_RUNNING &&
params->state.video_stream_param.get() != nullptr) {
return RespondNow(
Error("SetState: status must be RUNNING to set videoStreamParam."));
}
MediaPerceptionAPIManager* manager =
MediaPerceptionAPIManager::Get(browser_context());
manager->SetState(
......
......@@ -84,6 +84,21 @@ namespace mediaPerceptionPrivate {
ComponentStatus status;
};
// The parameters for processing a particular video stream.
dictionary VideoStreamParam {
// Identifies the video stream described by these parameters.
DOMString? id;
// Frame width in pixels.
long? width;
// Frame height in pixels.
long? height;
// The frame rate at which this video stream would be processed.
long? frameRate;
};
// The system and configuration state of the analytics process.
dictionary State {
Status status;
......@@ -96,6 +111,10 @@ namespace mediaPerceptionPrivate {
// Return parameter for $(ref:setState) or $(ref:getState) that
// specifies the error type for failure cases.
ServiceError? serviceError;
// A list of video streams processed by the analytics process. To set this
// parameter, status has to be <code>RUNNING</code>.
VideoStreamParam[]? videoStreamParam;
};
dictionary Point {
......
......@@ -12,7 +12,15 @@ function getStateUninitialized() {
function setStateRunning() {
chrome.mediaPerceptionPrivate.setState({
status: 'RUNNING',
deviceContext: 'device_context'
deviceContext: 'device_context',
videoStreamParam: [
{
id: 'FaceDetection',
width: 1280,
height: 1920,
frameRate: 30,
},
],
}, chrome.test.callbackPass(function(state) {
chrome.test.assertEq('RUNNING', state.status);
}));
......@@ -44,6 +52,21 @@ function setStateSuspendedButWithDeviceContextFail() {
}, chrome.test.callbackFail(error));
}
function setStateSuspendedButWithVideoStreamParamFail() {
const error = 'SetState: status must be RUNNING to set videoStreamParam.';
chrome.mediaPerceptionPrivate.setState({
status: 'SUSPENDED',
videoStreamParam: [
{
id: 'FaceDetection',
width: 1280,
height: 1920,
frameRate: 30,
},
],
}, chrome.test.callbackFail(error));
}
function setStateRestarted() {
chrome.mediaPerceptionPrivate.setState({
status: 'RESTARTING',
......@@ -68,6 +91,7 @@ chrome.test.runTests([
getStateRunning,
setStateUnsettable,
setStateSuspendedButWithDeviceContextFail,
setStateSuspendedButWithVideoStreamParamFail,
setStateRestarted,
setStateStopped]);
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