| 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 <map> | 5 #include <map> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/process_util.h" | 12 #include "base/process_util.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
| 15 #include "content/browser/browser_thread_impl.h" | 15 #include "content/browser/browser_thread_impl.h" |
| 16 #include "content/browser/renderer_host/media/audio_input_device_manager.h" | |
| 17 #include "content/browser/renderer_host/media/media_stream_manager.h" | 16 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 18 #include "content/browser/renderer_host/media/video_capture_host.h" | 17 #include "content/browser/renderer_host/media/video_capture_host.h" |
| 19 #include "content/browser/renderer_host/media/video_capture_manager.h" | 18 #include "content/browser/renderer_host/media/video_capture_manager.h" |
| 20 #include "content/common/media/video_capture_messages.h" | 19 #include "content/common/media/video_capture_messages.h" |
| 20 #include "content/public/common/media_stream_request.h" |
| 21 #include "content/public/test/mock_resource_context.h" | 21 #include "content/public/test/mock_resource_context.h" |
| 22 #include "media/audio/audio_manager.h" | 22 #include "media/audio/audio_manager.h" |
| 23 #include "media/video/capture/video_capture_types.h" | 23 #include "media/video/capture/video_capture_types.h" |
| 24 #include "net/url_request/url_request_context.h" | 24 #include "net/url_request/url_request_context.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 27 |
| 28 using ::testing::_; | 28 using ::testing::_; |
| 29 using ::testing::AtLeast; | 29 using ::testing::AtLeast; |
| 30 using ::testing::AnyNumber; | 30 using ::testing::AnyNumber; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 IPC_MESSAGE_HANDLER(VideoCaptureMsg_DeviceInfo, OnDeviceInfoDispatch) | 139 IPC_MESSAGE_HANDLER(VideoCaptureMsg_DeviceInfo, OnDeviceInfoDispatch) |
| 140 IPC_MESSAGE_UNHANDLED(handled = false) | 140 IPC_MESSAGE_UNHANDLED(handled = false) |
| 141 IPC_END_MESSAGE_MAP() | 141 IPC_END_MESSAGE_MAP() |
| 142 EXPECT_TRUE(handled); | 142 EXPECT_TRUE(handled); |
| 143 | 143 |
| 144 delete message; | 144 delete message; |
| 145 return true; | 145 return true; |
| 146 } | 146 } |
| 147 | 147 |
| 148 virtual media_stream::VideoCaptureManager* GetVideoCaptureManager() OVERRIDE { | 148 virtual media_stream::VideoCaptureManager* GetVideoCaptureManager() OVERRIDE { |
| 149 return manager_->video_capture_manager(); | 149 return manager_->GetVideoCaptureManager( |
| 150 content::MEDIA_STREAM_DEVICE_TYPE_USER_VIDEO_CAPTURE); |
| 150 } | 151 } |
| 151 | 152 |
| 152 // These handler methods do minimal things and delegate to the mock methods. | 153 // These handler methods do minimal things and delegate to the mock methods. |
| 153 void OnNewBufferCreatedDispatch(int device_id, | 154 void OnNewBufferCreatedDispatch(int device_id, |
| 154 base::SharedMemoryHandle handle, | 155 base::SharedMemoryHandle handle, |
| 155 int length, int buffer_id) { | 156 int length, int buffer_id) { |
| 156 OnNewBufferCreated(device_id, handle, length, buffer_id); | 157 OnNewBufferCreated(device_id, handle, length, buffer_id); |
| 157 base::SharedMemory* dib = new base::SharedMemory(handle, false); | 158 base::SharedMemory* dib = new base::SharedMemory(handle, false); |
| 158 dib->Map(length); | 159 dib->Map(length); |
| 159 filled_dib_[buffer_id] = dib; | 160 filled_dib_[buffer_id] = dib; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 virtual void SetUp() OVERRIDE { | 206 virtual void SetUp() OVERRIDE { |
| 206 // Create a message loop so VideoCaptureHostTest can use it. | 207 // Create a message loop so VideoCaptureHostTest can use it. |
| 207 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); | 208 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); |
| 208 | 209 |
| 209 // MediaStreamManager must be created on the IO thread. | 210 // MediaStreamManager must be created on the IO thread. |
| 210 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO, | 211 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO, |
| 211 message_loop_.get())); | 212 message_loop_.get())); |
| 212 | 213 |
| 213 // Create our own MediaStreamManager. | 214 // Create our own MediaStreamManager. |
| 214 audio_manager_.reset(media::AudioManager::Create()); | 215 audio_manager_.reset(media::AudioManager::Create()); |
| 215 scoped_refptr<media_stream::AudioInputDeviceManager> | 216 media_stream_manager_.reset(new media_stream::MediaStreamManager()); |
| 216 audio_input_device_manager( | 217 media_stream_manager_->UseAudioManager(audio_manager_.get()); |
| 217 new media_stream::AudioInputDeviceManager(audio_manager_.get())); | |
| 218 scoped_refptr<media_stream::VideoCaptureManager> video_capture_manager( | |
| 219 new media_stream::VideoCaptureManager()); | |
| 220 media_stream_manager_.reset(new media_stream::MediaStreamManager( | |
| 221 audio_input_device_manager, video_capture_manager)); | |
| 222 | |
| 223 #ifndef TEST_REAL_CAPTURE_DEVICE | 218 #ifndef TEST_REAL_CAPTURE_DEVICE |
| 224 media_stream_manager_->UseFakeDevice(); | 219 media_stream_manager_->UseFakeDevice(); |
| 225 #endif | 220 #endif |
| 226 | 221 |
| 227 host_ = new MockVideoCaptureHost(media_stream_manager_.get()); | 222 host_ = new MockVideoCaptureHost(media_stream_manager_.get()); |
| 228 | 223 |
| 229 // Simulate IPC channel connected. | 224 // Simulate IPC channel connected. |
| 230 host_->OnChannelConnected(base::GetCurrentProcId()); | 225 host_->OnChannelConnected(base::GetCurrentProcId()); |
| 231 } | 226 } |
| 232 | 227 |
| 233 virtual void TearDown() OVERRIDE { | 228 virtual void TearDown() OVERRIDE { |
| 234 // Verifies and removes the expectations on host_ and | 229 // Verifies and removes the expectations on host_ and |
| 235 // returns true iff successful. | 230 // returns true iff successful. |
| 236 Mock::VerifyAndClearExpectations(host_); | 231 Mock::VerifyAndClearExpectations(host_); |
| 237 | 232 |
| 238 EXPECT_CALL(*host_, OnStateChanged(kDeviceId, | 233 EXPECT_CALL(*host_, OnStateChanged(kDeviceId, |
| 239 video_capture::kStopped)) | 234 video_capture::kStopped)) |
| 240 .Times(AnyNumber()); | 235 .Times(AnyNumber()); |
| 241 | 236 |
| 242 // Simulate closing the IPC channel. | 237 // Simulate closing the IPC channel. |
| 243 host_->OnChannelClosing(); | 238 host_->OnChannelClosing(); |
| 244 | 239 |
| 245 // Release the reference to the mock object. The object will be destructed | 240 // Release the reference to the mock object. The object will be destructed |
| 246 // on message_loop_. | 241 // on message_loop_. |
| 247 host_ = NULL; | 242 host_ = NULL; |
| 248 | 243 |
| 249 // We need to continue running message_loop_ to complete all destructions. | 244 // We need to continue running message_loop_ to complete all destructions. |
| 250 message_loop_->RunAllPending(); | 245 message_loop_->RunAllPending(); |
| 251 | 246 |
| 252 // Delete the IO message loop to delete the device thread, | 247 // Delete the IO message loop. This will cause the MediaStreamManager to be |
| 253 // AudioInputDeviceManager and VideoCaptureManager. | 248 // notified so it will stop its device thread and device managers. |
| 254 message_loop_.reset(); | 249 message_loop_.reset(); |
| 255 } | 250 } |
| 256 | 251 |
| 257 void StartCapture() { | 252 void StartCapture() { |
| 258 InSequence s; | 253 InSequence s; |
| 259 // 1. First - get info about the new resolution | 254 // 1. First - get info about the new resolution |
| 260 EXPECT_CALL(*host_, OnDeviceInfo(kDeviceId)); | 255 EXPECT_CALL(*host_, OnDeviceInfo(kDeviceId)); |
| 261 | 256 |
| 262 // 2. Change state to started | 257 // 2. Change state to started |
| 263 EXPECT_CALL(*host_, OnStateChanged(kDeviceId, | 258 EXPECT_CALL(*host_, OnStateChanged(kDeviceId, |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 } | 382 } |
| 388 | 383 |
| 389 #ifdef DUMP_VIDEO | 384 #ifdef DUMP_VIDEO |
| 390 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) { | 385 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) { |
| 391 CaptureAndDumpVideo(640, 480, 30); | 386 CaptureAndDumpVideo(640, 480, 30); |
| 392 } | 387 } |
| 393 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) { | 388 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) { |
| 394 CaptureAndDumpVideo(1280, 720, 30); | 389 CaptureAndDumpVideo(1280, 720, 30); |
| 395 } | 390 } |
| 396 #endif | 391 #endif |
| OLD | NEW |