Browse Source

bug: 多线程读取导致无法正确获取codec信息,解决方法增加同步 close #139

hexleo 4 years ago
parent
commit
1b22ed52ea

+ 2 - 1
Android/PlayerProj/animplayer/src/main/java/com/tencent/qgame/animplayer/AudioPlayer.kt

@@ -75,7 +75,8 @@ class AudioPlayer(val player: AnimPlayer) {
         }
         extractor.selectTrack(audioIndex)
         val format = extractor.getTrackFormat(audioIndex)
-        val mime =format.getString(MediaFormat.KEY_MIME) ?: ""
+        val mime = format.getString(MediaFormat.KEY_MIME) ?: ""
+        ALog.i(TAG, "audio mime=$mime")
         if (!MediaUtil.checkSupportCodec(mime)) {
             ALog.e(TAG, "mime=$mime not support")
             release()

+ 2 - 2
Android/PlayerProj/animplayer/src/main/java/com/tencent/qgame/animplayer/HardDecoder.kt

@@ -99,12 +99,12 @@ class HardDecoder(player: AnimPlayer) : Decoder(player), SurfaceTexture.OnFrameA
             // 是否支持h265
             if (MediaUtil.checkIsHevc(format)) {
                 if (Build.VERSION.SDK_INT  < Build.VERSION_CODES.LOLLIPOP
-                    || !MediaUtil.isDeviceSupportHevc) {
+                    || !MediaUtil.checkSupportCodec(MediaUtil.MIME_HEVC)) {
 
                     onFailed(Constant.REPORT_ERROR_TYPE_HEVC_NOT_SUPPORT,
                         "${Constant.ERROR_MSG_HEVC_NOT_SUPPORT} " +
                                 "sdk:${Build.VERSION.SDK_INT}" +
-                                ",support hevc:" + MediaUtil.isDeviceSupportHevc)
+                                ",support hevc:" + MediaUtil.checkSupportCodec(MediaUtil.MIME_HEVC))
                     release(null, null)
                     return
                 }

+ 2 - 4
Android/PlayerProj/animplayer/src/main/java/com/tencent/qgame/animplayer/util/MediaUtil.kt

@@ -30,10 +30,7 @@ object MediaUtil {
     private var isTypeMapInit = false
     private val supportTypeMap = HashMap<String, Boolean>()
 
-    val isDeviceSupportHevc by lazy {
-        checkSupportCodec("video/hevc")
-    }
-
+    const val MIME_HEVC = "video/hevc"
 
     fun getExtractor(file: IFileContainer): MediaExtractor {
         val extractor = MediaExtractor()
@@ -78,6 +75,7 @@ object MediaUtil {
     /**
      * 检查设备解码支持类型
      */
+    @Synchronized
     fun checkSupportCodec(mimeType: String): Boolean {
         if (!isTypeMapInit) {
             isTypeMapInit = true