rtmp: make C_EncodeInt32LE take a []byte dst

This commit is contained in:
Dan Kortschak 2018-09-14 21:28:19 +09:30
parent 4f2beed32f
commit a2620e003b
1 changed files with 4 additions and 10 deletions

View File

@ -47,6 +47,7 @@ import "C"
import ( import (
"bytes" "bytes"
"encoding/binary"
"errors" "errors"
"fmt" "fmt"
"log" "log"
@ -1242,14 +1243,8 @@ func C_DecodeInt32LE(data []byte) int32 {
// int EncodeInt32LE(char* output, int nVal); // int EncodeInt32LE(char* output, int nVal);
// rtmp.c +3537 // rtmp.c +3537
func C_EncodeInt32LE(output *byte, nVal int32) int32 { func C_EncodeInt32LE(dst []byte, v int32) int32 {
*output = byte(nVal) binary.LittleEndian.PutUint32(dst, uint32(v))
nVal >>= 8
(*[_Gi]byte)(unsafe.Pointer(output))[1] = byte(nVal)
nVal >>= 8
(*[_Gi]byte)(unsafe.Pointer(output))[2] = byte(nVal)
nVal >>= 8
(*[_Gi]byte)(unsafe.Pointer(output))[3] = byte(nVal)
return 4 return 4
} }
@ -1613,8 +1608,7 @@ func C_RTMP_SendPacket(r *C_RTMP, packet *C_RTMPPacket, queue int) (ok bool) {
} }
if nSize > 8 { if nSize > 8 {
// TODO: port this hptr = incBytePtr(hptr, int(C_EncodeInt32LE((*[_Gi]byte)(hptr)[:4], packet.m_nInfoField2)))
hptr = incBytePtr(hptr, int(C_EncodeInt32LE((*byte)(hptr), packet.m_nInfoField2)))
} }
if t >= 0xffffff { if t >= 0xffffff {