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

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 Andrew's comments and fixed some testbots' errors 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 } else {
scherkus (not reviewing) 2012/10/26 17:28:22 nit: remove else
no longer working on chromium 2012/10/29 15:01:36 Done.
280 // WebRtcAudioDeviceImpl can only support one renderer.
281 return NULL;
282 }
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. 295 // The requested stream have been generated.
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 WebKit::WebVector<WebKit::WebMediaStreamSource> audio_source_vector( 303 WebKit::WebVector<WebKit::WebMediaStreamSource> audio_source_vector(
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 503
468 DVLOG(1) << "MediaStreamImpl::CreateRemoteVideoDecoder label:" 504 DVLOG(1) << "MediaStreamImpl::CreateRemoteVideoDecoder label:"
469 << stream->label(); 505 << stream->label();
470 506
471 return new RTCVideoDecoder( 507 return new RTCVideoDecoder(
472 message_loop_factory->GetMessageLoop(media::MessageLoopFactory::kDecoder), 508 message_loop_factory->GetMessageLoop(media::MessageLoopFactory::kDecoder),
473 base::MessageLoopProxy::current(), 509 base::MessageLoopProxy::current(),
474 stream->video_tracks()->at(0)); 510 stream->video_tracks()->at(0));
475 } 511 }
476 512
513 scoped_refptr<WebRtcAudioRenderer> MediaStreamImpl::CreateRemoteAudioRenderer(
514 webrtc::MediaStreamInterface* stream) {
515 if (!stream->audio_tracks() || stream->audio_tracks()->count() == 0)
516 return NULL;
517
518 DVLOG(1) << "MediaStreamImpl::CreateRemoteAudioRenderer label:"
519 << stream->label();
520
521 return new WebRtcAudioRenderer();
522 }
523
477 MediaStreamSourceExtraData::MediaStreamSourceExtraData( 524 MediaStreamSourceExtraData::MediaStreamSourceExtraData(
478 const media_stream::StreamDeviceInfo& device_info) 525 const media_stream::StreamDeviceInfo& device_info)
479 : device_info_(device_info) { 526 : device_info_(device_info) {
480 } 527 }
481 528
482 MediaStreamSourceExtraData::~MediaStreamSourceExtraData() {} 529 MediaStreamSourceExtraData::~MediaStreamSourceExtraData() {}
483 530
484 MediaStreamExtraData::MediaStreamExtraData( 531 MediaStreamExtraData::MediaStreamExtraData(
485 webrtc::MediaStreamInterface* remote_stream) 532 webrtc::MediaStreamInterface* remote_stream)
486 : remote_stream_(remote_stream) { 533 : remote_stream_(remote_stream) {
(...skipping 11 matching lines...) Expand all
498 const StreamStopCallback& stop_callback) { 545 const StreamStopCallback& stop_callback) {
499 stream_stop_callback_ = stop_callback; 546 stream_stop_callback_ = stop_callback;
500 } 547 }
501 548
502 void MediaStreamExtraData::OnLocalStreamStop() { 549 void MediaStreamExtraData::OnLocalStreamStop() {
503 if (!stream_stop_callback_.is_null()) 550 if (!stream_stop_callback_.is_null())
504 stream_stop_callback_.Run(local_stream_->label()); 551 stream_stop_callback_.Run(local_stream_->label());
505 } 552 }
506 553
507 } // namespace content 554 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698