Skip to content

Commit

Permalink
change flags to isKeyFrame
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroSG94 committed Oct 1, 2024
1 parent 5e0db87 commit 740db74
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions common/src/main/java/com/pedro/common/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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())

Expand Down
2 changes: 1 addition & 1 deletion common/src/main/java/com/pedro/common/frame/MediaFrame.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rtsp/src/main/java/com/pedro/rtsp/rtp/packets/Av1Packet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<RtpFrame>()
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 740db74

Please sign in to comment.