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

Side by Side Diff: media/renderers/audio_renderer_impl.cc

Issue 2552493002: [Media] Record time it takes to start rendering audio and video (Closed)
Patch Set: Audio and video first render times Created 4 years 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 (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>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/callback_helpers.h" 14 #include "base/callback_helpers.h"
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/metrics/histogram_macros.h"
17 #include "base/power_monitor/power_monitor.h" 18 #include "base/power_monitor/power_monitor.h"
18 #include "base/single_thread_task_runner.h" 19 #include "base/single_thread_task_runner.h"
19 #include "base/time/default_tick_clock.h" 20 #include "base/time/default_tick_clock.h"
20 #include "build/build_config.h" 21 #include "build/build_config.h"
21 #include "media/base/audio_buffer.h" 22 #include "media/base/audio_buffer.h"
22 #include "media/base/audio_buffer_converter.h" 23 #include "media/base/audio_buffer_converter.h"
23 #include "media/base/audio_latency.h" 24 #include "media/base/audio_latency.h"
24 #include "media/base/bind_to_current_loop.h" 25 #include "media/base/bind_to_current_loop.h"
25 #include "media/base/channel_mixing_matrix.h" 26 #include "media/base/channel_mixing_matrix.h"
26 #include "media/base/demuxer_stream.h" 27 #include "media/base/demuxer_stream.h"
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 DVLOG(1) << __func__ << "(" << time << ")"; 166 DVLOG(1) << __func__ << "(" << time << ")";
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();
176 start_rendering_time_ = tick_clock_->NowTicks();
175 first_packet_timestamp_ = kNoTimestamp; 177 first_packet_timestamp_ = kNoTimestamp;
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();
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 772
771 int64_t frames_delayed = AudioTimestampHelper::TimeToFrames( 773 int64_t frames_delayed = AudioTimestampHelper::TimeToFrames(
772 delay, audio_parameters_.sample_rate()); 774 delay, audio_parameters_.sample_rate());
773 775
774 if (!stop_rendering_time_.is_null()) { 776 if (!stop_rendering_time_.is_null()) {
775 audio_clock_->CompensateForSuspendedWrites( 777 audio_clock_->CompensateForSuspendedWrites(
776 last_render_time_ - stop_rendering_time_, frames_delayed); 778 last_render_time_ - stop_rendering_time_, frames_delayed);
777 stop_rendering_time_ = base::TimeTicks(); 779 stop_rendering_time_ = base::TimeTicks();
778 } 780 }
779 781
782 if (!start_rendering_time_.is_null()) {
783 UMA_HISTOGRAM_MEDIUM_TIMES(
784 "Media.Audio.FirstRenderTime",
785 tick_clock_->NowTicks() - start_rendering_time_);
786 start_rendering_time_ = base::TimeTicks();
787 }
788
780 // Ensure Stop() hasn't destroyed our |algorithm_| on the pipeline thread. 789 // Ensure Stop() hasn't destroyed our |algorithm_| on the pipeline thread.
781 if (!algorithm_) { 790 if (!algorithm_) {
782 audio_clock_->WroteAudio(0, frames_requested, frames_delayed, 791 audio_clock_->WroteAudio(0, frames_requested, frames_delayed,
783 playback_rate_); 792 playback_rate_);
784 return 0; 793 return 0;
785 } 794 }
786 795
787 if (playback_rate_ == 0 || is_suspending_) { 796 if (playback_rate_ == 0 || is_suspending_) {
788 audio_clock_->WroteAudio(0, frames_requested, frames_delayed, 797 audio_clock_->WroteAudio(0, frames_requested, frames_delayed,
789 playback_rate_); 798 playback_rate_);
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 // All channels with a zero mix are muted and can be ignored. 995 // All channels with a zero mix are muted and can be ignored.
987 std::vector<bool> channel_mask(audio_parameters_.channels(), false); 996 std::vector<bool> channel_mask(audio_parameters_.channels(), false);
988 for (size_t ch = 0; ch < matrix.size(); ++ch) { 997 for (size_t ch = 0; ch < matrix.size(); ++ch) {
989 channel_mask[ch] = std::any_of(matrix[ch].begin(), matrix[ch].end(), 998 channel_mask[ch] = std::any_of(matrix[ch].begin(), matrix[ch].end(),
990 [](float mix) { return !!mix; }); 999 [](float mix) { return !!mix; });
991 } 1000 }
992 algorithm_->SetChannelMask(std::move(channel_mask)); 1001 algorithm_->SetChannelMask(std::move(channel_mask));
993 } 1002 }
994 1003
995 } // namespace media 1004 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698