OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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; |
11 import android.media.MediaCodecInfo; | |
12 import android.media.MediaCodecList; | |
11 import android.media.MediaCrypto; | 13 import android.media.MediaCrypto; |
12 import android.media.MediaFormat; | 14 import android.media.MediaFormat; |
13 import android.view.Surface; | 15 import android.view.Surface; |
14 import android.util.Log; | 16 import android.util.Log; |
15 | 17 |
16 import java.io.IOException; | 18 import java.io.IOException; |
17 import java.nio.ByteBuffer; | 19 import java.nio.ByteBuffer; |
18 | 20 |
19 import org.chromium.base.CalledByNative; | 21 import org.chromium.base.CalledByNative; |
20 import org.chromium.base.JNINamespace; | 22 import org.chromium.base.JNINamespace; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 @CalledByNative("DequeueOutputResult") | 75 @CalledByNative("DequeueOutputResult") |
74 private int offset() { return mOffset; } | 76 private int offset() { return mOffset; } |
75 | 77 |
76 @CalledByNative("DequeueOutputResult") | 78 @CalledByNative("DequeueOutputResult") |
77 private long presentationTimeMicroseconds() { return mPresentationTimeMi croseconds; } | 79 private long presentationTimeMicroseconds() { return mPresentationTimeMi croseconds; } |
78 | 80 |
79 @CalledByNative("DequeueOutputResult") | 81 @CalledByNative("DequeueOutputResult") |
80 private int numBytes() { return mNumBytes; } | 82 private int numBytes() { return mNumBytes; } |
81 } | 83 } |
82 | 84 |
83 private MediaCodecBridge(String mime) throws IOException { | 85 private static String getSecureDecoderNameForMime(String mime) { |
84 mMediaCodec = MediaCodec.createDecoderByType(mime); | 86 int count = MediaCodecList.getCodecCount(); |
87 for (int i = 0; i < count; ++i) { | |
88 MediaCodecInfo info = MediaCodecList.getCodecInfoAt(i); | |
89 if (info.isEncoder()) { | |
90 continue; | |
91 } | |
92 | |
93 String[] supportedTypes = info.getSupportedTypes(); | |
94 for (int j = 0; j < supportedTypes.length; ++j) { | |
95 if (supportedTypes[j].equalsIgnoreCase(mime)) { | |
96 return info.getName() + ".secure"; | |
97 } | |
98 } | |
99 } | |
100 | |
101 return null; | |
102 } | |
103 | |
104 private MediaCodecBridge(MediaCodec media_codec) { | |
105 assert(media_codec != null); | |
106 mMediaCodec = media_codec; | |
85 mLastPresentationTimeUs = 0; | 107 mLastPresentationTimeUs = 0; |
86 mFlushed = true; | 108 mFlushed = true; |
87 } | 109 } |
88 | 110 |
89 @CalledByNative | 111 @CalledByNative |
90 private static MediaCodecBridge create(String mime) { | 112 private static MediaCodecBridge create(String mime, boolean secure) { |
91 MediaCodecBridge mediaCodecBridge = null; | 113 MediaCodec media_codec = null; |
qinmin
2013/08/27 21:41:12
java coding style use camelCase
xhwang
2013/08/28 01:21:24
Done.
| |
92 try { | 114 try { |
93 mediaCodecBridge = new MediaCodecBridge(mime); | 115 if (secure) { |
94 } catch (IOException e) { | 116 media_codec = MediaCodec.createByCodecName(getSecureDecoderNameF orMime(mime)); |
95 Log.e(TAG, "Failed to create MediaCodecBridge " + e.toString()); | 117 } else { |
118 media_codec = MediaCodec.createDecoderByType(mime); | |
119 } | |
120 } catch (Exception e) { | |
qinmin
2013/08/27 21:41:12
use specific exception type
xhwang
2013/08/28 01:21:24
Well this is complicated. The old code assumes Med
| |
121 Log.e(TAG, "Failed to create MediaCodec " + e.toString()); | |
96 } | 122 } |
97 | 123 |
98 return mediaCodecBridge; | 124 if (media_codec == null) { |
125 return null; | |
126 } | |
127 | |
128 return new MediaCodecBridge(media_codec); | |
99 } | 129 } |
100 | 130 |
101 @CalledByNative | 131 @CalledByNative |
102 private void release() { | 132 private void release() { |
103 mMediaCodec.release(); | 133 mMediaCodec.release(); |
104 if (mAudioTrack != null) { | 134 if (mAudioTrack != null) { |
105 mAudioTrack.release(); | 135 mAudioTrack.release(); |
106 } | 136 } |
107 } | 137 } |
108 | 138 |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 } | 331 } |
302 | 332 |
303 private void resetLastPresentationTimeIfNeeded(long presentationTimeUs) { | 333 private void resetLastPresentationTimeIfNeeded(long presentationTimeUs) { |
304 if (mFlushed) { | 334 if (mFlushed) { |
305 mLastPresentationTimeUs = | 335 mLastPresentationTimeUs = |
306 Math.max(presentationTimeUs - MAX_PRESENTATION_TIMESTAMP_SHI FT_US, 0); | 336 Math.max(presentationTimeUs - MAX_PRESENTATION_TIMESTAMP_SHI FT_US, 0); |
307 mFlushed = false; | 337 mFlushed = false; |
308 } | 338 } |
309 } | 339 } |
310 } | 340 } |
OLD | NEW |