Created AMF 'enum'

This commit is contained in:
saxon 2018-07-28 17:14:02 +09:30
parent 7ddd2ac6d1
commit fadac283e5
1 changed files with 36 additions and 13 deletions

View File

@ -77,6 +77,26 @@ const (
RTMPT_IDLE
RTMPT_CLOSE
)
const (
AMF_NUMBER = iota
AMF_BOOLEAN
AMF_STRING
AMF_OBJECT
AMF_MOVIECLIP /* reserved, not used */
AMF_NULL
AMF_UNDEFINED
AMF_REFERENCE
AMF_ECMA_ARRAY
AMF_OBJECT_END
AMF_STRICT_ARRAY
AMF_DATE
AMF_LONG_STRING
AMF_UNSUPPORTED
AMF_RECORDSET /* reserved, not used */
AMF_XML_DOC
AMF_TYPED_OBJECT
AMF_AVMPLUS /* switch to AMF3 */
)
const (
RTMP_PACKET_TYPE_CHUNK_SIZE = 0x01
@ -135,6 +155,7 @@ const (
RTMP_SWF_HASHLEN = 32
RTMP_SIG_SIZE = 1536
RTMP_LARGE_HEADER_SIZE = 12
AMF_INVALID = 0xff
)
const (
@ -724,15 +745,14 @@ func rtmpConnect1(r *C.RTMP, cp *C.RTMPPacket) int {
if debugMode {
log.Println("... handshaked...")
}
if C.SendConnectPacket(r, cp) == 0 {
//if sendConnectPacket(r, cp) == 0 {
//if C.SendConnectPacket(r, cp) == 0 {
if sendConnectPacket(r, cp) == 0 {
log.Println("RTMP connect failed!")
return 0
}
return 1
}
// TODO: complete this
func handShake(r *C.RTMP, FP9HandShake int32) int {
var bMatch int
//uptime := uint32(0)
@ -923,7 +943,8 @@ func sendConnectPacket(r *C.RTMP, cp *C.RTMPPacket) int {
var enc *byte
if cp != nil {
return sendPacket(r, cp, 1)
//return rtmpSendPacket(r, cp, 1)
return int(C.RTMP_SendPacket(r, cp, 1))
}
packet.m_nChannel = 0x03
@ -936,15 +957,17 @@ func sendConnectPacket(r *C.RTMP, cp *C.RTMPPacket) int {
RTMP_MAX_HEADER_SIZE))
enc = (*byte)(unsafe.Pointer(packet.m_body))
enc = amfEncodeString(enc, (*byte)(pend), &av_connect)
enc = (*C.char)(unsafe.Pointer(C.AMF_EncodeString(enc, (*C.char)(unsafe.Pointer(pend)), &av_connect)))
// enc = amfEncodeString(enc, pend, &av_connect)
r.m_numInvokes += 1
// TODO: port this
enc = amfEncodeNumber(enc, pend, float64(r.m_numInvokes))
enc = (*byte)(unsafe.Pointer(C.AMF_EncodeNumber((*C.char))))
//enc = amfEncodeNumber(enc, pend, float64(r.m_numInvokes))
// TODO: port this const
*indxBytePtr(unsafe.Pointer(enc), 0) = C.AMF_OBJECT
// TODO: port this
enc = amfEncodeNamedString(enc, pend, &av_app, &r.Link.app)
enc = (*C.char)(unsafe.Pointer(C.AMF_EncodeNamedString((*C.char)(
unsafe.Pointer(enc)), (*C.char)(unsafe.Pointer(pend)), &av_app, &r.Link.app)))
// enc = amfEncodeNamedString(enc, pend, &av_app, &r.Link.app)
if enc == nil {
return 0
}
@ -1054,7 +1077,7 @@ func sendConnectPacket(r *C.RTMP, cp *C.RTMPPacket) int {
packet.m_nBodySize = C.uint32_t(int(uintptr(decBytePtr(unsafe.Pointer(enc),
int(uintptr(unsafe.Pointer(packet.m_body)))))))
return sendPacket(r, &packet, 1)
return rtmpSendPacket(r, &packet, 1)
}
func rtmpConnectStream(r *C.RTMP, seekTime int32) int {
@ -1186,7 +1209,7 @@ func rtmpWrite(r *C.RTMP, data []byte) int {
buf = incBytePtr(buf, num)
if pkt.m_nBytesRead == pkt.m_nBodySize {
// TODO: Port this
ret = sendPacket(r, pkt, 0)
ret = rtmpSendPacket(r, pkt, 0)
// TODO: Port this
C.RTMPPacket_Free(pkt)
pkt.m_nBytesRead = 0
@ -1204,7 +1227,7 @@ func rtmpWrite(r *C.RTMP, data []byte) int {
}
// send packet version 1 - less C stuff
func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int {
func rtmpSendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int {
var prevPacket *C.RTMPPacket
last := 0
var nSize, hSize, cSize, nChunkSize, tlen int
@ -1346,7 +1369,7 @@ func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int {
nChunkSize = int(r.m_outChunkSize)
if debugMode {
log.Printf("sendPacket: fd=%v, size=%v", r.m_sb.sb_socket, nSize)
log.Printf("rtmpSendPacket: fd=%v, size=%v", r.m_sb.sb_socket, nSize)
}
// send all chunks in one HTTP request