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 <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
18 #include "base/threading/platform_thread.h" | 18 #include "base/threading/platform_thread.h" |
19 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
20 #include "chromecast/base/chromecast_switches.h" | 20 #include "chromecast/base/chromecast_switches.h" |
21 #include "chromecast/media/cma/backend/alsa/alsa_wrapper.h" | 21 #include "chromecast/media/cma/backend/alsa/alsa_wrapper.h" |
22 #include "chromecast/media/cma/backend/alsa/audio_filter_factory.h" | 22 #include "chromecast/media/cma/backend/alsa/audio_filter_factory.h" |
23 #include "chromecast/media/cma/backend/alsa/stream_mixer_alsa_input_impl.h" | 23 #include "chromecast/media/cma/backend/alsa/stream_mixer_alsa_input_impl.h" |
24 #include "media/base/audio_bus.h" | 24 #include "media/base/audio_bus.h" |
25 #include "media/base/media_switches.h" | 25 #include "media/base/media_switches.h" |
26 #include "media/base/vector_math.h" | |
27 | 26 |
28 #define RETURN_REPORT_ERROR(snd_func, ...) \ | 27 #define RETURN_REPORT_ERROR(snd_func, ...) \ |
29 do { \ | 28 do { \ |
30 int err = alsa_->snd_func(__VA_ARGS__); \ | 29 int err = alsa_->snd_func(__VA_ARGS__); \ |
31 if (err < 0) { \ | 30 if (err < 0) { \ |
32 LOG(ERROR) << #snd_func " error: " << alsa_->StrError(err); \ | 31 LOG(ERROR) << #snd_func " error: " << alsa_->StrError(err); \ |
33 SignalError(); \ | 32 SignalError(); \ |
34 return; \ | 33 return; \ |
35 } \ | 34 } \ |
36 } while (0) | 35 } while (0) |
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
823 if (!temp_ || temp_->frames() < chunk_size) { | 822 if (!temp_ || temp_->frames() < chunk_size) { |
824 temp_ = ::media::AudioBus::Create(kNumOutputChannels, chunk_size); | 823 temp_ = ::media::AudioBus::Create(kNumOutputChannels, chunk_size); |
825 } | 824 } |
826 | 825 |
827 mixed_->ZeroFramesPartial(0, chunk_size); | 826 mixed_->ZeroFramesPartial(0, chunk_size); |
828 | 827 |
829 // Loop through active inputs, polling them for data, and mixing them. | 828 // Loop through active inputs, polling them for data, and mixing them. |
830 for (InputQueue* input : active_inputs) { | 829 for (InputQueue* input : active_inputs) { |
831 input->GetResampledData(temp_.get(), chunk_size); | 830 input->GetResampledData(temp_.get(), chunk_size); |
832 for (int c = 0; c < kNumOutputChannels; ++c) { | 831 for (int c = 0; c < kNumOutputChannels; ++c) { |
833 float volume_scalar = input->volume_multiplier(); | 832 float volume_scalar = input->volume_multiplier(); |
kmackay
2016/09/14 20:48:15
volume_multipler() method not needed anymore
jyw
2016/09/15 01:12:15
Done.
| |
834 DCHECK(volume_scalar >= 0.0 && volume_scalar <= 1.0) << volume_scalar; | 833 DCHECK(volume_scalar >= 0.0 && volume_scalar <= 1.0) << volume_scalar; |
835 ::media::vector_math::FMAC(temp_->channel(c), volume_scalar, chunk_size, | 834 input->VolumeScaleAccumulate(temp_->channel(c), chunk_size, |
836 mixed_->channel(c)); | 835 mixed_->channel(c)); |
837 } | 836 } |
838 } | 837 } |
839 | 838 |
840 WriteMixedPcm(*mixed_, chunk_size, false /* is_silence */); | 839 WriteMixedPcm(*mixed_, chunk_size, false /* is_silence */); |
841 return true; | 840 return true; |
842 } | 841 } |
843 | 842 |
844 ssize_t StreamMixerAlsa::BytesPerOutputFormatSample() { | 843 ssize_t StreamMixerAlsa::BytesPerOutputFormatSample() { |
845 return alsa_->PcmFormatSize(pcm_format_, 1); | 844 return alsa_->PcmFormatSize(pcm_format_, 1); |
846 } | 845 } |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
943 DCHECK(std::find(loopback_observers_.begin(), loopback_observers_.end(), | 942 DCHECK(std::find(loopback_observers_.begin(), loopback_observers_.end(), |
944 observer) != loopback_observers_.end()); | 943 observer) != loopback_observers_.end()); |
945 loopback_observers_.erase(std::remove(loopback_observers_.begin(), | 944 loopback_observers_.erase(std::remove(loopback_observers_.begin(), |
946 loopback_observers_.end(), observer), | 945 loopback_observers_.end(), observer), |
947 loopback_observers_.end()); | 946 loopback_observers_.end()); |
948 observer->OnRemoved(); | 947 observer->OnRemoved(); |
949 } | 948 } |
950 | 949 |
951 } // namespace media | 950 } // namespace media |
952 } // namespace chromecast | 951 } // namespace chromecast |
OLD | NEW |