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