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,
|
0,
|
||||||
}
|
}
|
||||||
|
|
||||||
C_WriteN(r, unsafe.Pointer(&packet[0]), int(unsafe.Sizeof(packet)))
|
C_WriteN(r, packet)
|
||||||
|
|
||||||
if C_ReadN(r, &packet[0], 8) != 8 {
|
if C_ReadN(r, &packet[0], 8) != 8 {
|
||||||
return false
|
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);
|
// int WriteN(RTMP* r, const char* buffer, int n);
|
||||||
// rtmp.c +1502
|
// rtmp.c +1502
|
||||||
func C_WriteN(r *C_RTMP, buffer unsafe.Pointer, n int) (ok bool) {
|
func C_WriteN(r *C_RTMP, buf []byte) (ok bool) {
|
||||||
ptr := buffer
|
for len(buf) != 0 {
|
||||||
for n > 0 {
|
nBytes := int(C_RTMPSockBuf_Send(&r.m_sb, buf))
|
||||||
var nBytes int
|
|
||||||
|
|
||||||
nBytes = int(C_RTMPSockBuf_Send(&r.m_sb, pl2b((*byte)(ptr), n)))
|
|
||||||
|
|
||||||
if nBytes < 0 {
|
if nBytes < 0 {
|
||||||
if debugMode {
|
if debugMode {
|
||||||
log.Println("C_WriteN, RTMP send error")
|
log.Println("C_WriteN, RTMP send error")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: port this
|
|
||||||
C_RTMP_Close(r)
|
C_RTMP_Close(r)
|
||||||
n = 1
|
return false
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if nBytes == 0 {
|
if nBytes == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
buf = buf[nBytes:]
|
||||||
n -= nBytes
|
|
||||||
ptr = incBytePtr(ptr, nBytes)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// !ok here is equivalent to io.ErrShortWrite.
|
// !ok here is equivalent to io.ErrShortWrite.
|
||||||
return n == 0
|
return len(buf) == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// int SendConnectPacket(RTMP* r, RTMPPacket* cp);
|
// 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))
|
(*[_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
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1487,7 +1479,7 @@ func C_HandShake(r *C_RTMP, FP9HandShake int32) (ok bool) {
|
||||||
suptime = inet.Ntohl(suptime)
|
suptime = inet.Ntohl(suptime)
|
||||||
|
|
||||||
// 2nd part of handshake
|
// 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
|
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)
|
toff = incBytePtr(toff, nChunkSize+hSize)
|
||||||
} else {
|
} else {
|
||||||
// TODO: port this
|
// TODO: port this
|
||||||
if !C_WriteN(r, header, nChunkSize+hSize) {
|
if !C_WriteN(r, pl2b((*byte)(header), nChunkSize+hSize)) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1693,8 +1685,7 @@ func C_RTMP_SendPacket(r *C_RTMP, packet *C_RTMPPacket, queue int) (ok bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if tbuf != nil {
|
if tbuf != nil {
|
||||||
ok := C_WriteN(r, tbuf, int(uintptr(decBytePtr(toff, int(uintptr(tbuf))))))
|
ok := C_WriteN(r, pl2b((*byte)(tbuf), int(uintptr(toff)-uintptr(tbuf))))
|
||||||
////C.free(tbuf)
|
|
||||||
tbuf = nil
|
tbuf = nil
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
Loading…
Reference in New Issue