From 740db747a951b668b57373bb0aa831a76236dfdc Mon Sep 17 00:00:00 2001 From: pedroSG94 Date: Tue, 1 Oct 2024 20:55:49 +0200 Subject: [PATCH] change flags to isKeyFrame --- common/src/main/java/com/pedro/common/Extensions.kt | 4 ++-- common/src/main/java/com/pedro/common/frame/MediaFrame.kt | 2 +- .../main/java/com/pedro/rtmp/flv/video/packet/Av1Packet.kt | 2 +- .../main/java/com/pedro/rtmp/flv/video/packet/H264Packet.kt | 2 +- .../main/java/com/pedro/rtmp/flv/video/packet/H265Packet.kt | 2 +- rtsp/src/main/java/com/pedro/rtsp/rtp/packets/Av1Packet.kt | 2 +- rtsp/src/main/java/com/pedro/rtsp/rtp/packets/H264Packet.kt | 2 +- srt/src/main/java/com/pedro/srt/mpeg2ts/packets/H26XPacket.kt | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/common/src/main/java/com/pedro/common/Extensions.kt b/common/src/main/java/com/pedro/common/Extensions.kt index 8b60f991c..b6074a071 100644 --- a/common/src/main/java/com/pedro/common/Extensions.kt +++ b/common/src/main/java/com/pedro/common/Extensions.kt @@ -43,7 +43,7 @@ import kotlin.coroutines.Continuation */ @Suppress("DEPRECATION") -fun MediaFrame.Info.isKeyframe(): Boolean { +fun MediaCodec.BufferInfo.isKeyframe(): Boolean { return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { this.flags == MediaCodec.BUFFER_FLAG_KEY_FRAME } else { @@ -143,7 +143,7 @@ fun Throwable.validMessage(): String { return (message ?: "").ifEmpty { javaClass.simpleName } } -fun MediaCodec.BufferInfo.toMediaFrameInfo() = MediaFrame.Info(offset, size, presentationTimeUs, flags) +fun MediaCodec.BufferInfo.toMediaFrameInfo() = MediaFrame.Info(offset, size, presentationTimeUs, isKeyframe()) fun ByteBuffer.clone(): ByteBuffer = ByteBuffer.wrap(toByteArray()) diff --git a/common/src/main/java/com/pedro/common/frame/MediaFrame.kt b/common/src/main/java/com/pedro/common/frame/MediaFrame.kt index 2959ef47f..32529c870 100644 --- a/common/src/main/java/com/pedro/common/frame/MediaFrame.kt +++ b/common/src/main/java/com/pedro/common/frame/MediaFrame.kt @@ -11,7 +11,7 @@ data class MediaFrame( val offset: Int, val size: Int, val timestamp: Long, - val flags: Int + val isKeyFrame: Boolean ) enum class Type { diff --git a/rtmp/src/main/java/com/pedro/rtmp/flv/video/packet/Av1Packet.kt b/rtmp/src/main/java/com/pedro/rtmp/flv/video/packet/Av1Packet.kt index c0ad14cc7..1c122ef81 100644 --- a/rtmp/src/main/java/com/pedro/rtmp/flv/video/packet/Av1Packet.kt +++ b/rtmp/src/main/java/com/pedro/rtmp/flv/video/packet/Av1Packet.kt @@ -96,7 +96,7 @@ class Av1Packet: BasePacket() { val size = fixedBuffer.remaining() buffer = ByteArray(header.size + size) - val nalType = if (info.isKeyframe()) VideoDataType.KEYFRAME.value else VideoDataType.INTER_FRAME.value + val nalType = if (info.isKeyFrame) VideoDataType.KEYFRAME.value else VideoDataType.INTER_FRAME.value header[0] = (0b10000000 or (nalType shl 4) or FourCCPacketType.CODED_FRAMES.value).toByte() fixedBuffer.get(buffer, header.size, size) diff --git a/rtmp/src/main/java/com/pedro/rtmp/flv/video/packet/H264Packet.kt b/rtmp/src/main/java/com/pedro/rtmp/flv/video/packet/H264Packet.kt index 3d5391e87..ac6359bd3 100644 --- a/rtmp/src/main/java/com/pedro/rtmp/flv/video/packet/H264Packet.kt +++ b/rtmp/src/main/java/com/pedro/rtmp/flv/video/packet/H264Packet.kt @@ -109,7 +109,7 @@ class H264Packet: BasePacket() { val type: Int = (validBuffer.get(0) and 0x1F).toInt() var nalType = VideoDataType.INTER_FRAME.value - if (type == VideoNalType.IDR.value || info.isKeyframe()) { + if (type == VideoNalType.IDR.value || info.isKeyFrame) { nalType = VideoDataType.KEYFRAME.value } else if (type == VideoNalType.SPS.value || type == VideoNalType.PPS.value) { // we don't need send it because we already do it in video config diff --git a/rtmp/src/main/java/com/pedro/rtmp/flv/video/packet/H265Packet.kt b/rtmp/src/main/java/com/pedro/rtmp/flv/video/packet/H265Packet.kt index 912ffd4e6..61c440842 100644 --- a/rtmp/src/main/java/com/pedro/rtmp/flv/video/packet/H265Packet.kt +++ b/rtmp/src/main/java/com/pedro/rtmp/flv/video/packet/H265Packet.kt @@ -117,7 +117,7 @@ class H265Packet: BasePacket() { val type: Int = validBuffer.get(0).toInt().shr(1 and 0x3f) var nalType = VideoDataType.INTER_FRAME.value - if (type == VideoNalType.IDR_N_LP.value || type == VideoNalType.IDR_W_DLP.value || info.isKeyframe()) { + if (type == VideoNalType.IDR_N_LP.value || type == VideoNalType.IDR_W_DLP.value || info.isKeyFrame) { nalType = VideoDataType.KEYFRAME.value } else if (type == VideoNalType.HEVC_VPS.value || type == VideoNalType.HEVC_SPS.value || type == VideoNalType.HEVC_PPS.value) { // we don't need send it because we already do it in video config diff --git a/rtsp/src/main/java/com/pedro/rtsp/rtp/packets/Av1Packet.kt b/rtsp/src/main/java/com/pedro/rtsp/rtp/packets/Av1Packet.kt index f413b840b..977b9a78c 100644 --- a/rtsp/src/main/java/com/pedro/rtsp/rtp/packets/Av1Packet.kt +++ b/rtsp/src/main/java/com/pedro/rtsp/rtp/packets/Av1Packet.kt @@ -94,7 +94,7 @@ class Av1Packet: BasePacket( markPacket(buffer) //mark end frame } val oSize = if (isFirstPacket) obuList.size else 1 - buffer[RtpConstants.RTP_HEADER_LENGTH] = generateAv1AggregationHeader(bufferInfo.isKeyframe(), isFirstPacket, isLastPacket, oSize) + buffer[RtpConstants.RTP_HEADER_LENGTH] = generateAv1AggregationHeader(bufferInfo.isKeyFrame, isFirstPacket, isLastPacket, oSize) updateSeq(buffer) val rtpFrame = RtpFrame(buffer, rtpTs, buffer.size, channelIdentifier) frames.add(rtpFrame) diff --git a/rtsp/src/main/java/com/pedro/rtsp/rtp/packets/H264Packet.kt b/rtsp/src/main/java/com/pedro/rtsp/rtp/packets/H264Packet.kt index 3d23f21a5..65e71059a 100644 --- a/rtsp/src/main/java/com/pedro/rtsp/rtp/packets/H264Packet.kt +++ b/rtsp/src/main/java/com/pedro/rtsp/rtp/packets/H264Packet.kt @@ -65,7 +65,7 @@ class H264Packet: BasePacket(RtpConstants.clockVideoFrequency, val naluLength = fixedBuffer.remaining() val type: Int = (header[header.size - 1] and 0x1F).toInt() val frames = mutableListOf() - if (type == RtpConstants.IDR || bufferInfo.isKeyframe()) { + if (type == RtpConstants.IDR || bufferInfo.isKeyFrame) { stapA?.let { val buffer = getBuffer(it.size + RtpConstants.RTP_HEADER_LENGTH) val rtpTs = updateTimeStamp(buffer, ts) diff --git a/srt/src/main/java/com/pedro/srt/mpeg2ts/packets/H26XPacket.kt b/srt/src/main/java/com/pedro/srt/mpeg2ts/packets/H26XPacket.kt index baf3b10d8..ecee92f69 100644 --- a/srt/src/main/java/com/pedro/srt/mpeg2ts/packets/H26XPacket.kt +++ b/srt/src/main/java/com/pedro/srt/mpeg2ts/packets/H26XPacket.kt @@ -57,7 +57,7 @@ class H26XPacket( val fixedBuffer = byteBuffer.removeInfo(info) val length = fixedBuffer.remaining() if (length < 0) return - val isKeyFrame = info.isKeyframe() + val isKeyFrame = info.isKeyFrame if (codec == Codec.HEVC) { val sps = this.sps