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_audio_source.h" |
12 #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_stream_video_source.h" | 13 #include "content/renderer/media/mock_media_stream_video_source.h" |
14 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" | |
15 #include "content/renderer/media/webrtc_local_audio_track.h" | |
16 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | 14 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
17 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | 15 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
18 #include "third_party/WebKit/public/platform/WebString.h" | 16 #include "third_party/WebKit/public/platform/WebString.h" |
19 #include "third_party/WebKit/public/platform/WebVector.h" | 17 #include "third_party/WebKit/public/platform/WebVector.h" |
20 | 18 |
21 namespace content { | 19 namespace content { |
22 | 20 |
23 static const char kTestStreamLabel[] = "stream_label"; | 21 namespace { |
| 22 |
| 23 const char kTestStreamLabel[] = "stream_label"; |
| 24 |
| 25 class MockCDQualityAudioSource : public MediaStreamAudioSource { |
| 26 public: |
| 27 MockCDQualityAudioSource() : MediaStreamAudioSource(true) { |
| 28 MediaStreamAudioSource::SetFormat(media::AudioParameters( |
| 29 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 30 media::CHANNEL_LAYOUT_STEREO, |
| 31 media::AudioParameters::kAudioCDSampleRate, |
| 32 16, |
| 33 media::AudioParameters::kAudioCDSampleRate / 100)); |
| 34 MediaStreamAudioSource::SetDeviceInfo(StreamDeviceInfo( |
| 35 MEDIA_DEVICE_AUDIO_CAPTURE, "Mock audio device", "mock_audio_device_id", |
| 36 media::AudioParameters::kAudioCDSampleRate, |
| 37 media::CHANNEL_LAYOUT_STEREO, |
| 38 media::AudioParameters::kAudioCDSampleRate / 100)); |
| 39 } |
| 40 |
| 41 private: |
| 42 DISALLOW_COPY_AND_ASSIGN(MockCDQualityAudioSource); |
| 43 }; |
| 44 |
| 45 } // namespace |
24 | 46 |
25 MockMediaStreamRegistry::MockMediaStreamRegistry() {} | 47 MockMediaStreamRegistry::MockMediaStreamRegistry() {} |
26 | 48 |
27 void MockMediaStreamRegistry::Init(const std::string& stream_url) { | 49 void MockMediaStreamRegistry::Init(const std::string& stream_url) { |
28 stream_url_ = stream_url; | 50 stream_url_ = stream_url; |
29 const blink::WebVector<blink::WebMediaStreamTrack> webkit_audio_tracks; | 51 const blink::WebVector<blink::WebMediaStreamTrack> webkit_audio_tracks; |
30 const blink::WebVector<blink::WebMediaStreamTrack> webkit_video_tracks; | 52 const blink::WebVector<blink::WebMediaStreamTrack> webkit_video_tracks; |
31 const blink::WebString label(kTestStreamLabel); | 53 const blink::WebString label(kTestStreamLabel); |
32 test_stream_.initialize(label, webkit_audio_tracks, webkit_video_tracks); | 54 test_stream_.initialize(label, webkit_audio_tracks, webkit_video_tracks); |
33 test_stream_.setExtraData(new MediaStream()); | 55 test_stream_.setExtraData(new MediaStream()); |
(...skipping 14 matching lines...) Expand all Loading... |
48 constraints.initialize(); | 70 constraints.initialize(); |
49 | 71 |
50 MediaStreamVideoTrack* native_track = new MediaStreamVideoTrack( | 72 MediaStreamVideoTrack* native_track = new MediaStreamVideoTrack( |
51 native_source, constraints, MediaStreamVideoSource::ConstraintsCallback(), | 73 native_source, constraints, MediaStreamVideoSource::ConstraintsCallback(), |
52 true /* enabled */); | 74 true /* enabled */); |
53 blink_track.setExtraData(native_track); | 75 blink_track.setExtraData(native_track); |
54 test_stream_.addTrack(blink_track); | 76 test_stream_.addTrack(blink_track); |
55 } | 77 } |
56 | 78 |
57 void MockMediaStreamRegistry::AddAudioTrack(const std::string& track_id) { | 79 void MockMediaStreamRegistry::AddAudioTrack(const std::string& track_id) { |
58 blink::WebMediaStreamSource audio_source; | 80 blink::WebMediaStreamSource blink_source; |
59 audio_source.initialize( | 81 blink_source.initialize( |
60 "mock audio source id", blink::WebMediaStreamSource::TypeAudio, | 82 "mock audio source id", blink::WebMediaStreamSource::TypeAudio, |
61 "mock audio source name", false /* remote */); | 83 "mock audio source name", false /* remote */); |
62 audio_source.setExtraData(new MediaStreamAudioSource()); | 84 MediaStreamAudioSource* const source = new MockCDQualityAudioSource(); |
| 85 blink_source.setExtraData(source); // Takes ownership. |
| 86 |
63 blink::WebMediaStreamTrack blink_track; | 87 blink::WebMediaStreamTrack blink_track; |
64 blink_track.initialize(audio_source); | 88 blink_track.initialize(blink_source); |
65 const scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( | 89 CHECK(source->ConnectToTrack(blink_track)); |
66 WebRtcLocalAudioTrackAdapter::Create(track_id, | 90 |
67 nullptr /* track source */)); | |
68 std::unique_ptr<WebRtcLocalAudioTrack> native_track( | |
69 new WebRtcLocalAudioTrack(adapter.get())); | |
70 blink_track.setExtraData(native_track.release()); | |
71 test_stream_.addTrack(blink_track); | 91 test_stream_.addTrack(blink_track); |
72 } | 92 } |
73 | 93 |
74 blink::WebMediaStream MockMediaStreamRegistry::GetMediaStream( | 94 blink::WebMediaStream MockMediaStreamRegistry::GetMediaStream( |
75 const std::string& url) { | 95 const std::string& url) { |
76 return (url != stream_url_) ? blink::WebMediaStream() : test_stream_; | 96 return (url != stream_url_) ? blink::WebMediaStream() : test_stream_; |
77 } | 97 } |
78 | 98 |
79 } // namespace content | 99 } // namespace content |
OLD | NEW |