| OLD | NEW |
| 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/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 return NULL; // This is not a valid stream. | 264 return NULL; // This is not a valid stream. |
| 265 | 265 |
| 266 DVLOG(1) << "MediaStreamImpl::GetAudioRenderer stream:" | 266 DVLOG(1) << "MediaStreamImpl::GetAudioRenderer stream:" |
| 267 << UTF16ToUTF8(web_stream.id()); | 267 << UTF16ToUTF8(web_stream.id()); |
| 268 | 268 |
| 269 MediaStreamExtraData* extra_data = | 269 MediaStreamExtraData* extra_data = |
| 270 static_cast<MediaStreamExtraData*>(web_stream.extraData()); | 270 static_cast<MediaStreamExtraData*>(web_stream.extraData()); |
| 271 | 271 |
| 272 if (extra_data->is_local()) { | 272 if (extra_data->is_local()) { |
| 273 // Create the local audio renderer if the stream contains audio tracks. | 273 // Create the local audio renderer if the stream contains audio tracks. |
| 274 return CreateLocalAudioRenderer(extra_data->stream().get()); | 274 blink::WebVector<blink::WebMediaStreamTrack> audio_tracks; |
| 275 web_stream.audioTracks(audio_tracks); |
| 276 if (audio_tracks.isEmpty()) |
| 277 return NULL; |
| 278 |
| 279 // TODO(xians): Add support for the case that the media stream contains |
| 280 // multiple audio tracks. |
| 281 return CreateLocalAudioRenderer(audio_tracks[0]); |
| 275 } | 282 } |
| 276 | 283 |
| 277 webrtc::MediaStreamInterface* stream = extra_data->stream().get(); | 284 webrtc::MediaStreamInterface* stream = extra_data->stream().get(); |
| 278 if (!stream || stream->GetAudioTracks().empty()) | 285 if (!stream || stream->GetAudioTracks().empty()) |
| 279 return NULL; | 286 return NULL; |
| 280 | 287 |
| 281 // This is a remote media stream. | 288 // This is a remote media stream. |
| 282 WebRtcAudioDeviceImpl* audio_device = | 289 WebRtcAudioDeviceImpl* audio_device = |
| 283 dependency_factory_->GetWebRtcAudioDevice(); | 290 dependency_factory_->GetWebRtcAudioDevice(); |
| 284 | 291 |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 &buffer_size)) { | 799 &buffer_size)) { |
| 793 GetDefaultOutputDeviceParams(&sample_rate, &buffer_size); | 800 GetDefaultOutputDeviceParams(&sample_rate, &buffer_size); |
| 794 } | 801 } |
| 795 | 802 |
| 796 return new WebRtcAudioRenderer(RenderViewObserver::routing_id(), | 803 return new WebRtcAudioRenderer(RenderViewObserver::routing_id(), |
| 797 session_id, sample_rate, buffer_size); | 804 session_id, sample_rate, buffer_size); |
| 798 } | 805 } |
| 799 | 806 |
| 800 scoped_refptr<WebRtcLocalAudioRenderer> | 807 scoped_refptr<WebRtcLocalAudioRenderer> |
| 801 MediaStreamImpl::CreateLocalAudioRenderer( | 808 MediaStreamImpl::CreateLocalAudioRenderer( |
| 802 webrtc::MediaStreamInterface* stream) { | 809 const blink::WebMediaStreamTrack& audio_track) { |
| 803 if (stream->GetAudioTracks().empty()) | 810 DVLOG(1) << "MediaStreamImpl::CreateLocalAudioRenderer"; |
| 804 return NULL; | |
| 805 | |
| 806 DVLOG(1) << "MediaStreamImpl::CreateLocalAudioRenderer label:" | |
| 807 << stream->label(); | |
| 808 | |
| 809 webrtc::AudioTrackVector audio_tracks = stream->GetAudioTracks(); | |
| 810 DCHECK_EQ(audio_tracks.size(), 1u); | |
| 811 webrtc::AudioTrackInterface* audio_track = audio_tracks[0]; | |
| 812 DVLOG(1) << "audio_track.kind : " << audio_track->kind() | |
| 813 << "audio_track.id : " << audio_track->id() | |
| 814 << "audio_track.enabled: " << audio_track->enabled(); | |
| 815 | 811 |
| 816 int session_id = 0, sample_rate = 0, buffer_size = 0; | 812 int session_id = 0, sample_rate = 0, buffer_size = 0; |
| 817 if (!GetAuthorizedDeviceInfoForAudioRenderer(&session_id, | 813 if (!GetAuthorizedDeviceInfoForAudioRenderer(&session_id, |
| 818 &sample_rate, | 814 &sample_rate, |
| 819 &buffer_size)) { | 815 &buffer_size)) { |
| 820 GetDefaultOutputDeviceParams(&sample_rate, &buffer_size); | 816 GetDefaultOutputDeviceParams(&sample_rate, &buffer_size); |
| 821 } | 817 } |
| 822 | 818 |
| 823 // Create a new WebRtcLocalAudioRenderer instance and connect it to the | 819 // Create a new WebRtcLocalAudioRenderer instance and connect it to the |
| 824 // existing WebRtcAudioCapturer so that the renderer can use it as source. | 820 // existing WebRtcAudioCapturer so that the renderer can use it as source. |
| 825 return new WebRtcLocalAudioRenderer( | 821 return new WebRtcLocalAudioRenderer( |
| 826 static_cast<WebRtcLocalAudioTrack*>(audio_track), | 822 audio_track, |
| 827 RenderViewObserver::routing_id(), | 823 RenderViewObserver::routing_id(), |
| 828 session_id, | 824 session_id, |
| 829 buffer_size); | 825 buffer_size); |
| 830 } | 826 } |
| 831 | 827 |
| 832 bool MediaStreamImpl::GetAuthorizedDeviceInfoForAudioRenderer( | 828 bool MediaStreamImpl::GetAuthorizedDeviceInfoForAudioRenderer( |
| 833 int* session_id, | 829 int* session_id, |
| 834 int* output_sample_rate, | 830 int* output_sample_rate, |
| 835 int* output_frames_per_buffer) { | 831 int* output_frames_per_buffer) { |
| 836 DCHECK(CalledOnValidThread()); | 832 DCHECK(CalledOnValidThread()); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 enable_automatic_output_device_selection( | 891 enable_automatic_output_device_selection( |
| 896 enable_automatic_output_device_selection), | 892 enable_automatic_output_device_selection), |
| 897 frame(frame), | 893 frame(frame), |
| 898 request(request) { | 894 request(request) { |
| 899 } | 895 } |
| 900 | 896 |
| 901 MediaStreamImpl::UserMediaRequestInfo::~UserMediaRequestInfo() { | 897 MediaStreamImpl::UserMediaRequestInfo::~UserMediaRequestInfo() { |
| 902 } | 898 } |
| 903 | 899 |
| 904 } // namespace content | 900 } // namespace content |
| OLD | NEW |