mirror of https://bitbucket.org/ausocean/av.git
rtmp: simplify recv call in C_RTMPSockBuf_Fill
This commit is contained in:
parent
b9fcb2202f
commit
bb6ee2a3ce
19
rtmp/rtmp.go
19
rtmp/rtmp.go
|
@ -615,10 +615,9 @@ func C_ReadN(r *C_RTMP, buffer *byte, n int) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
if nRead > 0 {
|
if nRead > 0 {
|
||||||
memmove(unsafe.Pointer(ptr), unsafe.Pointer(r.m_sb.sb_start), uintptr(nRead))
|
memmove(unsafe.Pointer(ptr), unsafe.Pointer(&r.m_sb.sb_buf[r.m_sb.sb_start]), uintptr(nRead))
|
||||||
r.m_sb.sb_start = (*byte)(incBytePtr(unsafe.Pointer(r.m_sb.sb_start),
|
r.m_sb.sb_start += nRead
|
||||||
nRead))
|
r.m_sb.sb_size -= nRead
|
||||||
r.m_sb.sb_size -= int32(nRead)
|
|
||||||
nBytes = nRead
|
nBytes = nRead
|
||||||
r.m_nBytesIn += int32(nRead)
|
r.m_nBytesIn += int32(nRead)
|
||||||
if r.m_bSendCounter && r.m_nBytesIn > (r.m_nBytesInSent+r.m_nClientBW/10) {
|
if r.m_bSendCounter && r.m_nBytesIn > (r.m_nBytesInSent+r.m_nClientBW/10) {
|
||||||
|
@ -1797,15 +1796,11 @@ func C_CloseInternal(r *C_RTMP, reconnect int32) {
|
||||||
// rtmp.c +4253
|
// rtmp.c +4253
|
||||||
func C_RTMPSockBuf_Fill(sb *C_RTMPSockBuf) int {
|
func C_RTMPSockBuf_Fill(sb *C_RTMPSockBuf) int {
|
||||||
if sb.sb_size == 0 {
|
if sb.sb_size == 0 {
|
||||||
sb.sb_start = &sb.sb_buf[0]
|
sb.sb_start = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
nBytes := C.long(unsafe.Sizeof(sb.sb_buf)) - 1 - C.long(sb.sb_size) -
|
nBytes := C.long((len(sb.sb_buf) - 1) - (sb.sb_size + sb.sb_start))
|
||||||
C.long(uintptr(unsafe.Pointer(sb.sb_start))-uintptr(unsafe.Pointer(
|
nBytes, err := C.recv(C.int(sb.sb_socket), unsafe.Pointer(&sb.sb_buf[sb.sb_start+sb.sb_size]), C.size_t(nBytes), 0)
|
||||||
&sb.sb_buf[0])))
|
|
||||||
|
|
||||||
nBytes, err := C.recv(C.int(sb.sb_socket), unsafe.Pointer(uintptr(unsafe.Pointer(
|
|
||||||
sb.sb_start))+uintptr(int(sb.sb_size))), C.size_t(nBytes), 0)
|
|
||||||
if nBytes == -1 {
|
if nBytes == -1 {
|
||||||
log.Printf("C_RTMPSockBuf_Fill: recv error: %v", err)
|
log.Printf("C_RTMPSockBuf_Fill: recv error: %v", err)
|
||||||
if err == syscall.EWOULDBLOCK || err == syscall.EAGAIN {
|
if err == syscall.EWOULDBLOCK || err == syscall.EAGAIN {
|
||||||
|
@ -1813,7 +1808,7 @@ func C_RTMPSockBuf_Fill(sb *C_RTMPSockBuf) int {
|
||||||
nBytes = 0
|
nBytes = 0
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sb.sb_size += int32(nBytes)
|
sb.sb_size += int(nBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
return int(nBytes)
|
return int(nBytes)
|
||||||
|
|
|
@ -137,8 +137,8 @@ type C_RTMPPacket struct {
|
||||||
// rtmp.h +127
|
// rtmp.h +127
|
||||||
type C_RTMPSockBuf struct {
|
type C_RTMPSockBuf struct {
|
||||||
sb_socket int32
|
sb_socket int32
|
||||||
sb_size int32
|
sb_size int
|
||||||
sb_start *byte
|
sb_start int
|
||||||
sb_buf [RTMP_BUFFER_CACHE_SIZE]byte // port const
|
sb_buf [RTMP_BUFFER_CACHE_SIZE]byte // port const
|
||||||
sb_timedout bool
|
sb_timedout bool
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue