Ported RTMP_ClientPacket to C_RTMP_ClientPacket - not tested yet

This commit is contained in:
saxon 2018-08-12 18:37:39 +09:30
parent 1ed14d523d
commit 1c8e7b01fc
1 changed files with 132 additions and 1 deletions

View File

@ -680,7 +680,7 @@ func C_RTMP_ParseURL(url *byte, protocol *int32, host *C.AVal, port *uint32,
host.av_val = (*C.char)(unsafe.Pointer(p))
host.av_len = C.int(hostlen)
// TODO: use new logger with this
//RTMP_Log(RTMP_LOGDEBUG, "Parsed host : %.*s", hostlen, host->av_val);
//RTMP_Log(RTMP_LOGDEBUG, "Parsed host : %.*s", hostlen, host.av_val);
} else {
// TODO: use new logger with this
// RTMP_Log(RTMP_LOGWARNING, "Hostname exceeds 255 characters!");
@ -1732,6 +1732,137 @@ func C_RTMP_ConnectStream(r *C.RTMP, seekTime int32) int {
return int(r.m_bPlaying)
}
// int RTMP_ClientPacket()
// rtmp.c +1226
func C_RTMP_ClientPacket(r *C.RTMP, packet *C.RTMPPacket) int32 {
var bHasMediaPacket int32 = 0
switch packet.m_packetType {
case RTMP_PACKET_TYPE_CHUNK_SIZE:
/* chunk size */
// TODO: port this
C.HandleChangeChunkSize(r, packet)
case RTMP_PACKET_TYPE_BYTES_READ_REPORT:
/* bytes read report */
// TODO: usue new logger here
//RTMP_Log(RTMP_LOGDEBUG, "%s, received: bytes read report", __FUNCTION__);
case RTMP_PACKET_TYPE_CONTROL:
/* ctrl */
// TODO: port this
C.HandleCtrl(r, packet)
case RTMP_PACKET_TYPE_SERVER_BW:
/* server bw */
// TODO: port this
C.HandleServerBW(r, packet)
case RTMP_PACKET_TYPE_CLIENT_BW:
/* client bw */
// TODO: port this
C.HandleClientBW(r, packet)
case RTMP_PACKET_TYPE_AUDIO:
/* audio data */
/*RTMP_Log(RTMP_LOGDEBUG, "%s, received: audio %lu bytes", __FUNCTION__, packet.m_nBodySize); */
// TODO port this
//C.HandleAudio(r, packet) NOTE this does nothing
bHasMediaPacket = 1
if r.m_mediaChannel == 0 {
r.m_mediaChannel = packet.m_nChannel
}
if r.m_pausing == 0 {
r.m_mediaStamp = packet.m_nTimeStamp
}
case RTMP_PACKET_TYPE_VIDEO:
/* video data */
/*RTMP_Log(RTMP_LOGDEBUG, "%s, received: video %lu bytes", __FUNCTION__, packet.m_nBodySize); */
// TODO port this
// C.HandleVideo(r, packet) NOTE this does nothing
bHasMediaPacket = 1
if r.m_mediaChannel == 0 {
r.m_mediaChannel = packet.m_nChannel
}
if r.m_pausing == 0 {
r.m_mediaStamp = packet.m_nTimeStamp
}
case RTMP_PACKET_TYPE_FLEX_MESSAGE:
/* flex message */
{
// TODO use new logger here
// RTMP_Log(RTMP_LOGDEBUG,"%s, flex message, size %u bytes, not fully supported", __FUNCTION__, packet.m_nBodySize);
if C.HandleInvoke(r, (*C.char)(incBytePtr(unsafe.Pointer(packet.m_body), 1)),
C.uint(packet.m_nBodySize-1)) == 1 {
bHasMediaPacket = 2
}
}
case RTMP_PACKET_TYPE_INFO:
/* metadata (notify) */
// TODO use new logger here
//RTMP_Log(RTMP_LOGDEBUG, "%s, received: notify %u bytes", __FUNCTION__,packet.m_nBodySize);
if C.HandleMetadata(r, packet.m_body, C.uint(packet.m_nBodySize)) != 0 {
bHasMediaPacket = 1
}
case RTMP_PACKET_TYPE_INVOKE:
/* invoke */
// TODO use new logger here
//RTMP_Log(RTMP_LOGDEBUG, "%s, received: invoke %u bytes", __FUNCTION__,packet.m_nBodySize);
/*RTMP_LogHex(packet.m_body, packet.m_nBodySize); */
if C.HandleInvoke(r, packet.m_body, C.uint(packet.m_nBodySize)) == 1 {
bHasMediaPacket = 2
}
case RTMP_PACKET_TYPE_FLASH_VIDEO:
{
/* go through FLV packets and handle metadata packets */
var pos uint32 = 0
var nTimeStamp uint32 = uint32(packet.m_nTimeStamp)
for pos+11 < uint32(packet.m_nBodySize) {
var dataSize uint32 = C_AMF_DecodeInt24((*byte)(incBytePtr(unsafe.Pointer(
packet.m_body), int(pos+1)))) /* size without header (11) and prevTagSize (4) */
if pos+11+dataSize+4 > uint32(packet.m_nBodySize) {
// TODO use new logger here
// RTMP_Log(RTMP_LOGWARNING, "Stream corrupt?!");
break
}
switch {
case *indxBytePtr(unsafe.Pointer(packet.m_body), int(pos)) == 0x12:
C.HandleMetadata(r, (*C.char)(incBytePtr(unsafe.Pointer(packet.m_body),
int(pos+11))), C.uint(dataSize))
case *indxBytePtr(unsafe.Pointer(packet.m_body), int(pos)) == 8 ||
*indxBytePtr(unsafe.Pointer(packet.m_body), int(pos)) == 9:
nTimeStamp = C_AMF_DecodeInt24((*byte)(incBytePtr(unsafe.Pointer(
packet.m_body), int(pos+4))))
nTimeStamp |= uint32(*indxBytePtr(unsafe.Pointer(packet.m_body),
int(pos+7)) << 24)
}
pos += (11 + dataSize + 4)
}
if r.m_pausing == 0 {
r.m_mediaStamp = C.uint32_t(nTimeStamp)
}
/* FLV tag(s) */
/*RTMP_Log(RTMP_LOGDEBUG, "%s, received: FLV tag(s) %lu bytes", __FUNCTION__, packet.m_nBodySize); */
bHasMediaPacket = 1
}
default:
// TODO use new logger here
// RTMP_Log(RTMP_LOGDEBUG, "%s, unknown packet type received: 0x%02x", __FUNCTION__,packet.m_packetType);
}
return bHasMediaPacket
}
// void RTMPPacket_Free(RTMPPacket* p);
// rtmp.c +203
func C_RTMPPacket_Free(p *C.RTMPPacket) {