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

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

Issue 15979027: start/stop the source of the capturer when 1st audiotrack/last audiotrack is added/removed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed Henrik's comments. Created 7 years, 6 months 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
« no previous file with comments | « no previous file | content/renderer/media/mock_media_stream_dependency_factory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_dependency_factory.h" 5 #include "content/renderer/media/media_stream_dependency_factory.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 return false; 401 return false;
402 } 402 }
403 } 403 }
404 404
405 WebKit::WebMediaStreamSource::Type type = track.source().type(); 405 WebKit::WebMediaStreamSource::Type type = track.source().type();
406 DCHECK(type == WebKit::WebMediaStreamSource::TypeAudio || 406 DCHECK(type == WebKit::WebMediaStreamSource::TypeAudio ||
407 type == WebKit::WebMediaStreamSource::TypeVideo); 407 type == WebKit::WebMediaStreamSource::TypeVideo);
408 408
409 std::string track_id = UTF16ToUTF8(track.id()); 409 std::string track_id = UTF16ToUTF8(track.id());
410 if (source.type() == WebKit::WebMediaStreamSource::TypeAudio) { 410 if (source.type() == WebKit::WebMediaStreamSource::TypeAudio) {
411 // TODO(henrika,xians): Refactor how an audio track is created to harmonize
412 // with video tracks.
413 scoped_refptr<webrtc::AudioTrackInterface> audio_track( 411 scoped_refptr<webrtc::AudioTrackInterface> audio_track(
414 CreateLocalAudioTrack(track_id, source_data->local_audio_source())); 412 CreateLocalAudioTrack(track_id, source_data->local_audio_source()));
415 audio_track->set_enabled(track.isEnabled()); 413 audio_track->set_enabled(track.isEnabled());
416 if (GetWebRtcAudioDevice()) { 414 // Start the audio track. This will hook the |audio_track| to the capturer
417 WebRtcAudioCapturer* capturer = GetWebRtcAudioDevice()->capturer().get(); 415 // as the sink of the audio, and only start the source of the capturer if
418 if (!capturer->is_recording()) 416 // it is the first audio track connecting to the capturer.
419 capturer->Start(); 417 static_cast<WebRtcLocalAudioTrack*>(audio_track.get())->Start();
420 } 418
421 return native_stream->AddTrack(audio_track.get()); 419 return native_stream->AddTrack(audio_track.get());
422 } else { 420 } else {
423 scoped_refptr<webrtc::VideoTrackInterface> video_track( 421 scoped_refptr<webrtc::VideoTrackInterface> video_track(
424 CreateLocalVideoTrack(track_id, source_data->video_source())); 422 CreateLocalVideoTrack(track_id, source_data->video_source()));
425 video_track->set_enabled(track.isEnabled()); 423 video_track->set_enabled(track.isEnabled());
426 return native_stream->AddTrack(video_track.get()); 424 return native_stream->AddTrack(video_track.get());
427 } 425 }
428 } 426 }
429 427
430 bool MediaStreamDependencyFactory::AddNativeVideoMediaTrack( 428 bool MediaStreamDependencyFactory::AddNativeVideoMediaTrack(
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 MediaStreamDependencyFactory::GetWebRtcAudioDevice() { 682 MediaStreamDependencyFactory::GetWebRtcAudioDevice() {
685 return audio_device_.get(); 683 return audio_device_.get();
686 } 684 }
687 685
688 void MediaStreamDependencyFactory::StopLocalAudioSource( 686 void MediaStreamDependencyFactory::StopLocalAudioSource(
689 const WebKit::WebMediaStream& description) { 687 const WebKit::WebMediaStream& description) {
690 MediaStreamExtraData* extra_data = static_cast<MediaStreamExtraData*>( 688 MediaStreamExtraData* extra_data = static_cast<MediaStreamExtraData*>(
691 description.extraData()); 689 description.extraData());
692 if (extra_data && extra_data->is_local() && extra_data->stream().get() && 690 if (extra_data && extra_data->is_local() && extra_data->stream().get() &&
693 !extra_data->stream()->GetAudioTracks().empty()) { 691 !extra_data->stream()->GetAudioTracks().empty()) {
694 if (GetWebRtcAudioDevice()) { 692 // Stop the audio track. This will unhook the audio track from the capturer
695 scoped_refptr<WebRtcAudioCapturer> capturer = 693 // and will shutdown the source of the capturer if it is the last audio
696 GetWebRtcAudioDevice()->capturer(); 694 // track connecting to the capturer.
697 if (capturer.get()) 695 static_cast<WebRtcLocalAudioTrack*>(
698 capturer->Stop(); 696 extra_data->stream()->GetAudioTracks()[0].get())->Stop();
699 }
700 } 697 }
701 } 698 }
702 699
703 void MediaStreamDependencyFactory::InitializeWorkerThread( 700 void MediaStreamDependencyFactory::InitializeWorkerThread(
704 talk_base::Thread** thread, 701 talk_base::Thread** thread,
705 base::WaitableEvent* event) { 702 base::WaitableEvent* event) {
706 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); 703 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop();
707 jingle_glue::JingleThreadWrapper::current()->set_send_allowed(true); 704 jingle_glue::JingleThreadWrapper::current()->set_send_allowed(true);
708 *thread = jingle_glue::JingleThreadWrapper::current(); 705 *thread = jingle_glue::JingleThreadWrapper::current();
709 event->Signal(); 706 event->Signal();
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 // processed before returning. We wait for the above task to finish before 794 // processed before returning. We wait for the above task to finish before
798 // letting the the function continue to avoid any potential race issues. 795 // letting the the function continue to avoid any potential race issues.
799 chrome_worker_thread_.Stop(); 796 chrome_worker_thread_.Stop();
800 } else { 797 } else {
801 NOTREACHED() << "Worker thread not running."; 798 NOTREACHED() << "Worker thread not running.";
802 } 799 }
803 } 800 }
804 } 801 }
805 802
806 } // namespace content 803 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/renderer/media/mock_media_stream_dependency_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698