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