summaryrefslogtreecommitdiffstats
path: root/content/renderer/media/mock_media_stream_registry.cc
blob: e0e2dce73e0e307df32de8745c98ef085bdbfb7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/renderer/media/mock_media_stream_registry.h"

#include <string>

#include "base/utf_string_conversions.h"
#include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
#include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/platform/WebVector.h"
#include "third_party/libjingle/source/talk/media/base/videocapturer.h"

namespace content {

static const std::string kTestStreamLabel = "stream_label";

MockMediaStreamRegistry::MockMediaStreamRegistry(
    MockMediaStreamDependencyFactory* factory)
    : factory_(factory) {
}

void MockMediaStreamRegistry::Init(const std::string& stream_url) {
  stream_url_ = stream_url;
  scoped_refptr<webrtc::MediaStreamInterface> stream(
      factory_->CreateLocalMediaStream(kTestStreamLabel));
  WebKit::WebVector<WebKit::WebMediaStreamTrack> webkit_audio_tracks;
  WebKit::WebVector<WebKit::WebMediaStreamTrack> webkit_video_tracks;
  WebKit::WebString webkit_stream_label(UTF8ToUTF16(stream->label()));
  test_stream_.initialize(webkit_stream_label,
                          webkit_audio_tracks, webkit_video_tracks);
  test_stream_.setExtraData(new MediaStreamExtraData(stream, false));
}

bool MockMediaStreamRegistry::AddVideoTrack(const std::string& track_id) {
  cricket::VideoCapturer* capturer = NULL;
  return factory_->AddNativeVideoMediaTrack(track_id, &test_stream_, capturer);
}

WebKit::WebMediaStream MockMediaStreamRegistry::GetMediaStream(
    const std::string& url) {
  if (url != stream_url_) {
    return WebKit::WebMediaStream();
  }
  return test_stream_;
}

const WebKit::WebMediaStream MockMediaStreamRegistry::test_stream() const {
  return test_stream_;
}

}  // namespace content