| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "media/renderers/audio_renderer_impl.h" | 5 #include "media/renderers/audio_renderer_impl.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 last_decoded_channel_layout_(CHANNEL_LAYOUT_NONE), | 51 last_decoded_channel_layout_(CHANNEL_LAYOUT_NONE), |
| 52 playback_rate_(0.0), | 52 playback_rate_(0.0), |
| 53 state_(kUninitialized), | 53 state_(kUninitialized), |
| 54 buffering_state_(BUFFERING_HAVE_NOTHING), | 54 buffering_state_(BUFFERING_HAVE_NOTHING), |
| 55 rendering_(false), | 55 rendering_(false), |
| 56 sink_playing_(false), | 56 sink_playing_(false), |
| 57 pending_read_(false), | 57 pending_read_(false), |
| 58 received_end_of_stream_(false), | 58 received_end_of_stream_(false), |
| 59 rendered_end_of_stream_(false), | 59 rendered_end_of_stream_(false), |
| 60 is_suspending_(false), | 60 is_suspending_(false), |
| 61 rendered_first_frame_(false), |
| 61 weak_factory_(this) { | 62 weak_factory_(this) { |
| 62 audio_buffer_stream_->set_config_change_observer(base::Bind( | 63 audio_buffer_stream_->set_config_change_observer(base::Bind( |
| 63 &AudioRendererImpl::OnConfigChange, weak_factory_.GetWeakPtr())); | 64 &AudioRendererImpl::OnConfigChange, weak_factory_.GetWeakPtr())); |
| 64 | 65 |
| 65 // Tests may not have a power monitor. | 66 // Tests may not have a power monitor. |
| 66 base::PowerMonitor* monitor = base::PowerMonitor::Get(); | 67 base::PowerMonitor* monitor = base::PowerMonitor::Get(); |
| 67 if (!monitor) | 68 if (!monitor) |
| 68 return; | 69 return; |
| 69 | 70 |
| 70 // PowerObserver's must be added and removed from the same thread, but we | 71 // PowerObserver's must be added and removed from the same thread, but we |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 DCHECK(task_runner_->BelongsToCurrentThread()); | 167 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 167 | 168 |
| 168 base::AutoLock auto_lock(lock_); | 169 base::AutoLock auto_lock(lock_); |
| 169 DCHECK(!rendering_); | 170 DCHECK(!rendering_); |
| 170 DCHECK_EQ(state_, kFlushed); | 171 DCHECK_EQ(state_, kFlushed); |
| 171 | 172 |
| 172 start_timestamp_ = time; | 173 start_timestamp_ = time; |
| 173 ended_timestamp_ = kInfiniteDuration; | 174 ended_timestamp_ = kInfiniteDuration; |
| 174 last_render_time_ = stop_rendering_time_ = base::TimeTicks(); | 175 last_render_time_ = stop_rendering_time_ = base::TimeTicks(); |
| 175 first_packet_timestamp_ = kNoTimestamp; | 176 first_packet_timestamp_ = kNoTimestamp; |
| 177 rendered_first_frame_ = false; |
| 176 audio_clock_.reset(new AudioClock(time, audio_parameters_.sample_rate())); | 178 audio_clock_.reset(new AudioClock(time, audio_parameters_.sample_rate())); |
| 177 } | 179 } |
| 178 | 180 |
| 179 base::TimeDelta AudioRendererImpl::CurrentMediaTime() { | 181 base::TimeDelta AudioRendererImpl::CurrentMediaTime() { |
| 180 base::AutoLock auto_lock(lock_); | 182 base::AutoLock auto_lock(lock_); |
| 181 | 183 |
| 182 // Return the current time based on the known extents of the rendered audio | 184 // Return the current time based on the known extents of the rendered audio |
| 183 // data plus an estimate based on the last time those values were calculated. | 185 // data plus an estimate based on the last time those values were calculated. |
| 184 base::TimeDelta current_media_time = audio_clock_->front_timestamp(); | 186 base::TimeDelta current_media_time = audio_clock_->front_timestamp(); |
| 185 if (!last_render_time_.is_null()) { | 187 if (!last_render_time_.is_null()) { |
| (...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 760 AudioBus* audio_bus) { | 762 AudioBus* audio_bus) { |
| 761 const int frames_requested = audio_bus->frames(); | 763 const int frames_requested = audio_bus->frames(); |
| 762 DVLOG(4) << __func__ << " delay:" << delay | 764 DVLOG(4) << __func__ << " delay:" << delay |
| 763 << " prior_frames_skipped:" << prior_frames_skipped | 765 << " prior_frames_skipped:" << prior_frames_skipped |
| 764 << " frames_requested:" << frames_requested; | 766 << " frames_requested:" << frames_requested; |
| 765 | 767 |
| 766 int frames_written = 0; | 768 int frames_written = 0; |
| 767 { | 769 { |
| 768 base::AutoLock auto_lock(lock_); | 770 base::AutoLock auto_lock(lock_); |
| 769 last_render_time_ = tick_clock_->NowTicks(); | 771 last_render_time_ = tick_clock_->NowTicks(); |
| 772 if (!rendered_first_frame_) { |
| 773 rendered_first_frame_ = true; |
| 774 client_->OnFirstFrameRender(); |
| 775 } |
| 770 | 776 |
| 771 int64_t frames_delayed = AudioTimestampHelper::TimeToFrames( | 777 int64_t frames_delayed = AudioTimestampHelper::TimeToFrames( |
| 772 delay, audio_parameters_.sample_rate()); | 778 delay, audio_parameters_.sample_rate()); |
| 773 | 779 |
| 774 if (!stop_rendering_time_.is_null()) { | 780 if (!stop_rendering_time_.is_null()) { |
| 775 audio_clock_->CompensateForSuspendedWrites( | 781 audio_clock_->CompensateForSuspendedWrites( |
| 776 last_render_time_ - stop_rendering_time_, frames_delayed); | 782 last_render_time_ - stop_rendering_time_, frames_delayed); |
| 777 stop_rendering_time_ = base::TimeTicks(); | 783 stop_rendering_time_ = base::TimeTicks(); |
| 778 } | 784 } |
| 779 | 785 |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 // All channels with a zero mix are muted and can be ignored. | 992 // All channels with a zero mix are muted and can be ignored. |
| 987 std::vector<bool> channel_mask(audio_parameters_.channels(), false); | 993 std::vector<bool> channel_mask(audio_parameters_.channels(), false); |
| 988 for (size_t ch = 0; ch < matrix.size(); ++ch) { | 994 for (size_t ch = 0; ch < matrix.size(); ++ch) { |
| 989 channel_mask[ch] = std::any_of(matrix[ch].begin(), matrix[ch].end(), | 995 channel_mask[ch] = std::any_of(matrix[ch].begin(), matrix[ch].end(), |
| 990 [](float mix) { return !!mix; }); | 996 [](float mix) { return !!mix; }); |
| 991 } | 997 } |
| 992 algorithm_->SetChannelMask(std::move(channel_mask)); | 998 algorithm_->SetChannelMask(std::move(channel_mask)); |
| 993 } | 999 } |
| 994 | 1000 |
| 995 } // namespace media | 1001 } // namespace media |
| OLD | NEW |