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

Side by Side Diff: media/base/android/java/src/org/chromium/media/MediaCodecBridge.java

Issue 1681613002: Remove MediaCodecBridge::GetOutputBuffersCount() and GetOutputBuffersCapacity() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing comments Created 4 years, 10 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 package org.chromium.media; 5 package org.chromium.media;
6 6
7 import android.annotation.TargetApi; 7 import android.annotation.TargetApi;
8 import android.media.AudioFormat; 8 import android.media.AudioFormat;
9 import android.media.AudioManager; 9 import android.media.AudioManager;
10 import android.media.AudioTrack; 10 import android.media.AudioTrack;
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 292
293 @CalledByNative 293 @CalledByNative
294 private ByteBuffer getOutputBuffer(int index) { 294 private ByteBuffer getOutputBuffer(int index) {
295 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { 295 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
296 return mMediaCodec.getOutputBuffer(index); 296 return mMediaCodec.getOutputBuffer(index);
297 } 297 }
298 return mOutputBuffers[index]; 298 return mOutputBuffers[index];
299 } 299 }
300 300
301 @CalledByNative 301 @CalledByNative
302 private int getOutputBuffersCount() {
303 return mOutputBuffers != null ? mOutputBuffers.length : -1;
304 }
305
306 @CalledByNative
307 private int getOutputBuffersCapacity() {
308 return mOutputBuffers != null ? mOutputBuffers[0].capacity() : -1;
309 }
310
311 @CalledByNative
312 private int queueInputBuffer( 302 private int queueInputBuffer(
313 int index, int offset, int size, long presentationTimeUs, int flags) { 303 int index, int offset, int size, long presentationTimeUs, int flags) {
314 resetLastPresentationTimeIfNeeded(presentationTimeUs); 304 resetLastPresentationTimeIfNeeded(presentationTimeUs);
315 try { 305 try {
316 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
317 mMediaCodec.getInputBuffer(index);
318 }
319 mMediaCodec.queueInputBuffer(index, offset, size, presentationTimeUs , flags); 306 mMediaCodec.queueInputBuffer(index, offset, size, presentationTimeUs , flags);
320 } catch (Exception e) { 307 } catch (Exception e) {
321 Log.e(TAG, "Failed to queue input buffer", e); 308 Log.e(TAG, "Failed to queue input buffer", e);
322 return MEDIA_CODEC_ERROR; 309 return MEDIA_CODEC_ERROR;
323 } 310 }
324 return MEDIA_CODEC_OK; 311 return MEDIA_CODEC_OK;
325 } 312 }
326 313
327 @TargetApi(Build.VERSION_CODES.KITKAT) 314 @TargetApi(Build.VERSION_CODES.KITKAT)
328 @CalledByNative 315 @CalledByNative
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 } catch (IllegalStateException e) { 348 } catch (IllegalStateException e) {
362 Log.e(TAG, "Failed to queue secure input buffer, IllegalStateExcepti on " + e); 349 Log.e(TAG, "Failed to queue secure input buffer, IllegalStateExcepti on " + e);
363 return MEDIA_CODEC_ERROR; 350 return MEDIA_CODEC_ERROR;
364 } 351 }
365 return MEDIA_CODEC_OK; 352 return MEDIA_CODEC_OK;
366 } 353 }
367 354
368 @CalledByNative 355 @CalledByNative
369 private void releaseOutputBuffer(int index, boolean render) { 356 private void releaseOutputBuffer(int index, boolean render) {
370 try { 357 try {
371 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
372 mMediaCodec.getOutputBuffer(index);
373 }
374 mMediaCodec.releaseOutputBuffer(index, render); 358 mMediaCodec.releaseOutputBuffer(index, render);
375 } catch (IllegalStateException e) { 359 } catch (IllegalStateException e) {
376 // TODO(qinmin): May need to report the error to the caller. crbug.c om/356498. 360 // TODO(qinmin): May need to report the error to the caller. crbug.c om/356498.
377 Log.e(TAG, "Failed to release output buffer", e); 361 Log.e(TAG, "Failed to release output buffer", e);
378 } 362 }
379 } 363 }
380 364
381 @SuppressWarnings("deprecation") 365 @SuppressWarnings("deprecation")
382 @CalledByNative 366 @CalledByNative
383 private DequeueOutputResult dequeueOutputBuffer(long timeoutUs) { 367 private DequeueOutputResult dequeueOutputBuffer(long timeoutUs) {
384 MediaCodec.BufferInfo info = new MediaCodec.BufferInfo(); 368 MediaCodec.BufferInfo info = new MediaCodec.BufferInfo();
385 int status = MEDIA_CODEC_ERROR; 369 int status = MEDIA_CODEC_ERROR;
386 int index = -1; 370 int index = -1;
387 try { 371 try {
388 int indexOrStatus = mMediaCodec.dequeueOutputBuffer(info, timeoutUs) ; 372 int indexOrStatus = mMediaCodec.dequeueOutputBuffer(info, timeoutUs) ;
389 if (info.presentationTimeUs < mLastPresentationTimeUs) { 373 if (info.presentationTimeUs < mLastPresentationTimeUs) {
390 // TODO(qinmin): return a special code through DequeueOutputResu lt 374 // TODO(qinmin): return a special code through DequeueOutputResu lt
391 // to notify the native code the the frame has a wrong presentat ion 375 // to notify the native code the the frame has a wrong presentat ion
392 // timestamp and should be skipped. 376 // timestamp and should be skipped.
393 info.presentationTimeUs = mLastPresentationTimeUs; 377 info.presentationTimeUs = mLastPresentationTimeUs;
394 } 378 }
395 mLastPresentationTimeUs = info.presentationTimeUs; 379 mLastPresentationTimeUs = info.presentationTimeUs;
396 380
397 if (indexOrStatus >= 0) { // index! 381 if (indexOrStatus >= 0) { // index!
398 status = MEDIA_CODEC_OK; 382 status = MEDIA_CODEC_OK;
399 index = indexOrStatus; 383 index = indexOrStatus;
400 } else if (indexOrStatus == MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED) { 384 } else if (indexOrStatus == MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED) {
385 assert Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT;
401 mOutputBuffers = mMediaCodec.getOutputBuffers(); 386 mOutputBuffers = mMediaCodec.getOutputBuffers();
402 status = MEDIA_CODEC_OUTPUT_BUFFERS_CHANGED; 387 status = MEDIA_CODEC_OUTPUT_BUFFERS_CHANGED;
403 } else if (indexOrStatus == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) { 388 } else if (indexOrStatus == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) {
404 status = MEDIA_CODEC_OUTPUT_FORMAT_CHANGED; 389 status = MEDIA_CODEC_OUTPUT_FORMAT_CHANGED;
405 MediaFormat newFormat = mMediaCodec.getOutputFormat(); 390 MediaFormat newFormat = mMediaCodec.getOutputFormat();
406 if (mAudioTrack != null && newFormat.containsKey(MediaFormat.KEY _SAMPLE_RATE)) { 391 if (mAudioTrack != null && newFormat.containsKey(MediaFormat.KEY _SAMPLE_RATE)) {
407 int newSampleRate = newFormat.getInteger(MediaFormat.KEY_SAM PLE_RATE); 392 int newSampleRate = newFormat.getInteger(MediaFormat.KEY_SAM PLE_RATE);
408 if (mAudioTrack.setPlaybackRate(newSampleRate) != AudioTrack .SUCCESS) { 393 if (mAudioTrack.setPlaybackRate(newSampleRate) != AudioTrack .SUCCESS) {
409 status = MEDIA_CODEC_ERROR; 394 status = MEDIA_CODEC_ERROR;
410 } 395 }
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 608 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
624 return AudioFormat.CHANNEL_OUT_7POINT1_SURROUND; 609 return AudioFormat.CHANNEL_OUT_7POINT1_SURROUND;
625 } else { 610 } else {
626 return AudioFormat.CHANNEL_OUT_7POINT1; 611 return AudioFormat.CHANNEL_OUT_7POINT1;
627 } 612 }
628 default: 613 default:
629 return AudioFormat.CHANNEL_OUT_DEFAULT; 614 return AudioFormat.CHANNEL_OUT_DEFAULT;
630 } 615 }
631 } 616 }
632 } 617 }
OLDNEW
« no previous file with comments | « content/common/gpu/media/android_video_encode_accelerator.cc ('k') | media/base/android/media_codec_bridge.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698