fix:调整缓冲区大小和配置项
This commit is contained in:
parent
c8a4e5d28e
commit
c97f719ccb
@ -49,7 +49,7 @@ class VideoDecoder(
|
|||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "VideoDecoder"
|
private const val TAG = "VideoDecoder"
|
||||||
private const val TIMEOUT_US = 10000L
|
private const val TIMEOUT_US = 10000L
|
||||||
private const val INPUT_BUFFER_QUEUE_CAPACITY = 100 // 增大输入缓冲区容量
|
private const val BUFFER_QUEUE_CAPACITY = 100 // 增大输入缓冲区容量
|
||||||
}
|
}
|
||||||
|
|
||||||
// region 成员变量定义
|
// region 成员变量定义
|
||||||
@ -60,12 +60,12 @@ class VideoDecoder(
|
|||||||
private var mediaCodec: MediaCodec? = null
|
private var mediaCodec: MediaCodec? = null
|
||||||
|
|
||||||
// 输入帧队列,支持并发,容量较大以防止丢帧
|
// 输入帧队列,支持并发,容量较大以防止丢帧
|
||||||
private val inputFrameQueue = LinkedBlockingQueue<FrameData>(INPUT_BUFFER_QUEUE_CAPACITY)
|
private val inputFrameQueue = LinkedBlockingQueue<FrameData>(BUFFER_QUEUE_CAPACITY)
|
||||||
private var running = true // 解码器运行状态
|
private var running = true // 解码器运行状态
|
||||||
private val frameSeqSet = Collections.newSetFromMap(ConcurrentHashMap<Int, Boolean>()) // 防止重复帧入队
|
private val frameSeqSet = Collections.newSetFromMap(ConcurrentHashMap<Int, Boolean>()) // 防止重复帧入队
|
||||||
|
|
||||||
// 解码输出缓冲区,增大容量
|
// 解码输出缓冲区,增大容量
|
||||||
private val outputFrameQueue = LinkedBlockingQueue<DecodedFrame>(100)
|
private val outputFrameQueue = LinkedBlockingQueue<DecodedFrame>(BUFFER_QUEUE_CAPACITY)
|
||||||
|
|
||||||
// 渲染线程控制
|
// 渲染线程控制
|
||||||
private var scheduler = Executors.newSingleThreadScheduledExecutor()
|
private var scheduler = Executors.newSingleThreadScheduledExecutor()
|
||||||
@ -80,7 +80,7 @@ class VideoDecoder(
|
|||||||
|
|
||||||
// 渲染帧率(fps),可由外部控制,默认30
|
// 渲染帧率(fps),可由外部控制,默认30
|
||||||
@Volatile
|
@Volatile
|
||||||
var renderFps: Int = 20
|
var renderFps: Int = 25
|
||||||
|
|
||||||
// 兜底:记录最近一次I帧的frameSeq,P/B帧依赖校验
|
// 兜底:记录最近一次I帧的frameSeq,P/B帧依赖校验
|
||||||
@Volatile
|
@Volatile
|
||||||
@ -99,7 +99,7 @@ class VideoDecoder(
|
|||||||
// 1. 新增成员变量
|
// 1. 新增成员变量
|
||||||
@Volatile
|
@Volatile
|
||||||
private var latestRenderedTimestampMs: Long? = null
|
private var latestRenderedTimestampMs: Long? = null
|
||||||
private val MAX_ALLOWED_DELAY_MS = 650 // 最大允许延迟,单位毫秒
|
private val MAX_ALLOWED_DELAY_MS = 750 // 最大允许延迟,单位毫秒
|
||||||
@Volatile
|
@Volatile
|
||||||
private var timestampBaseMs: Long? = null
|
private var timestampBaseMs: Long? = null
|
||||||
@Volatile
|
@Volatile
|
||||||
@ -109,7 +109,7 @@ class VideoDecoder(
|
|||||||
private val reorderBuffer = mutableMapOf<Int, FrameData>() // key: frameSeq
|
private val reorderBuffer = mutableMapOf<Int, FrameData>() // key: frameSeq
|
||||||
private val receivedIFrames = mutableSetOf<Int>() // 已收到的I帧frameSeq
|
private val receivedIFrames = mutableSetOf<Int>() // 已收到的I帧frameSeq
|
||||||
private val reorderLock = ReentrantLock() // 线程安全
|
private val reorderLock = ReentrantLock() // 线程安全
|
||||||
private val MAX_REORDER_BUFFER_SIZE = 50
|
private val MAX_REORDER_BUFFER_SIZE = BUFFER_QUEUE_CAPACITY
|
||||||
|
|
||||||
// 输入帧结构体
|
// 输入帧结构体
|
||||||
private data class FrameData(
|
private data class FrameData(
|
||||||
@ -152,7 +152,7 @@ class VideoDecoder(
|
|||||||
format.setInteger(MediaFormat.KEY_LOW_LATENCY, 1)
|
format.setInteger(MediaFormat.KEY_LOW_LATENCY, 1)
|
||||||
format.setInteger(MediaFormat.KEY_PRIORITY, 0)
|
format.setInteger(MediaFormat.KEY_PRIORITY, 0)
|
||||||
format.setInteger(MediaFormat.KEY_MAX_B_FRAMES, 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-low-latency.enable", 1)
|
||||||
format.setInteger("vendor.qti-ext-dec-picture-order.enable", 0)
|
format.setInteger("vendor.qti-ext-dec-picture-order.enable", 0)
|
||||||
@ -247,9 +247,10 @@ class VideoDecoder(
|
|||||||
mainHandler.post { onFrameRendered() }
|
mainHandler.post { onFrameRendered() }
|
||||||
hasNotifiedFlutter = true
|
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 {
|
} else {
|
||||||
Log.w(TAG, "[Render] 渲染空转,无帧可渲染,当前outputFrameQueue=${outputFrameQueue.size}")
|
// Log.w(TAG, "[Render] 渲染空转,无帧可渲染,当前outputFrameQueue=${outputFrameQueue.size}")
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "[RenderTask] Exception", e)
|
Log.e(TAG, "[RenderTask] Exception", e)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user