| 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/threading/platform_thread.h" | 20 #include "base/threading/platform_thread.h" |
| 21 #include "base/threading/thread_task_runner_handle.h" | 21 #include "base/threading/thread_task_runner_handle.h" |
| 22 #include "chromecast/base/chromecast_switches.h" | 22 #include "chromecast/base/chromecast_switches.h" |
| 23 #include "chromecast/base/serializers.h" |
| 23 #include "chromecast/media/base/audio_device_ids.h" | 24 #include "chromecast/media/base/audio_device_ids.h" |
| 24 #include "chromecast/media/cma/backend/alsa/alsa_wrapper.h" | 25 #include "chromecast/media/cma/backend/alsa/alsa_wrapper.h" |
| 25 #include "chromecast/media/cma/backend/alsa/audio_filter_factory.h" | |
| 26 #include "chromecast/media/cma/backend/alsa/filter_group.h" | 26 #include "chromecast/media/cma/backend/alsa/filter_group.h" |
| 27 #include "chromecast/media/cma/backend/alsa/post_processing_pipeline_parser.h" |
| 27 #include "chromecast/media/cma/backend/alsa/stream_mixer_alsa_input_impl.h" | 28 #include "chromecast/media/cma/backend/alsa/stream_mixer_alsa_input_impl.h" |
| 28 #include "media/audio/audio_device_description.h" | 29 #include "media/audio/audio_device_description.h" |
| 29 #include "media/base/audio_bus.h" | 30 #include "media/base/audio_bus.h" |
| 30 #include "media/base/media_switches.h" | 31 #include "media/base/media_switches.h" |
| 31 | 32 |
| 32 #define RETURN_REPORT_ERROR(snd_func, ...) \ | 33 #define RETURN_REPORT_ERROR(snd_func, ...) \ |
| 33 do { \ | 34 do { \ |
| 34 int err = alsa_->snd_func(__VA_ARGS__); \ | 35 int err = alsa_->snd_func(__VA_ARGS__); \ |
| 35 if (err < 0) { \ | 36 if (err < 0) { \ |
| 36 LOG(ERROR) << #snd_func " error: " << alsa_->StrError(err); \ | 37 LOG(ERROR) << #snd_func " error: " << alsa_->StrError(err); \ |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 LOG(INFO) << "Setting fixed sample rate to " << fixed_samples_per_second; | 205 LOG(INFO) << "Setting fixed sample rate to " << fixed_samples_per_second; |
| 205 } | 206 } |
| 206 | 207 |
| 207 fixed_output_samples_per_second_ = fixed_samples_per_second; | 208 fixed_output_samples_per_second_ = fixed_samples_per_second; |
| 208 | 209 |
| 209 low_sample_rate_cutoff_ = | 210 low_sample_rate_cutoff_ = |
| 210 chromecast::GetSwitchValueBoolean(switches::kAlsaEnableUpsampling, false) | 211 chromecast::GetSwitchValueBoolean(switches::kAlsaEnableUpsampling, false) |
| 211 ? kLowSampleRateCutoff | 212 ? kLowSampleRateCutoff |
| 212 : 0; | 213 : 0; |
| 213 | 214 |
| 215 // Read post-processing configuration file |
| 216 PostProcessingPipelineParser pipeline_parser; |
| 217 pipeline_parser.Initialize(); |
| 218 |
| 214 // Create filter groups. | 219 // Create filter groups. |
| 215 // TODO(bshaya): Switch to filter groups based on AudioContentType. | 220 // TODO(bshaya): Switch to filter groups based on AudioContentType. |
| 216 filter_groups_.push_back(base::MakeUnique<FilterGroup>( | 221 filter_groups_.push_back(base::MakeUnique<FilterGroup>( |
| 217 std::unordered_set<std::string>( | 222 std::unordered_set<std::string>( |
| 218 {::media::AudioDeviceDescription::kCommunicationsDeviceId}), | 223 {::media::AudioDeviceDescription::kCommunicationsDeviceId}), |
| 219 AudioFilterFactory::COMMUNICATION_AUDIO_FILTER, | 224 AudioContentType::kMedia, kNumOutputChannels, |
| 220 AudioContentType::kMedia)); | 225 pipeline_parser.GetPipelineByDeviceId( |
| 226 ::media::AudioDeviceDescription::kCommunicationsDeviceId))); |
| 221 filter_groups_.push_back(base::MakeUnique<FilterGroup>( | 227 filter_groups_.push_back(base::MakeUnique<FilterGroup>( |
| 222 std::unordered_set<std::string>({kAlarmAudioDeviceId}), | 228 std::unordered_set<std::string>({kAlarmAudioDeviceId}), |
| 223 AudioFilterFactory::ALARM_AUDIO_FILTER, AudioContentType::kAlarm)); | 229 AudioContentType::kAlarm, kNumOutputChannels, |
| 230 pipeline_parser.GetPipelineByDeviceId(kAlarmAudioDeviceId))); |
| 224 filter_groups_.push_back(base::MakeUnique<FilterGroup>( | 231 filter_groups_.push_back(base::MakeUnique<FilterGroup>( |
| 225 std::unordered_set<std::string>({kTtsAudioDeviceId}), | 232 std::unordered_set<std::string>({kTtsAudioDeviceId}), |
| 226 AudioFilterFactory::TTS_AUDIO_FILTER, AudioContentType::kCommunication)); | 233 AudioContentType::kCommunication, kNumOutputChannels, |
| 234 pipeline_parser.GetPipelineByDeviceId(kTtsAudioDeviceId))); |
| 227 filter_groups_.push_back(base::MakeUnique<FilterGroup>( | 235 filter_groups_.push_back(base::MakeUnique<FilterGroup>( |
| 228 std::unordered_set<std::string>( | 236 std::unordered_set<std::string>( |
| 229 {::media::AudioDeviceDescription::kDefaultDeviceId, | 237 {::media::AudioDeviceDescription::kDefaultDeviceId, |
| 230 kLocalAudioDeviceId, ""}), | 238 kLocalAudioDeviceId, ""}), |
| 231 AudioFilterFactory::MEDIA_AUDIO_FILTER, AudioContentType::kMedia)); | 239 AudioContentType::kMedia, kNumOutputChannels, |
| 240 pipeline_parser.GetPipelineByDeviceId( |
| 241 ::media::AudioDeviceDescription::kDefaultDeviceId))); |
| 232 | 242 |
| 243 // TODO(bshaya): Add support for final mix AudioPostProcessor. |
| 233 DefineAlsaParameters(); | 244 DefineAlsaParameters(); |
| 234 } | 245 } |
| 235 | 246 |
| 236 void StreamMixerAlsa::ResetTaskRunnerForTest() { | 247 void StreamMixerAlsa::ResetTaskRunnerForTest() { |
| 237 mixer_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 248 mixer_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| 238 } | 249 } |
| 239 | 250 |
| 240 void StreamMixerAlsa::DefineAlsaParameters() { | 251 void StreamMixerAlsa::DefineAlsaParameters() { |
| 241 // Get the ALSA output configuration from the command line. | 252 // Get the ALSA output configuration from the command line. |
| 242 alsa_buffer_size_ = GetSwitchValueNonNegativeInt( | 253 alsa_buffer_size_ = GetSwitchValueNonNegativeInt( |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 if (err < 0) { | 499 if (err < 0) { |
| 489 LOG(ERROR) << "Error setting ALSA playback parameters: " | 500 LOG(ERROR) << "Error setting ALSA playback parameters: " |
| 490 << alsa_->StrError(err); | 501 << alsa_->StrError(err); |
| 491 SignalError(); | 502 SignalError(); |
| 492 return; | 503 return; |
| 493 } | 504 } |
| 494 } | 505 } |
| 495 | 506 |
| 496 // Initialize filters | 507 // Initialize filters |
| 497 for (auto&& filter_group : filter_groups_) { | 508 for (auto&& filter_group : filter_groups_) { |
| 498 filter_group->Initialize(output_samples_per_second_, | 509 filter_group->Initialize(output_samples_per_second_); |
| 499 ::media::SampleFormat::kSampleFormatS32); | |
| 500 } | 510 } |
| 501 | 511 |
| 502 RETURN_REPORT_ERROR(PcmPrepare, pcm_); | 512 RETURN_REPORT_ERROR(PcmPrepare, pcm_); |
| 503 RETURN_REPORT_ERROR(PcmStatusMalloc, &pcm_status_); | 513 RETURN_REPORT_ERROR(PcmStatusMalloc, &pcm_status_); |
| 504 | 514 |
| 505 rendering_delay_.timestamp_microseconds = kNoTimestamp; | 515 rendering_delay_.timestamp_microseconds = kNoTimestamp; |
| 506 rendering_delay_.delay_microseconds = 0; | 516 rendering_delay_.delay_microseconds = 0; |
| 507 | 517 |
| 508 state_ = kStateNormalPlayback; | 518 state_ = kStateNormalPlayback; |
| 509 } | 519 } |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 | 976 |
| 967 for (auto&& filter : filter_groups_) { | 977 for (auto&& filter : filter_groups_) { |
| 968 if (filter->content_type() == type) { | 978 if (filter->content_type() == type) { |
| 969 filter->set_volume(effective_volume); | 979 filter->set_volume(effective_volume); |
| 970 } | 980 } |
| 971 } | 981 } |
| 972 } | 982 } |
| 973 | 983 |
| 974 } // namespace media | 984 } // namespace media |
| 975 } // namespace chromecast | 985 } // namespace chromecast |
| OLD | NEW |