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

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

Issue 1963343002: Report media error if PlayOutputBuffer failed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Min's comment Created 4 years, 7 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
« no previous file with comments | « media/base/android/audio_decoder_job.h ('k') | media/base/android/audio_media_codec_decoder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/sdk_media_codec_bridge.h" 10 #include "media/base/android/sdk_media_codec_bridge.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 audio_timestamp_helper_->SetBaseTimestamp(base_timestamp_); 95 audio_timestamp_helper_->SetBaseTimestamp(base_timestamp_);
96 } 96 }
97 97
98 void AudioDecoderJob::ReleaseOutputBuffer( 98 void AudioDecoderJob::ReleaseOutputBuffer(
99 int output_buffer_index, 99 int output_buffer_index,
100 size_t offset, 100 size_t offset,
101 size_t size, 101 size_t size,
102 bool render_output, 102 bool render_output,
103 bool /* is_late_frame */, 103 bool /* is_late_frame */,
104 base::TimeDelta current_presentation_timestamp, 104 base::TimeDelta current_presentation_timestamp,
105 const ReleaseOutputCompletionCallback& callback) { 105 MediaCodecStatus status,
106 const DecoderCallback& callback) {
106 render_output = render_output && (size != 0u); 107 render_output = render_output && (size != 0u);
107 bool is_audio_underrun = false; 108 bool is_audio_underrun = false;
109
110 // Ignore input value.
111 current_presentation_timestamp = kNoTimestamp();
112
108 if (render_output) { 113 if (render_output) {
109 bool postpone = false;
110 int64_t head_position; 114 int64_t head_position;
111 MediaCodecStatus status = 115 MediaCodecStatus play_status =
112 (static_cast<AudioCodecBridge*>(media_codec_bridge_.get())) 116 (static_cast<AudioCodecBridge*>(media_codec_bridge_.get()))
113 ->PlayOutputBuffer(output_buffer_index, size, offset, postpone, 117 ->PlayOutputBuffer(output_buffer_index, size, offset, false,
114 &head_position); 118 &head_position);
115 // TODO(timav,watk): This CHECK maintains the behavior of this call before 119 if (play_status == MEDIA_CODEC_OK) {
116 // we started catching CodecException and returning it as MEDIA_CODEC_ERROR. 120 base::TimeTicks current_time = base::TimeTicks::Now();
117 // It needs to be handled some other way. http://crbug.com/585978
118 CHECK_EQ(status, MEDIA_CODEC_OK);
119 121
120 base::TimeTicks current_time = base::TimeTicks::Now(); 122 size_t bytes_per_frame =
123 kBytesPerAudioOutputSample * output_num_channels_;
124 size_t new_frames_count = size / bytes_per_frame;
125 frame_count_ += new_frames_count;
126 audio_timestamp_helper_->AddFrames(new_frames_count);
127 int64_t frames_to_play = frame_count_ - head_position;
128 DCHECK_GE(frames_to_play, 0);
121 129
122 size_t bytes_per_frame = kBytesPerAudioOutputSample * output_num_channels_; 130 const base::TimeDelta last_buffered =
123 size_t new_frames_count = size / bytes_per_frame; 131 audio_timestamp_helper_->GetTimestamp();
124 frame_count_ += new_frames_count;
125 audio_timestamp_helper_->AddFrames(new_frames_count);
126 int64_t frames_to_play = frame_count_ - head_position;
127 DCHECK_GE(frames_to_play, 0);
128 132
129 const base::TimeDelta last_buffered = 133 current_presentation_timestamp =
130 audio_timestamp_helper_->GetTimestamp(); 134 last_buffered -
135 audio_timestamp_helper_->GetFrameDuration(frames_to_play);
131 136
132 current_presentation_timestamp = 137 // Potential audio underrun is considered a late frame for UMA.
133 last_buffered - 138 is_audio_underrun = !next_frame_time_limit_.is_null() &&
134 audio_timestamp_helper_->GetFrameDuration(frames_to_play); 139 next_frame_time_limit_ < current_time;
135 140
136 // Potential audio underrun is considered a late frame for UMA. 141 next_frame_time_limit_ =
137 is_audio_underrun = !next_frame_time_limit_.is_null() && 142 current_time + (last_buffered - current_presentation_timestamp);
138 next_frame_time_limit_ < current_time; 143 } else {
144 DLOG(ERROR) << __FUNCTION__ << ": PlayOutputBuffer failed for index:"
145 << output_buffer_index;
139 146
140 next_frame_time_limit_ = 147 // Override output status.
141 current_time + (last_buffered - current_presentation_timestamp); 148 status = MEDIA_CODEC_ERROR;
142 } else { 149 }
143 current_presentation_timestamp = kNoTimestamp();
144 } 150 }
151
145 media_codec_bridge_->ReleaseOutputBuffer(output_buffer_index, false); 152 media_codec_bridge_->ReleaseOutputBuffer(output_buffer_index, false);
146 153
147 callback.Run(is_audio_underrun, current_presentation_timestamp, 154 callback.Run(status, is_audio_underrun, current_presentation_timestamp,
148 audio_timestamp_helper_->GetTimestamp()); 155 audio_timestamp_helper_->GetTimestamp());
149 } 156 }
150 157
151 bool AudioDecoderJob::ComputeTimeToRender() const { 158 bool AudioDecoderJob::ComputeTimeToRender() const {
152 return false; 159 return false;
153 } 160 }
154 161
155 bool AudioDecoderJob::AreDemuxerConfigsChanged( 162 bool AudioDecoderJob::AreDemuxerConfigsChanged(
156 const DemuxerConfigs& configs) const { 163 const DemuxerConfigs& configs) const {
157 return audio_codec_ != configs.audio_codec || 164 return audio_codec_ != configs.audio_codec ||
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 DVLOG(2) << __FUNCTION__ << ": new sampling rate " << output_sampling_rate_; 218 DVLOG(2) << __FUNCTION__ << ": new sampling rate " << output_sampling_rate_;
212 needs_recreate_audio_track = true; 219 needs_recreate_audio_track = true;
213 220
214 ResetTimestampHelper(); 221 ResetTimestampHelper();
215 } 222 }
216 223
217 const int old_num_channels = output_num_channels_; 224 const int old_num_channels = output_num_channels_;
218 status = media_codec_bridge_->GetOutputChannelCount(&output_num_channels_); 225 status = media_codec_bridge_->GetOutputChannelCount(&output_num_channels_);
219 226
220 if (status == MEDIA_CODEC_OK && old_num_channels != output_num_channels_) { 227 if (status == MEDIA_CODEC_OK && old_num_channels != output_num_channels_) {
221 DCHECK_GT(output_sampling_rate_, 0); 228 DCHECK_GT(output_num_channels_, 0);
222 DVLOG(2) << __FUNCTION__ << ": new channel count " << output_num_channels_; 229 DVLOG(2) << __FUNCTION__ << ": new channel count " << output_num_channels_;
223 needs_recreate_audio_track = true; 230 needs_recreate_audio_track = true;
224 } 231 }
225 232
226 if (needs_recreate_audio_track && 233 if (needs_recreate_audio_track &&
227 !static_cast<AudioCodecBridge*>(media_codec_bridge_.get()) 234 !static_cast<AudioCodecBridge*>(media_codec_bridge_.get())
228 ->CreateAudioTrack(output_sampling_rate_, output_num_channels_)) { 235 ->CreateAudioTrack(output_sampling_rate_, output_num_channels_)) {
229 DLOG(ERROR) << __FUNCTION__ << ": cannot create AudioTrack"; 236 DLOG(ERROR) << __FUNCTION__ << ": cannot create AudioTrack";
230 return false; 237 return false;
231 } 238 }
232 239
233 return true; 240 return true;
234 } 241 }
235 242
236 } // namespace media 243 } // namespace media
OLDNEW
« no previous file with comments | « media/base/android/audio_decoder_job.h ('k') | media/base/android/audio_media_codec_decoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698