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

Side by Side Diff: media/base/android/audio_media_codec_decoder.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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_media_codec_decoder.h" 5 #include "media/base/android/audio_media_codec_decoder.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "media/base/android/media_statistics.h" 9 #include "media/base/android/media_statistics.h"
10 #include "media/base/android/sdk_media_codec_bridge.h" 10 #include "media/base/android/sdk_media_codec_bridge.h"
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 DVLOG(2) << __FUNCTION__ << ": new sampling rate " << output_sampling_rate_; 188 DVLOG(2) << __FUNCTION__ << ": new sampling rate " << output_sampling_rate_;
189 needs_recreate_audio_track = true; 189 needs_recreate_audio_track = true;
190 190
191 ResetTimestampHelper(); 191 ResetTimestampHelper();
192 } 192 }
193 193
194 const int old_num_channels = output_num_channels_; 194 const int old_num_channels = output_num_channels_;
195 status = media_codec_bridge_->GetOutputChannelCount(&output_num_channels_); 195 status = media_codec_bridge_->GetOutputChannelCount(&output_num_channels_);
196 196
197 if (status == MEDIA_CODEC_OK && old_num_channels != output_num_channels_) { 197 if (status == MEDIA_CODEC_OK && old_num_channels != output_num_channels_) {
198 DCHECK_GT(output_sampling_rate_, 0); 198 DCHECK_GT(output_num_channels_, 0);
199 DVLOG(2) << __FUNCTION__ << ": new channel count " << output_num_channels_; 199 DVLOG(2) << __FUNCTION__ << ": new channel count " << output_num_channels_;
200 needs_recreate_audio_track = true; 200 needs_recreate_audio_track = true;
201 } 201 }
202 202
203 if (needs_recreate_audio_track && 203 if (needs_recreate_audio_track &&
204 !static_cast<AudioCodecBridge*>(media_codec_bridge_.get()) 204 !static_cast<AudioCodecBridge*>(media_codec_bridge_.get())
205 ->CreateAudioTrack(output_sampling_rate_, output_num_channels_)) { 205 ->CreateAudioTrack(output_sampling_rate_, output_num_channels_)) {
206 DLOG(ERROR) << __FUNCTION__ << ": cannot create AudioTrack"; 206 DLOG(ERROR) << __FUNCTION__ << ": cannot create AudioTrack";
207 return false; 207 return false;
208 } 208 }
209 209
210 return true; 210 return true;
211 } 211 }
212 212
213 void AudioMediaCodecDecoder::Render(int buffer_index, 213 bool AudioMediaCodecDecoder::Render(int buffer_index,
214 size_t offset, 214 size_t offset,
215 size_t size, 215 size_t size,
216 RenderMode render_mode, 216 RenderMode render_mode,
217 base::TimeDelta pts, 217 base::TimeDelta pts,
218 bool eos_encountered) { 218 bool eos_encountered) {
219 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread()); 219 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
220 220
221 DVLOG(2) << class_name() << "::" << __FUNCTION__ << " pts:" << pts << " " 221 DVLOG(2) << class_name() << "::" << __FUNCTION__ << " pts:" << pts << " "
222 << AsString(render_mode); 222 << AsString(render_mode);
223 223
224 const bool do_play = (render_mode != kRenderSkip); 224 const bool do_play = (render_mode != kRenderSkip);
225 225
226 if (do_play) { 226 if (do_play) {
227 AudioCodecBridge* audio_codec = 227 AudioCodecBridge* audio_codec =
228 static_cast<AudioCodecBridge*>(media_codec_bridge_.get()); 228 static_cast<AudioCodecBridge*>(media_codec_bridge_.get());
229 229
230 DCHECK(audio_codec); 230 DCHECK(audio_codec);
231 231
232 const bool postpone = (render_mode == kRenderAfterPreroll); 232 const bool postpone = (render_mode == kRenderAfterPreroll);
233 233
234 int64_t head_position; 234 int64_t head_position;
235 MediaCodecStatus status = audio_codec->PlayOutputBuffer( 235 MediaCodecStatus status = audio_codec->PlayOutputBuffer(
236 buffer_index, size, offset, postpone, &head_position); 236 buffer_index, size, offset, postpone, &head_position);
237 // TODO(timav,watk): This CHECK maintains the behavior of this call before 237
238 // we started catching CodecException and returning it as MEDIA_CODEC_ERROR. 238 if (status != MEDIA_CODEC_OK) {
239 // It needs to be handled some other way. http://crbug.com/585978 239 DLOG(ERROR) << class_name() << "::" << __FUNCTION__ << " pts:" << pts
240 CHECK_EQ(status, MEDIA_CODEC_OK); 240 << " PlayOutputBuffer failed for index:" << buffer_index;
241 media_codec_bridge_->ReleaseOutputBuffer(buffer_index, false);
242 return false;
243 }
241 244
242 base::TimeTicks current_time = base::TimeTicks::Now(); 245 base::TimeTicks current_time = base::TimeTicks::Now();
243 246
244 frame_statistics_->IncrementFrameCount(); 247 frame_statistics_->IncrementFrameCount();
245 248
246 // Reset the base timestamp if we have not started playing. 249 // Reset the base timestamp if we have not started playing.
247 // SetBaseTimestamp() must be called before AddFrames() since it resets the 250 // SetBaseTimestamp() must be called before AddFrames() since it resets the
248 // internal frame count. 251 // internal frame count.
249 if (postpone && !frame_count_) 252 if (postpone && !frame_count_)
250 SetBaseTimestamp(pts); 253 SetBaseTimestamp(pts);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 293
291 media_task_runner_->PostTask( 294 media_task_runner_->PostTask(
292 FROM_HERE, base::Bind(update_current_time_cb_, now_playing, 295 FROM_HERE, base::Bind(update_current_time_cb_, now_playing,
293 last_buffered, false)); 296 last_buffered, false));
294 } 297 }
295 } 298 }
296 299
297 media_codec_bridge_->ReleaseOutputBuffer(buffer_index, false); 300 media_codec_bridge_->ReleaseOutputBuffer(buffer_index, false);
298 301
299 CheckLastFrame(eos_encountered, false); // no delayed tasks 302 CheckLastFrame(eos_encountered, false); // no delayed tasks
303
304 return true;
300 } 305 }
301 306
302 void AudioMediaCodecDecoder::SetVolumeInternal() { 307 void AudioMediaCodecDecoder::SetVolumeInternal() {
303 DCHECK(media_task_runner_->BelongsToCurrentThread()); 308 DCHECK(media_task_runner_->BelongsToCurrentThread());
304 309
305 if (media_codec_bridge_) { 310 if (media_codec_bridge_) {
306 static_cast<AudioCodecBridge*>(media_codec_bridge_.get()) 311 static_cast<AudioCodecBridge*>(media_codec_bridge_.get())
307 ->SetVolume(volume_); 312 ->SetVolume(volume_);
308 } 313 }
309 } 314 }
310 315
311 void AudioMediaCodecDecoder::ResetTimestampHelper() { 316 void AudioMediaCodecDecoder::ResetTimestampHelper() {
312 // Media thread or Decoder thread 317 // Media thread or Decoder thread
313 // When this method is called on Media thread, decoder thread 318 // When this method is called on Media thread, decoder thread
314 // should not be running. 319 // should not be running.
315 320
316 if (audio_timestamp_helper_) 321 if (audio_timestamp_helper_)
317 base_timestamp_ = audio_timestamp_helper_->GetTimestamp(); 322 base_timestamp_ = audio_timestamp_helper_->GetTimestamp();
318 323
319 audio_timestamp_helper_.reset( 324 audio_timestamp_helper_.reset(
320 new AudioTimestampHelper(output_sampling_rate_)); 325 new AudioTimestampHelper(output_sampling_rate_));
321 326
322 audio_timestamp_helper_->SetBaseTimestamp(base_timestamp_); 327 audio_timestamp_helper_->SetBaseTimestamp(base_timestamp_);
323 } 328 }
324 329
325 } // namespace media 330 } // namespace media
OLDNEW
« no previous file with comments | « media/base/android/audio_media_codec_decoder.h ('k') | media/base/android/media_codec_decoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698