diff --git a/android/src/main/kotlin/top/skychip/video_decode_plugin/VideoDecoder.kt b/android/src/main/kotlin/top/skychip/video_decode_plugin/VideoDecoder.kt index b73ef1d..3b5303d 100644 --- a/android/src/main/kotlin/top/skychip/video_decode_plugin/VideoDecoder.kt +++ b/android/src/main/kotlin/top/skychip/video_decode_plugin/VideoDecoder.kt @@ -49,7 +49,7 @@ class VideoDecoder( companion object { private const val TAG = "VideoDecoder" private const val TIMEOUT_US = 10000L - private const val INPUT_BUFFER_QUEUE_CAPACITY = 100 // 增大输入缓冲区容量 + private const val BUFFER_QUEUE_CAPACITY = 100 // 增大输入缓冲区容量 } // region 成员变量定义 @@ -60,12 +60,12 @@ class VideoDecoder( private var mediaCodec: MediaCodec? = null // 输入帧队列,支持并发,容量较大以防止丢帧 - private val inputFrameQueue = LinkedBlockingQueue(INPUT_BUFFER_QUEUE_CAPACITY) + private val inputFrameQueue = LinkedBlockingQueue(BUFFER_QUEUE_CAPACITY) private var running = true // 解码器运行状态 private val frameSeqSet = Collections.newSetFromMap(ConcurrentHashMap()) // 防止重复帧入队 // 解码输出缓冲区,增大容量 - private val outputFrameQueue = LinkedBlockingQueue(100) + private val outputFrameQueue = LinkedBlockingQueue(BUFFER_QUEUE_CAPACITY) // 渲染线程控制 private var scheduler = Executors.newSingleThreadScheduledExecutor() @@ -80,7 +80,7 @@ class VideoDecoder( // 渲染帧率(fps),可由外部控制,默认30 @Volatile - var renderFps: Int = 20 + var renderFps: Int = 25 // 兜底:记录最近一次I帧的frameSeq,P/B帧依赖校验 @Volatile @@ -99,7 +99,7 @@ class VideoDecoder( // 1. 新增成员变量 @Volatile private var latestRenderedTimestampMs: Long? = null - private val MAX_ALLOWED_DELAY_MS = 650 // 最大允许延迟,单位毫秒 + private val MAX_ALLOWED_DELAY_MS = 750 // 最大允许延迟,单位毫秒 @Volatile private var timestampBaseMs: Long? = null @Volatile @@ -109,7 +109,7 @@ class VideoDecoder( private val reorderBuffer = mutableMapOf() // key: frameSeq private val receivedIFrames = mutableSetOf() // 已收到的I帧frameSeq private val reorderLock = ReentrantLock() // 线程安全 - private val MAX_REORDER_BUFFER_SIZE = 50 + private val MAX_REORDER_BUFFER_SIZE = BUFFER_QUEUE_CAPACITY // 输入帧结构体 private data class FrameData( @@ -152,7 +152,7 @@ class VideoDecoder( format.setInteger(MediaFormat.KEY_LOW_LATENCY, 1) format.setInteger(MediaFormat.KEY_PRIORITY, 0) format.setInteger(MediaFormat.KEY_MAX_B_FRAMES, 0) - + format.setInteger(MediaFormat.KEY_FRAME_RATE, renderFps); // 高通解码器特定配置 format.setInteger("vendor.qti-ext-dec-low-latency.enable", 1) format.setInteger("vendor.qti-ext-dec-picture-order.enable", 0) @@ -247,9 +247,10 @@ class VideoDecoder( mainHandler.post { onFrameRendered() } hasNotifiedFlutter = true } - Log.d(TAG, "[Render] 渲染: bufferIdx=${frame.bufferIndex}, pts=${frame.timestampUs}, 当前outputFrameQueue=${outputFrameQueue.size}") + // Log.d(TAG, "[Render] 渲染: bufferIdx=${frame.bufferIndex}, pts=${frame.timestampUs}, " + +// "当前outputFrameQueue=${outputFrameQueue.size}") } else { - Log.w(TAG, "[Render] 渲染空转,无帧可渲染,当前outputFrameQueue=${outputFrameQueue.size}") +// Log.w(TAG, "[Render] 渲染空转,无帧可渲染,当前outputFrameQueue=${outputFrameQueue.size}") } } catch (e: Exception) { Log.e(TAG, "[RenderTask] Exception", e)