OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chromecast/media/cma/backend/alsa/stream_mixer_alsa.h" | 5 #include "chromecast/media/cma/backend/alsa/stream_mixer_alsa.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <limits> | 9 #include <limits> |
10 #include <unordered_set> | 10 #include <unordered_set> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
18 #include "base/numerics/saturated_arithmetic.h" | 18 #include "base/numerics/saturated_arithmetic.h" |
19 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
| 20 #include "base/stl_util.h" |
20 #include "base/threading/platform_thread.h" | 21 #include "base/threading/platform_thread.h" |
21 #include "base/threading/thread_task_runner_handle.h" | 22 #include "base/threading/thread_task_runner_handle.h" |
22 #include "base/time/time.h" | 23 #include "base/time/time.h" |
23 #include "chromecast/base/chromecast_switches.h" | 24 #include "chromecast/base/chromecast_switches.h" |
24 #include "chromecast/media/base/audio_device_ids.h" | 25 #include "chromecast/media/base/audio_device_ids.h" |
25 #include "chromecast/media/cma/backend/alsa/alsa_wrapper.h" | 26 #include "chromecast/media/cma/backend/alsa/alsa_wrapper.h" |
26 #include "chromecast/media/cma/backend/alsa/filter_group.h" | 27 #include "chromecast/media/cma/backend/alsa/filter_group.h" |
27 #include "chromecast/media/cma/backend/alsa/post_processing_pipeline_parser.h" | 28 #include "chromecast/media/cma/backend/alsa/post_processing_pipeline_parser.h" |
28 #include "chromecast/media/cma/backend/alsa/stream_mixer_alsa_input_impl.h" | 29 #include "chromecast/media/cma/backend/alsa/stream_mixer_alsa_input_impl.h" |
29 #include "media/audio/audio_device_description.h" | 30 #include "media/audio/audio_device_description.h" |
(...skipping 984 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1014 snd_pcm_sframes_t delay_frames = alsa_->PcmStatusGetDelay(pcm_status_); | 1015 snd_pcm_sframes_t delay_frames = alsa_->PcmStatusGetDelay(pcm_status_); |
1015 alsa_rendering_delay_.delay_microseconds = | 1016 alsa_rendering_delay_.delay_microseconds = |
1016 static_cast<int64_t>(delay_frames) * base::Time::kMicrosecondsPerSecond / | 1017 static_cast<int64_t>(delay_frames) * base::Time::kMicrosecondsPerSecond / |
1017 output_samples_per_second_; | 1018 output_samples_per_second_; |
1018 } | 1019 } |
1019 | 1020 |
1020 void StreamMixerAlsa::AddLoopbackAudioObserver( | 1021 void StreamMixerAlsa::AddLoopbackAudioObserver( |
1021 CastMediaShlib::LoopbackAudioObserver* observer) { | 1022 CastMediaShlib::LoopbackAudioObserver* observer) { |
1022 RUN_ON_MIXER_THREAD(&StreamMixerAlsa::AddLoopbackAudioObserver, observer); | 1023 RUN_ON_MIXER_THREAD(&StreamMixerAlsa::AddLoopbackAudioObserver, observer); |
1023 DCHECK(observer); | 1024 DCHECK(observer); |
1024 DCHECK(std::find(loopback_observers_.begin(), loopback_observers_.end(), | 1025 DCHECK(!base::ContainsValue(loopback_observers_, observer)); |
1025 observer) == loopback_observers_.end()); | |
1026 loopback_observers_.push_back(observer); | 1026 loopback_observers_.push_back(observer); |
1027 } | 1027 } |
1028 | 1028 |
1029 void StreamMixerAlsa::RemoveLoopbackAudioObserver( | 1029 void StreamMixerAlsa::RemoveLoopbackAudioObserver( |
1030 CastMediaShlib::LoopbackAudioObserver* observer) { | 1030 CastMediaShlib::LoopbackAudioObserver* observer) { |
1031 RUN_ON_MIXER_THREAD(&StreamMixerAlsa::RemoveLoopbackAudioObserver, observer); | 1031 RUN_ON_MIXER_THREAD(&StreamMixerAlsa::RemoveLoopbackAudioObserver, observer); |
1032 DCHECK(std::find(loopback_observers_.begin(), loopback_observers_.end(), | 1032 DCHECK(base::ContainsValue(loopback_observers_, observer)); |
1033 observer) != loopback_observers_.end()); | |
1034 loopback_observers_.erase(std::remove(loopback_observers_.begin(), | 1033 loopback_observers_.erase(std::remove(loopback_observers_.begin(), |
1035 loopback_observers_.end(), observer), | 1034 loopback_observers_.end(), observer), |
1036 loopback_observers_.end()); | 1035 loopback_observers_.end()); |
1037 observer->OnRemoved(); | 1036 observer->OnRemoved(); |
1038 } | 1037 } |
1039 | 1038 |
1040 void StreamMixerAlsa::SetVolume(AudioContentType type, float level) { | 1039 void StreamMixerAlsa::SetVolume(AudioContentType type, float level) { |
1041 RUN_ON_MIXER_THREAD(&StreamMixerAlsa::SetVolume, type, level); | 1040 RUN_ON_MIXER_THREAD(&StreamMixerAlsa::SetVolume, type, level); |
1042 volume_info_[type].volume = level; | 1041 volume_info_[type].volume = level; |
1043 float effective_volume = volume_info_[type].GetEffectiveVolume(); | 1042 float effective_volume = volume_info_[type].GetEffectiveVolume(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1080 for (auto&& input : inputs_) { | 1079 for (auto&& input : inputs_) { |
1081 // Volume limits don't apply to effects streams. | 1080 // Volume limits don't apply to effects streams. |
1082 if (input->primary() && input->content_type() == type) { | 1081 if (input->primary() && input->content_type() == type) { |
1083 input->SetContentTypeVolume(effective_volume, fade_ms); | 1082 input->SetContentTypeVolume(effective_volume, fade_ms); |
1084 } | 1083 } |
1085 } | 1084 } |
1086 } | 1085 } |
1087 | 1086 |
1088 } // namespace media | 1087 } // namespace media |
1089 } // namespace chromecast | 1088 } // namespace chromecast |
OLD | NEW |