Fix build break
[chromium-blink-merge.git] / content / renderer / media / media_stream_center.cc
blob14b0327c51ef18d54bbc1adbb5f99290b57451e7
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"
7 #include <string>
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"
26 namespace content {
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);
40 if (native_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);
48 NOTREACHED();
49 return NULL;
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);
68 if (track)
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);
77 if (track)
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());
86 if (!extra_data) {
87 NOTREACHED();
88 return;
91 extra_data->OnLocalStreamStop();
94 void MediaStreamCenter::didCreateMediaStream(
95 WebKit::WebMediaStream& stream) {
96 if (!rtc_factory_)
97 return;
98 rtc_factory_->CreateNativeLocalMediaStream(&stream);
101 bool MediaStreamCenter::didAddMediaStreamTrack(
102 const WebKit::WebMediaStream& stream,
103 const WebKit::WebMediaStreamTrack& track) {
104 if (!rtc_factory_)
105 return false;
107 return rtc_factory_->AddNativeMediaStreamTrack(stream, track);
110 bool MediaStreamCenter::didRemoveMediaStreamTrack(
111 const WebKit::WebMediaStream& stream,
112 const WebKit::WebMediaStreamTrack& track) {
113 if (!rtc_factory_)
114 return false;
116 return rtc_factory_->RemoveNativeMediaStreamTrack(stream, track);
119 } // namespace content