OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/video/capture/fake_video_capture_device.h" | 5 #include "media/video/capture/fake_video_capture_device.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 capture_format_.width = 640; | 85 capture_format_.width = 640; |
86 capture_format_.height = 480; | 86 capture_format_.height = 480; |
87 capture_format_.frame_rate = 30; | 87 capture_format_.frame_rate = 30; |
88 } else { // QVGA | 88 } else { // QVGA |
89 capture_format_.width = 320; | 89 capture_format_.width = 320; |
90 capture_format_.height = 240; | 90 capture_format_.height = 240; |
91 capture_format_.frame_rate = 30; | 91 capture_format_.frame_rate = 30; |
92 } | 92 } |
93 capture_format_.stride = capture_format_.width; | 93 capture_format_.stride = capture_format_.width; |
94 | 94 |
95 size_t fake_frame_size = | 95 const size_t fake_frame_size = VideoFrame::AllocationSize( |
96 capture_format_.width * capture_format_.height * 3 / 2; | 96 VideoFrame::I420, |
| 97 gfx::Size(capture_format_.width, capture_format_.height)); |
97 fake_frame_.reset(new uint8[fake_frame_size]); | 98 fake_frame_.reset(new uint8[fake_frame_size]); |
98 | 99 |
99 state_ = kAllocated; | 100 state_ = kAllocated; |
100 observer_->OnFrameInfo(capture_format_); | 101 observer_->OnFrameInfo(capture_format_); |
101 } | 102 } |
102 | 103 |
103 void FakeVideoCaptureDevice::Reallocate() { | 104 void FakeVideoCaptureDevice::Reallocate() { |
104 DCHECK_EQ(state_, kCapturing); | 105 DCHECK_EQ(state_, kCapturing); |
105 capture_format_ = capabilities_roster_.at(++capabilities_roster_index_ % | 106 capture_format_ = capabilities_roster_.at(++capabilities_roster_index_ % |
106 capabilities_roster_.size()); | 107 capabilities_roster_.size()); |
107 DCHECK_EQ(capture_format_.color, VideoCaptureCapability::kI420); | 108 DCHECK_EQ(capture_format_.color, VideoCaptureCapability::kI420); |
108 DVLOG(3) << "Reallocating FakeVideoCaptureDevice, new capture resolution (" | 109 DVLOG(3) << "Reallocating FakeVideoCaptureDevice, new capture resolution (" |
109 << capture_format_.width << "x" << capture_format_.height << ")"; | 110 << capture_format_.width << "x" << capture_format_.height << ")"; |
110 | 111 |
111 size_t fake_frame_size = | 112 const size_t fake_frame_size = VideoFrame::AllocationSize( |
112 capture_format_.width * capture_format_.height * 3 / 2; | 113 VideoFrame::I420, |
| 114 gfx::Size(capture_format_.width, capture_format_.height)); |
113 fake_frame_.reset(new uint8[fake_frame_size]); | 115 fake_frame_.reset(new uint8[fake_frame_size]); |
114 | 116 |
115 observer_->OnFrameInfoChanged(capture_format_); | 117 observer_->OnFrameInfoChanged(capture_format_); |
116 } | 118 } |
117 | 119 |
118 void FakeVideoCaptureDevice::Start() { | 120 void FakeVideoCaptureDevice::Start() { |
119 if (state_ != kAllocated) { | 121 if (state_ != kAllocated) { |
120 return; // Wrong state. | 122 return; // Wrong state. |
121 } | 123 } |
122 state_ = kCapturing; | 124 state_ = kCapturing; |
(...skipping 22 matching lines...) Expand all Loading... |
145 | 147 |
146 const VideoCaptureDevice::Name& FakeVideoCaptureDevice::device_name() { | 148 const VideoCaptureDevice::Name& FakeVideoCaptureDevice::device_name() { |
147 return device_name_; | 149 return device_name_; |
148 } | 150 } |
149 | 151 |
150 void FakeVideoCaptureDevice::OnCaptureTask() { | 152 void FakeVideoCaptureDevice::OnCaptureTask() { |
151 if (state_ != kCapturing) { | 153 if (state_ != kCapturing) { |
152 return; | 154 return; |
153 } | 155 } |
154 | 156 |
155 int frame_size = capture_format_.width * capture_format_.height * 3 / 2; | 157 const size_t frame_size = VideoFrame::AllocationSize( |
| 158 VideoFrame::I420, |
| 159 gfx::Size(capture_format_.width, capture_format_.height)); |
156 memset(fake_frame_.get(), 0, frame_size); | 160 memset(fake_frame_.get(), 0, frame_size); |
157 | 161 |
158 SkBitmap bitmap; | 162 SkBitmap bitmap; |
159 bitmap.setConfig(SkBitmap::kA8_Config, | 163 bitmap.setConfig(SkBitmap::kA8_Config, |
160 capture_format_.width, | 164 capture_format_.width, |
161 capture_format_.height, | 165 capture_format_.height, |
162 capture_format_.width); | 166 capture_format_.width); |
163 bitmap.setPixels(fake_frame_.get()); | 167 bitmap.setPixels(fake_frame_.get()); |
164 | 168 |
165 SkCanvas canvas(bitmap); | 169 SkCanvas canvas(bitmap); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 30, | 251 30, |
248 VideoCaptureCapability::kI420, | 252 VideoCaptureCapability::kI420, |
249 0, | 253 0, |
250 false, | 254 false, |
251 VariableResolutionVideoCaptureDevice)); | 255 VariableResolutionVideoCaptureDevice)); |
252 | 256 |
253 capabilities_roster_index_ = 0; | 257 capabilities_roster_index_ = 0; |
254 } | 258 } |
255 | 259 |
256 } // namespace media | 260 } // namespace media |
OLD | NEW |