1 // Copyright (c) 2012 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.
5 #include "content/renderer/media/media_stream_center.h"
9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/string_number_conversions.h"
12 #include "base/utf_string_conversions.h"
13 #include "content/renderer/media/media_stream_dependency_factory.h"
14 #include "content/renderer/media/media_stream_extra_data.h"
15 #include "content/renderer/media/media_stream_impl.h"
16 #include "content/renderer/render_view_impl.h"
17 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStream.h"
18 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamCenterClient.h"
19 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamSource.h"
20 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamSourcesRequest.h"
21 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamTrack.h"
22 #include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h"
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
24 #include "third_party/libjingle/source/talk/app/webrtc/jsep.h"
28 static webrtc::MediaStreamInterface
* GetNativeMediaStream(
29 const WebKit::WebMediaStream
& stream
) {
30 MediaStreamExtraData
* extra_data
=
31 static_cast<MediaStreamExtraData
*>(stream
.extraData());
32 return extra_data
->stream();
35 static webrtc::MediaStreamTrackInterface
* GetNativeMediaStreamTrack(
36 const WebKit::WebMediaStream
& stream
,
37 const WebKit::WebMediaStreamTrack
& component
) {
38 std::string track_id
= UTF16ToUTF8(component
.id());
39 webrtc::MediaStreamInterface
* native_stream
= GetNativeMediaStream(stream
);
41 if (component
.source().type() == WebKit::WebMediaStreamSource::TypeAudio
) {
42 return native_stream
->FindAudioTrack(track_id
);
44 if (component
.source().type() == WebKit::WebMediaStreamSource::TypeVideo
) {
45 return native_stream
->FindVideoTrack(track_id
);
52 MediaStreamCenter::MediaStreamCenter(WebKit::WebMediaStreamCenterClient
* client
,
53 MediaStreamDependencyFactory
* factory
)
54 : rtc_factory_(factory
) {
57 void MediaStreamCenter::queryMediaStreamSources(
58 const WebKit::WebMediaStreamSourcesRequest
& request
) {
59 WebKit::WebVector
<WebKit::WebMediaStreamSource
> audioSources
, videoSources
;
60 request
.didCompleteQuery(audioSources
, videoSources
);
63 void MediaStreamCenter::didEnableMediaStreamTrack(
64 const WebKit::WebMediaStream
& stream
,
65 const WebKit::WebMediaStreamTrack
& component
) {
66 webrtc::MediaStreamTrackInterface
* track
=
67 GetNativeMediaStreamTrack(stream
, component
);
69 track
->set_enabled(true);
72 void MediaStreamCenter::didDisableMediaStreamTrack(
73 const WebKit::WebMediaStream
& stream
,
74 const WebKit::WebMediaStreamTrack
& component
) {
75 webrtc::MediaStreamTrackInterface
* track
=
76 GetNativeMediaStreamTrack(stream
, component
);
78 track
->set_enabled(false);
81 void MediaStreamCenter::didStopLocalMediaStream(
82 const WebKit::WebMediaStream
& stream
) {
83 DVLOG(1) << "MediaStreamCenter::didStopLocalMediaStream";
84 MediaStreamExtraData
* extra_data
=
85 static_cast<MediaStreamExtraData
*>(stream
.extraData());
91 extra_data
->OnLocalStreamStop();
94 void MediaStreamCenter::didCreateMediaStream(
95 WebKit::WebMediaStream
& stream
) {
98 rtc_factory_
->CreateNativeLocalMediaStream(&stream
);
101 bool MediaStreamCenter::didAddMediaStreamTrack(
102 const WebKit::WebMediaStream
& stream
,
103 const WebKit::WebMediaStreamTrack
& track
) {
107 return rtc_factory_
->AddNativeMediaStreamTrack(stream
, track
);
110 bool MediaStreamCenter::didRemoveMediaStreamTrack(
111 const WebKit::WebMediaStream
& stream
,
112 const WebKit::WebMediaStreamTrack
& track
) {
116 return rtc_factory_
->RemoveNativeMediaStreamTrack(stream
, track
);
119 } // namespace content