| 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/webrtc/processed_local_audio_source.h" | 5 #include "content/renderer/media/webrtc/processed_local_audio_source.h" | 
| 6 | 6 | 
| 7 #include <algorithm> | 7 #include <algorithm> | 
| 8 #include <utility> | 8 #include <utility> | 
| 9 | 9 | 
| 10 #include "base/logging.h" | 10 #include "base/logging.h" | 
| 11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" | 
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" | 
| 13 #include "content/renderer/media/audio_device_factory.h" | 13 #include "content/renderer/media/audio_device_factory.h" | 
| 14 #include "content/renderer/media/media_stream_audio_processor_options.h" | 14 #include "content/renderer/media/media_stream_audio_processor_options.h" | 
| 15 #include "content/renderer/media/media_stream_constraints_util.h" | 15 #include "content/renderer/media/media_stream_constraints_util.h" | 
| 16 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" | 16 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" | 
| 17 #include "content/renderer/media/webrtc_audio_device_impl.h" | 17 #include "content/renderer/media/webrtc_audio_device_impl.h" | 
| 18 #include "content/renderer/media/webrtc_logging.h" | 18 #include "content/renderer/media/webrtc_logging.h" | 
| 19 #include "content/renderer/render_frame_impl.h" | 19 #include "content/renderer/render_frame_impl.h" | 
| 20 #include "media/base/channel_layout.h" | 20 #include "media/base/channel_layout.h" | 
| 21 #include "media/base/sample_rates.h" | 21 #include "media/base/sample_rates.h" | 
| 22 #include "third_party/webrtc/api/mediaconstraintsinterface.h" | 22 #include "third_party/webrtc/api/mediaconstraintsinterface.h" | 
| 23 #include "third_party/webrtc/media/base/mediachannel.h" | 23 #include "third_party/webrtc/media/base/mediachannel.h" | 
| 24 | 24 | 
| 25 namespace content { | 25 namespace content { | 
| 26 | 26 | 
| 27 namespace { | 27 namespace { | 
| 28 // Used as an identifier for ProcessedLocalAudioSource::From(). | 28 // Used as an identifier for ProcessedLocalAudioSource::From(). | 
| 29 void* const kClassIdentifier = const_cast<void**>(&kClassIdentifier); | 29 void* const kPLASClassIdentifier = const_cast<void**>(&kPLASClassIdentifier); | 
| 30 }  // namespace | 30 }  // namespace | 
| 31 | 31 | 
| 32 ProcessedLocalAudioSource::ProcessedLocalAudioSource( | 32 ProcessedLocalAudioSource::ProcessedLocalAudioSource( | 
| 33     int consumer_render_frame_id, | 33     int consumer_render_frame_id, | 
| 34     const MediaStreamDevice& device, | 34     const MediaStreamDevice& device, | 
| 35     const AudioProcessingProperties& audio_processing_properties, | 35     const AudioProcessingProperties& audio_processing_properties, | 
| 36     const ConstraintsCallback& started_callback, | 36     const ConstraintsCallback& started_callback, | 
| 37     PeerConnectionDependencyFactory* factory) | 37     PeerConnectionDependencyFactory* factory) | 
| 38     : MediaStreamAudioSource(true /* is_local_source */), | 38     : MediaStreamAudioSource(true /* is_local_source */), | 
| 39       consumer_render_frame_id_(consumer_render_frame_id), | 39       consumer_render_frame_id_(consumer_render_frame_id), | 
| 40       pc_factory_(factory), | 40       pc_factory_(factory), | 
| 41       audio_processing_properties_(audio_processing_properties), | 41       audio_processing_properties_(audio_processing_properties), | 
| 42       started_callback_(started_callback), | 42       started_callback_(started_callback), | 
| 43       volume_(0), | 43       volume_(0), | 
| 44       allow_invalid_render_frame_id_for_testing_(false) { | 44       allow_invalid_render_frame_id_for_testing_(false) { | 
| 45   DCHECK(pc_factory_); | 45   DCHECK(pc_factory_); | 
| 46   DVLOG(1) << "ProcessedLocalAudioSource::ProcessedLocalAudioSource()"; | 46   DVLOG(1) << "ProcessedLocalAudioSource::ProcessedLocalAudioSource()"; | 
| 47   SetDevice(device); | 47   SetDevice(device); | 
| 48 } | 48 } | 
| 49 | 49 | 
| 50 ProcessedLocalAudioSource::~ProcessedLocalAudioSource() { | 50 ProcessedLocalAudioSource::~ProcessedLocalAudioSource() { | 
| 51   DVLOG(1) << "ProcessedLocalAudioSource::~ProcessedLocalAudioSource()"; | 51   DVLOG(1) << "ProcessedLocalAudioSource::~ProcessedLocalAudioSource()"; | 
| 52   EnsureSourceIsStopped(); | 52   EnsureSourceIsStopped(); | 
| 53 } | 53 } | 
| 54 | 54 | 
| 55 // static | 55 // static | 
| 56 ProcessedLocalAudioSource* ProcessedLocalAudioSource::From( | 56 ProcessedLocalAudioSource* ProcessedLocalAudioSource::From( | 
| 57     MediaStreamAudioSource* source) { | 57     MediaStreamAudioSource* source) { | 
| 58   if (source && source->GetClassIdentifier() == kClassIdentifier) | 58   if (source && source->GetClassIdentifier() == kPLASClassIdentifier) | 
| 59     return static_cast<ProcessedLocalAudioSource*>(source); | 59     return static_cast<ProcessedLocalAudioSource*>(source); | 
| 60   return nullptr; | 60   return nullptr; | 
| 61 } | 61 } | 
| 62 | 62 | 
| 63 void* ProcessedLocalAudioSource::GetClassIdentifier() const { | 63 void* ProcessedLocalAudioSource::GetClassIdentifier() const { | 
| 64   return kClassIdentifier; | 64   return kPLASClassIdentifier; | 
| 65 } | 65 } | 
| 66 | 66 | 
| 67 bool ProcessedLocalAudioSource::EnsureSourceIsStarted() { | 67 bool ProcessedLocalAudioSource::EnsureSourceIsStarted() { | 
| 68   DCHECK(thread_checker_.CalledOnValidThread()); | 68   DCHECK(thread_checker_.CalledOnValidThread()); | 
| 69 | 69 | 
| 70   { | 70   { | 
| 71     base::AutoLock auto_lock(source_lock_); | 71     base::AutoLock auto_lock(source_lock_); | 
| 72     if (source_) | 72     if (source_) | 
| 73       return true; | 73       return true; | 
| 74   } | 74   } | 
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 356 | 356 | 
| 357   // If the buffer size is missing from the MediaStreamDevice, provide 10ms as a | 357   // If the buffer size is missing from the MediaStreamDevice, provide 10ms as a | 
| 358   // fall-back. | 358   // fall-back. | 
| 359   // | 359   // | 
| 360   // TODO(miu): Identify where/why the buffer size might be missing, fix the | 360   // TODO(miu): Identify where/why the buffer size might be missing, fix the | 
| 361   // code, and then require it here. http://crbug.com/638081 | 361   // code, and then require it here. http://crbug.com/638081 | 
| 362   return (sample_rate / 100); | 362   return (sample_rate / 100); | 
| 363 } | 363 } | 
| 364 | 364 | 
| 365 }  // namespace content | 365 }  // namespace content | 
| OLD | NEW | 
|---|