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

Side by Side Diff: chromecast/media/cma/backend/alsa/stream_mixer_alsa.cc

Issue 2341783004: [chromecast] Slew stream volume changes in StreamMixerAlsa. (Closed)
Patch Set: address comments Created 4 years, 3 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 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
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 input->VolumeScaleAccumulate(temp_->channel(c), chunk_size,
kmackay 2016/09/15 01:51:36 does this work properly? seems like it will slew o
jyw 2016/09/15 22:16:23 Done.
834 DCHECK(volume_scalar >= 0.0 && volume_scalar <= 1.0) << volume_scalar; 833 mixed_->channel(c));
835 ::media::vector_math::FMAC(temp_->channel(c), volume_scalar, chunk_size,
836 mixed_->channel(c));
837 } 834 }
838 } 835 }
839 836
840 WriteMixedPcm(*mixed_, chunk_size, false /* is_silence */); 837 WriteMixedPcm(*mixed_, chunk_size, false /* is_silence */);
841 return true; 838 return true;
842 } 839 }
843 840
844 ssize_t StreamMixerAlsa::BytesPerOutputFormatSample() { 841 ssize_t StreamMixerAlsa::BytesPerOutputFormatSample() {
845 return alsa_->PcmFormatSize(pcm_format_, 1); 842 return alsa_->PcmFormatSize(pcm_format_, 1);
846 } 843 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 DCHECK(std::find(loopback_observers_.begin(), loopback_observers_.end(), 940 DCHECK(std::find(loopback_observers_.begin(), loopback_observers_.end(),
944 observer) != loopback_observers_.end()); 941 observer) != loopback_observers_.end());
945 loopback_observers_.erase(std::remove(loopback_observers_.begin(), 942 loopback_observers_.erase(std::remove(loopback_observers_.begin(),
946 loopback_observers_.end(), observer), 943 loopback_observers_.end(), observer),
947 loopback_observers_.end()); 944 loopback_observers_.end());
948 observer->OnRemoved(); 945 observer->OnRemoved();
949 } 946 }
950 947
951 } // namespace media 948 } // namespace media
952 } // namespace chromecast 949 } // namespace chromecast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698