Chromium Code Reviews

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

Issue 698273003: Use MediaFormat's crop rectangle when available instead of width/height. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « no previous file | no next file » | 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 package org.chromium.media; 5 package org.chromium.media;
6 6
7 import android.media.AudioFormat; 7 import android.media.AudioFormat;
8 import android.media.AudioManager; 8 import android.media.AudioManager;
9 import android.media.AudioTrack; 9 import android.media.AudioTrack;
10 import android.media.MediaCodec; 10 import android.media.MediaCodec;
(...skipping 44 matching lines...)
55 private static final int MAX_ADAPTIVE_PLAYBACK_HEIGHT = 1080; 55 private static final int MAX_ADAPTIVE_PLAYBACK_HEIGHT = 1080;
56 56
57 // After a flush(), dequeueOutputBuffer() can often produce empty presentati on timestamps 57 // After a flush(), dequeueOutputBuffer() can often produce empty presentati on timestamps
58 // for several frames. As a result, the player may find that the time does n ot increase 58 // for several frames. As a result, the player may find that the time does n ot increase
59 // after decoding a frame. To detect this, we check whether the presentation timestamp from 59 // after decoding a frame. To detect this, we check whether the presentation timestamp from
60 // dequeueOutputBuffer() is larger than input_timestamp - MAX_PRESENTATION_T IMESTAMP_SHIFT_US 60 // dequeueOutputBuffer() is larger than input_timestamp - MAX_PRESENTATION_T IMESTAMP_SHIFT_US
61 // after a flush. And we set the presentation timestamp from dequeueOutputBu ffer() to be 61 // after a flush. And we set the presentation timestamp from dequeueOutputBu ffer() to be
62 // non-decreasing for the remaining frames. 62 // non-decreasing for the remaining frames.
63 private static final long MAX_PRESENTATION_TIMESTAMP_SHIFT_US = 100000; 63 private static final long MAX_PRESENTATION_TIMESTAMP_SHIFT_US = 100000;
64 64
65 // TODO(qinmin): Use MediaFormat constants when part of the public API.
66 private static final String KEY_CROP_LEFT = "crop-left";
67 private static final String KEY_CROP_RIGHT = "crop-right";
68 private static final String KEY_CROP_BOTTOM = "crop-bottom";
69 private static final String KEY_CROP_TOP = "crop-top";
70
65 private ByteBuffer[] mInputBuffers; 71 private ByteBuffer[] mInputBuffers;
66 private ByteBuffer[] mOutputBuffers; 72 private ByteBuffer[] mOutputBuffers;
67 73
68 private MediaCodec mMediaCodec; 74 private MediaCodec mMediaCodec;
69 private AudioTrack mAudioTrack; 75 private AudioTrack mAudioTrack;
70 private boolean mFlushed; 76 private boolean mFlushed;
71 private long mLastPresentationTimeUs; 77 private long mLastPresentationTimeUs;
72 private String mMime; 78 private String mMime;
73 private boolean mAdaptivePlaybackSupported; 79 private boolean mAdaptivePlaybackSupported;
74 80
(...skipping 162 matching lines...)
237 for (int i = 0; i < count; ++i) { 243 for (int i = 0; i < count; ++i) {
238 MediaCodecInfo info = MediaCodecList.getCodecInfoAt(i); 244 MediaCodecInfo info = MediaCodecList.getCodecInfoAt(i);
239 if (!info.isEncoder()) 245 if (!info.isEncoder())
240 continue; 246 continue;
241 247
242 String[] supportedTypes = info.getSupportedTypes(); 248 String[] supportedTypes = info.getSupportedTypes();
243 for (int j = 0; j < supportedTypes.length; ++j) { 249 for (int j = 0; j < supportedTypes.length; ++j) {
244 if (!supportedTypes[j].equalsIgnoreCase(mime)) 250 if (!supportedTypes[j].equalsIgnoreCase(mime))
245 continue; 251 continue;
246 252
247 MediaCodecInfo.CodecCapabilities capabilities = 253 MediaCodecInfo.CodecCapabilities capabilities = info.getCapabili tiesForType(mime);
gunsch 2014/11/05 00:05:51 note: this change was due to a presubmit error, pr
qinmin 2014/11/05 00:28:00 this line is now more than 100 chars long, what is
gunsch 2014/11/05 00:31:44 Yes, indentation was the warning. This is only 98
248 info.getCapabilitiesForType(mime);
249 return capabilities.colorFormats; 254 return capabilities.colorFormats;
250 } 255 }
251 } 256 }
252 return null; 257 return null;
253 } 258 }
254 259
255 @SuppressWarnings("deprecation") 260 @SuppressWarnings("deprecation")
256 private static String getDecoderNameForMime(String mime) { 261 private static String getDecoderNameForMime(String mime) {
257 int count = MediaCodecList.getCodecCount(); 262 int count = MediaCodecList.getCodecCount();
258 for (int i = 0; i < count; ++i) { 263 for (int i = 0; i < count; ++i) {
(...skipping 135 matching lines...)
394 } 399 }
395 400
396 @CalledByNative 401 @CalledByNative
397 private void stop() { 402 private void stop() {
398 mMediaCodec.stop(); 403 mMediaCodec.stop();
399 if (mAudioTrack != null) { 404 if (mAudioTrack != null) {
400 mAudioTrack.pause(); 405 mAudioTrack.pause();
401 } 406 }
402 } 407 }
403 408
409 private boolean outputFormatHasCropValues(MediaFormat format) {
410 return format.containsKey(KEY_CROP_RIGHT) && format.containsKey(KEY_CROP _LEFT)
411 && format.containsKey(KEY_CROP_BOTTOM) && format.containsKey(KEY _CROP_TOP);
412 }
413
404 @CalledByNative 414 @CalledByNative
405 private int getOutputHeight() { 415 private int getOutputHeight() {
406 return mMediaCodec.getOutputFormat().getInteger(MediaFormat.KEY_HEIGHT); 416 MediaFormat format = mMediaCodec.getOutputFormat();
417 return outputFormatHasCropValues(format)
418 ? format.getInteger(KEY_CROP_BOTTOM) - format.getInteger(KEY_CRO P_TOP) + 1
419 : format.getInteger(MediaFormat.KEY_HEIGHT);
407 } 420 }
408 421
409 @CalledByNative 422 @CalledByNative
410 private int getOutputWidth() { 423 private int getOutputWidth() {
411 return mMediaCodec.getOutputFormat().getInteger(MediaFormat.KEY_WIDTH); 424 MediaFormat format = mMediaCodec.getOutputFormat();
425 return outputFormatHasCropValues(format)
426 ? format.getInteger(KEY_CROP_RIGHT) - format.getInteger(KEY_CROP _LEFT) + 1
427 : format.getInteger(MediaFormat.KEY_WIDTH);
412 } 428 }
413 429
414 @CalledByNative 430 @CalledByNative
415 private ByteBuffer getInputBuffer(int index) { 431 private ByteBuffer getInputBuffer(int index) {
416 return mInputBuffers[index]; 432 return mInputBuffers[index];
417 } 433 }
418 434
419 @CalledByNative 435 @CalledByNative
420 private ByteBuffer getOutputBuffer(int index) { 436 private ByteBuffer getOutputBuffer(int index) {
421 return mOutputBuffers[index]; 437 return mOutputBuffers[index];
(...skipping 290 matching lines...)
712 return AudioFormat.CHANNEL_OUT_QUAD; 728 return AudioFormat.CHANNEL_OUT_QUAD;
713 case 6: 729 case 6:
714 return AudioFormat.CHANNEL_OUT_5POINT1; 730 return AudioFormat.CHANNEL_OUT_5POINT1;
715 case 8: 731 case 8:
716 return AudioFormat.CHANNEL_OUT_7POINT1; 732 return AudioFormat.CHANNEL_OUT_7POINT1;
717 default: 733 default:
718 return AudioFormat.CHANNEL_OUT_DEFAULT; 734 return AudioFormat.CHANNEL_OUT_DEFAULT;
719 } 735 }
720 } 736 }
721 } 737 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine