| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/capture/video/video_capture_device.h" | 5 #include "media/capture/video/video_capture_device.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 using ::testing::SaveArg; | 66 using ::testing::SaveArg; |
| 67 | 67 |
| 68 namespace media { | 68 namespace media { |
| 69 namespace { | 69 namespace { |
| 70 | 70 |
| 71 static const gfx::Size kCaptureSizes[] = {gfx::Size(640, 480), | 71 static const gfx::Size kCaptureSizes[] = {gfx::Size(640, 480), |
| 72 gfx::Size(1280, 720)}; | 72 gfx::Size(1280, 720)}; |
| 73 | 73 |
| 74 class MockClient : public VideoCaptureDevice::Client { | 74 class MockClient : public VideoCaptureDevice::Client { |
| 75 public: | 75 public: |
| 76 MOCK_METHOD9(OnIncomingCapturedYuvData, | |
| 77 void(const uint8_t* y_data, | |
| 78 const uint8_t* u_data, | |
| 79 const uint8_t* v_data, | |
| 80 size_t y_stride, | |
| 81 size_t u_stride, | |
| 82 size_t v_stride, | |
| 83 const VideoCaptureFormat& frame_format, | |
| 84 int clockwise_rotation, | |
| 85 const base::TimeTicks& timestamp)); | |
| 86 MOCK_METHOD0(DoReserveOutputBuffer, void(void)); | 76 MOCK_METHOD0(DoReserveOutputBuffer, void(void)); |
| 87 MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void)); | 77 MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void)); |
| 88 MOCK_METHOD0(DoOnIncomingCapturedVideoFrame, void(void)); | 78 MOCK_METHOD0(DoOnIncomingCapturedVideoFrame, void(void)); |
| 89 MOCK_METHOD0(DoResurrectLastOutputBuffer, void(void)); | 79 MOCK_METHOD0(DoResurrectLastOutputBuffer, void(void)); |
| 90 MOCK_METHOD2(OnError, | 80 MOCK_METHOD2(OnError, |
| 91 void(const tracked_objects::Location& from_here, | 81 void(const tracked_objects::Location& from_here, |
| 92 const std::string& reason)); | 82 const std::string& reason)); |
| 93 MOCK_CONST_METHOD0(GetBufferPoolUtilization, double(void)); | 83 MOCK_CONST_METHOD0(GetBufferPoolUtilization, double(void)); |
| 94 | 84 |
| 95 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb) | 85 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb) |
| 96 : main_thread_(base::ThreadTaskRunnerHandle::Get()), | 86 : main_thread_(base::ThreadTaskRunnerHandle::Get()), |
| 97 frame_cb_(frame_cb) {} | 87 frame_cb_(frame_cb) {} |
| 98 | 88 |
| 99 void OnIncomingCapturedData(const uint8_t* data, | 89 void OnIncomingCapturedData(const uint8_t* data, |
| 100 int length, | 90 int length, |
| 101 const VideoCaptureFormat& format, | 91 const VideoCaptureFormat& format, |
| 102 int rotation, | 92 int rotation, |
| 103 const base::TimeTicks& timestamp) override { | 93 base::TimeTicks reference_time, |
| 94 base::TimeDelta timestamp) override { |
| 104 ASSERT_GT(length, 0); | 95 ASSERT_GT(length, 0); |
| 105 ASSERT_TRUE(data != NULL); | 96 ASSERT_TRUE(data != NULL); |
| 106 main_thread_->PostTask(FROM_HERE, base::Bind(frame_cb_, format)); | 97 main_thread_->PostTask(FROM_HERE, base::Bind(frame_cb_, format)); |
| 107 } | 98 } |
| 108 | 99 |
| 109 // Trampoline methods to workaround GMOCK problems with std::unique_ptr<>. | 100 // Trampoline methods to workaround GMOCK problems with std::unique_ptr<>. |
| 110 std::unique_ptr<Buffer> ReserveOutputBuffer( | 101 std::unique_ptr<Buffer> ReserveOutputBuffer( |
| 111 const gfx::Size& dimensions, | 102 const gfx::Size& dimensions, |
| 112 media::VideoPixelFormat format, | 103 media::VideoPixelFormat format, |
| 113 media::VideoPixelStorage storage) override { | 104 media::VideoPixelStorage storage) override { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 } | 163 } |
| 173 | 164 |
| 174 void SetUp() override { | 165 void SetUp() override { |
| 175 #if defined(OS_ANDROID) | 166 #if defined(OS_ANDROID) |
| 176 VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice( | 167 VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice( |
| 177 base::android::AttachCurrentThread()); | 168 base::android::AttachCurrentThread()); |
| 178 #endif | 169 #endif |
| 179 #if defined(OS_MACOSX) | 170 #if defined(OS_MACOSX) |
| 180 AVFoundationGlue::InitializeAVFoundation(); | 171 AVFoundationGlue::InitializeAVFoundation(); |
| 181 #endif | 172 #endif |
| 182 EXPECT_CALL(*client_, OnIncomingCapturedYuvData(_, _, _, _, _, _, _, _, _)) | |
| 183 .Times(0); | |
| 184 EXPECT_CALL(*client_, DoReserveOutputBuffer()).Times(0); | 173 EXPECT_CALL(*client_, DoReserveOutputBuffer()).Times(0); |
| 185 EXPECT_CALL(*client_, DoOnIncomingCapturedBuffer()).Times(0); | 174 EXPECT_CALL(*client_, DoOnIncomingCapturedBuffer()).Times(0); |
| 186 EXPECT_CALL(*client_, DoOnIncomingCapturedVideoFrame()).Times(0); | 175 EXPECT_CALL(*client_, DoOnIncomingCapturedVideoFrame()).Times(0); |
| 187 } | 176 } |
| 188 | 177 |
| 189 void ResetWithNewClient() { | 178 void ResetWithNewClient() { |
| 190 client_.reset(new MockClient(base::Bind( | 179 client_.reset(new MockClient(base::Bind( |
| 191 &VideoCaptureDeviceTest::OnFrameCaptured, base::Unretained(this)))); | 180 &VideoCaptureDeviceTest::OnFrameCaptured, base::Unretained(this)))); |
| 192 } | 181 } |
| 193 | 182 |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 // GetDeviceSupportedFormats(). | 475 // GetDeviceSupportedFormats(). |
| 487 std::unique_ptr<VideoCaptureDevice::Name> name = | 476 std::unique_ptr<VideoCaptureDevice::Name> name = |
| 488 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); | 477 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); |
| 489 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else | 478 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else |
| 490 // to test here | 479 // to test here |
| 491 // since we cannot forecast the hardware capabilities. | 480 // since we cannot forecast the hardware capabilities. |
| 492 ASSERT_FALSE(name); | 481 ASSERT_FALSE(name); |
| 493 } | 482 } |
| 494 | 483 |
| 495 }; // namespace media | 484 }; // namespace media |
| OLD | NEW |