| 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 "content/renderer/media/mock_media_stream_dispatcher.h" | 5 #include "content/renderer/media/mock_media_stream_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "content/public/common/media_stream_request.h" | 8 #include "content/public/common/media_stream_request.h" |
| 9 #include "media/base/audio_parameters.h" | 9 #include "media/base/audio_parameters.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| 12 // Used for ID for output devices and for matching output device ID for input | 12 // Used for ID for output devices and for matching output device ID for input |
| 13 // devices. | 13 // devices. |
| 14 const char kAudioOutputDeviceIdPrefix[] = "audio_output_device_id"; | 14 const char kAudioOutputDeviceIdPrefix[] = "audio_output_device_id"; |
| 15 | 15 |
| 16 namespace content { | 16 namespace content { |
| 17 | 17 |
| 18 MockMediaStreamDispatcher::MockMediaStreamDispatcher() | 18 MockMediaStreamDispatcher::MockMediaStreamDispatcher() |
| 19 : MediaStreamDispatcher(NULL), | 19 : MediaStreamDispatcher(NULL), |
| 20 audio_input_request_id_(-1), | 20 audio_input_request_id_(-1), |
| 21 audio_output_request_id_(-1), | |
| 22 video_request_id_(-1), | |
| 23 request_stream_counter_(0), | 21 request_stream_counter_(0), |
| 24 stop_audio_device_counter_(0), | 22 stop_audio_device_counter_(0), |
| 25 stop_video_device_counter_(0), | 23 stop_video_device_counter_(0), |
| 26 session_id_(0), | 24 session_id_(0), |
| 27 test_same_id_(false) {} | 25 test_same_id_(false) {} |
| 28 | 26 |
| 29 MockMediaStreamDispatcher::~MockMediaStreamDispatcher() {} | 27 MockMediaStreamDispatcher::~MockMediaStreamDispatcher() {} |
| 30 | 28 |
| 31 void MockMediaStreamDispatcher::GenerateStream( | 29 void MockMediaStreamDispatcher::GenerateStream( |
| 32 int request_id, | 30 int request_id, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 49 } | 47 } |
| 50 ++request_stream_counter_; | 48 ++request_stream_counter_; |
| 51 } | 49 } |
| 52 | 50 |
| 53 void MockMediaStreamDispatcher::CancelGenerateStream( | 51 void MockMediaStreamDispatcher::CancelGenerateStream( |
| 54 int request_id, | 52 int request_id, |
| 55 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler) { | 53 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler) { |
| 56 EXPECT_EQ(request_id, audio_input_request_id_); | 54 EXPECT_EQ(request_id, audio_input_request_id_); |
| 57 } | 55 } |
| 58 | 56 |
| 59 void MockMediaStreamDispatcher::EnumerateDevices( | |
| 60 int request_id, | |
| 61 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, | |
| 62 MediaStreamType type, | |
| 63 const url::Origin& security_origin) { | |
| 64 NOTREACHED(); | |
| 65 } | |
| 66 | |
| 67 void MockMediaStreamDispatcher::StopStreamDevice( | 57 void MockMediaStreamDispatcher::StopStreamDevice( |
| 68 const StreamDeviceInfo& device_info) { | 58 const StreamDeviceInfo& device_info) { |
| 69 if (IsAudioInputMediaType(device_info.device.type)) { | 59 if (IsAudioInputMediaType(device_info.device.type)) { |
| 70 ++stop_audio_device_counter_; | 60 ++stop_audio_device_counter_; |
| 71 return; | 61 return; |
| 72 } | 62 } |
| 73 if (IsVideoMediaType(device_info.device.type)) { | 63 if (IsVideoMediaType(device_info.device.type)) { |
| 74 ++stop_video_device_counter_; | 64 ++stop_video_device_counter_; |
| 75 return; | 65 return; |
| 76 } | 66 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 95 bool matched_output) { | 85 bool matched_output) { |
| 96 StreamDeviceInfo audio; | 86 StreamDeviceInfo audio; |
| 97 audio.device.id = test_same_id_ ? "test_id" : "audio_input_device_id"; | 87 audio.device.id = test_same_id_ ? "test_id" : "audio_input_device_id"; |
| 98 audio.device.id = audio.device.id + base::IntToString(session_id_); | 88 audio.device.id = audio.device.id + base::IntToString(session_id_); |
| 99 audio.device.name = "microphone"; | 89 audio.device.name = "microphone"; |
| 100 audio.device.type = MEDIA_DEVICE_AUDIO_CAPTURE; | 90 audio.device.type = MEDIA_DEVICE_AUDIO_CAPTURE; |
| 101 audio.device.video_facing = MEDIA_VIDEO_FACING_NONE; | 91 audio.device.video_facing = MEDIA_VIDEO_FACING_NONE; |
| 102 if (matched_output) { | 92 if (matched_output) { |
| 103 audio.device.matched_output_device_id = | 93 audio.device.matched_output_device_id = |
| 104 kAudioOutputDeviceIdPrefix + base::IntToString(session_id_); | 94 kAudioOutputDeviceIdPrefix + base::IntToString(session_id_); |
| 105 audio.device.group_id = | |
| 106 kAudioOutputDeviceIdPrefix + base::IntToString(session_id_); | |
| 107 } else { | |
| 108 audio.device.group_id = audio.device.id + "groupid"; | |
| 109 } | 95 } |
| 110 audio.session_id = session_id_; | 96 audio.session_id = session_id_; |
| 111 audio.device.input.sample_rate = media::AudioParameters::kAudioCDSampleRate; | 97 audio.device.input.sample_rate = media::AudioParameters::kAudioCDSampleRate; |
| 112 audio.device.input.channel_layout = media::CHANNEL_LAYOUT_STEREO; | 98 audio.device.input.channel_layout = media::CHANNEL_LAYOUT_STEREO; |
| 113 audio.device.input.frames_per_buffer = audio.device.input.sample_rate / 100; | 99 audio.device.input.frames_per_buffer = audio.device.input.sample_rate / 100; |
| 114 audio_input_array_.push_back(audio); | 100 audio_input_array_.push_back(audio); |
| 115 } | 101 } |
| 116 | 102 |
| 117 void MockMediaStreamDispatcher::AddAudioOutputDeviceToArray() { | |
| 118 StreamDeviceInfo audio; | |
| 119 audio.device.id = kAudioOutputDeviceIdPrefix + base::IntToString(session_id_); | |
| 120 audio.device.group_id = | |
| 121 kAudioOutputDeviceIdPrefix + base::IntToString(session_id_); | |
| 122 audio.device.name = "speaker"; | |
| 123 audio.device.type = MEDIA_DEVICE_AUDIO_OUTPUT; | |
| 124 audio.device.video_facing = MEDIA_VIDEO_FACING_NONE; | |
| 125 audio.session_id = session_id_; | |
| 126 audio_output_array_.push_back(audio); | |
| 127 } | |
| 128 | |
| 129 void MockMediaStreamDispatcher::AddVideoDeviceToArray(bool facing_user) { | 103 void MockMediaStreamDispatcher::AddVideoDeviceToArray(bool facing_user) { |
| 130 StreamDeviceInfo video; | 104 StreamDeviceInfo video; |
| 131 video.device.id = test_same_id_ ? "test_id" : "video_device_id"; | 105 video.device.id = test_same_id_ ? "test_id" : "video_device_id"; |
| 132 video.device.id = video.device.id + base::IntToString(session_id_); | 106 video.device.id = video.device.id + base::IntToString(session_id_); |
| 133 video.device.name = "usb video camera"; | 107 video.device.name = "usb video camera"; |
| 134 video.device.type = MEDIA_DEVICE_VIDEO_CAPTURE; | 108 video.device.type = MEDIA_DEVICE_VIDEO_CAPTURE; |
| 135 video.device.video_facing = facing_user ? MEDIA_VIDEO_FACING_USER | 109 video.device.video_facing = facing_user ? MEDIA_VIDEO_FACING_USER |
| 136 : MEDIA_VIDEO_FACING_ENVIRONMENT; | 110 : MEDIA_VIDEO_FACING_ENVIRONMENT; |
| 137 video.session_id = session_id_; | 111 video.session_id = session_id_; |
| 138 video_array_.push_back(video); | 112 video_array_.push_back(video); |
| 139 } | 113 } |
| 140 | 114 |
| 141 } // namespace content | 115 } // namespace content |
| OLD | NEW |