Skip to content

Commit 668e631

Browse files
authored
Merge pull request #42 from cats-oss/feature/chunktype3
Fixed RTMP chunk type 3
2 parents 755cae7 + bdf69cc commit 668e631

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

Source/Rtmp/RTMPSessionHandlePacket.swift

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,28 @@ extension RTMPSession {
180180
return true
181181

182182
case .only:
183-
streamInBuffer.didRead(1)
183+
guard let previousChunk = previousChunkMap[chunk_stream_id] else {
184+
Logger.error("could not find previous chunk with stream id \(chunk_stream_id)")
185+
return false
186+
}
187+
// the message length is the same as previous message.
188+
Logger.debug("Previous chunk length:\(previousChunk.msg_length), " +
189+
"msgid:\(previousChunk.msg_type_id), streamid:\(String(describing: previousChunk.msg_stream_id))")
190+
guard streamInBuffer.availableBytes >= 1 else {
191+
Logger.debug("Not enough a header")
192+
// DEBUG only
193+
Logger.dumpBuffer("RTMPChunk3 ERROR",
194+
buf: streamInBuffer.readBuffer, size: streamInBuffer.availableBytes)
195+
return false
196+
}
197+
var msg: [UInt8] = .init(repeating: 0, count: Int(previousChunk.msg_length))
198+
let full_msgsize = tryReadOneMessage(&msg, from_offset: 1)
199+
guard full_msgsize > 0 else {
200+
Logger.debug("Not enough one message in buffer")
201+
return false
202+
}
203+
streamInBuffer.didRead(1 + full_msgsize)
204+
handleMessage(msg, msgTypeId: previousChunk.msg_type_id)
184205
return true
185206
}
186207
}

0 commit comments

Comments
 (0)