| OLD | NEW |
| (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.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/mock_camera_module.h" |
| 16 #include "media/capture/video/chromeos/mojo/arc_camera3.mojom.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 |
| 20 using testing::_; |
| 21 using testing::A; |
| 22 using testing::Invoke; |
| 23 |
| 24 namespace media { |
| 25 |
| 26 class CameraHalDelegateTest : public ::testing::Test { |
| 27 public: |
| 28 CameraHalDelegateTest() |
| 29 : message_loop_(new base::MessageLoop), |
| 30 hal_delegate_thread_("HalDelegateThread") {} |
| 31 |
| 32 void SetUp() override { |
| 33 hal_delegate_thread_.Start(); |
| 34 camera_hal_delegate_ = |
| 35 new CameraHalDelegate(hal_delegate_thread_.task_runner()); |
| 36 camera_hal_delegate_->StartForTesting( |
| 37 mock_camera_module_.GetInterfacePtrInfo()); |
| 38 } |
| 39 |
| 40 void TearDown() override { |
| 41 camera_hal_delegate_->Reset(); |
| 42 hal_delegate_thread_.Stop(); |
| 43 } |
| 44 |
| 45 void Wait() { |
| 46 run_loop_.reset(new base::RunLoop()); |
| 47 run_loop_->Run(); |
| 48 } |
| 49 |
| 50 protected: |
| 51 scoped_refptr<CameraHalDelegate> camera_hal_delegate_; |
| 52 testing::StrictMock<unittest_internal::MockCameraModule> mock_camera_module_; |
| 53 |
| 54 private: |
| 55 std::unique_ptr<base::MessageLoop> message_loop_; |
| 56 base::Thread hal_delegate_thread_; |
| 57 std::unique_ptr<base::RunLoop> run_loop_; |
| 58 DISALLOW_COPY_AND_ASSIGN(CameraHalDelegateTest); |
| 59 }; |
| 60 |
| 61 TEST_F(CameraHalDelegateTest, GetBuiltinCameraInfo) { |
| 62 auto get_number_of_cameras_cb = |
| 63 [](arc::mojom::CameraModule::GetNumberOfCamerasCallback& cb) { |
| 64 std::move(cb).Run(2); |
| 65 }; |
| 66 |
| 67 auto get_camera_info_cb = [](uint32_t camera_id, |
| 68 arc::mojom::CameraModule::GetCameraInfoCallback& |
| 69 cb) { |
| 70 arc::mojom::CameraInfoPtr camera_info = arc::mojom::CameraInfo::New(); |
| 71 arc::mojom::CameraMetadataPtr static_metadata = |
| 72 arc::mojom::CameraMetadata::New(); |
| 73 static_metadata->entry_count = 1; |
| 74 static_metadata->entry_capacity = 1; |
| 75 static_metadata->entries = |
| 76 std::vector<arc::mojom::CameraMetadataEntryPtr>(); |
| 77 |
| 78 arc::mojom::CameraMetadataEntryPtr entry = |
| 79 arc::mojom::CameraMetadataEntry::New(); |
| 80 entry->index = 0; |
| 81 entry->tag = arc::mojom::CameraMetadataTag:: |
| 82 ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS; |
| 83 entry->type = arc::mojom::EntryType::TYPE_INT64; |
| 84 entry->count = 8; |
| 85 std::vector<int64_t> min_frame_durations(8); |
| 86 min_frame_durations[0] = static_cast<int64_t>( |
| 87 arc::mojom::HalPixelFormat::HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED); |
| 88 min_frame_durations[1] = 1280; |
| 89 min_frame_durations[2] = 720; |
| 90 min_frame_durations[3] = 33333333; |
| 91 min_frame_durations[4] = static_cast<int64_t>( |
| 92 arc::mojom::HalPixelFormat::HAL_PIXEL_FORMAT_YCbCr_420_888); |
| 93 min_frame_durations[5] = 1280; |
| 94 min_frame_durations[6] = 720; |
| 95 min_frame_durations[7] = 16666666; |
| 96 uint8_t* as_int8 = reinterpret_cast<uint8_t*>(min_frame_durations.data()); |
| 97 entry->data.assign(as_int8, as_int8 + entry->count * sizeof(int64_t)); |
| 98 static_metadata->entries->push_back(std::move(entry)); |
| 99 |
| 100 switch (camera_id) { |
| 101 case 0: |
| 102 camera_info->facing = arc::mojom::CameraFacing::CAMERA_FACING_BACK; |
| 103 camera_info->orientation = 0; |
| 104 camera_info->static_camera_characteristics = std::move(static_metadata); |
| 105 break; |
| 106 case 1: |
| 107 camera_info->facing = arc::mojom::CameraFacing::CAMERA_FACING_FRONT; |
| 108 camera_info->orientation = 0; |
| 109 camera_info->static_camera_characteristics = std::move(static_metadata); |
| 110 break; |
| 111 default: |
| 112 FAIL() << "Invalid camera id"; |
| 113 } |
| 114 std::move(cb).Run(0, std::move(camera_info)); |
| 115 }; |
| 116 |
| 117 EXPECT_CALL(mock_camera_module_, DoGetNumberOfCameras(_)) |
| 118 .Times(1) |
| 119 .WillOnce(Invoke(get_number_of_cameras_cb)); |
| 120 EXPECT_CALL( |
| 121 mock_camera_module_, |
| 122 DoSetCallbacks(A<arc::mojom::CameraModuleCallbacksPtr&>(), |
| 123 A<arc::mojom::CameraModule::SetCallbacksCallback&>())) |
| 124 .Times(1); |
| 125 EXPECT_CALL( |
| 126 mock_camera_module_, |
| 127 DoGetCameraInfo(0, A<arc::mojom::CameraModule::GetCameraInfoCallback&>())) |
| 128 .Times(1) |
| 129 .WillOnce(Invoke(get_camera_info_cb)); |
| 130 EXPECT_CALL( |
| 131 mock_camera_module_, |
| 132 DoGetCameraInfo(1, A<arc::mojom::CameraModule::GetCameraInfoCallback&>())) |
| 133 .Times(1) |
| 134 .WillOnce(Invoke(get_camera_info_cb)); |
| 135 |
| 136 VideoCaptureDeviceDescriptors descriptors; |
| 137 camera_hal_delegate_->GetDeviceDescriptors(&descriptors); |
| 138 |
| 139 ASSERT_EQ(2U, descriptors.size()); |
| 140 // We have workaround to always put front camera at first. |
| 141 ASSERT_EQ(std::to_string(1), descriptors[0].device_id); |
| 142 ASSERT_EQ(VideoFacingMode::MEDIA_VIDEO_FACING_USER, descriptors[0].facing); |
| 143 ASSERT_EQ(std::to_string(0), descriptors[1].device_id); |
| 144 ASSERT_EQ(VideoFacingMode::MEDIA_VIDEO_FACING_ENVIRONMENT, |
| 145 descriptors[1].facing); |
| 146 |
| 147 VideoCaptureFormats supported_formats; |
| 148 camera_hal_delegate_->GetSupportedFormats(descriptors[0], &supported_formats); |
| 149 |
| 150 // IMPLEMENTATION_DEFINED format should be filtered; currently YCbCr_420_888 |
| 151 // format corresponds to NV12 in Chrome. |
| 152 ASSERT_EQ(1U, supported_formats.size()); |
| 153 ASSERT_EQ(gfx::Size(1280, 720), supported_formats[0].frame_size); |
| 154 ASSERT_FLOAT_EQ(60.0, supported_formats[0].frame_rate); |
| 155 ASSERT_EQ(PIXEL_FORMAT_NV12, supported_formats[0].pixel_format); |
| 156 } |
| 157 |
| 158 } // namespace media |
| OLD | NEW |