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 "base/time/time.h" | 22 #include "base/time/time.h" |
23 #include "chromecast/base/chromecast_switches.h" | 23 #include "chromecast/base/chromecast_switches.h" |
24 #include "chromecast/media/base/audio_device_ids.h" | 24 #include "chromecast/media/base/audio_device_ids.h" |
25 #include "chromecast/media/cma/backend/alsa/alsa_wrapper.h" | 25 #include "chromecast/media/cma/backend/alsa/alsa_wrapper.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/post_processing_pipeline_parser.h" |
28 #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" |
| 29 #include "chromecast/public/media/audio_post_processor_shlib.h" |
29 #include "media/audio/audio_device_description.h" | 30 #include "media/audio/audio_device_description.h" |
30 #include "media/base/audio_bus.h" | 31 #include "media/base/audio_bus.h" |
31 #include "media/base/audio_sample_types.h" | 32 #include "media/base/audio_sample_types.h" |
32 #include "media/base/media_switches.h" | 33 #include "media/base/media_switches.h" |
33 | 34 |
34 #define RETURN_REPORT_ERROR(snd_func, ...) \ | 35 #define RETURN_REPORT_ERROR(snd_func, ...) \ |
35 do { \ | 36 do { \ |
36 int err = alsa_->snd_func(__VA_ARGS__); \ | 37 int err = alsa_->snd_func(__VA_ARGS__); \ |
37 if (err < 0) { \ | 38 if (err < 0) { \ |
38 LOG(ERROR) << #snd_func " error: " << alsa_->StrError(err); \ | 39 LOG(ERROR) << #snd_func " error: " << alsa_->StrError(err); \ |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 const char kOutputDeviceDefaultName[] = "default"; | 75 const char kOutputDeviceDefaultName[] = "default"; |
75 const int kNumInputChannels = 2; | 76 const int kNumInputChannels = 2; |
76 | 77 |
77 const int kDefaultOutputBufferSizeFrames = 4096; | 78 const int kDefaultOutputBufferSizeFrames = 4096; |
78 const bool kPcmRecoverIsSilent = false; | 79 const bool kPcmRecoverIsSilent = false; |
79 // The number of frames of silence to write (to prevent underrun) when no inputs | 80 // The number of frames of silence to write (to prevent underrun) when no inputs |
80 // are present. | 81 // are present. |
81 const int kPreventUnderrunChunkSize = 512; | 82 const int kPreventUnderrunChunkSize = 512; |
82 const int kDefaultCheckCloseTimeoutMs = 2000; | 83 const int kDefaultCheckCloseTimeoutMs = 2000; |
83 | 84 |
84 const int kMaxWriteSizeMs = 20; | |
85 // The minimum amount of data that we allow in the ALSA buffer before starting | 85 // The minimum amount of data that we allow in the ALSA buffer before starting |
86 // to skip inputs with no available data. | 86 // to skip inputs with no available data. |
87 const int kMinBufferedDataMs = 8; | 87 const int kMinBufferedDataMs = 8; |
88 | 88 |
89 // A list of supported sample rates. | 89 // A list of supported sample rates. |
90 // TODO(jyw): move this up into chromecast/public for 1) documentation and | 90 // TODO(jyw): move this up into chromecast/public for 1) documentation and |
91 // 2) to help when implementing IsSampleRateSupported() | 91 // 2) to help when implementing IsSampleRateSupported() |
92 // clang-format off | 92 // clang-format off |
93 const int kSupportedSampleRates[] = | 93 const int kSupportedSampleRates[] = |
94 { 8000, 11025, 12000, | 94 { 8000, 11025, 12000, |
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 bool StreamMixerAlsa::TryWriteFrames() { | 844 bool StreamMixerAlsa::TryWriteFrames() { |
845 DCHECK(mixer_task_runner_->BelongsToCurrentThread()); | 845 DCHECK(mixer_task_runner_->BelongsToCurrentThread()); |
846 DCHECK_GE(filter_groups_.size(), 1u); | 846 DCHECK_GE(filter_groups_.size(), 1u); |
847 | 847 |
848 if (state_ != kStateNormalPlayback) { | 848 if (state_ != kStateNormalPlayback) { |
849 return false; | 849 return false; |
850 } | 850 } |
851 | 851 |
852 const int min_frames_in_buffer = | 852 const int min_frames_in_buffer = |
853 output_samples_per_second_ * kMinBufferedDataMs / 1000; | 853 output_samples_per_second_ * kMinBufferedDataMs / 1000; |
854 int chunk_size = output_samples_per_second_ * kMaxWriteSizeMs / 1000; | 854 int chunk_size = |
| 855 output_samples_per_second_ * kMaxAudioWriteTimeMilliseconds / 1000; |
855 bool is_silence = true; | 856 bool is_silence = true; |
856 for (auto&& filter_group : filter_groups_) { | 857 for (auto&& filter_group : filter_groups_) { |
857 filter_group->ClearActiveInputs(); | 858 filter_group->ClearActiveInputs(); |
858 } | 859 } |
859 for (auto&& input : inputs_) { | 860 for (auto&& input : inputs_) { |
860 int read_size = input->MaxReadSize(); | 861 int read_size = input->MaxReadSize(); |
861 if (read_size > 0) { | 862 if (read_size > 0) { |
862 DCHECK(input->filter_group()); | 863 DCHECK(input->filter_group()); |
863 input->filter_group()->AddActiveInput(input.get()); | 864 input->filter_group()->AddActiveInput(input.get()); |
864 chunk_size = std::min(chunk_size, read_size); | 865 chunk_size = std::min(chunk_size, read_size); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1080 for (auto&& input : inputs_) { | 1081 for (auto&& input : inputs_) { |
1081 // Volume limits don't apply to effects streams. | 1082 // Volume limits don't apply to effects streams. |
1082 if (input->primary() && input->content_type() == type) { | 1083 if (input->primary() && input->content_type() == type) { |
1083 input->SetContentTypeVolume(effective_volume, fade_ms); | 1084 input->SetContentTypeVolume(effective_volume, fade_ms); |
1084 } | 1085 } |
1085 } | 1086 } |
1086 } | 1087 } |
1087 | 1088 |
1088 } // namespace media | 1089 } // namespace media |
1089 } // namespace chromecast | 1090 } // namespace chromecast |
OLD | NEW |