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

Side by Side Diff: media/base/android/audio_decoder_job.cc

Issue 1367403003: Added UMA metrics for MediaSourcePlayer and MediaCodecPlayer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mtplayer-drm
Patch Set: Addressed Xiaohan's comments Created 5 years, 2 months 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/base/android/audio_decoder_job.h" 5 #include "media/base/android/audio_decoder_job.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/threading/thread.h" 9 #include "base/threading/thread.h"
10 #include "media/base/android/media_codec_bridge.h" 10 #include "media/base/android/media_codec_bridge.h"
11 #include "media/base/android/media_statistics.h"
11 #include "media/base/audio_timestamp_helper.h" 12 #include "media/base/audio_timestamp_helper.h"
12 #include "media/base/timestamp_constants.h" 13 #include "media/base/timestamp_constants.h"
13 14
14 namespace { 15 namespace {
15 16
16 // Use 16bit PCM for audio output. Keep this value in sync with the output 17 // Use 16bit PCM for audio output. Keep this value in sync with the output
17 // format we passed to AudioTrack in MediaCodecBridge. 18 // format we passed to AudioTrack in MediaCodecBridge.
18 const int kBytesPerAudioOutputSample = 2; 19 const int kBytesPerAudioOutputSample = 2;
19 } 20 }
20 21
21 namespace media { 22 namespace media {
22 23
23 class AudioDecoderThread : public base::Thread { 24 class AudioDecoderThread : public base::Thread {
24 public: 25 public:
25 AudioDecoderThread() : base::Thread("MediaSource_AudioDecoderThread") { 26 AudioDecoderThread() : base::Thread("MediaSource_AudioDecoderThread") {
26 Start(); 27 Start();
27 } 28 }
28 }; 29 };
29 30
30 // TODO(qinmin): Check if it is tolerable to use worker pool to handle all the 31 // TODO(qinmin): Check if it is tolerable to use worker pool to handle all the
31 // decoding tasks so that we don't need a global thread here. 32 // decoding tasks so that we don't need a global thread here.
32 // http://crbug.com/245750 33 // http://crbug.com/245750
33 base::LazyInstance<AudioDecoderThread>::Leaky 34 base::LazyInstance<AudioDecoderThread>::Leaky
34 g_audio_decoder_thread = LAZY_INSTANCE_INITIALIZER; 35 g_audio_decoder_thread = LAZY_INSTANCE_INITIALIZER;
35 36
36 AudioDecoderJob::AudioDecoderJob( 37 AudioDecoderJob::AudioDecoderJob(
37 const base::Closure& request_data_cb, 38 const base::Closure& request_data_cb,
38 const base::Closure& on_demuxer_config_changed_cb) 39 const base::Closure& on_demuxer_config_changed_cb,
40 FrameStatistics* frame_statistics)
39 : MediaDecoderJob(g_audio_decoder_thread.Pointer()->task_runner(), 41 : MediaDecoderJob(g_audio_decoder_thread.Pointer()->task_runner(),
40 request_data_cb, 42 request_data_cb,
41 on_demuxer_config_changed_cb), 43 on_demuxer_config_changed_cb,
44 frame_statistics),
42 audio_codec_(kUnknownAudioCodec), 45 audio_codec_(kUnknownAudioCodec),
43 num_channels_(0), 46 num_channels_(0),
44 config_sampling_rate_(0), 47 config_sampling_rate_(0),
45 volume_(-1.0), 48 volume_(-1.0),
46 bytes_per_frame_(0), 49 bytes_per_frame_(0),
47 output_sampling_rate_(0), 50 output_sampling_rate_(0),
48 frame_count_(0) { 51 frame_count_(0) {
49 } 52 }
50 53
51 AudioDecoderJob::~AudioDecoderJob() {} 54 AudioDecoderJob::~AudioDecoderJob() {}
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 size_t offset, 102 size_t offset,
100 size_t size, 103 size_t size,
101 bool render_output, 104 bool render_output,
102 base::TimeDelta current_presentation_timestamp, 105 base::TimeDelta current_presentation_timestamp,
103 const ReleaseOutputCompletionCallback& callback) { 106 const ReleaseOutputCompletionCallback& callback) {
104 render_output = render_output && (size != 0u); 107 render_output = render_output && (size != 0u);
105 if (render_output) { 108 if (render_output) {
106 int64 head_position = (static_cast<AudioCodecBridge*>( 109 int64 head_position = (static_cast<AudioCodecBridge*>(
107 media_codec_bridge_.get()))->PlayOutputBuffer( 110 media_codec_bridge_.get()))->PlayOutputBuffer(
108 output_buffer_index, size, offset); 111 output_buffer_index, size, offset);
112
113 base::TimeTicks current_time = base::TimeTicks::Now();
114
109 size_t new_frames_count = size / bytes_per_frame_; 115 size_t new_frames_count = size / bytes_per_frame_;
110 frame_count_ += new_frames_count; 116 frame_count_ += new_frames_count;
111 audio_timestamp_helper_->AddFrames(new_frames_count); 117 audio_timestamp_helper_->AddFrames(new_frames_count);
112 int64 frames_to_play = frame_count_ - head_position; 118 int64 frames_to_play = frame_count_ - head_position;
113 DCHECK_GE(frames_to_play, 0); 119 DCHECK_GE(frames_to_play, 0);
120
121 const base::TimeDelta last_buffered =
122 audio_timestamp_helper_->GetTimestamp();
123
114 current_presentation_timestamp = 124 current_presentation_timestamp =
115 audio_timestamp_helper_->GetTimestamp() - 125 last_buffered -
116 audio_timestamp_helper_->GetFrameDuration(frames_to_play); 126 audio_timestamp_helper_->GetFrameDuration(frames_to_play);
127
128 if (!next_frame_time_limit_.is_null() &&
129 next_frame_time_limit_ < current_time) {
130 DCHECK(frame_statistics_);
131 frame_statistics_->AddLateFrame(current_time - next_frame_time_limit_);
xhwang 2015/10/01 21:58:57 This DCHECK is not necessary. In debug build l.131
Tima Vaisburd 2015/10/02 00:44:32 I thought DCHECK will provide extra information. R
132 }
133
134 next_frame_time_limit_ =
135 current_time + (last_buffered - current_presentation_timestamp);
117 } else { 136 } else {
118 current_presentation_timestamp = kNoTimestamp(); 137 current_presentation_timestamp = kNoTimestamp();
119 } 138 }
120 media_codec_bridge_->ReleaseOutputBuffer(output_buffer_index, false); 139 media_codec_bridge_->ReleaseOutputBuffer(output_buffer_index, false);
121 140
122 callback.Run(current_presentation_timestamp, 141 callback.Run(current_presentation_timestamp,
123 audio_timestamp_helper_->GetTimestamp()); 142 audio_timestamp_helper_->GetTimestamp());
124 } 143 }
125 144
126 bool AudioDecoderJob::ComputeTimeToRender() const { 145 bool AudioDecoderJob::ComputeTimeToRender() const {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 void AudioDecoderJob::OnOutputFormatChanged() { 191 void AudioDecoderJob::OnOutputFormatChanged() {
173 DCHECK(media_codec_bridge_); 192 DCHECK(media_codec_bridge_);
174 193
175 int old_sampling_rate = output_sampling_rate_; 194 int old_sampling_rate = output_sampling_rate_;
176 output_sampling_rate_ = media_codec_bridge_->GetOutputSamplingRate(); 195 output_sampling_rate_ = media_codec_bridge_->GetOutputSamplingRate();
177 if (output_sampling_rate_ != old_sampling_rate) 196 if (output_sampling_rate_ != old_sampling_rate)
178 ResetTimestampHelper(); 197 ResetTimestampHelper();
179 } 198 }
180 199
181 } // namespace media 200 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698