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 return mojo::ScopedSharedBufferHandle(); |
| 61 } |
| 62 |
| 63 std::unique_ptr<VideoCaptureBufferHandle> GetHandleForInProcessAccess() |
| 64 override { |
| 65 return base::MakeUnique<StubBufferHandle>(mapped_size_, data_); |
| 66 } |
| 67 |
| 68 private: |
| 69 const size_t mapped_size_; |
| 70 uint8_t* const data_; |
| 71 }; |
| 72 |
| 73 class StubReadWritePermission |
| 74 : public VideoCaptureDevice::Client::Buffer::ScopedAccessPermission { |
| 75 public: |
| 76 StubReadWritePermission(uint8_t* data) : data_(data) {} |
| 77 ~StubReadWritePermission() override { delete[] data_; } |
| 78 |
| 79 private: |
| 80 uint8_t* const data_; |
| 81 }; |
| 82 |
| 83 VideoCaptureDevice::Client::Buffer CreateStubBuffer(int buffer_id, |
| 84 size_t mapped_size) { |
| 85 auto buffer = new uint8_t[mapped_size]; |
| 86 const int arbitrary_frame_feedback_id = 0; |
| 87 return VideoCaptureDevice::Client::Buffer( |
| 88 buffer_id, arbitrary_frame_feedback_id, |
| 89 base::MakeUnique<StubBufferHandleProvider>(mapped_size, buffer), |
| 90 base::MakeUnique<StubReadWritePermission>(buffer)); |
| 91 }; |
| 92 |
67 class MockClient : public VideoCaptureDevice::Client { | 93 class MockClient : public VideoCaptureDevice::Client { |
68 public: | 94 public: |
69 MOCK_METHOD2(OnError, | 95 MOCK_METHOD2(OnError, |
70 void(const tracked_objects::Location& from_here, | 96 void(const tracked_objects::Location& from_here, |
71 const std::string& reason)); | 97 const std::string& reason)); |
72 | 98 |
73 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb) | 99 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb) |
74 : frame_cb_(frame_cb) {} | 100 : frame_cb_(frame_cb) {} |
75 | 101 |
76 // Client virtual methods for capturing using Device Buffers. | 102 // Client virtual methods for capturing using Device Buffers. |
77 void OnIncomingCapturedData(const uint8_t* data, | 103 void OnIncomingCapturedData(const uint8_t* data, |
78 int length, | 104 int length, |
79 const VideoCaptureFormat& format, | 105 const VideoCaptureFormat& format, |
80 int rotation, | 106 int rotation, |
81 base::TimeTicks reference_time, | 107 base::TimeTicks reference_time, |
82 base::TimeDelta timestamp, | 108 base::TimeDelta timestamp, |
83 int frame_feedback_id) override { | 109 int frame_feedback_id) override { |
84 frame_cb_.Run(format); | 110 frame_cb_.Run(format); |
85 } | 111 } |
86 // Virtual methods for capturing using Client's Buffers. | 112 // Virtual methods for capturing using Client's Buffers. |
87 std::unique_ptr<Buffer> ReserveOutputBuffer(const gfx::Size& dimensions, | 113 Buffer ReserveOutputBuffer(const gfx::Size& dimensions, |
88 media::VideoPixelFormat format, | 114 media::VideoPixelFormat format, |
89 media::VideoPixelStorage storage, | 115 media::VideoPixelStorage storage, |
90 int frame_feedback_id) override { | 116 int frame_feedback_id) override { |
91 EXPECT_TRUE((format == media::PIXEL_FORMAT_ARGB && | 117 EXPECT_TRUE((format == media::PIXEL_FORMAT_ARGB && |
92 storage == media::PIXEL_STORAGE_CPU)); | 118 storage == media::PIXEL_STORAGE_CPU)); |
93 EXPECT_GT(dimensions.GetArea(), 0); | 119 EXPECT_GT(dimensions.GetArea(), 0); |
94 const VideoCaptureFormat frame_format(dimensions, 0.0, format); | 120 const VideoCaptureFormat frame_format(dimensions, 0.0, format); |
95 return base::MakeUnique<MockBuffer>(0, frame_feedback_id, | 121 return CreateStubBuffer(0, frame_format.ImageAllocationSize()); |
96 frame_format.ImageAllocationSize()); | |
97 } | 122 } |
98 void OnIncomingCapturedBuffer(std::unique_ptr<Buffer> buffer, | 123 void OnIncomingCapturedBuffer(Buffer buffer, |
99 const VideoCaptureFormat& format, | 124 const VideoCaptureFormat& format, |
100 base::TimeTicks reference_time, | 125 base::TimeTicks reference_time, |
101 base::TimeDelta timestamp) override { | 126 base::TimeDelta timestamp) override { |
102 frame_cb_.Run(format); | 127 frame_cb_.Run(format); |
103 } | 128 } |
104 void OnIncomingCapturedBufferExt( | 129 void OnIncomingCapturedBufferExt( |
105 std::unique_ptr<Buffer> buffer, | 130 Buffer buffer, |
106 const VideoCaptureFormat& format, | 131 const VideoCaptureFormat& format, |
107 base::TimeTicks reference_time, | 132 base::TimeTicks reference_time, |
108 base::TimeDelta timestamp, | 133 base::TimeDelta timestamp, |
109 gfx::Rect visible_rect, | 134 gfx::Rect visible_rect, |
110 const VideoFrameMetadata& additional_metadata) override { | 135 const VideoFrameMetadata& additional_metadata) override { |
111 frame_cb_.Run(format); | 136 frame_cb_.Run(format); |
112 } | 137 } |
113 std::unique_ptr<Buffer> ResurrectLastOutputBuffer( | 138 Buffer ResurrectLastOutputBuffer(const gfx::Size& dimensions, |
114 const gfx::Size& dimensions, | 139 media::VideoPixelFormat format, |
115 media::VideoPixelFormat format, | 140 media::VideoPixelStorage storage, |
116 media::VideoPixelStorage storage, | 141 int frame_feedback_id) override { |
117 int frame_feedback_id) override { | 142 return Buffer(); |
118 return std::unique_ptr<Buffer>(); | |
119 } | 143 } |
120 double GetBufferPoolUtilization() const override { return 0.0; } | 144 double GetBufferPoolUtilization() const override { return 0.0; } |
121 | 145 |
122 private: | 146 private: |
123 base::Callback<void(const VideoCaptureFormat&)> frame_cb_; | 147 base::Callback<void(const VideoCaptureFormat&)> frame_cb_; |
124 }; | 148 }; |
125 | 149 |
126 class DeviceEnumerationListener | 150 class DeviceEnumerationListener |
127 : public base::RefCounted<DeviceEnumerationListener> { | 151 : public base::RefCounted<DeviceEnumerationListener> { |
128 public: | 152 public: |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 INSTANTIATE_TEST_CASE_P( | 500 INSTANTIATE_TEST_CASE_P( |
477 , | 501 , |
478 FakeVideoCaptureDeviceCommandLineTest, | 502 FakeVideoCaptureDeviceCommandLineTest, |
479 Values(CommandLineTestData{"fps=-1", 5, 1u}, | 503 Values(CommandLineTestData{"fps=-1", 5, 1u}, |
480 CommandLineTestData{"fps=29.97, device-count=1", 29.97f, 1u}, | 504 CommandLineTestData{"fps=29.97, device-count=1", 29.97f, 1u}, |
481 CommandLineTestData{"fps=60, device-count=2", 60, 2u}, | 505 CommandLineTestData{"fps=60, device-count=2", 60, 2u}, |
482 CommandLineTestData{"fps=1000, device-count=-1", 60, 1u}, | 506 CommandLineTestData{"fps=1000, device-count=-1", 60, 1u}, |
483 CommandLineTestData{"device-count=2", 20, 2u}, | 507 CommandLineTestData{"device-count=2", 20, 2u}, |
484 CommandLineTestData{"device-count=0", 20, 1u})); | 508 CommandLineTestData{"device-count=0", 20, 1u})); |
485 }; // namespace media | 509 }; // namespace media |
OLD | NEW |