Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(487)

Side by Side Diff: media/capture/video/chromeos/camera_hal_delegate_unittest.cc

Issue 2837273004: media: add video capture device for ARC++ camera HAL v3 (Closed)
Patch Set: address chfremer's comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "media/capture/video/chromeos/camera_hal_delegate_unittest.h"
6
7 #include <stddef.h>
8 #include <stdint.h>
9
10 #include <memory>
11 #include <utility>
12
13 #include "base/message_loop/message_loop.h"
14 #include "base/run_loop.h"
15 #include "media/capture/video/chromeos/mojo/arc_camera3.mojom.h"
16 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18
19 using testing::_;
20 using testing::A;
21 using testing::Invoke;
22
23 namespace media {
24
25 class CameraHalDelegateTest : public ::testing::Test {
26 public:
27 CameraHalDelegateTest()
28 : message_loop_(new base::MessageLoop),
29 hal_delegate_thread_("HalDelegateThread") {}
30
31 void SetUp() override {
32 hal_delegate_thread_.Start();
33 camera_hal_delegate_ =
34 new CameraHalDelegate(hal_delegate_thread_.task_runner());
35 camera_hal_delegate_->StartForTesting(
36 mock_camera_module_.GetInterfacePtrInfo());
37 }
38
39 void TearDown() override {
40 camera_hal_delegate_->Reset();
41 hal_delegate_thread_.Stop();
42 }
43
44 void Wait() {
45 run_loop_.reset(new base::RunLoop());
46 run_loop_->Run();
47 }
48
49 protected:
50 scoped_refptr<CameraHalDelegate> camera_hal_delegate_;
51 testing::StrictMock<unittest_internal::MockCameraModule> mock_camera_module_;
52
53 private:
54 std::unique_ptr<base::MessageLoop> message_loop_;
55 base::Thread hal_delegate_thread_;
56 std::unique_ptr<base::RunLoop> run_loop_;
57 DISALLOW_COPY_AND_ASSIGN(CameraHalDelegateTest);
58 };
59
60 TEST_F(CameraHalDelegateTest, GetBuiltinCameraInfo) {
chfremer 2017/06/01 00:16:27 This test case provides coverage for GetDeviceDesc
jcliang 2017/06/01 17:11:17 OpenDevice is covered by the tests in video_captur
61 auto get_number_of_cameras_cb =
62 [](arc::mojom::CameraModule::GetNumberOfCamerasCallback& cb) {
63 std::move(cb).Run(2);
64 };
65
66 auto get_camera_info_cb = [](uint32_t camera_id,
67 arc::mojom::CameraModule::GetCameraInfoCallback&
68 cb) {
69 arc::mojom::CameraInfoPtr camera_info = arc::mojom::CameraInfo::New();
70 arc::mojom::CameraMetadataPtr static_metadata =
71 arc::mojom::CameraMetadata::New();
72 static_metadata->entry_count = 1;
73 static_metadata->entry_capacity = 1;
74 static_metadata->entries =
75 std::vector<arc::mojom::CameraMetadataEntryPtr>();
76
77 arc::mojom::CameraMetadataEntryPtr entry =
78 arc::mojom::CameraMetadataEntry::New();
79 entry->index = 0;
80 entry->tag = arc::mojom::CameraMetadataTag::
81 ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS;
82 entry->type = arc::mojom::EntryType::TYPE_INT64;
83 entry->count = 8;
84 std::vector<int64_t> min_frame_durations(8);
85 min_frame_durations[0] = static_cast<int64_t>(
86 arc::mojom::HalPixelFormat::HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED);
87 min_frame_durations[1] = 1280;
88 min_frame_durations[2] = 720;
89 min_frame_durations[3] = 33333333;
90 min_frame_durations[4] = static_cast<int64_t>(
91 arc::mojom::HalPixelFormat::HAL_PIXEL_FORMAT_YCbCr_420_888);
92 min_frame_durations[5] = 1280;
93 min_frame_durations[6] = 720;
94 min_frame_durations[7] = 16666666;
95 uint8_t* as_int8 = reinterpret_cast<uint8_t*>(min_frame_durations.data());
96 entry->data.assign(as_int8, as_int8 + entry->count * sizeof(int64_t));
97 static_metadata->entries->push_back(std::move(entry));
98
99 switch (camera_id) {
100 case 0:
101 camera_info->facing = arc::mojom::CameraFacing::CAMERA_FACING_BACK;
102 camera_info->orientation = 0;
103 camera_info->static_camera_characteristics = std::move(static_metadata);
104 break;
105 case 1:
106 camera_info->facing = arc::mojom::CameraFacing::CAMERA_FACING_FRONT;
107 camera_info->orientation = 0;
108 camera_info->static_camera_characteristics = std::move(static_metadata);
109 break;
110 default:
111 FAIL() << "Invalid camera id";
112 }
113 std::move(cb).Run(0, std::move(camera_info));
114 };
115
116 EXPECT_CALL(mock_camera_module_, DoGetNumberOfCameras(_))
117 .Times(1)
118 .WillOnce(Invoke(get_number_of_cameras_cb));
119 EXPECT_CALL(
120 mock_camera_module_,
121 DoSetCallbacks(A<arc::mojom::CameraModuleCallbacksPtr&>(),
122 A<arc::mojom::CameraModule::SetCallbacksCallback&>()))
123 .Times(1);
124 EXPECT_CALL(
125 mock_camera_module_,
126 DoGetCameraInfo(0, A<arc::mojom::CameraModule::GetCameraInfoCallback&>()))
127 .Times(1)
128 .WillOnce(Invoke(get_camera_info_cb));
129 EXPECT_CALL(
130 mock_camera_module_,
131 DoGetCameraInfo(1, A<arc::mojom::CameraModule::GetCameraInfoCallback&>()))
132 .Times(1)
133 .WillOnce(Invoke(get_camera_info_cb));
134
135 VideoCaptureDeviceDescriptors descriptors;
136 camera_hal_delegate_->GetDeviceDescriptors(&descriptors);
137
138 ASSERT_EQ(2U, descriptors.size());
139 // We have workaround to always put front camera at first.
140 ASSERT_EQ(std::to_string(1), descriptors[0].device_id);
141 ASSERT_EQ(VideoFacingMode::MEDIA_VIDEO_FACING_USER, descriptors[0].facing);
142 ASSERT_EQ(std::to_string(0), descriptors[1].device_id);
143 ASSERT_EQ(VideoFacingMode::MEDIA_VIDEO_FACING_ENVIRONMENT,
144 descriptors[1].facing);
145
146 VideoCaptureFormats supported_formats;
147 camera_hal_delegate_->GetSupportedFormats(descriptors[0], &supported_formats);
148
149 // IMPLEMENTATION_DEFINED format should be filtered; currently YCbCr_420_888
150 // format corresponds to NV12 in Chrome.
151 ASSERT_EQ(1U, supported_formats.size());
152 ASSERT_EQ(gfx::Size(1280, 720), supported_formats[0].frame_size);
153 ASSERT_FLOAT_EQ(60.0, supported_formats[0].frame_rate);
154 ASSERT_EQ(PIXEL_FORMAT_NV12, supported_formats[0].pixel_format);
155 }
156
157 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698