mirror of https://bitbucket.org/ausocean/av.git
Move amfEncodeString under rtmpWrite
This commit is contained in:
parent
9ac7f6d1f7
commit
f7c9719d5b
rtmp
57
rtmp/rtmp.go
57
rtmp/rtmp.go
|
@ -172,32 +172,6 @@ func (s *session) Write(data []byte) (int, error) {
|
||||||
return len(data), nil
|
return len(data), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func afmEncodeString(output *byte, outend *byte, bv *C.AVal) *byte {
|
|
||||||
outputPtr := unsafe.Pointer(output)
|
|
||||||
outendPtr := unsafe.Pointer(outend)
|
|
||||||
if (bv.av_len < 65536 && uintptr(incBytePtr(outputPtr, 1+2+int(bv.av_len))) > uintptr(outendPtr)) || uintptr(incBytePtr(outputPtr, 1+4+int(bv.av_len))) > uintptr(outendPtr) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if bv.av_len < 65536 {
|
|
||||||
*(*C.char)(outputPtr) = C.AMF_STRING
|
|
||||||
incBytePtr(outputPtr, 1)
|
|
||||||
|
|
||||||
// TODO Encode Int16
|
|
||||||
outputPtr = unsafe.Pointer(C.AMF_EncodeInt16((*C.char)(outputPtr), (*C.char)(outendPtr), (C.short)(bv.av_len)))
|
|
||||||
} else {
|
|
||||||
*(*C.char)(outputPtr) = C.AMF_LONG_STRING
|
|
||||||
incBytePtr(outputPtr, 1)
|
|
||||||
|
|
||||||
// TODO Encode Int16
|
|
||||||
outputPtr = unsafe.Pointer(C.AMF_EncodeInt32((*C.char)(outputPtr), (*C.char)(outendPtr), bv.av_len))
|
|
||||||
}
|
|
||||||
C.memcpy(unsafe.Pointer(outputPtr), unsafe.Pointer(bv.av_val), (C.ulong)(bv.av_len))
|
|
||||||
incBytePtr(outputPtr, int(bv.av_len))
|
|
||||||
|
|
||||||
return (*byte)(outputPtr)
|
|
||||||
}
|
|
||||||
|
|
||||||
// rtmpWrite writes data to the current rtmp connection encapsulated by r
|
// rtmpWrite writes data to the current rtmp connection encapsulated by r
|
||||||
func rtmpWrite(r *C.RTMP, data []byte) int {
|
func rtmpWrite(r *C.RTMP, data []byte) int {
|
||||||
buf := sliceToPtr(data)
|
buf := sliceToPtr(data)
|
||||||
|
@ -295,6 +269,33 @@ func rtmpWrite(r *C.RTMP, data []byte) int {
|
||||||
return size + s2
|
return size + s2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func afmEncodeString(output *byte, outend *byte, bv *C.AVal) *byte {
|
||||||
|
outputPtr := unsafe.Pointer(output)
|
||||||
|
outendPtr := unsafe.Pointer(outend)
|
||||||
|
if (bv.av_len < 65536 && uintptr(incBytePtr(outputPtr, 1+2+int(bv.av_len))) > uintptr(outendPtr)) || uintptr(incBytePtr(outputPtr, 1+4+int(bv.av_len))) > uintptr(outendPtr) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if bv.av_len < 65536 {
|
||||||
|
*(*C.char)(outputPtr) = C.AMF_STRING
|
||||||
|
incBytePtr(outputPtr, 1)
|
||||||
|
|
||||||
|
// TODO Encode Int16
|
||||||
|
outputPtr = unsafe.Pointer(C.AMF_EncodeInt16((*C.char)(outputPtr), (*C.char)(outendPtr), (C.short)(bv.av_len)))
|
||||||
|
} else {
|
||||||
|
*(*C.char)(outputPtr) = C.AMF_LONG_STRING
|
||||||
|
incBytePtr(outputPtr, 1)
|
||||||
|
|
||||||
|
// TODO Encode Int16
|
||||||
|
outputPtr = unsafe.Pointer(C.AMF_EncodeInt32((*C.char)(outputPtr), (*C.char)(outendPtr), bv.av_len))
|
||||||
|
}
|
||||||
|
C.memcpy(unsafe.Pointer(outputPtr), unsafe.Pointer(bv.av_val), (C.ulong)(bv.av_len))
|
||||||
|
incBytePtr(outputPtr, int(bv.av_len))
|
||||||
|
|
||||||
|
return (*byte)(outputPtr)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// send packet version 1 - less C stuff
|
// send packet version 1 - less C stuff
|
||||||
func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int {
|
func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int {
|
||||||
var prevPacket *C.RTMPPacket
|
var prevPacket *C.RTMPPacket
|
||||||
|
@ -604,7 +605,7 @@ func writeN(r *C.RTMP, buffer unsafe.Pointer, n int) int {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
// TODO: port RTMP_METHOD
|
// TODO: port RTMP_METHOD
|
||||||
func avQueue(vals **C.RTMP_METHOD, num *int, av *C.AVal, txn int ) {
|
func avQueue(vals **C.RTMP_METHOD, num *int, av *C.AVal, txn int ) {
|
||||||
var rtmpMethodPtr *C.RTMP_METHOD
|
var rtmpMethodPtr *C.RTMP_METHOD
|
||||||
|
@ -622,7 +623,7 @@ func avQueue(vals **C.RTMP_METHOD, num *int, av *C.AVal, txn int ) {
|
||||||
(*(*C.RTMP_METHOD)(incPtr(unsafe.Pointer(*vals),*num,
|
(*(*C.RTMP_METHOD)(incPtr(unsafe.Pointer(*vals),*num,
|
||||||
int(unsafe.Sizeof(rtmpMethodPtr))))).name.av_val = (*C.char)(tmp)
|
int(unsafe.Sizeof(rtmpMethodPtr))))).name.av_val = (*C.char)(tmp)
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
// indxBytePtr returns a byte at the indx inc give a ptr
|
// indxBytePtr returns a byte at the indx inc give a ptr
|
||||||
func indxBytePtr(ptr unsafe.Pointer, inc int) *byte {
|
func indxBytePtr(ptr unsafe.Pointer, inc int) *byte {
|
||||||
|
|
Loading…
Reference in New Issue