| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/fake_video_capture_device.h" | 5 #include "media/capture/video/fake_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 16 matching lines...) Expand all Loading... |
| 27 using ::testing::_; | 27 using ::testing::_; |
| 28 using ::testing::Bool; | 28 using ::testing::Bool; |
| 29 using ::testing::Combine; | 29 using ::testing::Combine; |
| 30 using ::testing::SaveArg; | 30 using ::testing::SaveArg; |
| 31 using ::testing::Values; | 31 using ::testing::Values; |
| 32 | 32 |
| 33 namespace media { | 33 namespace media { |
| 34 | 34 |
| 35 namespace { | 35 namespace { |
| 36 | 36 |
| 37 // This class is a Client::Buffer that allocates and frees the requested |size|. | 37 class StubBufferHandle : public VideoCaptureBufferHandle { |
| 38 class MockBuffer : public VideoCaptureDevice::Client::Buffer { | |
| 39 public: | 38 public: |
| 40 MockBuffer(int buffer_id, int frame_feedback_id, size_t mapped_size) | 39 StubBufferHandle(size_t mapped_size, uint8_t* data) |
| 41 : id_(buffer_id), | 40 : mapped_size_(mapped_size), data_(data) {} |
| 42 frame_feedback_id_(frame_feedback_id), | |
| 43 mapped_size_(mapped_size), | |
| 44 data_(new uint8_t[mapped_size]) {} | |
| 45 ~MockBuffer() override { delete[] data_; } | |
| 46 | 41 |
| 47 int id() const override { return id_; } | |
| 48 int frame_feedback_id() const override { return frame_feedback_id_; } | |
| 49 gfx::Size dimensions() const override { return gfx::Size(); } | |
| 50 size_t mapped_size() const override { return mapped_size_; } | 42 size_t mapped_size() const override { return mapped_size_; } |
| 51 void* data(int plane) override { return data_; } | 43 uint8_t* data() override { return data_; } |
| 52 #if defined(OS_POSIX) && !(defined(OS_MACOSX) && !defined(OS_IOS)) | 44 const uint8_t* data() const override { return data_; } |
| 53 base::FileDescriptor AsPlatformFile() override { | |
| 54 return base::FileDescriptor(); | |
| 55 } | |
| 56 #endif | |
| 57 bool IsBackedByVideoFrame() const override { return false; }; | |
| 58 scoped_refptr<VideoFrame> GetVideoFrame() override { return nullptr; } | |
| 59 | 45 |
| 60 private: | 46 private: |
| 61 const int id_; | |
| 62 const int frame_feedback_id_; | |
| 63 const size_t mapped_size_; | 47 const size_t mapped_size_; |
| 64 uint8_t* const data_; | 48 uint8_t* const data_; |
| 65 }; | 49 }; |
| 66 | 50 |
| 51 class StubBufferHandleProvider |
| 52 : public VideoCaptureDevice::Client::Buffer::HandleProvider { |
| 53 public: |
| 54 StubBufferHandleProvider(size_t mapped_size, uint8_t* data) |
| 55 : mapped_size_(mapped_size), data_(data) {} |
| 56 |
| 57 ~StubBufferHandleProvider() override {} |
| 58 |
| 59 mojo::ScopedSharedBufferHandle GetHandleForInterProcessTransit() override { |
| 60 NOTREACHED(); |
| 61 return mojo::ScopedSharedBufferHandle(); |
| 62 } |
| 63 |
| 64 base::SharedMemoryHandle GetNonOwnedSharedMemoryHandleForLegacyIPC() |
| 65 override { |
| 66 NOTREACHED(); |
| 67 return base::SharedMemoryHandle(); |
| 68 } |
| 69 |
| 70 std::unique_ptr<VideoCaptureBufferHandle> GetHandleForInProcessAccess() |
| 71 override { |
| 72 return base::MakeUnique<StubBufferHandle>(mapped_size_, data_); |
| 73 } |
| 74 |
| 75 private: |
| 76 const size_t mapped_size_; |
| 77 uint8_t* const data_; |
| 78 }; |
| 79 |
| 80 class StubReadWritePermission |
| 81 : public VideoCaptureDevice::Client::Buffer::ScopedAccessPermission { |
| 82 public: |
| 83 StubReadWritePermission(uint8_t* data) : data_(data) {} |
| 84 ~StubReadWritePermission() override { delete[] data_; } |
| 85 |
| 86 private: |
| 87 uint8_t* const data_; |
| 88 }; |
| 89 |
| 90 VideoCaptureDevice::Client::Buffer CreateStubBuffer(int buffer_id, |
| 91 size_t mapped_size) { |
| 92 auto buffer = new uint8_t[mapped_size]; |
| 93 const int arbitrary_frame_feedback_id = 0; |
| 94 return VideoCaptureDevice::Client::Buffer( |
| 95 buffer_id, arbitrary_frame_feedback_id, |
| 96 base::MakeUnique<StubBufferHandleProvider>(mapped_size, buffer), |
| 97 base::MakeUnique<StubReadWritePermission>(buffer)); |
| 98 }; |
| 99 |
| 67 class MockClient : public VideoCaptureDevice::Client { | 100 class MockClient : public VideoCaptureDevice::Client { |
| 68 public: | 101 public: |
| 69 MOCK_METHOD2(OnError, | 102 MOCK_METHOD2(OnError, |
| 70 void(const tracked_objects::Location& from_here, | 103 void(const tracked_objects::Location& from_here, |
| 71 const std::string& reason)); | 104 const std::string& reason)); |
| 72 | 105 |
| 73 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb) | 106 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb) |
| 74 : frame_cb_(frame_cb) {} | 107 : frame_cb_(frame_cb) {} |
| 75 | 108 |
| 76 // Client virtual methods for capturing using Device Buffers. | 109 // Client virtual methods for capturing using Device Buffers. |
| 77 void OnIncomingCapturedData(const uint8_t* data, | 110 void OnIncomingCapturedData(const uint8_t* data, |
| 78 int length, | 111 int length, |
| 79 const VideoCaptureFormat& format, | 112 const VideoCaptureFormat& format, |
| 80 int rotation, | 113 int rotation, |
| 81 base::TimeTicks reference_time, | 114 base::TimeTicks reference_time, |
| 82 base::TimeDelta timestamp, | 115 base::TimeDelta timestamp, |
| 83 int frame_feedback_id) override { | 116 int frame_feedback_id) override { |
| 84 frame_cb_.Run(format); | 117 frame_cb_.Run(format); |
| 85 } | 118 } |
| 86 // Virtual methods for capturing using Client's Buffers. | 119 // Virtual methods for capturing using Client's Buffers. |
| 87 std::unique_ptr<Buffer> ReserveOutputBuffer(const gfx::Size& dimensions, | 120 Buffer ReserveOutputBuffer(const gfx::Size& dimensions, |
| 88 media::VideoPixelFormat format, | 121 media::VideoPixelFormat format, |
| 89 media::VideoPixelStorage storage, | 122 media::VideoPixelStorage storage, |
| 90 int frame_feedback_id) override { | 123 int frame_feedback_id) override { |
| 91 EXPECT_TRUE((format == media::PIXEL_FORMAT_ARGB && | 124 EXPECT_TRUE((format == media::PIXEL_FORMAT_ARGB && |
| 92 storage == media::PIXEL_STORAGE_CPU)); | 125 storage == media::PIXEL_STORAGE_CPU)); |
| 93 EXPECT_GT(dimensions.GetArea(), 0); | 126 EXPECT_GT(dimensions.GetArea(), 0); |
| 94 const VideoCaptureFormat frame_format(dimensions, 0.0, format); | 127 const VideoCaptureFormat frame_format(dimensions, 0.0, format); |
| 95 return base::MakeUnique<MockBuffer>(0, frame_feedback_id, | 128 return CreateStubBuffer(0, frame_format.ImageAllocationSize()); |
| 96 frame_format.ImageAllocationSize()); | |
| 97 } | 129 } |
| 98 void OnIncomingCapturedBuffer(std::unique_ptr<Buffer> buffer, | 130 void OnIncomingCapturedBuffer(Buffer buffer, |
| 99 const VideoCaptureFormat& format, | 131 const VideoCaptureFormat& format, |
| 100 base::TimeTicks reference_time, | 132 base::TimeTicks reference_time, |
| 101 base::TimeDelta timestamp) override { | 133 base::TimeDelta timestamp) override { |
| 102 frame_cb_.Run(format); | 134 frame_cb_.Run(format); |
| 103 } | 135 } |
| 104 void OnIncomingCapturedBufferExt( | 136 void OnIncomingCapturedBufferExt( |
| 105 std::unique_ptr<Buffer> buffer, | 137 Buffer buffer, |
| 106 const VideoCaptureFormat& format, | 138 const VideoCaptureFormat& format, |
| 107 base::TimeTicks reference_time, | 139 base::TimeTicks reference_time, |
| 108 base::TimeDelta timestamp, | 140 base::TimeDelta timestamp, |
| 109 gfx::Rect visible_rect, | 141 gfx::Rect visible_rect, |
| 110 const VideoFrameMetadata& additional_metadata) override { | 142 const VideoFrameMetadata& additional_metadata) override { |
| 111 frame_cb_.Run(format); | 143 frame_cb_.Run(format); |
| 112 } | 144 } |
| 113 std::unique_ptr<Buffer> ResurrectLastOutputBuffer( | 145 Buffer ResurrectLastOutputBuffer(const gfx::Size& dimensions, |
| 114 const gfx::Size& dimensions, | 146 media::VideoPixelFormat format, |
| 115 media::VideoPixelFormat format, | 147 media::VideoPixelStorage storage, |
| 116 media::VideoPixelStorage storage, | 148 int frame_feedback_id) override { |
| 117 int frame_feedback_id) override { | 149 return Buffer(); |
| 118 return std::unique_ptr<Buffer>(); | |
| 119 } | 150 } |
| 120 double GetBufferPoolUtilization() const override { return 0.0; } | 151 double GetBufferPoolUtilization() const override { return 0.0; } |
| 121 | 152 |
| 122 private: | 153 private: |
| 123 base::Callback<void(const VideoCaptureFormat&)> frame_cb_; | 154 base::Callback<void(const VideoCaptureFormat&)> frame_cb_; |
| 124 }; | 155 }; |
| 125 | 156 |
| 126 class DeviceEnumerationListener | 157 class DeviceEnumerationListener |
| 127 : public base::RefCounted<DeviceEnumerationListener> { | 158 : public base::RefCounted<DeviceEnumerationListener> { |
| 128 public: | 159 public: |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 INSTANTIATE_TEST_CASE_P( | 507 INSTANTIATE_TEST_CASE_P( |
| 477 , | 508 , |
| 478 FakeVideoCaptureDeviceCommandLineTest, | 509 FakeVideoCaptureDeviceCommandLineTest, |
| 479 Values(CommandLineTestData{"fps=-1", 5, 1u}, | 510 Values(CommandLineTestData{"fps=-1", 5, 1u}, |
| 480 CommandLineTestData{"fps=29.97, device-count=1", 29.97f, 1u}, | 511 CommandLineTestData{"fps=29.97, device-count=1", 29.97f, 1u}, |
| 481 CommandLineTestData{"fps=60, device-count=2", 60, 2u}, | 512 CommandLineTestData{"fps=60, device-count=2", 60, 2u}, |
| 482 CommandLineTestData{"fps=1000, device-count=-1", 60, 1u}, | 513 CommandLineTestData{"fps=1000, device-count=-1", 60, 1u}, |
| 483 CommandLineTestData{"device-count=2", 20, 2u}, | 514 CommandLineTestData{"device-count=2", 20, 2u}, |
| 484 CommandLineTestData{"device-count=0", 20, 1u})); | 515 CommandLineTestData{"device-count=0", 20, 1u})); |
| 485 }; // namespace media | 516 }; // namespace media |
| OLD | NEW |