mirror of https://bitbucket.org/ausocean/av.git
rtmp: make C_WriteN take a []byte
This commit is contained in:
parent
7b69015873
commit
d1f870223c
31
rtmp/rtmp.go
31
rtmp/rtmp.go
|
@ -470,7 +470,7 @@ func C_SocksNegotiate(r *C_RTMP) (ok bool) {
|
|||
0,
|
||||
}
|
||||
|
||||
C_WriteN(r, unsafe.Pointer(&packet[0]), int(unsafe.Sizeof(packet)))
|
||||
C_WriteN(r, packet)
|
||||
|
||||
if C_ReadN(r, &packet[0], 8) != 8 {
|
||||
return false
|
||||
|
@ -642,34 +642,26 @@ func C_ReadN(r *C_RTMP, buffer *byte, n int) int {
|
|||
|
||||
// int WriteN(RTMP* r, const char* buffer, int n);
|
||||
// rtmp.c +1502
|
||||
func C_WriteN(r *C_RTMP, buffer unsafe.Pointer, n int) (ok bool) {
|
||||
ptr := buffer
|
||||
for n > 0 {
|
||||
var nBytes int
|
||||
|
||||
nBytes = int(C_RTMPSockBuf_Send(&r.m_sb, pl2b((*byte)(ptr), n)))
|
||||
|
||||
func C_WriteN(r *C_RTMP, buf []byte) (ok bool) {
|
||||
for len(buf) != 0 {
|
||||
nBytes := int(C_RTMPSockBuf_Send(&r.m_sb, buf))
|
||||
if nBytes < 0 {
|
||||
if debugMode {
|
||||
log.Println("C_WriteN, RTMP send error")
|
||||
}
|
||||
|
||||
// TODO: port this
|
||||
C_RTMP_Close(r)
|
||||
n = 1
|
||||
break
|
||||
return false
|
||||
}
|
||||
|
||||
if nBytes == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
n -= nBytes
|
||||
ptr = incBytePtr(ptr, nBytes)
|
||||
buf = buf[nBytes:]
|
||||
}
|
||||
|
||||
// !ok here is equivalent to io.ErrShortWrite.
|
||||
return n == 0
|
||||
return len(buf) == 0
|
||||
}
|
||||
|
||||
// int SendConnectPacket(RTMP* r, RTMPPacket* cp);
|
||||
|
@ -1463,7 +1455,7 @@ func C_HandShake(r *C_RTMP, FP9HandShake int32) (ok bool) {
|
|||
(*[_Gi]byte)(unsafe.Pointer(clientsig))[i] = byte(rand.Intn(256))
|
||||
}
|
||||
|
||||
if !C_WriteN(r, unsafe.Pointer(&clientbuf[0]), RTMP_SIG_SIZE+1) {
|
||||
if !C_WriteN(r, pl2b(&clientbuf[0], RTMP_SIG_SIZE+1)) {
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -1487,7 +1479,7 @@ func C_HandShake(r *C_RTMP, FP9HandShake int32) (ok bool) {
|
|||
suptime = inet.Ntohl(suptime)
|
||||
|
||||
// 2nd part of handshake
|
||||
if !C_WriteN(r, unsafe.Pointer(&serversig[0]), RTMP_SIG_SIZE) {
|
||||
if !C_WriteN(r, pl2b(&serversig[0], RTMP_SIG_SIZE)) {
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -1652,7 +1644,7 @@ func C_RTMP_SendPacket(r *C_RTMP, packet *C_RTMPPacket, queue int) (ok bool) {
|
|||
toff = incBytePtr(toff, nChunkSize+hSize)
|
||||
} else {
|
||||
// TODO: port this
|
||||
if !C_WriteN(r, header, nChunkSize+hSize) {
|
||||
if !C_WriteN(r, pl2b((*byte)(header), nChunkSize+hSize)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
@ -1693,8 +1685,7 @@ func C_RTMP_SendPacket(r *C_RTMP, packet *C_RTMPPacket, queue int) (ok bool) {
|
|||
}
|
||||
|
||||
if tbuf != nil {
|
||||
ok := C_WriteN(r, tbuf, int(uintptr(decBytePtr(toff, int(uintptr(tbuf))))))
|
||||
////C.free(tbuf)
|
||||
ok := C_WriteN(r, pl2b((*byte)(tbuf), int(uintptr(toff)-uintptr(tbuf))))
|
||||
tbuf = nil
|
||||
|
||||
if !ok {
|
||||
|
|
Loading…
Reference in New Issue