Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling RTMPDataMessage. #1339

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Sources/RTMP/RTMPMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,15 @@ final class RTMPDataMessage: RTMPMessage {
return
}
stream.info.byteCount.mutate { $0 += Int64(payload.count) }
switch handlerName {
case "onMetaData":
stream.metadata = arguments[0] as? [String: Any?] ?? [:]
case "|RtmpSampleAccess":
stream.audioSampleAccess = arguments[0] as? Bool ?? true
stream.videoSampleAccess = arguments[1] as? Bool ?? true
default:
break
}
}
}

Expand Down
15 changes: 13 additions & 2 deletions Sources/RTMP/RTMPStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,16 @@ open class RTMPStream: NetStream {
}

static let defaultID: UInt32 = 0
/// The NetStreamInfo object whose properties contain data.
/// The RTMPStream metadata.
public internal(set) var metadata: [String: Any?] = [:]
/// The RTMPStreamInfo object whose properties contain data.
public internal(set) var info = RTMPStreamInfo()
/// The object encoding (AMF). Framework supports AMF0 only.
public private(set) var objectEncoding: RTMPObjectEncoding = RTMPConnection.defaultObjectEncoding
/// The boolean value that indicates audio samples allow access or not.
public internal(set) var audioSampleAccess = true
/// The boolean value that indicates video samples allow access or not.
public internal(set) var videoSampleAccess = true
/// Incoming audio plays on the stream or not.
public var receiveAudio = true {
didSet {
Expand Down Expand Up @@ -428,6 +434,9 @@ open class RTMPStream: NetStream {
case .open:
currentFPS = 0
frameCount = 0
audioSampleAccess = true
videoSampleAccess = true
metadata.removeAll()
info.clear()
delegate?.streamDidOpen(self)
for message in messages {
Expand Down Expand Up @@ -457,7 +466,9 @@ open class RTMPStream: NetStream {
dataTimeStamps.removeAll()
FCPublish()
case .publishing:
send(handlerName: "@setDataFrame", arguments: "onMetaData", makeMetaData())
let metadata = makeMetaData()
send(handlerName: "@setDataFrame", arguments: "onMetaData", metadata)
self.metadata = metadata
default:
break
}
Expand Down