Home | History | Annotate | Download | only in media
      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 "content/renderer/media/media_stream.h"
     11 #include "content/renderer/media/media_stream_video_track.h"
     12 #include "content/renderer/media/mock_media_stream_video_source.h"
     13 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
     14 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
     15 #include "third_party/WebKit/public/platform/WebString.h"
     16 #include "third_party/WebKit/public/platform/WebVector.h"
     17 
     18 namespace content {
     19 
     20 static const char kTestStreamLabel[] = "stream_label";
     21 
     22 MockMediaStreamRegistry::MockMediaStreamRegistry() {
     23 }
     24 
     25 void MockMediaStreamRegistry::Init(const std::string& stream_url) {
     26   stream_url_ = stream_url;
     27   blink::WebVector<blink::WebMediaStreamTrack> webkit_audio_tracks;
     28   blink::WebVector<blink::WebMediaStreamTrack> webkit_video_tracks;
     29   blink::WebString label(kTestStreamLabel);
     30   test_stream_.initialize(label, webkit_audio_tracks, webkit_video_tracks);
     31   test_stream_.setExtraData(new MediaStream(test_stream_));
     32 }
     33 
     34 void MockMediaStreamRegistry::AddVideoTrack(const std::string& track_id) {
     35   blink::WebMediaStreamSource blink_source;
     36   blink_source.initialize("mock video source id",
     37                           blink::WebMediaStreamSource::TypeVideo,
     38                           "mock video source name");
     39   MockMediaStreamVideoSource* native_source =
     40       new MockMediaStreamVideoSource(false);
     41   blink_source.setExtraData(native_source);
     42   blink::WebMediaStreamTrack blink_track;
     43   blink_track.initialize(base::UTF8ToUTF16(track_id), blink_source);
     44   blink::WebMediaConstraints constraints;
     45   constraints.initialize();
     46 
     47   MediaStreamVideoTrack* native_track =
     48       new MediaStreamVideoTrack(native_source,
     49                                 constraints,
     50                                 MediaStreamVideoSource::ConstraintsCallback(),
     51                                 true);
     52   blink_track.setExtraData(native_track);
     53   test_stream_.addTrack(blink_track);
     54 }
     55 
     56 blink::WebMediaStream MockMediaStreamRegistry::GetMediaStream(
     57     const std::string& url) {
     58   if (url != stream_url_) {
     59     return blink::WebMediaStream();
     60   }
     61   return test_stream_;
     62 }
     63 
     64 const blink::WebMediaStream MockMediaStreamRegistry::test_stream() const {
     65   return test_stream_;
     66 }
     67 
     68 }  // namespace content
     69