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

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: Do not override the status unless we got an error 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 const bool postpone = false;
qinmin 2016/05/11 20:58:29 nit:I would get rid of this variable and just use
Tima Vaisburd 2016/05/11 22:24:33 Done.
116
117 MediaCodecStatus play_status =
112 (static_cast<AudioCodecBridge*>(media_codec_bridge_.get())) 118 (static_cast<AudioCodecBridge*>(media_codec_bridge_.get()))
113 ->PlayOutputBuffer(output_buffer_index, size, offset, postpone, 119 ->PlayOutputBuffer(output_buffer_index, size, offset, postpone,
114 &head_position); 120 &head_position);
115 // TODO(timav,watk): This CHECK maintains the behavior of this call before 121 if (play_status == MEDIA_CODEC_OK) {
116 // we started catching CodecException and returning it as MEDIA_CODEC_ERROR. 122 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 123
120 base::TimeTicks current_time = base::TimeTicks::Now(); 124 size_t bytes_per_frame =
125 kBytesPerAudioOutputSample * output_num_channels_;
126 size_t new_frames_count = size / bytes_per_frame;
127 frame_count_ += new_frames_count;
128 audio_timestamp_helper_->AddFrames(new_frames_count);
129 int64_t frames_to_play = frame_count_ - head_position;
130 DCHECK_GE(frames_to_play, 0);
121 131
122 size_t bytes_per_frame = kBytesPerAudioOutputSample * output_num_channels_; 132 const base::TimeDelta last_buffered =
123 size_t new_frames_count = size / bytes_per_frame; 133 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 134
129 const base::TimeDelta last_buffered = 135 current_presentation_timestamp =
130 audio_timestamp_helper_->GetTimestamp(); 136 last_buffered -
137 audio_timestamp_helper_->GetFrameDuration(frames_to_play);
131 138
132 current_presentation_timestamp = 139 // Potential audio underrun is considered a late frame for UMA.
133 last_buffered - 140 is_audio_underrun = !next_frame_time_limit_.is_null() &&
134 audio_timestamp_helper_->GetFrameDuration(frames_to_play); 141 next_frame_time_limit_ < current_time;
135 142
136 // Potential audio underrun is considered a late frame for UMA. 143 next_frame_time_limit_ =
137 is_audio_underrun = !next_frame_time_limit_.is_null() && 144 current_time + (last_buffered - current_presentation_timestamp);
138 next_frame_time_limit_ < current_time; 145 } else {
146 DLOG(ERROR) << __FUNCTION__ << ": PlayOutputBuffer failed for index:"
147 << output_buffer_index;
139 148
140 next_frame_time_limit_ = 149 // Override output status.
141 current_time + (last_buffered - current_presentation_timestamp); 150 status = MEDIA_CODEC_ERROR;
142 } else { 151 }
143 current_presentation_timestamp = kNoTimestamp();
144 } 152 }
153
145 media_codec_bridge_->ReleaseOutputBuffer(output_buffer_index, false); 154 media_codec_bridge_->ReleaseOutputBuffer(output_buffer_index, false);
146 155
147 callback.Run(is_audio_underrun, current_presentation_timestamp, 156 callback.Run(status, is_audio_underrun, current_presentation_timestamp,
148 audio_timestamp_helper_->GetTimestamp()); 157 audio_timestamp_helper_->GetTimestamp());
149 } 158 }
150 159
151 bool AudioDecoderJob::ComputeTimeToRender() const { 160 bool AudioDecoderJob::ComputeTimeToRender() const {
152 return false; 161 return false;
153 } 162 }
154 163
155 bool AudioDecoderJob::AreDemuxerConfigsChanged( 164 bool AudioDecoderJob::AreDemuxerConfigsChanged(
156 const DemuxerConfigs& configs) const { 165 const DemuxerConfigs& configs) const {
157 return audio_codec_ != configs.audio_codec || 166 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_; 220 DVLOG(2) << __FUNCTION__ << ": new sampling rate " << output_sampling_rate_;
212 needs_recreate_audio_track = true; 221 needs_recreate_audio_track = true;
213 222
214 ResetTimestampHelper(); 223 ResetTimestampHelper();
215 } 224 }
216 225
217 const int old_num_channels = output_num_channels_; 226 const int old_num_channels = output_num_channels_;
218 status = media_codec_bridge_->GetOutputChannelCount(&output_num_channels_); 227 status = media_codec_bridge_->GetOutputChannelCount(&output_num_channels_);
219 228
220 if (status == MEDIA_CODEC_OK && old_num_channels != output_num_channels_) { 229 if (status == MEDIA_CODEC_OK && old_num_channels != output_num_channels_) {
221 DCHECK_GT(output_sampling_rate_, 0); 230 DCHECK_GT(output_num_channels_, 0);
222 DVLOG(2) << __FUNCTION__ << ": new channel count " << output_num_channels_; 231 DVLOG(2) << __FUNCTION__ << ": new channel count " << output_num_channels_;
223 needs_recreate_audio_track = true; 232 needs_recreate_audio_track = true;
224 } 233 }
225 234
226 if (needs_recreate_audio_track && 235 if (needs_recreate_audio_track &&
227 !static_cast<AudioCodecBridge*>(media_codec_bridge_.get()) 236 !static_cast<AudioCodecBridge*>(media_codec_bridge_.get())
228 ->CreateAudioTrack(output_sampling_rate_, output_num_channels_)) { 237 ->CreateAudioTrack(output_sampling_rate_, output_num_channels_)) {
229 DLOG(ERROR) << __FUNCTION__ << ": cannot create AudioTrack"; 238 DLOG(ERROR) << __FUNCTION__ << ": cannot create AudioTrack";
230 return false; 239 return false;
231 } 240 }
232 241
233 return true; 242 return true;
234 } 243 }
235 244
236 } // namespace media 245 } // 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