From 137d60bde6ca57251a0e883a4dfe5282d69aab71 Mon Sep 17 00:00:00 2001 From: saxon Date: Fri, 13 Jul 2018 03:37:57 +0930 Subject: [PATCH] Still can't find the bug --- rtmp/rtmp.go | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index 7f330aac..97a07498 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -48,6 +48,7 @@ import ( "strconv" "unsafe" _"fmt" + "math" ) const ( @@ -83,7 +84,7 @@ func NewSession(url string, connectTimeout uint) Session { func AVC(str string) C.AVal { var aval C.AVal aval.av_val = C.CString(str) - aval.av_len = C.int(unsafe.Sizeof(aval.av_val)-1) + aval.av_len = C.int(len(str)) return aval } @@ -119,6 +120,14 @@ func (s *session) Write(data []byte) (int, error) { return len(data), nil } +const ( + RTMP_PACKET_SIZE_LARGE = 0 + RTMP_PACKET_SIZE_MEDIUM = 1 + RTMP_PACKET_SIZE_SMALL = 2 + RTMP_PACKET_TYPE_INFO = 0x12 + RTMP_PACKET_TYPE_AUDIO = 0x08 + RTMP_PACKET_TYPE_VIDEO = 0x09 +) func rtmpWrite(r *C.RTMP, data []byte) int { buf := (*C.char)(unsafe.Pointer(&data[0])) var pkt = &r.m_write @@ -150,21 +159,21 @@ func rtmpWrite(r *C.RTMP, data []byte) int { buf = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(3))) pkt.m_nTimeStamp = C.AMF_DecodeInt24(buf) buf = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(3))) - pkt.m_nTimeStamp |= C.uint(*(*byte)(unsafe.Pointer(buf)) << 24) + pkt.m_nTimeStamp |= C.uint(*((*byte)(unsafe.Pointer(buf)))) << 24 buf = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(4))) s2 -= 11 - if ((pkt.m_packetType == C.RTMP_PACKET_TYPE_AUDIO || - pkt.m_packetType == C.RTMP_PACKET_TYPE_VIDEO) && - pkt.m_nTimeStamp == 0) || pkt.m_packetType == C.RTMP_PACKET_TYPE_INFO { + if ((pkt.m_packetType == RTMP_PACKET_TYPE_AUDIO || + pkt.m_packetType == RTMP_PACKET_TYPE_VIDEO) && + pkt.m_nTimeStamp == 0) || pkt.m_packetType == RTMP_PACKET_TYPE_INFO { - pkt.m_headerType = C.RTMP_PACKET_SIZE_LARGE + pkt.m_headerType = RTMP_PACKET_SIZE_LARGE - if pkt.m_packetType == C.RTMP_PACKET_TYPE_INFO { + if pkt.m_packetType == RTMP_PACKET_TYPE_INFO { pkt.m_nBodySize += 16 } } else { - pkt.m_headerType = C.RTMP_PACKET_SIZE_MEDIUM + pkt.m_headerType = RTMP_PACKET_SIZE_MEDIUM } if int(C.RTMPPacket_Alloc(pkt, pkt.m_nBodySize)) == 0 { @@ -176,10 +185,10 @@ func rtmpWrite(r *C.RTMP, data []byte) int { pend = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(enc)) + uintptr(pkt.m_nBodySize))) - if pkt.m_packetType == C.RTMP_PACKET_TYPE_INFO { + if pkt.m_packetType == RTMP_PACKET_TYPE_INFO { enc = C.AMF_EncodeString(enc, pend, &av_setDataFrame) - pkt.m_nBytesRead = (C.uint)(uintptr(unsafe.Pointer(enc)) - - uintptr(unsafe.Pointer(pkt.m_body))) + pkt.m_nBytesRead = C.uint(math.Abs(float64(uintptr(unsafe.Pointer(enc)) - + uintptr(unsafe.Pointer(pkt.m_body))))) } } else { enc = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(pkt.m_body)) +