rtmp: Implement afmEncodeInt16

This commit is contained in:
Jake Lane 2018-07-19 16:56:41 +09:30
parent 283fb1e3ab
commit b18ae29132
1 changed files with 53 additions and 10 deletions

View File

@ -509,16 +509,14 @@ func afmEncodeString(output *byte, outend *byte, bv *C.AVal) *byte {
*(*C.char)(outputPtr) = C.AMF_STRING *(*C.char)(outputPtr) = C.AMF_STRING
incBytePtr(outputPtr, 1) incBytePtr(outputPtr, 1)
// TODO Encode Int16 outputPtr = unsafe.Pointer(afmEncodeInt16((*byte)(outputPtr),
outputPtr = unsafe.Pointer(C.AMF_EncodeInt16((*C.char)(outputPtr), (*byte)(outendPtr), (int16)(bv.av_len)))
(*C.char)(outendPtr), (C.short)(bv.av_len)))
} else { } else {
*(*C.char)(outputPtr) = C.AMF_LONG_STRING *(*C.char)(outputPtr) = C.AMF_LONG_STRING
incBytePtr(outputPtr, 1) incBytePtr(outputPtr, 1)
// TODO Encode Int16 outputPtr = unsafe.Pointer(afmEncodeInt32((*byte)(outputPtr),
outputPtr = unsafe.Pointer(C.AMF_EncodeInt32((*C.char)(outputPtr), (*byte)(outendPtr), (int32)(bv.av_len)))
(*C.char)(outendPtr), bv.av_len))
} }
memmove(unsafe.Pointer(outputPtr), unsafe.Pointer(bv.av_val), uintptr(bv.av_len)) memmove(unsafe.Pointer(outputPtr), unsafe.Pointer(bv.av_val), uintptr(bv.av_len))
//C.memcpy(unsafe.Pointer(outputPtr), unsafe.Pointer(bv.av_val), (C.size_t)(bv.av_len)) //C.memcpy(unsafe.Pointer(outputPtr), unsafe.Pointer(bv.av_val), (C.size_t)(bv.av_len))
@ -527,6 +525,52 @@ func afmEncodeString(output *byte, outend *byte, bv *C.AVal) *byte {
return (*byte)(outputPtr) return (*byte)(outputPtr)
} }
// afmEncodeInt16 encodes a int16 into data
func afmEncodeInt16(output *byte, outend *byte, nVal int16) *byte {
outputPtr := unsafe.Pointer(output)
outendPtr := unsafe.Pointer(outend)
if uintptr(outputPtr)+2 > uintptr(outendPtr) {
// length < 2
return nil
}
// Assign output[1]
second := (*byte)(incBytePtr(outputPtr, 1))
*second = (byte)(nVal & 0xff)
// Assign output[0]
*output = (byte)(nVal >> 8)
return (*byte)(incBytePtr(outputPtr, 2))
}
// afmEncodeInt32 encodes a int32 into data
func afmEncodeInt32(output *byte, outend *byte, nVal int32) *byte {
outputPtr := unsafe.Pointer(output)
outendPtr := unsafe.Pointer(outend)
if uintptr(outputPtr)+4 > uintptr(outendPtr) {
// length < 4
return nil
}
// Assign output[3]
forth := (*byte)(incBytePtr(outputPtr, 3))
*forth = (byte)(nVal & 0xff)
// Assign output[2]
third := (*byte)(incBytePtr(outputPtr, 2))
*third = (byte)(nVal >> 8)
// Assign output[1]
second := (*byte)(incBytePtr(outputPtr, 1))
*second = (byte)(nVal >> 16)
// Assign output[0]
*output = (byte)(nVal >> 24)
return (*byte)(incBytePtr(outputPtr, 4))
}
// 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
@ -662,7 +706,7 @@ func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int {
} }
if t >= 0xffffff { if t >= 0xffffff {
hptr = unsafe.Pointer(C.AMF_EncodeInt32((*C.char)(hptr), (*C.char)(hend), C.int(t))) hptr = unsafe.Pointer(afmEncodeInt32((*byte)(hptr), (*byte)(hend), (int32)(t)))
} }
nSize = int(packet.m_nBodySize) nSize = int(packet.m_nBodySize)
@ -739,9 +783,8 @@ func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int {
} }
if t >= 0xffffff { if t >= 0xffffff {
extendedTimestamp := incBytePtr(header, 1+cSize) extendedTimestamp := incBytePtr(header, 1+cSize)
// TODO: port this afmEncodeInt32((*byte)(extendedTimestamp),
C.AMF_EncodeInt32((*C.char)(extendedTimestamp), (*byte)(incBytePtr(extendedTimestamp, 4)), (int32)(t))
(*C.char)(incBytePtr(extendedTimestamp, 4)), C.int(t))
} }
} }
} }