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 19 matching lines...) Expand all Loading... |
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 // This class is a Client::Buffer that allocates and frees the requested |size|. |
38 class MockBuffer : public VideoCaptureDevice::Client::Buffer { | 38 class MockBuffer : public VideoCaptureDevice::Client::Buffer { |
39 public: | 39 public: |
40 MockBuffer(int buffer_id, size_t mapped_size) | 40 MockBuffer(int buffer_id, int frame_feedback_id, size_t mapped_size) |
41 : id_(buffer_id), | 41 : id_(buffer_id), |
| 42 frame_feedback_id_(frame_feedback_id), |
42 mapped_size_(mapped_size), | 43 mapped_size_(mapped_size), |
43 data_(new uint8_t[mapped_size]) {} | 44 data_(new uint8_t[mapped_size]) {} |
44 ~MockBuffer() override { delete[] data_; } | 45 ~MockBuffer() override { delete[] data_; } |
45 | 46 |
46 int id() const override { return id_; } | 47 int id() const override { return id_; } |
| 48 int frame_feedback_id() const override { return frame_feedback_id_; } |
47 gfx::Size dimensions() const override { return gfx::Size(); } | 49 gfx::Size dimensions() const override { return gfx::Size(); } |
48 size_t mapped_size() const override { return mapped_size_; } | 50 size_t mapped_size() const override { return mapped_size_; } |
49 void* data(int plane) override { return data_; } | 51 void* data(int plane) override { return data_; } |
50 #if defined(OS_POSIX) && !(defined(OS_MACOSX) && !defined(OS_IOS)) | 52 #if defined(OS_POSIX) && !(defined(OS_MACOSX) && !defined(OS_IOS)) |
51 base::FileDescriptor AsPlatformFile() override { | 53 base::FileDescriptor AsPlatformFile() override { |
52 return base::FileDescriptor(); | 54 return base::FileDescriptor(); |
53 } | 55 } |
54 #endif | 56 #endif |
55 bool IsBackedByVideoFrame() const override { return false; }; | 57 bool IsBackedByVideoFrame() const override { return false; }; |
56 scoped_refptr<VideoFrame> GetVideoFrame() override { return nullptr; } | 58 scoped_refptr<VideoFrame> GetVideoFrame() override { return nullptr; } |
57 | 59 |
58 private: | 60 private: |
59 const int id_; | 61 const int id_; |
| 62 const int frame_feedback_id_; |
60 const size_t mapped_size_; | 63 const size_t mapped_size_; |
61 uint8_t* const data_; | 64 uint8_t* const data_; |
62 }; | 65 }; |
63 | 66 |
64 class MockClient : public VideoCaptureDevice::Client { | 67 class MockClient : public VideoCaptureDevice::Client { |
65 public: | 68 public: |
66 MOCK_METHOD2(OnError, | 69 MOCK_METHOD2(OnError, |
67 void(const tracked_objects::Location& from_here, | 70 void(const tracked_objects::Location& from_here, |
68 const std::string& reason)); | 71 const std::string& reason)); |
69 | 72 |
70 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb) | 73 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb) |
71 : frame_cb_(frame_cb) {} | 74 : frame_cb_(frame_cb) {} |
72 | 75 |
73 // Client virtual methods for capturing using Device Buffers. | 76 // Client virtual methods for capturing using Device Buffers. |
74 void OnIncomingCapturedData(const uint8_t* data, | 77 void OnIncomingCapturedData(const uint8_t* data, |
75 int length, | 78 int length, |
76 const VideoCaptureFormat& format, | 79 const VideoCaptureFormat& format, |
77 int rotation, | 80 int rotation, |
78 base::TimeTicks reference_time, | 81 base::TimeTicks reference_time, |
79 base::TimeDelta timestamp) override { | 82 base::TimeDelta timestamp, |
| 83 int frame_feedback_id) override { |
80 frame_cb_.Run(format); | 84 frame_cb_.Run(format); |
81 } | 85 } |
82 // Virtual methods for capturing using Client's Buffers. | 86 // Virtual methods for capturing using Client's Buffers. |
83 std::unique_ptr<Buffer> ReserveOutputBuffer( | 87 std::unique_ptr<Buffer> ReserveOutputBuffer(const gfx::Size& dimensions, |
84 const gfx::Size& dimensions, | 88 media::VideoPixelFormat format, |
85 media::VideoPixelFormat format, | 89 media::VideoPixelStorage storage, |
86 media::VideoPixelStorage storage) { | 90 int frame_feedback_id) override { |
87 EXPECT_TRUE((format == media::PIXEL_FORMAT_ARGB && | 91 EXPECT_TRUE((format == media::PIXEL_FORMAT_ARGB && |
88 storage == media::PIXEL_STORAGE_CPU)); | 92 storage == media::PIXEL_STORAGE_CPU)); |
89 EXPECT_GT(dimensions.GetArea(), 0); | 93 EXPECT_GT(dimensions.GetArea(), 0); |
90 const VideoCaptureFormat frame_format(dimensions, 0.0, format); | 94 const VideoCaptureFormat frame_format(dimensions, 0.0, format); |
91 return base::MakeUnique<MockBuffer>(0, frame_format.ImageAllocationSize()); | 95 return base::MakeUnique<MockBuffer>(0, frame_feedback_id, |
| 96 frame_format.ImageAllocationSize()); |
92 } | 97 } |
93 void OnIncomingCapturedBuffer(std::unique_ptr<Buffer> buffer, | 98 void OnIncomingCapturedBuffer(std::unique_ptr<Buffer> buffer, |
94 const VideoCaptureFormat& frame_format, | 99 const VideoCaptureFormat& format, |
95 base::TimeTicks reference_time, | 100 base::TimeTicks reference_time, |
96 base::TimeDelta timestamp) { | 101 base::TimeDelta timestamp) override { |
97 frame_cb_.Run(frame_format); | 102 frame_cb_.Run(format); |
98 } | 103 } |
99 void OnIncomingCapturedVideoFrame(std::unique_ptr<Buffer> buffer, | 104 void OnIncomingCapturedVideoFrame( |
100 scoped_refptr<media::VideoFrame> frame) { | 105 std::unique_ptr<Buffer> buffer, |
| 106 scoped_refptr<media::VideoFrame> frame) override { |
101 VideoCaptureFormat format(frame->natural_size(), 30.0, | 107 VideoCaptureFormat format(frame->natural_size(), 30.0, |
102 PIXEL_FORMAT_I420); | 108 PIXEL_FORMAT_I420); |
103 frame_cb_.Run(format); | 109 frame_cb_.Run(format); |
104 } | 110 } |
105 std::unique_ptr<Buffer> ResurrectLastOutputBuffer( | 111 std::unique_ptr<Buffer> ResurrectLastOutputBuffer( |
106 const gfx::Size& dimensions, | 112 const gfx::Size& dimensions, |
107 media::VideoPixelFormat format, | 113 media::VideoPixelFormat format, |
108 media::VideoPixelStorage storage) { | 114 media::VideoPixelStorage storage, |
| 115 int frame_feedback_id) override { |
109 return std::unique_ptr<Buffer>(); | 116 return std::unique_ptr<Buffer>(); |
110 } | 117 } |
111 double GetBufferPoolUtilization() const override { return 0.0; } | 118 double GetBufferPoolUtilization() const override { return 0.0; } |
112 | 119 |
113 private: | 120 private: |
114 base::Callback<void(const VideoCaptureFormat&)> frame_cb_; | 121 base::Callback<void(const VideoCaptureFormat&)> frame_cb_; |
115 }; | 122 }; |
116 | 123 |
117 class DeviceEnumerationListener | 124 class DeviceEnumerationListener |
118 : public base::RefCounted<DeviceEnumerationListener> { | 125 : public base::RefCounted<DeviceEnumerationListener> { |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 INSTANTIATE_TEST_CASE_P( | 474 INSTANTIATE_TEST_CASE_P( |
468 , | 475 , |
469 FakeVideoCaptureDeviceCommandLineTest, | 476 FakeVideoCaptureDeviceCommandLineTest, |
470 Values(CommandLineTestData{"fps=-1", 5, 1u}, | 477 Values(CommandLineTestData{"fps=-1", 5, 1u}, |
471 CommandLineTestData{"fps=29.97, device-count=1", 29.97f, 1u}, | 478 CommandLineTestData{"fps=29.97, device-count=1", 29.97f, 1u}, |
472 CommandLineTestData{"fps=60, device-count=2", 60, 2u}, | 479 CommandLineTestData{"fps=60, device-count=2", 60, 2u}, |
473 CommandLineTestData{"fps=1000, device-count=-1", 60, 1u}, | 480 CommandLineTestData{"fps=1000, device-count=-1", 60, 1u}, |
474 CommandLineTestData{"device-count=2", 20, 2u}, | 481 CommandLineTestData{"device-count=2", 20, 2u}, |
475 CommandLineTestData{"device-count=0", 20, 1u})); | 482 CommandLineTestData{"device-count=0", 20, 1u})); |
476 }; // namespace media | 483 }; // namespace media |
OLD | NEW |