| 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> |
| (...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 LOG(ERROR) << "Failed to get status"; | 778 LOG(ERROR) << "Failed to get status"; |
| 779 return false; | 779 return false; |
| 780 } | 780 } |
| 781 | 781 |
| 782 int frames_in_buffer = | 782 int frames_in_buffer = |
| 783 alsa_buffer_size_ - alsa_->PcmStatusGetAvail(pcm_status_); | 783 alsa_buffer_size_ - alsa_->PcmStatusGetAvail(pcm_status_); |
| 784 if (alsa_->PcmStatusGetState(pcm_status_) == SND_PCM_STATE_XRUN || | 784 if (alsa_->PcmStatusGetState(pcm_status_) == SND_PCM_STATE_XRUN || |
| 785 frames_in_buffer < min_frames_in_buffer) { | 785 frames_in_buffer < min_frames_in_buffer) { |
| 786 // If there has been (or soon will be) an underrun, continue without the | 786 // If there has been (or soon will be) an underrun, continue without the |
| 787 // empty primary input stream. | 787 // empty primary input stream. |
| 788 input->OnSkipped(); |
| 788 continue; | 789 continue; |
| 789 } | 790 } |
| 790 | 791 |
| 791 // A primary input cannot provide any data, so wait until later. | 792 // A primary input cannot provide any data, so wait until later. |
| 792 retry_write_frames_timer_->Start( | 793 retry_write_frames_timer_->Start( |
| 793 FROM_HERE, base::TimeDelta::FromMilliseconds(kMinBufferedDataMs / 2), | 794 FROM_HERE, base::TimeDelta::FromMilliseconds(kMinBufferedDataMs / 2), |
| 794 base::Bind(&StreamMixerAlsa::WriteFrames, base::Unretained(this))); | 795 base::Bind(&StreamMixerAlsa::WriteFrames, base::Unretained(this))); |
| 795 return false; | 796 return false; |
| 797 } else { |
| 798 input->OnSkipped(); |
| 796 } | 799 } |
| 797 } | 800 } |
| 798 | 801 |
| 799 if (active_inputs.empty()) { | 802 if (active_inputs.empty()) { |
| 800 // No inputs have any data to provide. | 803 // No inputs have any data to provide. Fill with silence to avoid underrun. |
| 801 if (!inputs_.empty()) { | |
| 802 return false; // If there are some inputs, don't fill with silence. | |
| 803 } | |
| 804 | |
| 805 // If we have no inputs, fill with silence to avoid underrun. | |
| 806 chunk_size = kPreventUnderrunChunkSize; | 804 chunk_size = kPreventUnderrunChunkSize; |
| 807 if (!mixed_ || mixed_->frames() < chunk_size) { | 805 if (!mixed_ || mixed_->frames() < chunk_size) { |
| 808 mixed_ = ::media::AudioBus::Create(kNumOutputChannels, chunk_size); | 806 mixed_ = ::media::AudioBus::Create(kNumOutputChannels, chunk_size); |
| 809 } | 807 } |
| 810 | 808 |
| 811 mixed_->Zero(); | 809 mixed_->Zero(); |
| 812 WriteMixedPcm(*mixed_, chunk_size, true /* is_silence */); | 810 WriteMixedPcm(*mixed_, chunk_size, true /* is_silence */); |
| 813 return true; | 811 return true; |
| 814 } | 812 } |
| 815 | 813 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 DCHECK(std::find(loopback_observers_.begin(), loopback_observers_.end(), | 940 DCHECK(std::find(loopback_observers_.begin(), loopback_observers_.end(), |
| 943 observer) != loopback_observers_.end()); | 941 observer) != loopback_observers_.end()); |
| 944 loopback_observers_.erase(std::remove(loopback_observers_.begin(), | 942 loopback_observers_.erase(std::remove(loopback_observers_.begin(), |
| 945 loopback_observers_.end(), observer), | 943 loopback_observers_.end(), observer), |
| 946 loopback_observers_.end()); | 944 loopback_observers_.end()); |
| 947 observer->OnRemoved(); | 945 observer->OnRemoved(); |
| 948 } | 946 } |
| 949 | 947 |
| 950 } // namespace media | 948 } // namespace media |
| 951 } // namespace chromecast | 949 } // namespace chromecast |
| OLD | NEW |