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 3 // found in the LICENSE file. 4 5 #include "content/renderer/media/mock_media_stream_registry.h" 6 7 #include <string> 8 9 #include "base/strings/utf_string_conversions.h" 10 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" 11 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" 12 #include "third_party/WebKit/public/platform/WebString.h" 13 #include "third_party/WebKit/public/platform/WebVector.h" 14 #include "third_party/libjingle/source/talk/media/base/videocapturer.h" 15 16 namespace content { 17 18 static const std::string kTestStreamLabel = "stream_label"; 19 20 MockMediaStreamRegistry::MockMediaStreamRegistry( 21 MockMediaStreamDependencyFactory* factory) 22 : factory_(factory) { 23 } 24 25 void MockMediaStreamRegistry::Init(const std::string& stream_url) { 26 stream_url_ = stream_url; 27 scoped_refptr<webrtc::MediaStreamInterface> stream( 28 factory_->CreateLocalMediaStream(kTestStreamLabel)); 29 blink::WebVector<blink::WebMediaStreamTrack> webkit_audio_tracks; 30 blink::WebVector<blink::WebMediaStreamTrack> webkit_video_tracks; 31 blink::WebString webkit_stream_label(UTF8ToUTF16(stream->label())); 32 test_stream_.initialize(webkit_stream_label, 33 webkit_audio_tracks, webkit_video_tracks); 34 test_stream_.setExtraData(new MediaStreamExtraData(stream.get(), false)); 35 } 36 37 bool MockMediaStreamRegistry::AddVideoTrack(const std::string& track_id) { 38 cricket::VideoCapturer* capturer = NULL; 39 return factory_->AddNativeVideoMediaTrack(track_id, &test_stream_, capturer); 40 } 41 42 blink::WebMediaStream MockMediaStreamRegistry::GetMediaStream( 43 const std::string& url) { 44 if (url != stream_url_) { 45 return blink::WebMediaStream(); 46 } 47 return test_stream_; 48 } 49 50 const blink::WebMediaStream MockMediaStreamRegistry::test_stream() const { 51 return test_stream_; 52 } 53 54 } // namespace content 55