| 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; | 11 import android.media.MediaCodecInfo; |
| 12 import android.media.MediaCodecList; | 12 import android.media.MediaCodecList; |
| 13 import android.media.MediaCrypto; | 13 import android.media.MediaCrypto; |
| 14 import android.media.MediaFormat; | 14 import android.media.MediaFormat; |
| 15 import android.os.Build; |
| 16 import android.util.Log; |
| 15 import android.view.Surface; | 17 import android.view.Surface; |
| 16 import android.util.Log; | |
| 17 | 18 |
| 18 import java.io.IOException; | 19 import java.io.IOException; |
| 19 import java.nio.ByteBuffer; | 20 import java.nio.ByteBuffer; |
| 20 import java.util.ArrayList; | 21 import java.util.ArrayList; |
| 21 import java.util.HashMap; | 22 import java.util.HashMap; |
| 22 import java.util.Map; | 23 import java.util.Map; |
| 23 | 24 |
| 24 import org.chromium.base.CalledByNative; | 25 import org.chromium.base.CalledByNative; |
| 25 import org.chromium.base.JNINamespace; | 26 import org.chromium.base.JNINamespace; |
| 26 | 27 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 @CalledByNative | 145 @CalledByNative |
| 145 private static CodecInfo[] getCodecsInfo() { | 146 private static CodecInfo[] getCodecsInfo() { |
| 146 Map<String, CodecInfo> CodecInfoMap = new HashMap<String, CodecInfo>(); | 147 Map<String, CodecInfo> CodecInfoMap = new HashMap<String, CodecInfo>(); |
| 147 int count = MediaCodecList.getCodecCount(); | 148 int count = MediaCodecList.getCodecCount(); |
| 148 for (int i = 0; i < count; ++i) { | 149 for (int i = 0; i < count; ++i) { |
| 149 MediaCodecInfo info = MediaCodecList.getCodecInfoAt(i); | 150 MediaCodecInfo info = MediaCodecList.getCodecInfoAt(i); |
| 150 if (info.isEncoder()) { | 151 if (info.isEncoder()) { |
| 151 continue; | 152 continue; |
| 152 } | 153 } |
| 153 | 154 |
| 155 boolean secureDecoderSupported = false; |
| 156 String codecString = info.getName(); |
| 157 // ".secure" codecs sometimes crash instead of throwing on pre-JBMR2 |
| 158 // platforms, but this code isn't run on them anyway (MediaDrm |
| 159 // unavailable) so we side-step the issue. http://crbug.com/314868 |
| 160 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { |
| 161 String secureCodecName = codecString + ".secure"; |
| 162 try { |
| 163 MediaCodec secureCodec = MediaCodec.createByCodecName(secure
CodecName); |
| 164 if (secureCodec != null) { |
| 165 secureDecoderSupported = true; |
| 166 secureCodec.release(); |
| 167 } |
| 168 } catch (Exception e) { |
| 169 Log.e(TAG, "Failed to create " + secureCodecName); |
| 170 } |
| 171 } |
| 172 |
| 154 String[] supportedTypes = info.getSupportedTypes(); | 173 String[] supportedTypes = info.getSupportedTypes(); |
| 155 String codecString = info.getName(); | |
| 156 String secureCodecName = codecString + ".secure"; | |
| 157 boolean secureDecoderSupported = false; | |
| 158 try { | |
| 159 MediaCodec secureCodec = MediaCodec.createByCodecName(secureCode
cName); | |
| 160 secureDecoderSupported = true; | |
| 161 secureCodec.release(); | |
| 162 } catch (Exception e) { | |
| 163 Log.e(TAG, "Failed to create " + secureCodecName); | |
| 164 } | |
| 165 for (int j = 0; j < supportedTypes.length; ++j) { | 174 for (int j = 0; j < supportedTypes.length; ++j) { |
| 166 if (!CodecInfoMap.containsKey(supportedTypes[j]) || secureDecode
rSupported) { | 175 if (!CodecInfoMap.containsKey(supportedTypes[j]) || secureDecode
rSupported) { |
| 167 CodecInfoMap.put(supportedTypes[j], new CodecInfo( | 176 CodecInfoMap.put(supportedTypes[j], new CodecInfo( |
| 168 supportedTypes[j], codecString, secureDecoderSupported))
; | 177 supportedTypes[j], codecString, secureDecoderSupported))
; |
| 169 } | 178 } |
| 170 } | 179 } |
| 171 } | 180 } |
| 172 return CodecInfoMap.values().toArray( | 181 return CodecInfoMap.values().toArray( |
| 173 new CodecInfo[CodecInfoMap.size()]); | 182 new CodecInfo[CodecInfoMap.size()]); |
| 174 } | 183 } |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 } | 489 } |
| 481 | 490 |
| 482 private void resetLastPresentationTimeIfNeeded(long presentationTimeUs) { | 491 private void resetLastPresentationTimeIfNeeded(long presentationTimeUs) { |
| 483 if (mFlushed) { | 492 if (mFlushed) { |
| 484 mLastPresentationTimeUs = | 493 mLastPresentationTimeUs = |
| 485 Math.max(presentationTimeUs - MAX_PRESENTATION_TIMESTAMP_SHI
FT_US, 0); | 494 Math.max(presentationTimeUs - MAX_PRESENTATION_TIMESTAMP_SHI
FT_US, 0); |
| 486 mFlushed = false; | 495 mFlushed = false; |
| 487 } | 496 } |
| 488 } | 497 } |
| 489 } | 498 } |
| OLD | NEW |