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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
// Copyright (c) 2012 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/media_stream_center.h"
#include <string>
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/string_number_conversions.h"
#include "base/utf_string_conversions.h"
#include "content/renderer/media/media_stream_dependency_factory.h"
#include "content/renderer/media/media_stream_extra_data.h"
#include "content/renderer/media/media_stream_impl.h"
#include "content/renderer/render_view_impl.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStream.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamCenterClient.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamSource.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamSourcesRequest.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamTrack.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
#include "third_party/libjingle/source/talk/app/webrtc/jsep.h"
namespace content {
static webrtc::MediaStreamInterface* GetNativeMediaStream(
const WebKit::WebMediaStream& stream) {
MediaStreamExtraData* extra_data =
static_cast<MediaStreamExtraData*>(stream.extraData());
return extra_data->stream();
}
static webrtc::MediaStreamTrackInterface* GetNativeMediaStreamTrack(
const WebKit::WebMediaStream& stream,
const WebKit::WebMediaStreamTrack& component) {
std::string track_id = UTF16ToUTF8(component.id());
webrtc::MediaStreamInterface* native_stream = GetNativeMediaStream(stream);
if (native_stream) {
if (component.source().type() == WebKit::WebMediaStreamSource::TypeAudio) {
return native_stream->FindAudioTrack(track_id);
}
if (component.source().type() == WebKit::WebMediaStreamSource::TypeVideo) {
return native_stream->FindVideoTrack(track_id);
}
}
NOTREACHED();
return NULL;
}
MediaStreamCenter::MediaStreamCenter(WebKit::WebMediaStreamCenterClient* client,
MediaStreamDependencyFactory* factory)
: rtc_factory_(factory) {
}
void MediaStreamCenter::queryMediaStreamSources(
const WebKit::WebMediaStreamSourcesRequest& request) {
WebKit::WebVector<WebKit::WebMediaStreamSource> audioSources, videoSources;
request.didCompleteQuery(audioSources, videoSources);
}
void MediaStreamCenter::didEnableMediaStreamTrack(
const WebKit::WebMediaStream& stream,
const WebKit::WebMediaStreamTrack& component) {
webrtc::MediaStreamTrackInterface* track =
GetNativeMediaStreamTrack(stream, component);
if (track)
track->set_enabled(true);
}
void MediaStreamCenter::didDisableMediaStreamTrack(
const WebKit::WebMediaStream& stream,
const WebKit::WebMediaStreamTrack& component) {
webrtc::MediaStreamTrackInterface* track =
GetNativeMediaStreamTrack(stream, component);
if (track)
track->set_enabled(false);
}
void MediaStreamCenter::didStopLocalMediaStream(
const WebKit::WebMediaStream& stream) {
DVLOG(1) << "MediaStreamCenter::didStopLocalMediaStream";
MediaStreamExtraData* extra_data =
static_cast<MediaStreamExtraData*>(stream.extraData());
if (!extra_data) {
NOTREACHED();
return;
}
extra_data->OnLocalStreamStop();
}
void MediaStreamCenter::didCreateMediaStream(
WebKit::WebMediaStream& stream) {
if (!rtc_factory_)
return;
rtc_factory_->CreateNativeLocalMediaStream(&stream);
}
bool MediaStreamCenter::didAddMediaStreamTrack(
const WebKit::WebMediaStream& stream,
const WebKit::WebMediaStreamTrack& track) {
if (!rtc_factory_)
return false;
return rtc_factory_->AddNativeMediaStreamTrack(stream, track);
}
bool MediaStreamCenter::didRemoveMediaStreamTrack(
const WebKit::WebMediaStream& stream,
const WebKit::WebMediaStreamTrack& track) {
if (!rtc_factory_)
return false;
return rtc_factory_->RemoveNativeMediaStreamTrack(stream, track);
}
} // namespace content
|