Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: content/renderer/media/media_stream_impl.cc

Issue 11270012: Adding audio support to the new webmediaplyer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed the nits from Andrew and fixed the chromeOS testbot error Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/media/media_stream_impl.h" 5 #include "content/renderer/media/media_stream_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
11 #include "base/stringprintf.h" 11 #include "base/stringprintf.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "content/renderer/media/media_stream_extra_data.h" 13 #include "content/renderer/media/media_stream_extra_data.h"
14 #include "content/renderer/media/media_stream_source_extra_data.h" 14 #include "content/renderer/media/media_stream_source_extra_data.h"
15 #include "content/renderer/media/media_stream_dependency_factory.h" 15 #include "content/renderer/media/media_stream_dependency_factory.h"
16 #include "content/renderer/media/media_stream_dispatcher.h" 16 #include "content/renderer/media/media_stream_dispatcher.h"
17 #include "content/renderer/media/rtc_video_decoder.h" 17 #include "content/renderer/media/rtc_video_decoder.h"
18 #include "content/renderer/media/rtc_video_renderer.h" 18 #include "content/renderer/media/rtc_video_renderer.h"
19 #include "content/renderer/media/video_capture_impl_manager.h" 19 #include "content/renderer/media/video_capture_impl_manager.h"
20 #include "content/renderer/media/webrtc_audio_renderer.h"
20 #include "content/renderer/media/webrtc_uma_histograms.h" 21 #include "content/renderer/media/webrtc_uma_histograms.h"
21 #include "media/base/message_loop_factory.h" 22 #include "media/base/message_loop_factory.h"
22 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaConstraints .h" 23 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaConstraints .h"
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamRegistr y.h" 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamRegistr y.h"
26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
27 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amComponent.h" 28 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amComponent.h"
28 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amSource.h" 29 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amSource.h"
29 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" 30 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
31 #include "webkit/media/media_stream_audio_renderer.h"
30 32
31 namespace { 33 namespace {
32 34
33 std::string GetMandatoryStreamConstraint( 35 std::string GetMandatoryStreamConstraint(
34 const WebKit::WebMediaConstraints& constraints, const std::string& key) { 36 const WebKit::WebMediaConstraints& constraints, const std::string& key) {
35 if (constraints.isNull()) 37 if (constraints.isNull())
36 return std::string(); 38 return std::string();
37 39
38 WebKit::WebString value; 40 WebKit::WebString value;
39 constraints.getMandatoryConstraintValue(UTF8ToUTF16(key), value); 41 constraints.getMandatoryConstraintValue(UTF8ToUTF16(key), value);
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 DVLOG(1) << "MediaStreamImpl::GetVideoDecoder stream:" 250 DVLOG(1) << "MediaStreamImpl::GetVideoDecoder stream:"
249 << UTF16ToUTF8(descriptor.label()); 251 << UTF16ToUTF8(descriptor.label());
250 252
251 webrtc::MediaStreamInterface* stream = GetNativeMediaStream(descriptor); 253 webrtc::MediaStreamInterface* stream = GetNativeMediaStream(descriptor);
252 if (stream) 254 if (stream)
253 return CreateVideoDecoder(stream, message_loop_factory); 255 return CreateVideoDecoder(stream, message_loop_factory);
254 NOTREACHED(); 256 NOTREACHED();
255 return NULL; 257 return NULL;
256 } 258 }
257 259
260 scoped_refptr<webkit_media::MediaStreamAudioRenderer>
261 MediaStreamImpl::GetAudioRenderer(const GURL& url) {
262 DCHECK(CalledOnValidThread());
263 WebKit::WebMediaStreamDescriptor descriptor(GetMediaStream(url));
264
265 if (descriptor.isNull() || !descriptor.extraData())
266 return NULL; // This is not a valid stream.
267
268 DVLOG(1) << "MediaStreamImpl::GetAudioRenderer stream:"
269 << UTF16ToUTF8(descriptor.label());
270
271 MediaStreamExtraData* extra_data =
272 static_cast<MediaStreamExtraData*>(descriptor.extraData());
273 if (extra_data->remote_stream()) {
274 scoped_refptr<WebRtcAudioRenderer> renderer =
275 CreateRemoteAudioRenderer(extra_data->remote_stream());
276
277 if (dependency_factory_->GetWebRtcAudioDevice()->SetRenderer(renderer)) {
278 return renderer;
279 }
280
281 // WebRtcAudioDeviceImpl can only support one renderer.
282 return NULL;
283 }
284
285 if (extra_data->local_stream()) {
286 // TODO(xians): Implement a WebRtcAudioFIFO to handle the local loopback.
287 return NULL;
288 }
289
290 NOTREACHED();
291 return NULL;
292 }
293
258 // Callback from MediaStreamDispatcher. 294 // Callback from MediaStreamDispatcher.
259 // The requested stream have been generated by the MediaStreamDispatcher. 295 // The requested stream have been generated by the MediaStreamDispatcher.
260 void MediaStreamImpl::OnStreamGenerated( 296 void MediaStreamImpl::OnStreamGenerated(
261 int request_id, 297 int request_id,
262 const std::string& label, 298 const std::string& label,
263 const media_stream::StreamDeviceInfoArray& audio_array, 299 const media_stream::StreamDeviceInfoArray& audio_array,
264 const media_stream::StreamDeviceInfoArray& video_array) { 300 const media_stream::StreamDeviceInfoArray& video_array) {
265 DCHECK(CalledOnValidThread()); 301 DCHECK(CalledOnValidThread());
266 302
267 UserMediaRequestInfo* request_info = FindUserMediaRequestInfo(request_id); 303 UserMediaRequestInfo* request_info = FindUserMediaRequestInfo(request_id);
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 530
495 DVLOG(1) << "MediaStreamImpl::CreateRemoteVideoDecoder label:" 531 DVLOG(1) << "MediaStreamImpl::CreateRemoteVideoDecoder label:"
496 << stream->label(); 532 << stream->label();
497 533
498 return new RTCVideoDecoder( 534 return new RTCVideoDecoder(
499 message_loop_factory->GetMessageLoop(media::MessageLoopFactory::kDecoder), 535 message_loop_factory->GetMessageLoop(media::MessageLoopFactory::kDecoder),
500 base::MessageLoopProxy::current(), 536 base::MessageLoopProxy::current(),
501 stream->video_tracks()->at(0)); 537 stream->video_tracks()->at(0));
502 } 538 }
503 539
540 scoped_refptr<WebRtcAudioRenderer> MediaStreamImpl::CreateRemoteAudioRenderer(
541 webrtc::MediaStreamInterface* stream) {
542 if (!stream->audio_tracks() || stream->audio_tracks()->count() == 0)
543 return NULL;
544
545 DVLOG(1) << "MediaStreamImpl::CreateRemoteAudioRenderer label:"
546 << stream->label();
547
548 return new WebRtcAudioRenderer();
549 }
550
504 MediaStreamSourceExtraData::MediaStreamSourceExtraData( 551 MediaStreamSourceExtraData::MediaStreamSourceExtraData(
505 const media_stream::StreamDeviceInfo& device_info) 552 const media_stream::StreamDeviceInfo& device_info)
506 : device_info_(device_info) { 553 : device_info_(device_info) {
507 } 554 }
508 555
509 MediaStreamSourceExtraData::~MediaStreamSourceExtraData() {} 556 MediaStreamSourceExtraData::~MediaStreamSourceExtraData() {}
510 557
511 MediaStreamExtraData::MediaStreamExtraData( 558 MediaStreamExtraData::MediaStreamExtraData(
512 webrtc::MediaStreamInterface* remote_stream) 559 webrtc::MediaStreamInterface* remote_stream)
513 : remote_stream_(remote_stream) { 560 : remote_stream_(remote_stream) {
(...skipping 11 matching lines...) Expand all
525 const StreamStopCallback& stop_callback) { 572 const StreamStopCallback& stop_callback) {
526 stream_stop_callback_ = stop_callback; 573 stream_stop_callback_ = stop_callback;
527 } 574 }
528 575
529 void MediaStreamExtraData::OnLocalStreamStop() { 576 void MediaStreamExtraData::OnLocalStreamStop() {
530 if (!stream_stop_callback_.is_null()) 577 if (!stream_stop_callback_.is_null())
531 stream_stop_callback_.Run(local_stream_->label()); 578 stream_stop_callback_.Run(local_stream_->label());
532 } 579 }
533 580
534 } // namespace content 581 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698