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 "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
| 11 // Used for ID for output devices and for matching output device ID for input |
| 12 // devices. |
| 13 const char kAudioOutputDeviceIdPrefix[] = "audio_output_device_id"; |
| 14 |
11 namespace content { | 15 namespace content { |
12 | 16 |
13 MockMediaStreamDispatcher::MockMediaStreamDispatcher() | 17 MockMediaStreamDispatcher::MockMediaStreamDispatcher() |
14 : MediaStreamDispatcher(NULL), | 18 : MediaStreamDispatcher(NULL), |
15 audio_request_id_(-1), | 19 audio_input_request_id_(-1), |
| 20 audio_output_request_id_(-1), |
16 video_request_id_(-1), | 21 video_request_id_(-1), |
17 request_stream_counter_(0), | 22 request_stream_counter_(0), |
18 stop_audio_device_counter_(0), | 23 stop_audio_device_counter_(0), |
19 stop_video_device_counter_(0), | 24 stop_video_device_counter_(0), |
20 session_id_(0) { | 25 session_id_(0) { |
21 } | 26 } |
22 | 27 |
23 MockMediaStreamDispatcher::~MockMediaStreamDispatcher() {} | 28 MockMediaStreamDispatcher::~MockMediaStreamDispatcher() {} |
24 | 29 |
25 void MockMediaStreamDispatcher::GenerateStream( | 30 void MockMediaStreamDispatcher::GenerateStream( |
26 int request_id, | 31 int request_id, |
27 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, | 32 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, |
28 const StreamOptions& components, | 33 const StreamOptions& components, |
29 const GURL& url) { | 34 const GURL& url) { |
30 // Audio and video share the same request so we use |audio_request_id_| only. | 35 // Audio and video share the same request so we use |audio_input_request_id_| |
31 audio_request_id_ = request_id; | 36 // only. |
| 37 audio_input_request_id_ = request_id; |
32 | 38 |
33 stream_label_ = "local_stream" + base::IntToString(request_id); | 39 stream_label_ = "local_stream" + base::IntToString(request_id); |
34 audio_array_.clear(); | 40 audio_input_array_.clear(); |
35 video_array_.clear(); | 41 video_array_.clear(); |
36 | 42 |
37 if (components.audio_requested) { | 43 if (components.audio_requested) { |
38 AddAudioDeviceToArray(); | 44 AddAudioInputDeviceToArray(false); |
39 } | 45 } |
40 if (components.video_requested) { | 46 if (components.video_requested) { |
41 AddVideoDeviceToArray(); | 47 AddVideoDeviceToArray(); |
42 } | 48 } |
43 ++request_stream_counter_; | 49 ++request_stream_counter_; |
44 } | 50 } |
45 | 51 |
46 void MockMediaStreamDispatcher::CancelGenerateStream( | 52 void MockMediaStreamDispatcher::CancelGenerateStream( |
47 int request_id, | 53 int request_id, |
48 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler) { | 54 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler) { |
49 EXPECT_EQ(request_id, audio_request_id_); | 55 EXPECT_EQ(request_id, audio_input_request_id_); |
50 } | 56 } |
51 | 57 |
52 void MockMediaStreamDispatcher::EnumerateDevices( | 58 void MockMediaStreamDispatcher::EnumerateDevices( |
53 int request_id, | 59 int request_id, |
54 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, | 60 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, |
55 MediaStreamType type, | 61 MediaStreamType type, |
56 const GURL& security_origin) { | 62 const GURL& security_origin) { |
57 if (type == MEDIA_DEVICE_AUDIO_CAPTURE) { | 63 if (type == MEDIA_DEVICE_AUDIO_CAPTURE) { |
58 audio_request_id_ = request_id; | 64 audio_input_request_id_ = request_id; |
59 audio_array_.clear(); | 65 audio_input_array_.clear(); |
60 AddAudioDeviceToArray(); | 66 AddAudioInputDeviceToArray(true); |
| 67 AddAudioInputDeviceToArray(false); |
| 68 } else if (type == MEDIA_DEVICE_AUDIO_OUTPUT) { |
| 69 audio_output_request_id_ = request_id; |
| 70 audio_output_array_.clear(); |
| 71 AddAudioOutputDeviceToArray(); |
61 } else if (type == MEDIA_DEVICE_VIDEO_CAPTURE) { | 72 } else if (type == MEDIA_DEVICE_VIDEO_CAPTURE) { |
62 video_request_id_ = request_id; | 73 video_request_id_ = request_id; |
63 video_array_.clear(); | 74 video_array_.clear(); |
64 AddVideoDeviceToArray(); | 75 AddVideoDeviceToArray(); |
65 } | 76 } |
66 } | 77 } |
67 | 78 |
68 void MockMediaStreamDispatcher::StopStreamDevice( | 79 void MockMediaStreamDispatcher::StopStreamDevice( |
69 const StreamDeviceInfo& device_info) { | 80 const StreamDeviceInfo& device_info) { |
70 if (IsAudioMediaType(device_info.device.type)) { | 81 if (IsAudioInputMediaType(device_info.device.type)) { |
71 ++stop_audio_device_counter_; | 82 ++stop_audio_device_counter_; |
72 return; | 83 return; |
73 } | 84 } |
74 if (IsVideoMediaType(device_info.device.type)) { | 85 if (IsVideoMediaType(device_info.device.type)) { |
75 ++stop_video_device_counter_; | 86 ++stop_video_device_counter_; |
76 return; | 87 return; |
77 } | 88 } |
78 NOTREACHED(); | 89 NOTREACHED(); |
79 } | 90 } |
80 | 91 |
81 bool MockMediaStreamDispatcher::IsStream(const std::string& label) { | 92 bool MockMediaStreamDispatcher::IsStream(const std::string& label) { |
82 return true; | 93 return true; |
83 } | 94 } |
84 | 95 |
85 int MockMediaStreamDispatcher::video_session_id(const std::string& label, | 96 int MockMediaStreamDispatcher::video_session_id(const std::string& label, |
86 int index) { | 97 int index) { |
87 return -1; | 98 return -1; |
88 } | 99 } |
89 | 100 |
90 int MockMediaStreamDispatcher::audio_session_id(const std::string& label, | 101 int MockMediaStreamDispatcher::audio_session_id(const std::string& label, |
91 int index) { | 102 int index) { |
92 return -1; | 103 return -1; |
93 } | 104 } |
94 | 105 |
95 void MockMediaStreamDispatcher::AddAudioDeviceToArray() { | 106 void MockMediaStreamDispatcher::AddAudioInputDeviceToArray( |
| 107 bool matched_output) { |
96 StreamDeviceInfo audio; | 108 StreamDeviceInfo audio; |
97 audio.device.id = "audio_device_id" + base::IntToString(session_id_); | 109 audio.device.id = "audio_input_device_id" + base::IntToString(session_id_); |
98 audio.device.name = "microphone"; | 110 audio.device.name = "microphone"; |
99 audio.device.type = MEDIA_DEVICE_AUDIO_CAPTURE; | 111 audio.device.type = MEDIA_DEVICE_AUDIO_CAPTURE; |
| 112 if (matched_output) { |
| 113 audio.device.matched_output_device_id = |
| 114 kAudioOutputDeviceIdPrefix + base::IntToString(session_id_); |
| 115 } |
100 audio.session_id = session_id_; | 116 audio.session_id = session_id_; |
101 audio_array_.push_back(audio); | 117 audio_input_array_.push_back(audio); |
| 118 } |
| 119 |
| 120 void MockMediaStreamDispatcher::AddAudioOutputDeviceToArray() { |
| 121 StreamDeviceInfo audio; |
| 122 audio.device.id = kAudioOutputDeviceIdPrefix + base::IntToString(session_id_); |
| 123 audio.device.name = "speaker"; |
| 124 audio.device.type = MEDIA_DEVICE_AUDIO_OUTPUT; |
| 125 audio.session_id = session_id_; |
| 126 audio_output_array_.push_back(audio); |
102 } | 127 } |
103 | 128 |
104 void MockMediaStreamDispatcher::AddVideoDeviceToArray() { | 129 void MockMediaStreamDispatcher::AddVideoDeviceToArray() { |
105 StreamDeviceInfo video; | 130 StreamDeviceInfo video; |
106 video.device.id = "video_device_id" + base::IntToString(session_id_); | 131 video.device.id = "video_device_id" + base::IntToString(session_id_); |
107 video.device.name = "usb video camera"; | 132 video.device.name = "usb video camera"; |
108 video.device.type = MEDIA_DEVICE_VIDEO_CAPTURE; | 133 video.device.type = MEDIA_DEVICE_VIDEO_CAPTURE; |
109 video.session_id = session_id_; | 134 video.session_id = session_id_; |
110 video_array_.push_back(video); | 135 video_array_.push_back(video); |
111 } | 136 } |
112 | 137 |
113 } // namespace content | 138 } // namespace content |
OLD | NEW |