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

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

Issue 1834323002: MediaStream audio: Refactor 3 separate "glue" implementations into one. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments from PS2: AudioInputDevice --> AudioCapturerSource, and refptr foo in WebRtcMedi… Created 4 years, 8 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_interface_provider.h" 5 #include "content/renderer/media/external_media_stream_audio_source.h"
6
7 #include "base/bind.h"
8 #include "media/mojo/interfaces/content_decryption_module.mojom.h"
9 #include "media/mojo/interfaces/renderer.mojom.h"
10 #include "mojo/public/cpp/bindings/interface_request.h"
11 #include "mojo/shell/public/cpp/connect.h"
12 6
13 namespace content { 7 namespace content {
14 8
15 MediaInterfaceProvider::MediaInterfaceProvider( 9 ExternalMediaStreamAudioSource::ExternalMediaStreamAudioSource(
16 const ConnectToApplicationCB& connect_to_app_cb) 10 scoped_refptr<media::AudioCapturerSource> source,
17 : connect_to_app_cb_(connect_to_app_cb) { 11 int sample_rate,
18 DCHECK(!connect_to_app_cb_.is_null()); 12 media::ChannelLayout channel_layout,
13 int frames_per_buffer,
14 bool is_remote)
15 : MediaStreamAudioSource(!is_remote), source_(std::move(source)),
16 was_started_(false) {
17 DVLOG(1)
18 << "ExternalMediaStreamAudioSource::ExternalMediaStreamAudioSource()";
19 DCHECK(source_.get());
20 MediaStreamAudioSource::SetFormat(media::AudioParameters(
21 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout,
22 sample_rate,
23 16, // Legacy parameter (data is always in 32-bit float format).
24 frames_per_buffer));
19 } 25 }
20 26
21 MediaInterfaceProvider::~MediaInterfaceProvider() { 27 ExternalMediaStreamAudioSource::~ExternalMediaStreamAudioSource() {
22 DCHECK(thread_checker_.CalledOnValidThread()); 28 DVLOG(1)
29 << "ExternalMediaStreamAudioSource::~ExternalMediaStreamAudioSource()";
30 EnsureSourceIsStopped();
23 } 31 }
24 32
25 void MediaInterfaceProvider::GetInterface(const mojo::String& interface_name, 33 bool ExternalMediaStreamAudioSource::EnsureSourceIsStarted() {
26 mojo::ScopedMessagePipeHandle pipe) {
27 DVLOG(1) << __FUNCTION__;
28 DCHECK(thread_checker_.CalledOnValidThread()); 34 DCHECK(thread_checker_.CalledOnValidThread());
29 35 if (was_started_)
30 if (interface_name == media::interfaces::ContentDecryptionModule::Name_) { 36 return true;
31 GetMediaServiceFactory()->CreateCdm( 37 VLOG(1) << "Starting externally-provided "
32 mojo::MakeRequest<media::interfaces::ContentDecryptionModule>( 38 << (is_local_source() ? "local" : "remote")
33 std::move(pipe))); 39 << " source with audio parameters={"
34 } else if (interface_name == media::interfaces::Renderer::Name_) { 40 << GetAudioParameters().AsHumanReadableString() << "}.";
35 GetMediaServiceFactory()->CreateRenderer( 41 source_->Initialize(GetAudioParameters(), this, -1);
36 mojo::MakeRequest<media::interfaces::Renderer>(std::move(pipe))); 42 source_->Start();
37 } else if (interface_name == media::interfaces::AudioDecoder::Name_) { 43 was_started_ = true;
38 GetMediaServiceFactory()->CreateAudioDecoder( 44 return true;
39 mojo::MakeRequest<media::interfaces::AudioDecoder>(std::move(pipe)));
40 } else {
41 NOTREACHED();
42 }
43 } 45 }
44 46
45 media::interfaces::ServiceFactory* 47 void ExternalMediaStreamAudioSource::EnsureSourceIsStopped() {
46 MediaInterfaceProvider::GetMediaServiceFactory() {
47 DVLOG(1) << __FUNCTION__;
48 DCHECK(thread_checker_.CalledOnValidThread()); 48 DCHECK(thread_checker_.CalledOnValidThread());
49 49 if (!source_)
50 if (!media_service_factory_) { 50 return;
51 mojo::shell::mojom::InterfaceProviderPtr interface_provider = 51 if (was_started_)
52 connect_to_app_cb_.Run(GURL("mojo:media")); 52 source_->Stop();
53 mojo::GetInterface(interface_provider.get(), &media_service_factory_); 53 source_ = nullptr;
54 media_service_factory_.set_connection_error_handler(base::Bind( 54 VLOG(1) << "Stopped externally-provided "
55 &MediaInterfaceProvider::OnConnectionError, base::Unretained(this))); 55 << (is_local_source() ? "local" : "remote")
56 } 56 << " source with audio parameters={"
57 57 << GetAudioParameters().AsHumanReadableString() << "}.";
58 return media_service_factory_.get();
59 } 58 }
60 59
61 void MediaInterfaceProvider::OnConnectionError() { 60 void ExternalMediaStreamAudioSource::Capture(const media::AudioBus* audio_bus,
62 DVLOG(1) << __FUNCTION__; 61 int audio_delay_milliseconds,
63 DCHECK(thread_checker_.CalledOnValidThread()); 62 double volume,
63 bool key_pressed) {
64 DCHECK(audio_bus);
65 // TODO(miu): Plumbing is needed to determine the actual capture timestamp
66 // of the audio, instead of just snapshotting TimeTicks::Now(), for proper
67 // audio/video sync. http://crbug.com/335335
68 MediaStreamAudioSource::DeliverDataToTracks(
69 *audio_bus, base::TimeTicks::Now() - base::TimeDelta::FromMilliseconds(
70 audio_delay_milliseconds));
perkj_chrome 2016/04/08 14:05:41 nit: indentation looks weird. git cl format?
miu 2016/04/19 00:40:22 Done. Yeah, `git cl format` did that.
71 }
64 72
65 media_service_factory_.reset(); 73 void ExternalMediaStreamAudioSource::OnCaptureError(const std::string& why) {
74 // As of this writing, this method doesn't get called for anything useful,
75 // and all other implementors just log the message, but don't disconnect sinks
76 // or take any other action. So, just log the error.
77 LOG(ERROR) << why;
66 } 78 }
67 79
68 } // namespace content 80 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698