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

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

Issue 1869103002: Enable adaptive playback for spitzer, use conservative size. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: removed a stale comment. Created 4 years, 8 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 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 } 448 }
449 449
450 return new DequeueOutputResult( 450 return new DequeueOutputResult(
451 status, index, info.flags, info.offset, info.presentationTimeUs, info.size); 451 status, index, info.flags, info.offset, info.presentationTimeUs, info.size);
452 } 452 }
453 453
454 @CalledByNative 454 @CalledByNative
455 private boolean configureVideo(MediaFormat format, Surface surface, MediaCry pto crypto, 455 private boolean configureVideo(MediaFormat format, Surface surface, MediaCry pto crypto,
456 int flags, boolean allowAdaptivePlayback) { 456 int flags, boolean allowAdaptivePlayback) {
457 try { 457 try {
458 if (mAdaptivePlaybackSupported && allowAdaptivePlayback) { 458 // If adaptive playback is turned off by request, then treat it as
459 format.setInteger(MediaFormat.KEY_MAX_WIDTH, MAX_ADAPTIVE_PLAYBA CK_WIDTH); 459 // not supported. Note that configureVideo is only called once
460 format.setInteger(MediaFormat.KEY_MAX_HEIGHT, MAX_ADAPTIVE_PLAYB ACK_HEIGHT); 460 // during creation, else this would prevent re-enabling adaptive
461 // playback later.
462 if (!allowAdaptivePlayback) mAdaptivePlaybackSupported = false;
463
464 if (mAdaptivePlaybackSupported) {
465 // The max size is a hint to the codec, and causes it to
466 // allocate more memory up front. It still supports higher
467 // resolutions if they arrive. So, we try to ask only for
468 // the initial size now, if it's known.
469 final int max_width = format.containsKey(MediaFormat.KEY_WIDTH)
Tima Vaisburd 2016/04/07 18:50:01 I think KEY_WITH and KEY_HEIGHT are mandatory keys
liberato (no reviews please) 2016/04/07 20:46:29 Done.
470 ? format.getInteger(MediaFormat.KEY_WIDTH)
471 : MAX_ADAPTIVE_PLAYBACK_WIDTH;
472 final int max_height = format.containsKey(MediaFormat.KEY_HEIGHT )
473 ? format.getInteger(MediaFormat.KEY_HEIGHT)
474 : MAX_ADAPTIVE_PLAYBACK_HEIGHT;
475 format.setInteger(MediaFormat.KEY_MAX_WIDTH, max_width);
476 format.setInteger(MediaFormat.KEY_MAX_HEIGHT, max_height);
461 } 477 }
462 mMediaCodec.configure(format, surface, crypto, flags); 478 mMediaCodec.configure(format, surface, crypto, flags);
463 return true; 479 return true;
464 } catch (IllegalArgumentException e) { 480 } catch (IllegalArgumentException e) {
465 Log.e(TAG, "Cannot configure the video codec, wrong format or surfac e", e); 481 Log.e(TAG, "Cannot configure the video codec, wrong format or surfac e", e);
466 } catch (IllegalStateException e) { 482 } catch (IllegalStateException e) {
467 Log.e(TAG, "Cannot configure the video codec", e); 483 Log.e(TAG, "Cannot configure the video codec", e);
468 } catch (MediaCodec.CryptoException e) { 484 } catch (MediaCodec.CryptoException e) {
469 Log.e(TAG, "Cannot configure the video codec: DRM error", e); 485 Log.e(TAG, "Cannot configure the video codec: DRM error", e);
470 } catch (Exception e) { 486 } catch (Exception e) {
(...skipping 18 matching lines...) Expand all
489 MediaFormat format = MediaFormat.createVideoFormat(mime, width, height); 505 MediaFormat format = MediaFormat.createVideoFormat(mime, width, height);
490 format.setInteger(MediaFormat.KEY_BIT_RATE, bitRate); 506 format.setInteger(MediaFormat.KEY_BIT_RATE, bitRate);
491 format.setInteger(MediaFormat.KEY_FRAME_RATE, frameRate); 507 format.setInteger(MediaFormat.KEY_FRAME_RATE, frameRate);
492 format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, iFrameInterval); 508 format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, iFrameInterval);
493 format.setInteger(MediaFormat.KEY_COLOR_FORMAT, colorFormat); 509 format.setInteger(MediaFormat.KEY_COLOR_FORMAT, colorFormat);
494 return format; 510 return format;
495 } 511 }
496 512
497 @CalledByNative 513 @CalledByNative
498 private boolean isAdaptivePlaybackSupported(int width, int height) { 514 private boolean isAdaptivePlaybackSupported(int width, int height) {
499 if (!mAdaptivePlaybackSupported) return false; 515 // If media codec has adaptive playback supported, then the max sizes
500 return width <= MAX_ADAPTIVE_PLAYBACK_WIDTH && height <= MAX_ADAPTIVE_PL AYBACK_HEIGHT; 516 // used during creation are only hints.
517 return mAdaptivePlaybackSupported;
501 } 518 }
502 519
503 @CalledByNative 520 @CalledByNative
504 private static void setCodecSpecificData(MediaFormat format, int index, byte [] bytes) { 521 private static void setCodecSpecificData(MediaFormat format, int index, byte [] bytes) {
505 // Codec Specific Data is set in the MediaFormat as ByteBuffer entries w ith keys csd-0, 522 // Codec Specific Data is set in the MediaFormat as ByteBuffer entries w ith keys csd-0,
506 // csd-1, and so on. See: http://developer.android.com/reference/android /media/MediaCodec.html 523 // csd-1, and so on. See: http://developer.android.com/reference/android /media/MediaCodec.html
507 // for details. 524 // for details.
508 String name; 525 String name;
509 switch (index) { 526 switch (index) {
510 case 0: 527 case 0:
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 682 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
666 return AudioFormat.CHANNEL_OUT_7POINT1_SURROUND; 683 return AudioFormat.CHANNEL_OUT_7POINT1_SURROUND;
667 } else { 684 } else {
668 return AudioFormat.CHANNEL_OUT_7POINT1; 685 return AudioFormat.CHANNEL_OUT_7POINT1;
669 } 686 }
670 default: 687 default:
671 return AudioFormat.CHANNEL_OUT_DEFAULT; 688 return AudioFormat.CHANNEL_OUT_DEFAULT;
672 } 689 }
673 } 690 }
674 } 691 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698