diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index 3f675515..5c61e42a 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -821,7 +821,8 @@ func readN(r *C.RTMP, buffer *byte, n int) int { avail = int(r.m_sb.sb_size) if avail == 0 { - if C.RTMPSockBuf_Fill(&r.m_sb) < 1 { + if rtmpSockBufFill(&r.m_sb) < 1 { + // if C.RTMPSockBuf_Fill(&r.m_sb) < 1 { if r.m_sb.sb_timedout == 0 { return 0 } @@ -864,6 +865,31 @@ func readN(r *C.RTMP, buffer *byte, n int) int { return nOriginalSize - n } +func rtmpSockBufFill(sb *C.RTMPSockBuf) int { + var nBytes int + + if sb.sb_size == 0 { + sb.sb_start = &sb.sb_buf[0] + } + + for { + nBytes = int(unsafe.Sizeof(sb.sb_buf)) - 1 - int(sb.sb_size) - + int(uintptr(unsafe.Pointer(sb.sb_start))-uintptr(unsafe.Pointer( + &sb.sb_buf[0]))) + + nBytes = int(C.recv(sb.sb_socket, unsafe.Pointer(uintptr(unsafe.Pointer( + sb.sb_start))+uintptr(int(sb.sb_size))), C.size_t(nBytes), 0)) + + if nBytes != -1 { + sb.sb_size += C.int(nBytes) + } else { + log.Println("rtmpSockBufFill: recv error!") + } + break + } + return nBytes +} + func sendConnectPacket(r *C.RTMP, cp *C.RTMPPacket) int { var packet C.RTMPPacket var pbuf [4096]byte