diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index e5095196..b0036153 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -778,29 +778,25 @@ func C_SendConnectPacket(r *C_RTMP, cp *C_RTMPPacket) (ok bool) { // int RTMP_SendCreateStream(RTMP* r); // rtmp.c +1725 func C_RTMP_SendCreateStream(r *C_RTMP) (ok bool) { - var packet C_RTMPPacket var pbuf [256]byte - var pend *byte = (*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(&pbuf[0])) + - unsafe.Sizeof(pbuf))) - var enc *byte + packet := C_RTMPPacket{ + m_nChannel: 0x03, /* control channel (invoke) */ + m_headerType: RTMP_PACKET_SIZE_MEDIUM, + m_packetType: RTMP_PACKET_TYPE_INVOKE, + m_nTimeStamp: 0, + m_nInfoField2: 0, + m_hasAbsTimestamp: false, + m_body: &pbuf[RTMP_MAX_HEADER_SIZE], + } + enc := pbuf[RTMP_MAX_HEADER_SIZE:] - packet.m_nChannel = 0x03 /* control channel (invoke) */ - packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM - packet.m_packetType = RTMP_PACKET_TYPE_INVOKE - packet.m_nTimeStamp = 0 - packet.m_nInfoField2 = 0 - packet.m_hasAbsTimestamp = false - packet.m_body = &pbuf[RTMP_MAX_HEADER_SIZE] - - enc = (*byte)(unsafe.Pointer(packet.m_body)) - enc = bAddr(C_AMF_EncodeString(pp2b(enc, pend), av_createStream)) + enc = C_AMF_EncodeString(enc, av_createStream) r.m_numInvokes++ - enc = bAddr(C_AMF_EncodeNumber(pp2b(enc, pend), float64(r.m_numInvokes))) - *enc = AMF_NULL - enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1)) + enc = C_AMF_EncodeNumber(enc, float64(r.m_numInvokes)) + enc[0] = AMF_NULL + enc = enc[1:] - packet.m_nBodySize = uint32(uintptr(unsafe.Pointer(enc)) - uintptr( - unsafe.Pointer(packet.m_body))) + packet.m_nBodySize = uint32((len(pbuf) - RTMP_MAX_HEADER_SIZE) - len(enc)) return C_RTMP_SendPacket(r, &packet, 1) } @@ -808,32 +804,29 @@ func C_RTMP_SendCreateStream(r *C_RTMP) (ok bool) { // int SendReleaseStream(RTMP* r); // rtmp.c +1816 func C_SendReleaseStream(r *C_RTMP) (ok bool) { - var packet C_RTMPPacket var pbuf [1024]byte - var pend *byte = (*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(&pbuf[0])) + - unsafe.Sizeof(pbuf))) - var enc *byte + packet := C_RTMPPacket{ + m_nChannel: 0x03, /* control channel (invoke) */ + m_headerType: RTMP_PACKET_SIZE_MEDIUM, + m_packetType: RTMP_PACKET_TYPE_INVOKE, + m_nTimeStamp: 0, + m_nInfoField2: 0, + m_hasAbsTimestamp: false, + m_body: &pbuf[RTMP_MAX_HEADER_SIZE], + } + enc := pbuf[RTMP_MAX_HEADER_SIZE:] - packet.m_nChannel = 0x03 /* control channel (invoke) */ - packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM - packet.m_packetType = RTMP_PACKET_TYPE_INVOKE - packet.m_nTimeStamp = 0 - packet.m_nInfoField2 = 0 - packet.m_hasAbsTimestamp = false - packet.m_body = &pbuf[RTMP_MAX_HEADER_SIZE] - - enc = (*byte)(unsafe.Pointer(packet.m_body)) - enc = bAddr(C_AMF_EncodeString(pp2b(enc, pend), av_releaseStream)) + enc = C_AMF_EncodeString(enc, av_releaseStream) r.m_numInvokes++ - enc = bAddr(C_AMF_EncodeNumber(pp2b(enc, pend), float64(r.m_numInvokes))) - *enc = AMF_NULL - enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1)) - enc = bAddr(C_AMF_EncodeString(pp2b(enc, pend), r.Link.playpath)) + enc = C_AMF_EncodeNumber(enc, float64(r.m_numInvokes)) + enc[0] = AMF_NULL + enc = enc[1:] + enc = C_AMF_EncodeString(enc, r.Link.playpath) if enc == nil { return false } - packet.m_nBodySize = uint32(uintptr(unsafe.Pointer(enc)) - uintptr( - unsafe.Pointer(packet.m_body))) + + packet.m_nBodySize = uint32((len(pbuf) - RTMP_MAX_HEADER_SIZE) - len(enc)) return C_RTMP_SendPacket(r, &packet, 0) } @@ -841,32 +834,29 @@ func C_SendReleaseStream(r *C_RTMP) (ok bool) { // int SendFCPublish(RTMP* r); // rtmp.c +1846 func C_SendFCPublish(r *C_RTMP) (ok bool) { - var packet C_RTMPPacket var pbuf [1024]byte - var pend *byte = (*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(&pbuf[0])) + - unsafe.Sizeof(pbuf))) - var enc *byte + packet := C_RTMPPacket{ + m_nChannel: 0x03, /* control channel (invoke) */ + m_headerType: RTMP_PACKET_SIZE_MEDIUM, + m_packetType: RTMP_PACKET_TYPE_INVOKE, + m_nTimeStamp: 0, + m_nInfoField2: 0, + m_hasAbsTimestamp: false, + m_body: &pbuf[RTMP_MAX_HEADER_SIZE], + } + enc := pbuf[RTMP_MAX_HEADER_SIZE:] - packet.m_nChannel = 0x03 /* control channel (invoke) */ - packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM - packet.m_packetType = RTMP_PACKET_TYPE_INVOKE - packet.m_nTimeStamp = 0 - packet.m_nInfoField2 = 0 - packet.m_hasAbsTimestamp = false - packet.m_body = &pbuf[RTMP_MAX_HEADER_SIZE] - - enc = (*byte)(unsafe.Pointer(packet.m_body)) - enc = bAddr(C_AMF_EncodeString(pp2b(enc, pend), av_FCPublish)) + enc = C_AMF_EncodeString(enc, av_FCPublish) r.m_numInvokes++ - enc = bAddr(C_AMF_EncodeNumber(pp2b(enc, pend), float64(r.m_numInvokes))) - *enc = AMF_NULL - enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1)) - enc = bAddr(C_AMF_EncodeString(pp2b(enc, pend), r.Link.playpath)) + enc = C_AMF_EncodeNumber(enc, float64(r.m_numInvokes)) + enc[0] = AMF_NULL + enc = enc[1:] + enc = C_AMF_EncodeString(enc, r.Link.playpath) if enc == nil { return false } - packet.m_nBodySize = uint32(uintptr(unsafe.Pointer(enc)) - uintptr( - unsafe.Pointer(packet.m_body))) + + packet.m_nBodySize = uint32((len(pbuf) - RTMP_MAX_HEADER_SIZE) - len(enc)) return C_RTMP_SendPacket(r, &packet, 0) } @@ -874,34 +864,30 @@ func C_SendFCPublish(r *C_RTMP) (ok bool) { // int SendFCUnpublish(RTMP *r); // rtmp.c +1875 func C_SendFCUnpublish(r *C_RTMP) (ok bool) { - var packet C_RTMPPacket var pbuf [1024]byte - var pend *byte = (*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(&pbuf[0])) + - unsafe.Sizeof(pbuf))) - var enc *byte + packet := C_RTMPPacket{ + m_nChannel: 0x03, /* control channel (invoke) */ + m_headerType: RTMP_PACKET_SIZE_MEDIUM, + m_packetType: RTMP_PACKET_TYPE_INVOKE, + m_nTimeStamp: 0, + m_nInfoField2: 0, + m_hasAbsTimestamp: false, + m_body: &pbuf[RTMP_MAX_HEADER_SIZE], + } + enc := pbuf[RTMP_MAX_HEADER_SIZE:] - packet.m_nChannel = 0x03 /* control channel (invoke) */ - packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM - packet.m_packetType = RTMP_PACKET_TYPE_INVOKE - packet.m_nTimeStamp = 0 - packet.m_nInfoField2 = 0 - packet.m_hasAbsTimestamp = false - packet.m_body = &pbuf[RTMP_MAX_HEADER_SIZE] - - enc = (*byte)(unsafe.Pointer(packet.m_body)) - enc = bAddr(C_AMF_EncodeString(pp2b(enc, pend), av_FCUnpublish)) + enc = C_AMF_EncodeString(enc, av_FCUnpublish) r.m_numInvokes++ - enc = bAddr(C_AMF_EncodeNumber(pp2b(enc, pend), float64(r.m_numInvokes))) - *enc = AMF_NULL - enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1)) - enc = bAddr(C_AMF_EncodeString(pp2b(enc, pend), r.Link.playpath)) + enc = C_AMF_EncodeNumber(enc, float64(r.m_numInvokes)) + enc[0] = AMF_NULL + enc = enc[1:] + enc = C_AMF_EncodeString(enc, r.Link.playpath) if enc == nil { return false } - packet.m_nBodySize = uint32(uintptr(unsafe.Pointer(enc)) - uintptr( - unsafe.Pointer(packet.m_body))) + packet.m_nBodySize = uint32((len(pbuf) - RTMP_MAX_HEADER_SIZE) - len(enc)) return C_RTMP_SendPacket(r, &packet, 0) } @@ -909,39 +895,35 @@ func C_SendFCUnpublish(r *C_RTMP) (ok bool) { // int SendPublish(RTMP* r); // rtmp.c +1908 func C_SendPublish(r *C_RTMP) (ok bool) { - var packet C_RTMPPacket var pbuf [1024]byte - var pend *byte = (*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(&pbuf[0])) + - unsafe.Sizeof(pbuf))) - var enc *byte + packet := C_RTMPPacket{ + m_nChannel: 0x04, /* source channel (invoke) */ + m_headerType: RTMP_PACKET_SIZE_LARGE, + m_packetType: RTMP_PACKET_TYPE_INVOKE, + m_nTimeStamp: 0, + m_nInfoField2: r.m_stream_id, + m_hasAbsTimestamp: false, + m_body: &pbuf[RTMP_MAX_HEADER_SIZE], + } + enc := pbuf[RTMP_MAX_HEADER_SIZE:] - packet.m_nChannel = 0x04 /* source channel (invoke) */ - packet.m_headerType = RTMP_PACKET_SIZE_LARGE - packet.m_packetType = RTMP_PACKET_TYPE_INVOKE - packet.m_nTimeStamp = 0 - packet.m_nInfoField2 = r.m_stream_id - packet.m_hasAbsTimestamp = false - packet.m_body = &pbuf[RTMP_MAX_HEADER_SIZE] - - enc = (*byte)(unsafe.Pointer(packet.m_body)) - enc = bAddr(C_AMF_EncodeString(pp2b(enc, pend), av_publish)) + enc = C_AMF_EncodeString(enc, av_publish) r.m_numInvokes++ - enc = bAddr(C_AMF_EncodeNumber(pp2b(enc, pend), float64(r.m_numInvokes))) - *enc = AMF_NULL - enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1)) - enc = bAddr(C_AMF_EncodeString(pp2b(enc, pend), r.Link.playpath)) + enc = C_AMF_EncodeNumber(enc, float64(r.m_numInvokes)) + enc[0] = AMF_NULL + enc = enc[1:] + enc = C_AMF_EncodeString(enc, r.Link.playpath) if enc == nil { return false } - enc = bAddr(C_AMF_EncodeString(pp2b(enc, pend), av_live)) + enc = C_AMF_EncodeString(enc, av_live) if enc == nil { return false } - packet.m_nBodySize = uint32(uintptr(unsafe.Pointer(enc)) - uintptr( - unsafe.Pointer(packet.m_body))) + packet.m_nBodySize = uint32((len(pbuf) - RTMP_MAX_HEADER_SIZE) - len(enc)) return C_RTMP_SendPacket(r, &packet, 1) } @@ -950,29 +932,26 @@ func C_SendPublish(r *C_RTMP) (ok bool) { // SendDeleteStream(RTMP *r, double dStreamId) // rtmp.c +1942 func C_SendDeleteStream(r *C_RTMP, dStreamId float64) (ok bool) { - var packet C_RTMPPacket var pbuf [256]byte - pend := (*byte)(incBytePtr(unsafe.Pointer(&pbuf[0]), 256)) - var enc *byte + packet := C_RTMPPacket{ + m_nChannel: 0x03, /* control channel (invoke) */ + m_headerType: RTMP_PACKET_SIZE_MEDIUM, + m_packetType: RTMP_PACKET_TYPE_INVOKE, + m_nTimeStamp: 0, + m_nInfoField2: 0, + m_hasAbsTimestamp: false, + m_body: &pbuf[RTMP_MAX_HEADER_SIZE], + } + enc := pbuf[RTMP_MAX_HEADER_SIZE:] - packet.m_nChannel = 0x03 /* control channel (invoke) */ - packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM - packet.m_packetType = RTMP_PACKET_TYPE_INVOKE - packet.m_nTimeStamp = 0 - packet.m_nInfoField2 = 0 - packet.m_hasAbsTimestamp = false - packet.m_body = &pbuf[RTMP_MAX_HEADER_SIZE] - - enc = (*byte)(unsafe.Pointer(packet.m_body)) - enc = bAddr(C_AMF_EncodeString(pp2b(enc, pend), av_deleteStream)) + enc = C_AMF_EncodeString(enc, av_deleteStream) r.m_numInvokes++ - enc = bAddr(C_AMF_EncodeNumber(pp2b(enc, pend), float64(r.m_numInvokes))) - *enc = AMF_NULL - enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1)) - enc = bAddr(C_AMF_EncodeNumber(pp2b(enc, pend), dStreamId)) + enc = C_AMF_EncodeNumber(enc, float64(r.m_numInvokes)) + enc[0] = AMF_NULL + enc = enc[1:] + enc = C_AMF_EncodeNumber(enc, dStreamId) - packet.m_nBodySize = uint32(uintptr(unsafe.Pointer(enc)) - uintptr( - unsafe.Pointer(packet.m_body))) + packet.m_nBodySize = uint32((len(pbuf) - RTMP_MAX_HEADER_SIZE) - len(enc)) /* no response expected */ return C_RTMP_SendPacket(r, &packet, 0) @@ -981,23 +960,22 @@ func C_SendDeleteStream(r *C_RTMP, dStreamId float64) (ok bool) { // int SendBytesReceived(RTMP* r); // rtmp.c +2080 func C_SendBytesReceived(r *C_RTMP) (ok bool) { - var packet C_RTMPPacket var pbuf [256]byte - pend := (*byte)(incBytePtr(unsafe.Pointer(&pbuf[0]), 256)) - - packet.m_nChannel = 0x02 /* control channel (invoke) */ - packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM - packet.m_packetType = RTMP_PACKET_TYPE_BYTES_READ_REPORT - packet.m_nTimeStamp = 0 - packet.m_nInfoField2 = 0 - packet.m_hasAbsTimestamp = false - packet.m_body = &pbuf[RTMP_MAX_HEADER_SIZE] - - packet.m_nBodySize = 4 - - C_AMF_EncodeInt32(pp2b(packet.m_body, pend), r.m_nBytesIn) + packet := C_RTMPPacket{ + m_nChannel: 0x02, /* control channel (invoke) */ + m_headerType: RTMP_PACKET_SIZE_MEDIUM, + m_packetType: RTMP_PACKET_TYPE_BYTES_READ_REPORT, + m_nTimeStamp: 0, + m_nInfoField2: 0, + m_hasAbsTimestamp: false, + m_body: &pbuf[RTMP_MAX_HEADER_SIZE], + } + enc := pbuf[RTMP_MAX_HEADER_SIZE:] r.m_nBytesInSent = r.m_nBytesIn + C_AMF_EncodeInt32(enc, r.m_nBytesIn) + + packet.m_nBodySize = 4 return C_RTMP_SendPacket(r, &packet, 0) } @@ -1005,29 +983,25 @@ func C_SendBytesReceived(r *C_RTMP) (ok bool) { // int SendCheckBW(RTMP* r); // rtmp.c +2105 func C_SendCheckBW(r *C_RTMP) (ok bool) { - var packet C_RTMPPacket var pbuf [256]byte - var pend *byte = (*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(&pbuf[0])) + - unsafe.Sizeof(pbuf))) - var enc *byte + packet := C_RTMPPacket{ + m_nChannel: 0x03, /* control channel (invoke) */ + m_headerType: RTMP_PACKET_SIZE_LARGE, + m_packetType: RTMP_PACKET_TYPE_INVOKE, + m_nTimeStamp: 0, + m_nInfoField2: 0, + m_hasAbsTimestamp: false, + m_body: &pbuf[RTMP_MAX_HEADER_SIZE], + } + enc := pbuf[RTMP_MAX_HEADER_SIZE:] - packet.m_nChannel = 0x03 /* control channel (invoke) */ - packet.m_headerType = RTMP_PACKET_SIZE_LARGE - packet.m_packetType = RTMP_PACKET_TYPE_INVOKE - packet.m_nTimeStamp = 0 - packet.m_nInfoField2 = 0 - packet.m_hasAbsTimestamp = false - packet.m_body = &pbuf[RTMP_MAX_HEADER_SIZE] - - enc = (*byte)(unsafe.Pointer(packet.m_body)) - enc = bAddr(C_AMF_EncodeString(pp2b(enc, pend), av__checkbw)) + enc = C_AMF_EncodeString(enc, av__checkbw) r.m_numInvokes++ - enc = bAddr(C_AMF_EncodeNumber(pp2b(enc, pend), float64(r.m_numInvokes))) - *enc = AMF_NULL - enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1)) + enc = C_AMF_EncodeNumber(enc, float64(r.m_numInvokes)) + enc[0] = AMF_NULL + enc = enc[1:] - packet.m_nBodySize = uint32(uintptr(unsafe.Pointer(enc)) - uintptr( - unsafe.Pointer(packet.m_body))) + packet.m_nBodySize = uint32((len(pbuf) - RTMP_MAX_HEADER_SIZE) - len(enc)) return C_RTMP_SendPacket(r, &packet, 0) } @@ -1043,7 +1017,6 @@ func C_AV_erase(m []C_RTMP_METHOD, i int) []C_RTMP_METHOD { // int HandleInvoke(RTMP* r, const char* body, unsigned int nBodySize); // rtmp.c +2912 func C_HandleInvoke(r *C_RTMP, body *byte, nBodySize uint32) (ok bool) { - if *body != 0x02 { // TODO use new logger here //RTMP_Log(RTMP_LOGWARNING, "%s, Sanity failed. no string method in invoke packet",