diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index 4711acc5..2a312d71 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -314,8 +314,6 @@ type RTMPChunk struct { c_header [RTMP_MAX_HEADER_SIZE]byte } -type ushort [2]byte - type RTMP_LNK struct { hostname AVal sockshost AVal @@ -341,8 +339,8 @@ type RTMP_LNK struct { protocol int timeout int pFlags int - socksport ushort - port ushort + socksport uint16 + port uint16 } type AMFObject struct { @@ -1167,6 +1165,34 @@ func amfPropEncode(p *C.AMFObjectProperty, pBuffer *byte, pBufEnd *byte) *byte { return pBuffer } +func amfEncode(obj *AMFObject, pBuffer *byte, pBufEnd *byte) *byte { + if uintptr(unsafe.Pointer(pBuffer))+uintptr(4) >= uintptr(unsafe.Pointer(pBufEnd)) { + return nil + } + + *(*byte)(unsafe.Pointer(pBuffer)) = AMF_OBJECT + pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), 1)) + + for i := 0; i < int(obj.o_num); i++ { + res := amfPropEncode((*C.AMFObjectProperty)(incPtr(unsafe.Pointer( + obj.o_props), i, int(unsafe.Sizeof(*obj.o_props)))), pBuffer, pBufEnd) + if res == nil { + log.Println("amfEncode: failed to encode property in index") + break + } else { + pBuffer = res + } + } + + if uintptr(incBytePtr(unsafe.Pointer(pBuffer), 3)) >= uintptr(unsafe.Pointer(pBufEnd)) { + return nil + } + + pBuffer = amfEncodeInt24(pBuffer, pBufEnd, int32(AMF_OBJECT_END)) + + return pBuffer +} + func rtmpConnectStream(r *C.RTMP, seekTime int32) int { var packet C.RTMPPacket memset((*byte)(unsafe.Pointer(&packet)), 0, int(unsafe.Sizeof(packet)))