Browse Source

Merge branch 'master' into feature/ContentMode_Support

casscai 5 years ago
parent
commit
003130d69a

+ 1 - 1
Android/PlayerProj/animplayer/publish.gradle

@@ -23,7 +23,7 @@ ext {
     // library artifact(单个module一般就填写library name)
     artifact = 'animplayer'
     libraryName = 'animplayer'
-    libraryVersion = '2.0.13'
+    libraryVersion = '2.0.14'
     libraryDescription = ''
     // bintrayName 是你在网页Repository页面能看到的名称
     bintrayName = 'vap'

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

@@ -20,7 +20,7 @@ import com.tencent.qgame.animplayer.mask.MaskConfig
 import com.tencent.qgame.animplayer.plugin.AnimPluginManager
 import com.tencent.qgame.animplayer.util.ALog
 
-class AnimPlayer(val animView: AnimView) {
+class AnimPlayer(val animView: IAnimView) {
 
     companion object {
         private const val TAG = "${Constant.TAG}.AnimPlayer"

+ 49 - 45
Android/PlayerProj/animplayer/src/main/java/com/tencent/qgame/animplayer/AnimView.kt

@@ -30,6 +30,7 @@ import com.tencent.qgame.animplayer.inter.IAnimListener
 import com.tencent.qgame.animplayer.inter.IFetchResource
 import com.tencent.qgame.animplayer.inter.OnResourceClickListener
 import com.tencent.qgame.animplayer.mask.MaskConfig
+import com.tencent.qgame.animplayer.textureview.InnerTextureView
 import com.tencent.qgame.animplayer.util.ALog
 import com.tencent.qgame.animplayer.util.IScaleType
 import com.tencent.qgame.animplayer.util.ScaleType
@@ -37,17 +38,19 @@ import com.tencent.qgame.animplayer.util.ScaleTypeUtil
 import java.io.File
 
 open class AnimView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0):
+    IAnimView,
     FrameLayout(context, attrs, defStyleAttr),
     TextureView.SurfaceTextureListener {
 
     companion object {
         private const val TAG = "${Constant.TAG}.AnimView"
     }
+    private val player: AnimPlayer
+
     private val uiHandler by lazy { Handler(Looper.getMainLooper()) }
     private var surface: SurfaceTexture? = null
-    private var player: AnimPlayer? = null
     private var animListener: IAnimListener? = null
-    private var innerTextureView: TextureView? = null
+    private var innerTextureView: InnerTextureView? = null
     private var lastFile: FileContainer? = null
     private val scaleTypeUtil = ScaleTypeUtil()
 
@@ -90,14 +93,15 @@ open class AnimView @JvmOverloads constructor(context: Context, attrs: Attribute
     init {
         hide()
         player = AnimPlayer(this)
-        player?.animListener = animProxyListener
+        player.animListener = animProxyListener
     }
 
 
-    fun prepareTextureView() {
+    override fun prepareTextureView() {
         uiHandler.post {
             removeAllViews()
-            innerTextureView = TextureView(context).apply {
+            innerTextureView = InnerTextureView(context).apply {
+                player = this@AnimView.player
                 isOpaque = false
                 surfaceTextureListener = this@AnimView
                 layoutParams = scaleTypeUtil.getLayoutParam(this)
@@ -106,13 +110,13 @@ open class AnimView @JvmOverloads constructor(context: Context, attrs: Attribute
         }
     }
 
-    fun getSurfaceTexture(): SurfaceTexture? {
+    override fun getSurfaceTexture(): SurfaceTexture? {
         return innerTextureView?.surfaceTexture ?: surface
     }
 
     override fun onSurfaceTextureSizeChanged(surface: SurfaceTexture, width: Int, height: Int) {
         ALog.i(TAG, "onSurfaceTextureSizeChanged $width x $height")
-        player?.onSurfaceTextureSizeChanged(width, height)
+        player.onSurfaceTextureSizeChanged(width, height)
     }
 
     override fun onSurfaceTextureUpdated(surface: SurfaceTexture) {
@@ -120,7 +124,7 @@ open class AnimView @JvmOverloads constructor(context: Context, attrs: Attribute
 
     override fun onSurfaceTextureDestroyed(surface: SurfaceTexture): Boolean {
         ALog.i(TAG, "onSurfaceTextureDestroyed")
-        player?.onSurfaceTextureDestroyed()
+        player.onSurfaceTextureDestroyed()
         uiHandler.post {
             innerTextureView?.surfaceTextureListener = null
             innerTextureView = null
@@ -132,7 +136,7 @@ open class AnimView @JvmOverloads constructor(context: Context, attrs: Attribute
     override fun onSurfaceTextureAvailable(surface: SurfaceTexture, width: Int, height: Int) {
         ALog.i(TAG, "onSurfaceTextureAvailable")
         this.surface = surface
-        player?.onSurfaceTextureAvailable(width, height)
+        player.onSurfaceTextureAvailable(width, height)
     }
 
     override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
@@ -144,9 +148,9 @@ open class AnimView @JvmOverloads constructor(context: Context, attrs: Attribute
     override fun onAttachedToWindow() {
         ALog.i(TAG, "onAttachedToWindow")
         super.onAttachedToWindow()
-        player?.isDetachedFromWindow = false
+        player.isDetachedFromWindow = false
         // 自动恢复播放
-        if ((player?.playLoop ?: 0) > 0) {
+        if ((player.playLoop ?: 0) > 0) {
             lastFile?.apply {
                 startPlay(this)
             }
@@ -159,72 +163,68 @@ open class AnimView @JvmOverloads constructor(context: Context, attrs: Attribute
         if (belowKitKat()) {
             release()
         }
-        player?.isDetachedFromWindow = true
-        player?.onSurfaceTextureDestroyed()
+        player.isDetachedFromWindow = true
+        player.onSurfaceTextureDestroyed()
     }
 
-    override fun dispatchTouchEvent(ev: MotionEvent?): Boolean {
-        val res = isRunning() && ev != null && player?.pluginManager?.onDispatchTouchEvent(ev) == true
-        return if (!res) super.dispatchTouchEvent(ev) else true
-    }
 
-    open fun setAnimListener(animListener: IAnimListener?) {
+    override fun setAnimListener(animListener: IAnimListener?) {
         this.animListener = animListener
     }
 
-    open fun setFetchResource(fetchResource: IFetchResource?) {
-        player?.pluginManager?.getMixAnimPlugin()?.resourceRequest = fetchResource
+    override fun setFetchResource(fetchResource: IFetchResource?) {
+        player.pluginManager.getMixAnimPlugin()?.resourceRequest = fetchResource
     }
 
-    open fun setOnResourceClickListener(resourceClickListener: OnResourceClickListener?) {
-        player?.pluginManager?.getMixAnimPlugin()?.resourceClickListener = resourceClickListener
+    override fun setOnResourceClickListener(resourceClickListener: OnResourceClickListener?) {
+        player.pluginManager.getMixAnimPlugin()?.resourceClickListener = resourceClickListener
     }
 
     /**
      * 兼容方案,优先保证表情显示
      */
     open fun enableAutoTxtColorFill(enable: Boolean) {
-        player?.pluginManager?.getMixAnimPlugin()?.autoTxtColorFill = enable
+        player.pluginManager.getMixAnimPlugin()?.autoTxtColorFill = enable
     }
 
-    fun setLoop(playLoop: Int) {
-        player?.playLoop = playLoop
+    override fun setLoop(playLoop: Int) {
+        player.playLoop = playLoop
     }
 
-    fun supportMask(isSupport : Boolean, isEdgeBlur : Boolean) {
-        player?.supportMaskBoolean = isSupport
-        player?.maskEdgeBlurBoolean = isEdgeBlur
+    override fun supportMask(isSupport : Boolean, isEdgeBlur : Boolean) {
+        player.supportMaskBoolean = isSupport
+        player.maskEdgeBlurBoolean = isEdgeBlur
     }
 
-    fun updateMaskConfig(maskConfig: MaskConfig?) {
-        player?.updateMaskConfig(maskConfig)
+    override fun updateMaskConfig(maskConfig: MaskConfig?) {
+        player.updateMaskConfig(maskConfig)
     }
 
 
     @Deprecated("Compatible older version mp4, default false")
     fun enableVersion1(enable: Boolean) {
-        player?.enableVersion1 = enable
+        player.enableVersion1 = enable
     }
 
     // 兼容老版本视频模式
     @Deprecated("Compatible older version mp4")
     fun setVideoMode(mode: Int) {
-        player?.videoMode = mode
+        player.videoMode = mode
     }
 
-    fun setFps(fps: Int) {
-        player?.fps = fps
+    override fun setFps(fps: Int) {
+        player.fps = fps
     }
 
-    fun setScaleType(type : ScaleType) {
+    override fun setScaleType(type : ScaleType) {
         scaleTypeUtil.currentScaleType = type
     }
 
-    fun setScaleType(scaleType: IScaleType) {
+    override fun setScaleType(scaleType: IScaleType) {
         scaleTypeUtil.scaleTypeImpl = scaleType
     }
 
-    fun startPlay(file: File) {
+    override fun startPlay(file: File) {
         try {
             val fileContainer = FileContainer(file)
             startPlay(fileContainer)
@@ -233,7 +233,7 @@ open class AnimView @JvmOverloads constructor(context: Context, attrs: Attribute
         }
     }
 
-    fun startPlay(assetManager: AssetManager, assetsPath: String) {
+    override fun startPlay(assetManager: AssetManager, assetsPath: String) {
         try {
             val fileContainer = FileContainer(assetManager, assetsPath)
             startPlay(fileContainer)
@@ -243,15 +243,15 @@ open class AnimView @JvmOverloads constructor(context: Context, attrs: Attribute
     }
 
 
-    fun startPlay(fileContainer: FileContainer) {
+    override fun startPlay(fileContainer: FileContainer) {
         ui {
             if (visibility != View.VISIBLE) {
                 ALog.e(TAG, "AnimView is GONE, can't play")
                 return@ui
             }
-            if (player?.isRunning() == false) {
+            if (!player.isRunning()) {
                 lastFile = fileContainer
-                player?.startPlay(fileContainer)
+                player.startPlay(fileContainer)
             } else {
                 ALog.i(TAG, "is running can not start")
             }
@@ -259,12 +259,16 @@ open class AnimView @JvmOverloads constructor(context: Context, attrs: Attribute
     }
 
 
-    fun stopPlay() {
-        player?.stopPlay()
+    override fun stopPlay() {
+        player.stopPlay()
+    }
+
+    override fun isRunning(): Boolean {
+        return player.isRunning()
     }
 
-    fun isRunning(): Boolean {
-        return player?.isRunning() ?: false
+    override fun getRealSize(): Pair<Int, Int> {
+        return scaleTypeUtil.getRealSize()
     }
 
     private fun hide() {

+ 63 - 0
Android/PlayerProj/animplayer/src/main/java/com/tencent/qgame/animplayer/IAnimView.kt

@@ -0,0 +1,63 @@
+/*
+ * Tencent is pleased to support the open source community by making vap available.
+ *
+ * Copyright (C) 2020 THL A29 Limited, a Tencent company.  All rights reserved.
+ *
+ * Licensed under the MIT License (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://opensource.org/licenses/MIT
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.tencent.qgame.animplayer
+
+import android.content.res.AssetManager
+import android.graphics.SurfaceTexture
+import com.tencent.qgame.animplayer.inter.IAnimListener
+import com.tencent.qgame.animplayer.inter.IFetchResource
+import com.tencent.qgame.animplayer.inter.OnResourceClickListener
+import com.tencent.qgame.animplayer.mask.MaskConfig
+import com.tencent.qgame.animplayer.util.IScaleType
+import com.tencent.qgame.animplayer.util.ScaleType
+import java.io.File
+
+interface IAnimView {
+
+    fun prepareTextureView()
+
+    fun getSurfaceTexture(): SurfaceTexture?
+
+    fun setAnimListener(animListener: IAnimListener?)
+
+    fun setFetchResource(fetchResource: IFetchResource?)
+
+    fun setOnResourceClickListener(resourceClickListener: OnResourceClickListener?)
+
+    fun setLoop(playLoop: Int)
+
+    fun supportMask(isSupport: Boolean, isEdgeBlur: Boolean)
+
+    fun updateMaskConfig(maskConfig: MaskConfig?)
+
+    fun setFps(fps: Int)
+
+    fun setScaleType(type: ScaleType)
+
+    fun setScaleType(scaleType: IScaleType)
+
+    fun startPlay(file: File)
+
+    fun startPlay(assetManager: AssetManager, assetsPath: String)
+
+    fun startPlay(fileContainer: FileContainer)
+
+    fun stopPlay()
+
+    fun isRunning(): Boolean
+
+    fun getRealSize(): Pair<Int, Int>
+}

+ 3 - 4
Android/PlayerProj/animplayer/src/main/java/com/tencent/qgame/animplayer/mix/MixTouch.kt

@@ -24,8 +24,7 @@ import com.tencent.qgame.animplayer.PointRect
 class MixTouch(private val mixAnimPlugin: MixAnimPlugin) {
 
     fun onTouchEvent(ev: MotionEvent): Resource? {
-        val viewWith = mixAnimPlugin.player.animView.width
-        val viewHeight = mixAnimPlugin.player.animView.height
+        val (viewWith, viewHeight) = mixAnimPlugin.player.animView.getRealSize()
         val videoWith = mixAnimPlugin.player.configManager.config?.width ?: return null
         val videoHeight = mixAnimPlugin.player.configManager.config?.height ?: return null
 
@@ -33,8 +32,8 @@ class MixTouch(private val mixAnimPlugin: MixAnimPlugin) {
 
         when(ev.action) {
             MotionEvent.ACTION_UP -> {
-                val x = ev.rawX * videoWith / viewWith
-                val y = ev.rawY * videoHeight / viewHeight
+                val x = ev.x * videoWith / viewWith.toFloat()
+                val y = ev.y * videoHeight / viewHeight.toFloat()
                 val list = mixAnimPlugin.frameAll?.map?.get(mixAnimPlugin.curFrameIndex)?.list
                 list?.forEach {frame ->
                     val src = mixAnimPlugin.srcMap?.map?.get(frame.srcId) ?: return@forEach

+ 21 - 0
Android/PlayerProj/animplayer/src/main/java/com/tencent/qgame/animplayer/textureview/InnerTextureView.kt

@@ -0,0 +1,21 @@
+package com.tencent.qgame.animplayer.textureview
+
+import android.content.Context
+import android.util.AttributeSet
+import android.view.MotionEvent
+import android.view.TextureView
+import com.tencent.qgame.animplayer.AnimPlayer
+
+class InnerTextureView @JvmOverloads constructor(
+    context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
+) : TextureView(context, attrs, defStyleAttr) {
+
+    var player: AnimPlayer? = null
+
+    override fun dispatchTouchEvent(ev: MotionEvent?): Boolean {
+        val res = player?.isRunning() == true
+                && ev != null
+                && player?.pluginManager?.onDispatchTouchEvent(ev) == true
+        return if (!res) super.dispatchTouchEvent(ev) else true
+    }
+}

+ 74 - 19
Android/PlayerProj/animplayer/src/main/java/com/tencent/qgame/animplayer/util/ScaleTypeUtil.kt

@@ -1,3 +1,18 @@
+/*
+ * Tencent is pleased to support the open source community by making vap available.
+ *
+ * Copyright (C) 2020 THL A29 Limited, a Tencent company.  All rights reserved.
+ *
+ * Licensed under the MIT License (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://opensource.org/licenses/MIT
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package com.tencent.qgame.animplayer.util
 
 import android.view.Gravity
@@ -14,6 +29,7 @@ enum class ScaleType {
 }
 
 interface IScaleType {
+
     fun getLayoutParam(
         layoutWidth: Int,
         layoutHeight: Int,
@@ -21,9 +37,15 @@ interface IScaleType {
         videoHeight: Int,
         layoutParams: FrameLayout.LayoutParams
     ): FrameLayout.LayoutParams
+
+    fun getRealSize(): Pair<Int, Int>
 }
 
 class ScaleTypeFitXY : IScaleType {
+
+    private var realWidth = 0
+    private var realHeight = 0
+
     override fun getLayoutParam(
         layoutWidth: Int,
         layoutHeight: Int,
@@ -33,11 +55,21 @@ class ScaleTypeFitXY : IScaleType {
     ): FrameLayout.LayoutParams {
         layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT
         layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
+        realWidth = layoutWidth
+        realHeight = layoutHeight
         return layoutParams
     }
+
+    override fun getRealSize(): Pair<Int, Int> {
+        return Pair(realWidth, realHeight)
+    }
 }
 
 class ScaleTypeFitCenter : IScaleType {
+
+    private var realWidth = 0
+    private var realHeight = 0
+
     override fun getLayoutParam(
         layoutWidth: Int,
         layoutHeight: Int,
@@ -47,12 +79,18 @@ class ScaleTypeFitCenter : IScaleType {
     ): FrameLayout.LayoutParams {
         val (w, h) = getFitCenterSize(layoutWidth, layoutHeight, videoWidth, videoHeight)
         if (w <= 0 && h <= 0) return layoutParams
+        realWidth = w
+        realHeight = h
         layoutParams.width = w
         layoutParams.height = h
         layoutParams.gravity = Gravity.CENTER
         return layoutParams
     }
 
+    override fun getRealSize(): Pair<Int, Int> {
+        return Pair(realWidth, realHeight)
+    }
+
     private fun getFitCenterSize(
         layoutWidth: Int,
         layoutHeight: Int,
@@ -78,6 +116,10 @@ class ScaleTypeFitCenter : IScaleType {
 }
 
 class ScaleTypeCenterCrop : IScaleType {
+
+    private var realWidth = 0
+    private var realHeight = 0
+
     override fun getLayoutParam(
         layoutWidth: Int,
         layoutHeight: Int,
@@ -87,12 +129,18 @@ class ScaleTypeCenterCrop : IScaleType {
     ): FrameLayout.LayoutParams {
         val (w, h) = getCenterCropSize(layoutWidth, layoutHeight, videoWidth, videoHeight)
         if (w <= 0 && h <= 0) return layoutParams
+        realWidth = w
+        realHeight = h
         layoutParams.width = w
         layoutParams.height = h
         layoutParams.gravity = Gravity.CENTER
         return layoutParams
     }
 
+    override fun getRealSize(): Pair<Int, Int> {
+        return Pair(realWidth, realHeight)
+    }
+
     private fun getCenterCropSize(
         layoutWidth: Int,
         layoutHeight: Int,
@@ -138,6 +186,16 @@ class ScaleTypeUtil {
     var videoHeight = 0
 
 
+    /**
+     * 获取实际视频容器宽高
+     * @return w h
+     */
+    fun getRealSize(): Pair<Int, Int> {
+        val size = getCurrentScaleType().getRealSize()
+        ALog.i(TAG, "get real size (${size.first}, ${size.second})")
+        return size
+    }
+
     fun getLayoutParam(view: View?): FrameLayout.LayoutParams {
         val layoutParams = (view?.layoutParams as? FrameLayout.LayoutParams)
             ?: FrameLayout.LayoutParams(
@@ -152,31 +210,28 @@ class ScaleTypeUtil {
             return layoutParams
         }
 
-        var tmpScaleType = scaleTypeImpl
-        if (tmpScaleType != null) {
-            ALog.i(TAG, "custom scaleType")
-            return tmpScaleType.getLayoutParam(
-                layoutWidth,
-                layoutHeight,
-                videoWidth,
-                videoHeight,
-                layoutParams
-            )
-        }
-        ALog.i(TAG, "scaleType=$currentScaleType")
-        tmpScaleType = when (currentScaleType) {
-            ScaleType.FIT_XY -> scaleTypeFitXY
-            ScaleType.FIT_CENTER -> scaleTypeFitCenter
-            ScaleType.CENTER_CROP -> scaleTypeCenterCrop
-        }
-        tmpScaleType.getLayoutParam(
+        return getCurrentScaleType().getLayoutParam(
             layoutWidth,
             layoutHeight,
             videoWidth,
             videoHeight,
             layoutParams
         )
-        return layoutParams
+    }
+
+    private fun getCurrentScaleType(): IScaleType {
+        val tmpScaleType = scaleTypeImpl
+        return if (tmpScaleType != null) {
+            ALog.i(TAG, "custom scaleType")
+            tmpScaleType
+        } else {
+            ALog.i(TAG, "scaleType=$currentScaleType")
+            when (currentScaleType) {
+                ScaleType.FIT_XY -> scaleTypeFitXY
+                ScaleType.FIT_CENTER -> scaleTypeFitCenter
+                ScaleType.CENTER_CROP -> scaleTypeCenterCrop
+            }
+        }
     }
 
 

+ 1 - 1
Android/README.md

@@ -106,7 +106,7 @@ repositories {
 }
 
 dependencies {
-    implementation "com.egame.vap:animplayer:2.0.13"
+    implementation "com.egame.vap:animplayer:2.0.14"
 }
 ```
 

+ 2 - 2
QGVAPlayer.podspec

@@ -16,7 +16,7 @@ Pod::Spec.new do |spec|
   #
 
   spec.name         = "QGVAPlayer"
-  spec.version      = "1.0.4"
+  spec.version      = "1.0.5"
   spec.summary      = "video animation player."
   spec.platform     = :ios, "8.0"
 
@@ -85,7 +85,7 @@ Pod::Spec.new do |spec|
   #  Supports git, hg, bzr, svn and HTTP.
   #
 
-  spec.source       = { :git => "https://github.com/Tencent/vap.git", :tag => "#{spec.version}"}
+  spec.source       = { :git => "https://github.com/Tencent/vap.git", :tag => "iOS#{spec.version}"}
 
 
   # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #

+ 1 - 1
iOS/QGVAPlayer/QGVAPlayer/Classes/Controllers/Decoders/QGMP4FrameHWDecoder.m

@@ -469,7 +469,7 @@ NSString *const QGMP4HWDErrorDomain = @"QGMP4HWDErrorDomain";
 }
 
 //decode callback
-void didDecompress(void *decompressionOutputRefCon, void *sourceFrameRefCon, OSStatus status, VTDecodeInfoFlags infoFlags, CVImageBufferRef pixelBuffer, CMTime presentationTimeStamp, CMTime presentationDuration ){
+static void didDecompress(void *decompressionOutputRefCon, void *sourceFrameRefCon, OSStatus status, VTDecodeInfoFlags infoFlags, CVImageBufferRef pixelBuffer, CMTime presentationTimeStamp, CMTime presentationDuration ){
     
     CVPixelBufferRef *outputPixelBuffer = (CVPixelBufferRef *)sourceFrameRefCon;
     *outputPixelBuffer = CVPixelBufferRetain(pixelBuffer);