Skip to content

Commit

Permalink
Merge pull request #141 from Tencent/bugfix/android_h265
Browse files Browse the repository at this point in the history
bug: 多线程读取导致无法正确获取codec信息,解决方法增加同步 close #139
  • Loading branch information
hexleo authored Sep 6, 2021
2 parents 7d3ca0c + 1b22ed5 commit e5827a3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -78,6 +75,7 @@ object MediaUtil {
/**
* 检查设备解码支持类型
*/
@Synchronized
fun checkSupportCodec(mimeType: String): Boolean {
if (!isTypeMapInit) {
isTypeMapInit = true
Expand Down

0 comments on commit e5827a3

Please sign in to comment.