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