| 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 { |
| 114 DoReserveOutputBuffer(); | 105 DoReserveOutputBuffer(); |
| 115 NOTREACHED() << "This should never be called"; | 106 NOTREACHED() << "This should never be called"; |
| 116 return std::unique_ptr<Buffer>(); | 107 return std::unique_ptr<Buffer>(); |
| 117 } | 108 } |
| 118 void OnIncomingCapturedBuffer(std::unique_ptr<Buffer> buffer, | 109 void OnIncomingCapturedBuffer(std::unique_ptr<Buffer> buffer, |
| 119 const VideoCaptureFormat& frame_format, | 110 const VideoCaptureFormat& frame_format, |
| 120 const base::TimeTicks& timestamp) override { | 111 base::TimeTicks reference_time, |
| 112 base::TimeDelta timestamp) override { |
| 121 DoOnIncomingCapturedBuffer(); | 113 DoOnIncomingCapturedBuffer(); |
| 122 } | 114 } |
| 123 void OnIncomingCapturedVideoFrame(std::unique_ptr<Buffer> buffer, | 115 void OnIncomingCapturedVideoFrame(std::unique_ptr<Buffer> buffer, |
| 124 const scoped_refptr<VideoFrame>& frame, | 116 const scoped_refptr<VideoFrame>& frame, |
| 125 const base::TimeTicks& timestamp) override { | 117 base::TimeTicks reference_time) override { |
| 126 DoOnIncomingCapturedVideoFrame(); | 118 DoOnIncomingCapturedVideoFrame(); |
| 127 } | 119 } |
| 128 std::unique_ptr<Buffer> ResurrectLastOutputBuffer( | 120 std::unique_ptr<Buffer> ResurrectLastOutputBuffer( |
| 129 const gfx::Size& dimensions, | 121 const gfx::Size& dimensions, |
| 130 media::VideoPixelFormat format, | 122 media::VideoPixelFormat format, |
| 131 media::VideoPixelStorage storage) { | 123 media::VideoPixelStorage storage) { |
| 132 DoResurrectLastOutputBuffer(); | 124 DoResurrectLastOutputBuffer(); |
| 133 NOTREACHED() << "This should never be called"; | 125 NOTREACHED() << "This should never be called"; |
| 134 return std::unique_ptr<Buffer>(); | 126 return std::unique_ptr<Buffer>(); |
| 135 } | 127 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 } | 164 } |
| 173 | 165 |
| 174 void SetUp() override { | 166 void SetUp() override { |
| 175 #if defined(OS_ANDROID) | 167 #if defined(OS_ANDROID) |
| 176 VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice( | 168 VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice( |
| 177 base::android::AttachCurrentThread()); | 169 base::android::AttachCurrentThread()); |
| 178 #endif | 170 #endif |
| 179 #if defined(OS_MACOSX) | 171 #if defined(OS_MACOSX) |
| 180 AVFoundationGlue::InitializeAVFoundation(); | 172 AVFoundationGlue::InitializeAVFoundation(); |
| 181 #endif | 173 #endif |
| 182 EXPECT_CALL(*client_, OnIncomingCapturedYuvData(_, _, _, _, _, _, _, _, _)) | |
| 183 .Times(0); | |
| 184 EXPECT_CALL(*client_, DoReserveOutputBuffer()).Times(0); | 174 EXPECT_CALL(*client_, DoReserveOutputBuffer()).Times(0); |
| 185 EXPECT_CALL(*client_, DoOnIncomingCapturedBuffer()).Times(0); | 175 EXPECT_CALL(*client_, DoOnIncomingCapturedBuffer()).Times(0); |
| 186 EXPECT_CALL(*client_, DoOnIncomingCapturedVideoFrame()).Times(0); | 176 EXPECT_CALL(*client_, DoOnIncomingCapturedVideoFrame()).Times(0); |
| 187 } | 177 } |
| 188 | 178 |
| 189 void ResetWithNewClient() { | 179 void ResetWithNewClient() { |
| 190 client_.reset(new MockClient(base::Bind( | 180 client_.reset(new MockClient(base::Bind( |
| 191 &VideoCaptureDeviceTest::OnFrameCaptured, base::Unretained(this)))); | 181 &VideoCaptureDeviceTest::OnFrameCaptured, base::Unretained(this)))); |
| 192 } | 182 } |
| 193 | 183 |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 // GetDeviceSupportedFormats(). | 476 // GetDeviceSupportedFormats(). |
| 487 std::unique_ptr<VideoCaptureDevice::Name> name = | 477 std::unique_ptr<VideoCaptureDevice::Name> name = |
| 488 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); | 478 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); |
| 489 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else | 479 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else |
| 490 // to test here | 480 // to test here |
| 491 // since we cannot forecast the hardware capabilities. | 481 // since we cannot forecast the hardware capabilities. |
| 492 ASSERT_FALSE(name); | 482 ASSERT_FALSE(name); |
| 493 } | 483 } |
| 494 | 484 |
| 495 }; // namespace media | 485 }; // namespace media |
| OLD | NEW |