Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Side by Side Diff: content/renderer/media/mock_media_stream_dispatcher.cc

Issue 344653003: Revert 274608 "Implement getMediaDevices." (Closed) Base URL: svn://svn.chromium.org/chrome/branches/2057/src/
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 namespace content { 11 namespace content {
12 12
13 MockMediaStreamDispatcher::MockMediaStreamDispatcher() 13 MockMediaStreamDispatcher::MockMediaStreamDispatcher()
14 : MediaStreamDispatcher(NULL), 14 : MediaStreamDispatcher(NULL),
15 audio_request_id_(-1), 15 request_id_(-1),
16 video_request_id_(-1),
17 request_stream_counter_(0), 16 request_stream_counter_(0),
18 stop_audio_device_counter_(0), 17 stop_audio_device_counter_(0),
19 stop_video_device_counter_(0), 18 stop_video_device_counter_(0),
20 session_id_(0) { 19 session_id_(0) {
21 } 20 }
22 21
23 MockMediaStreamDispatcher::~MockMediaStreamDispatcher() {} 22 MockMediaStreamDispatcher::~MockMediaStreamDispatcher() {}
24 23
25 void MockMediaStreamDispatcher::GenerateStream( 24 void MockMediaStreamDispatcher::GenerateStream(
26 int request_id, 25 int request_id,
27 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, 26 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler,
28 const StreamOptions& components, 27 const StreamOptions& components,
29 const GURL& url) { 28 const GURL& url) {
30 // Audio and video share the same request so we use |audio_request_id_| only. 29 request_id_ = request_id;
31 audio_request_id_ = request_id;
32 30
33 stream_label_ = "local_stream" + base::IntToString(request_id); 31 stream_label_ = "local_stream" + base::IntToString(request_id);
34 audio_array_.clear(); 32 audio_array_.clear();
35 video_array_.clear(); 33 video_array_.clear();
36 34
37 if (components.audio_requested) { 35 if (components.audio_requested) {
38 AddAudioDeviceToArray(); 36 StreamDeviceInfo audio;
37 audio.device.id = "audio_device_id" + base::IntToString(session_id_);
38 audio.device.name = "microphone";
39 audio.device.type = MEDIA_DEVICE_AUDIO_CAPTURE;
40 audio.session_id = session_id_;
41 audio_array_.push_back(audio);
39 } 42 }
40 if (components.video_requested) { 43 if (components.video_requested) {
41 AddVideoDeviceToArray(); 44 StreamDeviceInfo video;
45 video.device.id = "video_device_id" + base::IntToString(session_id_);
46 video.device.name = "usb video camera";
47 video.device.type = MEDIA_DEVICE_VIDEO_CAPTURE;
48 video.session_id = session_id_;
49 video_array_.push_back(video);
42 } 50 }
43 ++request_stream_counter_; 51 ++request_stream_counter_;
44 } 52 }
45 53
46 void MockMediaStreamDispatcher::CancelGenerateStream( 54 void MockMediaStreamDispatcher::CancelGenerateStream(
47 int request_id, 55 int request_id,
48 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler) { 56 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler) {
49 EXPECT_EQ(request_id, audio_request_id_); 57 EXPECT_EQ(request_id, request_id_);
50 }
51
52 void MockMediaStreamDispatcher::EnumerateDevices(
53 int request_id,
54 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler,
55 MediaStreamType type,
56 const GURL& security_origin) {
57 if (type == MEDIA_DEVICE_AUDIO_CAPTURE) {
58 audio_request_id_ = request_id;
59 audio_array_.clear();
60 AddAudioDeviceToArray();
61 } else if (type == MEDIA_DEVICE_VIDEO_CAPTURE) {
62 video_request_id_ = request_id;
63 video_array_.clear();
64 AddVideoDeviceToArray();
65 }
66 } 58 }
67 59
68 void MockMediaStreamDispatcher::StopStreamDevice( 60 void MockMediaStreamDispatcher::StopStreamDevice(
69 const StreamDeviceInfo& device_info) { 61 const StreamDeviceInfo& device_info) {
70 if (IsAudioMediaType(device_info.device.type)) { 62 if (IsAudioMediaType(device_info.device.type)) {
71 ++stop_audio_device_counter_; 63 ++stop_audio_device_counter_;
72 return; 64 return;
73 } 65 }
74 if (IsVideoMediaType(device_info.device.type)) { 66 if (IsVideoMediaType(device_info.device.type)) {
75 ++stop_video_device_counter_; 67 ++stop_video_device_counter_;
76 return; 68 return;
77 } 69 }
78 NOTREACHED(); 70 NOTREACHED();
79 } 71 }
80 72
81 bool MockMediaStreamDispatcher::IsStream(const std::string& label) { 73 bool MockMediaStreamDispatcher::IsStream(const std::string& label) {
82 return true; 74 return true;
83 } 75 }
84 76
85 int MockMediaStreamDispatcher::video_session_id(const std::string& label, 77 int MockMediaStreamDispatcher::video_session_id(const std::string& label,
86 int index) { 78 int index) {
87 return -1; 79 return -1;
88 } 80 }
89 81
90 int MockMediaStreamDispatcher::audio_session_id(const std::string& label, 82 int MockMediaStreamDispatcher::audio_session_id(const std::string& label,
91 int index) { 83 int index) {
92 return -1; 84 return -1;
93 } 85 }
94 86
95 void MockMediaStreamDispatcher::AddAudioDeviceToArray() {
96 StreamDeviceInfo audio;
97 audio.device.id = "audio_device_id" + base::IntToString(session_id_);
98 audio.device.name = "microphone";
99 audio.device.type = MEDIA_DEVICE_AUDIO_CAPTURE;
100 audio.session_id = session_id_;
101 audio_array_.push_back(audio);
102 }
103
104 void MockMediaStreamDispatcher::AddVideoDeviceToArray() {
105 StreamDeviceInfo video;
106 video.device.id = "video_device_id" + base::IntToString(session_id_);
107 video.device.name = "usb video camera";
108 video.device.type = MEDIA_DEVICE_VIDEO_CAPTURE;
109 video.session_id = session_id_;
110 video_array_.push_back(video);
111 }
112
113 } // namespace content 87 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/mock_media_stream_dispatcher.h ('k') | content/renderer/media/webrtc_uma_histograms.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698