Ported AMF_DecodeInt32 to C_AMF_DecodeInt32

This commit is contained in:
saxon 2018-08-12 20:45:06 +09:30
parent 4f1b6ff56f
commit 1fcb91dcef
1 changed files with 22 additions and 6 deletions

View File

@ -1765,7 +1765,7 @@ func C_RTMP_ClientPacket(r *C.RTMP, packet *C.RTMPPacket) int32 {
log.Println("RTMP_PACKET_TYPE_CLIENT_BW") log.Println("RTMP_PACKET_TYPE_CLIENT_BW")
// TODO: port this // TODO: port this
//C.HandleClientBW(r, packet) //C.HandleClientBW(r, packet)
C_HandlClientBW(r, packet) C_HandleClientBW(r, packet)
/* /*
case RTMP_PACKET_TYPE_AUDIO: case RTMP_PACKET_TYPE_AUDIO:
log.Println("RTMP_PACKET_TYPE_AUDIO") log.Println("RTMP_PACKET_TYPE_AUDIO")
@ -1871,7 +1871,8 @@ func C_RTMP_ClientPacket(r *C.RTMP, packet *C.RTMPPacket) int32 {
func C_HandleChangeChunkSize(r *C.RTMP, packet *C.RTMPPacket) { func C_HandleChangeChunkSize(r *C.RTMP, packet *C.RTMPPacket) {
if packet.m_nBodySize >= 4 { if packet.m_nBodySize >= 4 {
// TODO port C.AMF_DeocdeInt32 // TODO port C.AMF_DeocdeInt32
r.m_inChunkSize = C.AMF_DecodeInt32(packet.m_body) //r.m_inChunkSize = C.int(C.AMF_DecodeInt32((*C.char)(unsafe.Pointer(packet.m_body))))
r.m_inChunkSize = C.int(C_AMF_DecodeInt32((*byte)(unsafe.Pointer(packet.m_body))))
// TODO use new logger here // TODO use new logger here
// RTMP_Log(RTMP_LOGDEBUG, "%s, received: chunk size change to %d", __FUNCTION__, r->m_inChunkSize); // RTMP_Log(RTMP_LOGDEBUG, "%s, received: chunk size change to %d", __FUNCTION__, r->m_inChunkSize);
} }
@ -1881,7 +1882,8 @@ func C_HandleChangeChunkSize(r *C.RTMP, packet *C.RTMPPacket) {
// rtmp.c +3508 // rtmp.c +3508
func C_HandlServerBW(r *C.RTMP, packet *C.RTMPPacket) { func C_HandlServerBW(r *C.RTMP, packet *C.RTMPPacket) {
// TODO port AMF_DecodeInt32 // TODO port AMF_DecodeInt32
r.m_nServerBW = C.AMF_DecodeInt32(packet.m_body) r.m_nServerBW = C.int(C_AMF_DecodeInt32((*byte)(unsafe.Pointer(packet.m_body))))
//r.m_nServerBW = C.int(C.AMF_DecodeInt32((*C.char)(unsafe.Pointer(packet.m_body))))
// TODO use new logger here // TODO use new logger here
// RTMP_Log(RTMP_LOGDEBUG, "%s: server BW = %d", __FUNCTION__, r->m_nServerBW); // RTMP_Log(RTMP_LOGDEBUG, "%s: server BW = %d", __FUNCTION__, r->m_nServerBW);
} }
@ -1889,12 +1891,14 @@ func C_HandlServerBW(r *C.RTMP, packet *C.RTMPPacket) {
// void HandleClientBW(RTMP* r, const RTMPPacket* packet); // void HandleClientBW(RTMP* r, const RTMPPacket* packet);
// rtmp.c +3515 // rtmp.c +3515
func C_HandleClientBW(r *C.RTMP, packet *C.RTMPPacket) { func C_HandleClientBW(r *C.RTMP, packet *C.RTMPPacket) {
r.m_nClientBW = C.AMF_DeocdeInt32(packet.m_body) r.m_nClientBW = C.int(C_AMF_DecodeInt32((*byte)(unsafe.Pointer(packet.m_body))))
//r.m_nClientBW = C.int(C.AMF_DecodeInt32((*C.char)(unsafe.Pointer(packet.m_body))))
if packet.m_nBodySize > 4 { if packet.m_nBodySize > 4 {
r.m_nClientBW2 = packet.m_body[4] r.m_nClientBW2 = (C.uint8_t)(*indxBytePtr(unsafe.Pointer(packet.m_body), 4))
} else { } else {
r.m_nClientBW2 = -1 //r.m_nClientBW2 = -1
r.m_nClientBW2 = 0
} }
// TODO use new logger here // TODO use new logger here
// RTMP_Log(RTMP_LOGDEBUG, "%s: client BW = %d %d", __FUNCTION__, r->m_nClientBW, // RTMP_Log(RTMP_LOGDEBUG, "%s: client BW = %d %d", __FUNCTION__, r->m_nClientBW,
@ -2134,6 +2138,18 @@ func C_DecodeInt32LE(data *byte) int32 {
*c) *c)
} }
// unsigned int AMF_DeocdeInt32(const char* data);
// amf.c +59
func C_AMF_DecodeInt32(data *byte) uint32 {
c := (*uint8)(data)
val := uint32(
int32(*c)<<24 |
int32(*(*uint8)(incBytePtr(unsafe.Pointer(c), 1)))<<16 |
int32(*(*uint8)(incBytePtr(unsafe.Pointer(c), 2)))<<8 |
int32(*(*uint8)(incBytePtr(unsafe.Pointer(c), 3))))
return uint32(val)
}
// 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(output *byte, nVal int32) int32 {