mirror of https://bitbucket.org/ausocean/av.git
rtmp: use []byte for encoding in C_SendConnectPacket
This commit is contained in:
parent
55e454453b
commit
eccc9377ab
78
rtmp/rtmp.go
78
rtmp/rtmp.go
|
@ -655,88 +655,84 @@ func C_WriteN(r *C_RTMP, buf []byte) (ok bool) {
|
|||
// int SendConnectPacket(RTMP* r, RTMPPacket* cp);
|
||||
// rtmp.c +1579
|
||||
func C_SendConnectPacket(r *C_RTMP, cp *C_RTMPPacket) (ok bool) {
|
||||
var packet C_RTMPPacket
|
||||
var pbuf [4096]byte
|
||||
pend := (*byte)(incBytePtr(unsafe.Pointer(&pbuf[0]), int(unsafe.Sizeof(pbuf))))
|
||||
var enc *byte
|
||||
|
||||
if cp != nil {
|
||||
return C_RTMP_SendPacket(r, cp, 1)
|
||||
}
|
||||
|
||||
packet.m_nChannel = 0x03
|
||||
packet.m_headerType = RTMP_PACKET_SIZE_LARGE
|
||||
packet.m_packetType = RTMP_PACKET_TYPE_INVOKE
|
||||
packet.m_nTimeStamp = 0
|
||||
packet.m_nInfoField2 = 0
|
||||
packet.m_hasAbsTimestamp = false
|
||||
packet.m_body = &pbuf[RTMP_MAX_HEADER_SIZE]
|
||||
var pbuf [4096]byte
|
||||
packet := C_RTMPPacket{
|
||||
m_nChannel: 0x03,
|
||||
m_headerType: RTMP_PACKET_SIZE_LARGE,
|
||||
m_packetType: RTMP_PACKET_TYPE_INVOKE,
|
||||
m_nTimeStamp: 0,
|
||||
m_nInfoField2: 0,
|
||||
m_hasAbsTimestamp: false,
|
||||
m_body: &pbuf[RTMP_MAX_HEADER_SIZE],
|
||||
}
|
||||
enc := pbuf[RTMP_MAX_HEADER_SIZE:]
|
||||
|
||||
enc = (*byte)(unsafe.Pointer(packet.m_body))
|
||||
|
||||
enc = bAddr(C_AMF_EncodeString(pp2b(enc, pend), av_connect))
|
||||
enc = C_AMF_EncodeString(enc, av_connect)
|
||||
|
||||
r.m_numInvokes += 1
|
||||
enc = bAddr(C_AMF_EncodeNumber(pp2b(enc, pend), float64(r.m_numInvokes)))
|
||||
enc = C_AMF_EncodeNumber(enc, float64(r.m_numInvokes))
|
||||
|
||||
(*[_Gi]byte)(unsafe.Pointer(enc))[0] = AMF_OBJECT
|
||||
enc[0] = AMF_OBJECT
|
||||
enc = enc[1:]
|
||||
|
||||
enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1))
|
||||
|
||||
enc = bAddr(C_AMF_EncodeNamedString(pp2b(enc, pend), av_app, r.Link.app))
|
||||
enc = C_AMF_EncodeNamedString(enc, av_app, r.Link.app)
|
||||
if enc == nil {
|
||||
return false
|
||||
}
|
||||
if r.Link.protocol&RTMP_FEATURE_WRITE != 0 {
|
||||
enc = bAddr(C_AMF_EncodeNamedString(pp2b(enc, pend), av_type, av_nonprivate))
|
||||
enc = C_AMF_EncodeNamedString(enc, av_type, av_nonprivate)
|
||||
if enc == nil {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if r.Link.flashVer != "" {
|
||||
enc = bAddr(C_AMF_EncodeNamedString(pp2b(enc, pend), av_flashVer, r.Link.flashVer))
|
||||
enc = C_AMF_EncodeNamedString(enc, av_flashVer, r.Link.flashVer)
|
||||
if enc == nil {
|
||||
return false
|
||||
}
|
||||
}
|
||||
if r.Link.swfUrl != "" {
|
||||
enc = bAddr(C_AMF_EncodeNamedString(pp2b(enc, pend), av_swfUrl, r.Link.swfUrl))
|
||||
enc = C_AMF_EncodeNamedString(enc, av_swfUrl, r.Link.swfUrl)
|
||||
if enc == nil {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if r.Link.tcUrl != "" {
|
||||
enc = bAddr(C_AMF_EncodeNamedString(pp2b(enc, pend), av_tcUrl, r.Link.tcUrl))
|
||||
enc = C_AMF_EncodeNamedString(enc, av_tcUrl, r.Link.tcUrl)
|
||||
if enc == nil {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if r.Link.protocol&RTMP_FEATURE_WRITE == 0 {
|
||||
enc = bAddr(C_AMF_EncodeNamedBoolean(pp2b(enc, pend), av_fpad, false))
|
||||
enc = C_AMF_EncodeNamedBoolean(enc, av_fpad, false)
|
||||
if enc == nil {
|
||||
return false
|
||||
}
|
||||
enc = bAddr(C_AMF_EncodeNamedNumber(pp2b(enc, pend), av_capabilities, 15))
|
||||
enc = C_AMF_EncodeNamedNumber(enc, av_capabilities, 15)
|
||||
if enc == nil {
|
||||
return false
|
||||
}
|
||||
enc = bAddr(C_AMF_EncodeNamedNumber(pp2b(enc, pend), av_audioCodecs, r.m_fAudioCodecs))
|
||||
enc = C_AMF_EncodeNamedNumber(enc, av_audioCodecs, r.m_fAudioCodecs)
|
||||
if enc == nil {
|
||||
return false
|
||||
}
|
||||
enc = bAddr(C_AMF_EncodeNamedNumber(pp2b(enc, pend), av_videoCodecs, r.m_fVideoCodecs))
|
||||
enc = C_AMF_EncodeNamedNumber(enc, av_videoCodecs, r.m_fVideoCodecs)
|
||||
if enc == nil {
|
||||
return false
|
||||
}
|
||||
enc = bAddr(C_AMF_EncodeNamedNumber(pp2b(enc, pend), av_videoFunction, 1))
|
||||
enc = C_AMF_EncodeNamedNumber(enc, av_videoFunction, 1)
|
||||
if enc == nil {
|
||||
return false
|
||||
}
|
||||
if r.Link.pageUrl != "" {
|
||||
enc = bAddr(C_AMF_EncodeNamedString(pp2b(enc, pend), av_pageUrl, r.Link.pageUrl))
|
||||
enc = C_AMF_EncodeNamedString(enc, av_pageUrl, r.Link.pageUrl)
|
||||
if enc == nil {
|
||||
return false
|
||||
}
|
||||
|
@ -744,45 +740,37 @@ func C_SendConnectPacket(r *C_RTMP, cp *C_RTMPPacket) (ok bool) {
|
|||
}
|
||||
|
||||
if r.m_fEncoding != 0.0 || r.m_bSendEncoding {
|
||||
enc = bAddr(C_AMF_EncodeNamedNumber(pp2b(enc, pend), av_objectEncoding, r.m_fEncoding))
|
||||
enc = C_AMF_EncodeNamedNumber(enc, av_objectEncoding, r.m_fEncoding)
|
||||
if enc == nil {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if int(uintptr(incBytePtr(unsafe.Pointer(enc), 3))) >= int(uintptr(
|
||||
unsafe.Pointer(pend))) {
|
||||
if copy(enc, []byte{0, 0, AMF_OBJECT_END}) != 3 {
|
||||
return false
|
||||
}
|
||||
|
||||
(*[_Gi]byte)(unsafe.Pointer(enc))[0] = 0
|
||||
enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1))
|
||||
(*[_Gi]byte)(unsafe.Pointer(enc))[0] = 0
|
||||
enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1))
|
||||
(*[_Gi]byte)(unsafe.Pointer(enc))[0] = AMF_OBJECT_END
|
||||
enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1))
|
||||
enc = enc[3:]
|
||||
|
||||
/* add auth string */
|
||||
if r.Link.auth != "" {
|
||||
enc = bAddr(C_AMF_EncodeBoolean(pp2b(enc, pend), r.Link.lFlags&RTMP_LF_AUTH != 0))
|
||||
enc = C_AMF_EncodeBoolean(enc, r.Link.lFlags&RTMP_LF_AUTH != 0)
|
||||
if enc == nil {
|
||||
return false
|
||||
}
|
||||
enc = bAddr(C_AMF_EncodeString(pp2b(enc, pend), r.Link.auth))
|
||||
enc = C_AMF_EncodeString(enc, r.Link.auth)
|
||||
if enc == nil {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
for i := range r.Link.extras.o_props {
|
||||
enc = bAddr(C_AMF_PropEncode(&r.Link.extras.o_props[i], pp2b(enc, pend)))
|
||||
enc = C_AMF_PropEncode(&r.Link.extras.o_props[i], enc)
|
||||
if enc == nil {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
packet.m_nBodySize = uint32(uintptr(decBytePtr(unsafe.Pointer(enc),
|
||||
int(uintptr(unsafe.Pointer(packet.m_body))))))
|
||||
packet.m_nBodySize = uint32((len(pbuf) - RTMP_MAX_HEADER_SIZE) - len(enc))
|
||||
|
||||
return C_RTMP_SendPacket(r, &packet, 1)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue