mirror of https://bitbucket.org/ausocean/av.git
rtmp: make C_AMF_EncodeNumber take []byte
This commit is contained in:
parent
00b4e167f4
commit
458eb932aa
24
rtmp/amf.go
24
rtmp/amf.go
|
@ -172,22 +172,14 @@ func C_AMF_EncodeString(dst []byte, val string) *byte {
|
||||||
|
|
||||||
// char* AMF_EncodeNumber(char* output, char* outend, double dVal);
|
// char* AMF_EncodeNumber(char* output, char* outend, double dVal);
|
||||||
// amf.c +199
|
// amf.c +199
|
||||||
func C_AMF_EncodeNumber(output *byte, outend *byte, dVal float64) *byte {
|
func C_AMF_EncodeNumber(dst []byte, val float64) *byte {
|
||||||
if int(uintptr(unsafe.Pointer(output)))+1+8 > int(uintptr(unsafe.Pointer(outend))) {
|
if len(dst) < 9 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// TODO: port this
|
dst[0] = AMF_NUMBER
|
||||||
*(*byte)(unsafe.Pointer(output)) = AMF_NUMBER
|
dst = dst[1:]
|
||||||
output = (*byte)(incBytePtr(unsafe.Pointer(output), 1))
|
binary.BigEndian.PutUint64(dst, math.Float64bits(val))
|
||||||
// NOTE: here we are assuming little endian for both byte order and float
|
return &dst[8:][0]
|
||||||
// word order
|
|
||||||
var ci, co *uint8
|
|
||||||
ci = (*uint8)(unsafe.Pointer(&dVal))
|
|
||||||
co = (*uint8)(unsafe.Pointer(output))
|
|
||||||
for i := 0; i < 8; i++ {
|
|
||||||
(*[_Gi]byte)(unsafe.Pointer(co))[i] = (*[_Gi]byte)(unsafe.Pointer(ci))[7-i]
|
|
||||||
}
|
|
||||||
return (*byte)(incBytePtr(unsafe.Pointer(output), 8))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// char* AMF_EncodeBoolean(char* output, char* outend, int bVal);
|
// char* AMF_EncodeBoolean(char* output, char* outend, int bVal);
|
||||||
|
@ -232,7 +224,7 @@ func C_AMF_EncodeNamedNumber(output *byte, outend *byte, key string, val float64
|
||||||
binary.BigEndian.PutUint16(dst[:2], uint16(len(key)))
|
binary.BigEndian.PutUint16(dst[:2], uint16(len(key)))
|
||||||
copy(dst[2:], key)
|
copy(dst[2:], key)
|
||||||
output = (*byte)(incBytePtr(unsafe.Pointer(output), 2+len(key)))
|
output = (*byte)(incBytePtr(unsafe.Pointer(output), 2+len(key)))
|
||||||
return C_AMF_EncodeNumber(output, outend, val)
|
return C_AMF_EncodeNumber(pp2b(output, outend), val)
|
||||||
}
|
}
|
||||||
|
|
||||||
// char* AMF_EncodeNamedBoolean(char* output, char* outend, const C_AVal* strname, int bVal);
|
// char* AMF_EncodeNamedBoolean(char* output, char* outend, const C_AVal* strname, int bVal);
|
||||||
|
@ -303,7 +295,7 @@ func C_AMF_PropEncode(p *C_AMFObjectProperty, pBuffer *byte, pBufEnd *byte) *byt
|
||||||
|
|
||||||
switch p.p_type {
|
switch p.p_type {
|
||||||
case AMF_NUMBER:
|
case AMF_NUMBER:
|
||||||
pBuffer = C_AMF_EncodeNumber(pBuffer, pBufEnd, p.p_vu.p_number)
|
pBuffer = C_AMF_EncodeNumber(pp2b(pBuffer, pBufEnd), p.p_vu.p_number)
|
||||||
case AMF_BOOLEAN:
|
case AMF_BOOLEAN:
|
||||||
pBuffer = C_AMF_EncodeBoolean(pp2b(pBuffer, pBufEnd), p.p_vu.p_number != 0)
|
pBuffer = C_AMF_EncodeBoolean(pp2b(pBuffer, pBufEnd), p.p_vu.p_number != 0)
|
||||||
case AMF_STRING:
|
case AMF_STRING:
|
||||||
|
|
18
rtmp/rtmp.go
18
rtmp/rtmp.go
|
@ -673,7 +673,7 @@ func C_SendConnectPacket(r *C_RTMP, cp *C_RTMPPacket) (ok bool) {
|
||||||
enc = C_AMF_EncodeString(pp2b(enc, pend), av_connect)
|
enc = C_AMF_EncodeString(pp2b(enc, pend), av_connect)
|
||||||
|
|
||||||
r.m_numInvokes += 1
|
r.m_numInvokes += 1
|
||||||
enc = C_AMF_EncodeNumber(enc, pend, float64(r.m_numInvokes))
|
enc = C_AMF_EncodeNumber(pp2b(enc, pend), float64(r.m_numInvokes))
|
||||||
|
|
||||||
(*[_Gi]byte)(unsafe.Pointer(enc))[0] = AMF_OBJECT
|
(*[_Gi]byte)(unsafe.Pointer(enc))[0] = AMF_OBJECT
|
||||||
|
|
||||||
|
@ -808,7 +808,7 @@ func C_RTMP_SendCreateStream(r *C_RTMP) (ok bool) {
|
||||||
enc = (*byte)(unsafe.Pointer(packet.m_body))
|
enc = (*byte)(unsafe.Pointer(packet.m_body))
|
||||||
enc = C_AMF_EncodeString(pp2b(enc, pend), av_createStream)
|
enc = C_AMF_EncodeString(pp2b(enc, pend), av_createStream)
|
||||||
r.m_numInvokes++
|
r.m_numInvokes++
|
||||||
enc = C_AMF_EncodeNumber(enc, pend, float64(r.m_numInvokes))
|
enc = C_AMF_EncodeNumber(pp2b(enc, pend), float64(r.m_numInvokes))
|
||||||
*enc = AMF_NULL
|
*enc = AMF_NULL
|
||||||
enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1))
|
enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1))
|
||||||
|
|
||||||
|
@ -838,7 +838,7 @@ func C_SendReleaseStream(r *C_RTMP) (ok bool) {
|
||||||
enc = (*byte)(unsafe.Pointer(packet.m_body))
|
enc = (*byte)(unsafe.Pointer(packet.m_body))
|
||||||
enc = C_AMF_EncodeString(pp2b(enc, pend), av_releaseStream)
|
enc = C_AMF_EncodeString(pp2b(enc, pend), av_releaseStream)
|
||||||
r.m_numInvokes++
|
r.m_numInvokes++
|
||||||
enc = C_AMF_EncodeNumber(enc, pend, float64(r.m_numInvokes))
|
enc = C_AMF_EncodeNumber(pp2b(enc, pend), float64(r.m_numInvokes))
|
||||||
*enc = AMF_NULL
|
*enc = AMF_NULL
|
||||||
enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1))
|
enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1))
|
||||||
enc = C_AMF_EncodeString(pp2b(enc, pend), r.Link.playpath)
|
enc = C_AMF_EncodeString(pp2b(enc, pend), r.Link.playpath)
|
||||||
|
@ -871,7 +871,7 @@ func C_SendFCPublish(r *C_RTMP) (ok bool) {
|
||||||
enc = (*byte)(unsafe.Pointer(packet.m_body))
|
enc = (*byte)(unsafe.Pointer(packet.m_body))
|
||||||
enc = C_AMF_EncodeString(pp2b(enc, pend), av_FCPublish)
|
enc = C_AMF_EncodeString(pp2b(enc, pend), av_FCPublish)
|
||||||
r.m_numInvokes++
|
r.m_numInvokes++
|
||||||
enc = C_AMF_EncodeNumber(enc, pend, float64(r.m_numInvokes))
|
enc = C_AMF_EncodeNumber(pp2b(enc, pend), float64(r.m_numInvokes))
|
||||||
*enc = AMF_NULL
|
*enc = AMF_NULL
|
||||||
enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1))
|
enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1))
|
||||||
enc = C_AMF_EncodeString(pp2b(enc, pend), r.Link.playpath)
|
enc = C_AMF_EncodeString(pp2b(enc, pend), r.Link.playpath)
|
||||||
|
@ -904,7 +904,7 @@ func C_SendFCUnpublish(r *C_RTMP) (ok bool) {
|
||||||
enc = (*byte)(unsafe.Pointer(packet.m_body))
|
enc = (*byte)(unsafe.Pointer(packet.m_body))
|
||||||
enc = C_AMF_EncodeString(pp2b(enc, pend), av_FCUnpublish)
|
enc = C_AMF_EncodeString(pp2b(enc, pend), av_FCUnpublish)
|
||||||
r.m_numInvokes++
|
r.m_numInvokes++
|
||||||
enc = C_AMF_EncodeNumber(enc, pend, float64(r.m_numInvokes))
|
enc = C_AMF_EncodeNumber(pp2b(enc, pend), float64(r.m_numInvokes))
|
||||||
*enc = AMF_NULL
|
*enc = AMF_NULL
|
||||||
enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1))
|
enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1))
|
||||||
enc = C_AMF_EncodeString(pp2b(enc, pend), r.Link.playpath)
|
enc = C_AMF_EncodeString(pp2b(enc, pend), r.Link.playpath)
|
||||||
|
@ -939,7 +939,7 @@ func C_SendPublish(r *C_RTMP) (ok bool) {
|
||||||
enc = (*byte)(unsafe.Pointer(packet.m_body))
|
enc = (*byte)(unsafe.Pointer(packet.m_body))
|
||||||
enc = C_AMF_EncodeString(pp2b(enc, pend), av_publish)
|
enc = C_AMF_EncodeString(pp2b(enc, pend), av_publish)
|
||||||
r.m_numInvokes++
|
r.m_numInvokes++
|
||||||
enc = C_AMF_EncodeNumber(enc, pend, float64(r.m_numInvokes))
|
enc = C_AMF_EncodeNumber(pp2b(enc, pend), float64(r.m_numInvokes))
|
||||||
*enc = AMF_NULL
|
*enc = AMF_NULL
|
||||||
enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1))
|
enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1))
|
||||||
enc = C_AMF_EncodeString(pp2b(enc, pend), r.Link.playpath)
|
enc = C_AMF_EncodeString(pp2b(enc, pend), r.Link.playpath)
|
||||||
|
@ -979,10 +979,10 @@ func C_SendDeleteStream(r *C_RTMP, dStreamId float64) (ok bool) {
|
||||||
enc = (*byte)(unsafe.Pointer(packet.m_body))
|
enc = (*byte)(unsafe.Pointer(packet.m_body))
|
||||||
enc = C_AMF_EncodeString(pp2b(enc, pend), av_deleteStream)
|
enc = C_AMF_EncodeString(pp2b(enc, pend), av_deleteStream)
|
||||||
r.m_numInvokes++
|
r.m_numInvokes++
|
||||||
enc = C_AMF_EncodeNumber(enc, pend, float64(r.m_numInvokes))
|
enc = C_AMF_EncodeNumber(pp2b(enc, pend), float64(r.m_numInvokes))
|
||||||
*enc = AMF_NULL
|
*enc = AMF_NULL
|
||||||
enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1))
|
enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1))
|
||||||
enc = C_AMF_EncodeNumber(enc, pend, dStreamId)
|
enc = C_AMF_EncodeNumber(pp2b(enc, pend), dStreamId)
|
||||||
|
|
||||||
packet.m_nBodySize = uint32(uintptr(unsafe.Pointer(enc)) - uintptr(
|
packet.m_nBodySize = uint32(uintptr(unsafe.Pointer(enc)) - uintptr(
|
||||||
unsafe.Pointer(packet.m_body)))
|
unsafe.Pointer(packet.m_body)))
|
||||||
|
@ -1035,7 +1035,7 @@ func C_SendCheckBW(r *C_RTMP) (ok bool) {
|
||||||
enc = (*byte)(unsafe.Pointer(packet.m_body))
|
enc = (*byte)(unsafe.Pointer(packet.m_body))
|
||||||
enc = C_AMF_EncodeString(pp2b(enc, pend), av__checkbw)
|
enc = C_AMF_EncodeString(pp2b(enc, pend), av__checkbw)
|
||||||
r.m_numInvokes++
|
r.m_numInvokes++
|
||||||
enc = C_AMF_EncodeNumber(enc, pend, float64(r.m_numInvokes))
|
enc = C_AMF_EncodeNumber(pp2b(enc, pend), float64(r.m_numInvokes))
|
||||||
*enc = AMF_NULL
|
*enc = AMF_NULL
|
||||||
enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1))
|
enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue