OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_registry.h" | 5 #include "content/renderer/media/mock_media_stream_registry.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "content/renderer/media/media_stream.h" | 10 #include "content/renderer/media/media_stream.h" |
| 11 #include "content/renderer/media/media_stream_audio_source.h" |
11 #include "content/renderer/media/media_stream_video_track.h" | 12 #include "content/renderer/media/media_stream_video_track.h" |
| 13 #include "content/renderer/media/mock_media_constraint_factory.h" |
12 #include "content/renderer/media/mock_media_stream_video_source.h" | 14 #include "content/renderer/media/mock_media_stream_video_source.h" |
| 15 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" |
| 16 #include "content/renderer/media/webrtc_local_audio_track.h" |
13 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | 17 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
14 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | 18 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
15 #include "third_party/WebKit/public/platform/WebString.h" | 19 #include "third_party/WebKit/public/platform/WebString.h" |
16 #include "third_party/WebKit/public/platform/WebVector.h" | 20 #include "third_party/WebKit/public/platform/WebVector.h" |
17 | 21 |
18 namespace content { | 22 namespace content { |
19 | 23 |
20 static const char kTestStreamLabel[] = "stream_label"; | 24 static const char kTestStreamLabel[] = "stream_label"; |
21 | 25 |
22 MockMediaStreamRegistry::MockMediaStreamRegistry() {} | 26 MockMediaStreamRegistry::MockMediaStreamRegistry() {} |
23 | 27 |
24 void MockMediaStreamRegistry::Init(const std::string& stream_url) { | 28 void MockMediaStreamRegistry::Init(const std::string& stream_url) { |
25 stream_url_ = stream_url; | 29 stream_url_ = stream_url; |
26 const blink::WebVector<blink::WebMediaStreamTrack> webkit_audio_tracks; | 30 const blink::WebVector<blink::WebMediaStreamTrack> webkit_audio_tracks; |
27 const blink::WebVector<blink::WebMediaStreamTrack> webkit_video_tracks; | 31 const blink::WebVector<blink::WebMediaStreamTrack> webkit_video_tracks; |
28 const blink::WebString label(kTestStreamLabel); | 32 const blink::WebString label(kTestStreamLabel); |
29 test_stream_.initialize(label, webkit_audio_tracks, webkit_video_tracks); | 33 test_stream_.initialize(label, webkit_audio_tracks, webkit_video_tracks); |
30 test_stream_.setExtraData(new MediaStream(test_stream_)); | 34 test_stream_.setExtraData(new MediaStream(test_stream_)); |
31 } | 35 } |
32 | 36 |
33 void MockMediaStreamRegistry::AddVideoTrack(const std::string& track_id) { | 37 void MockMediaStreamRegistry::AddVideoTrack(const std::string& track_id) { |
34 blink::WebMediaStreamSource blink_source; | 38 blink::WebMediaStreamSource blink_source; |
35 blink_source.initialize("mock video source id", | 39 blink_source.initialize("mock video source id", |
36 blink::WebMediaStreamSource::TypeVideo, | 40 blink::WebMediaStreamSource::TypeVideo, |
37 "mock video source name", | 41 "mock video source name", |
38 false /* remote */, true /* readonly */); | 42 false /* remote */, true /* readonly */); |
39 MockMediaStreamVideoSource* native_source = | 43 MockMediaStreamVideoSource* native_source = |
40 new MockMediaStreamVideoSource(false); | 44 new MockMediaStreamVideoSource(false /* manual get supported formats */); |
41 blink_source.setExtraData(native_source); | 45 blink_source.setExtraData(native_source); |
42 blink::WebMediaStreamTrack blink_track; | 46 blink::WebMediaStreamTrack blink_track; |
43 blink_track.initialize(base::UTF8ToUTF16(track_id), blink_source); | 47 blink_track.initialize(base::UTF8ToUTF16(track_id), blink_source); |
44 blink::WebMediaConstraints constraints; | 48 blink::WebMediaConstraints constraints; |
45 constraints.initialize(); | 49 constraints.initialize(); |
46 | 50 |
47 MediaStreamVideoTrack* native_track = | 51 MediaStreamVideoTrack* native_track = new MediaStreamVideoTrack( |
48 new MediaStreamVideoTrack(native_source, | 52 native_source, constraints, MediaStreamVideoSource::ConstraintsCallback(), |
49 constraints, | 53 true /* enabled */); |
50 MediaStreamVideoSource::ConstraintsCallback(), | |
51 true); | |
52 blink_track.setExtraData(native_track); | 54 blink_track.setExtraData(native_track); |
53 test_stream_.addTrack(blink_track); | 55 test_stream_.addTrack(blink_track); |
54 } | 56 } |
55 | 57 |
| 58 void MockMediaStreamRegistry::AddAudioTrack(const std::string& track_id) { |
| 59 blink::WebMediaStreamSource audio_source; |
| 60 audio_source.initialize( |
| 61 "mock audio source id", blink::WebMediaStreamSource::TypeAudio, |
| 62 "mock audio source name", false /* remote */, true /* readonly */); |
| 63 audio_source.setExtraData(new MediaStreamAudioSource()); |
| 64 blink::WebMediaStreamTrack blink_track; |
| 65 blink_track.initialize(audio_source); |
| 66 const StreamDeviceInfo device_info( |
| 67 MEDIA_DEVICE_AUDIO_CAPTURE, "Mock audio device", "mock_audio_device_id"); |
| 68 const MockMediaConstraintFactory constraint_factory; |
| 69 const blink::WebMediaConstraints constraints = |
| 70 constraint_factory.CreateWebMediaConstraints(); |
| 71 const scoped_refptr<WebRtcAudioCapturer> capturer( |
| 72 WebRtcAudioCapturer::CreateCapturer(-1, /* render frame id */ |
| 73 device_info, constraints, |
| 74 nullptr, /* audio device */ |
| 75 nullptr /* audio source */)); |
| 76 const scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( |
| 77 WebRtcLocalAudioTrackAdapter::Create(track_id, |
| 78 nullptr /* track source */)); |
| 79 scoped_ptr<WebRtcLocalAudioTrack> native_track(new WebRtcLocalAudioTrack( |
| 80 adapter.get(), capturer, nullptr /* webaudio source */)); |
| 81 blink_track.setExtraData(native_track.release()); |
| 82 test_stream_.addTrack(blink_track); |
| 83 } |
| 84 |
56 blink::WebMediaStream MockMediaStreamRegistry::GetMediaStream( | 85 blink::WebMediaStream MockMediaStreamRegistry::GetMediaStream( |
57 const std::string& url) { | 86 const std::string& url) { |
58 return (url != stream_url_) ? blink::WebMediaStream() : test_stream_; | 87 return (url != stream_url_) ? blink::WebMediaStream() : test_stream_; |
59 } | 88 } |
60 | 89 |
61 } // namespace content | 90 } // namespace content |
OLD | NEW |