rtmp: remove C_AVal from C_RTMP_METHOD

This commit is contained in:
Dan Kortschak 2018-09-06 19:00:28 +09:30
parent 28f5ec6a47
commit bf2a2ec7a8
3 changed files with 27 additions and 53 deletions

View File

@ -85,17 +85,6 @@ func CAV(av *C_AVal) string {
return string((*[_Gi]byte)(unsafe.Pointer(av.av_val))[:av.av_len])
}
// #define AVMATCH(a1,a2)
// amf.h +63
func C_AVMATCH(a1, a2 *C_AVal) int32 {
if a1.av_len == a2.av_len && memcmp(unsafe.Pointer(a1.av_val),
unsafe.Pointer(a2.av_val), int(a1.av_len)) == 0 {
return 1
} else {
return 0
}
}
// typedef struct AMF_Object
// amf.h +67
type C_AMFObject struct {

View File

@ -66,16 +66,6 @@ const (
length = 512
)
// TODO(kortschak): Reduce this list.
var (
av_connect = AVC("connect")
av_createStream = AVC("createStream")
av_play = AVC("play")
av_publish = AVC("publish")
av_secureToken = AVC("secureToken")
av_set_playlist = AVC("set_playlist")
)
const (
// av_setDataFrame is a static const global in rtmp.c
setDataFrame = "@setDataFrame"
@ -89,6 +79,8 @@ const (
av_capabilities = "capabilities"
av_close = "close"
av_code = "code"
av_connect = "connect"
av_createStream = "createStream"
av_deleteStream = "deleteStream"
av_FCPublish = "FCPublish"
av_FCUnpublish = "FCUnpublish"
@ -116,8 +108,12 @@ const (
av_onStatus = "onStatus"
av_pageUrl = "pageUrl"
av_ping = "ping"
av_play = "play"
av_playlist_ready = "playlist_ready"
av_publish = "publish"
av_releaseStream = "releaseStream"
av_secureToken = "secureToken"
av_set_playlist = "set_playlist"
av_swfUrl = "swfUrl"
av_tcUrl = "tcUrl"
av_type = "type"
@ -741,7 +737,7 @@ func C_SendConnectPacket(r *C_RTMP, cp *C_RTMPPacket) (ok bool) {
enc = (*byte)(unsafe.Pointer(packet.m_body))
enc = C_AMF_EncodeString(enc, pend, CAV(&av_connect))
enc = C_AMF_EncodeString(enc, pend, av_connect)
r.m_numInvokes += 1
enc = C_AMF_EncodeNumber(enc, pend, float64(r.m_numInvokes))
@ -877,7 +873,7 @@ func C_RTMP_SendCreateStream(r *C_RTMP) (ok bool) {
packet.m_body = &pbuf[RTMP_MAX_HEADER_SIZE]
enc = (*byte)(unsafe.Pointer(packet.m_body))
enc = C_AMF_EncodeString(enc, pend, CAV(&av_createStream))
enc = C_AMF_EncodeString(enc, pend, av_createStream)
r.m_numInvokes++
enc = C_AMF_EncodeNumber(enc, pend, float64(r.m_numInvokes))
*enc = AMF_NULL
@ -1008,7 +1004,7 @@ func C_SendPublish(r *C_RTMP) (ok bool) {
packet.m_body = &pbuf[RTMP_MAX_HEADER_SIZE]
enc = (*byte)(unsafe.Pointer(packet.m_body))
enc = C_AMF_EncodeString(enc, pend, CAV(&av_publish))
enc = C_AMF_EncodeString(enc, pend, av_publish)
r.m_numInvokes++
enc = C_AMF_EncodeNumber(enc, pend, float64(r.m_numInvokes))
*enc = AMF_NULL
@ -1123,18 +1119,13 @@ func C_AV_erase(vals *C_RTMP_METHOD, num *int32, i, freeit int32) {
//C.free(unsafe.Pointer((*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(vals), int(i),
//int(unsafe.Sizeof(*vals))))).name.av_val))
}
(*num)--
*num--
for ; i < *num; i++ {
*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(vals), int(i),
int(unsafe.Sizeof(*vals)))) = *(*C_RTMP_METHOD)(incPtr(
unsafe.Pointer(vals), int(i+1), int(unsafe.Sizeof(*vals))))
}
(*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(vals), int(i),
int(unsafe.Sizeof(*vals))))).name.av_val = nil
(*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(vals), int(i),
int(unsafe.Sizeof(*vals))))).name.av_len = 0
(*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(vals), int(i),
int(unsafe.Sizeof(*vals))))).num = 0
*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(vals), int(i), int(unsafe.Sizeof(*vals)))) = C_RTMP_METHOD{}
}
// void AV_queue(RTMP_METHOD** vals, int* num, C_AVal* av, int txn);
@ -1144,14 +1135,11 @@ func C_AV_queue(vals **C_RTMP_METHOD, num *int32, av string, txn int32) {
*vals = (*C_RTMP_METHOD)(C.realloc(unsafe.Pointer(*vals), C.size_t((*num+16)*int32(unsafe.Sizeof(**vals)))))
}
tmp := make([]byte, len(av)+1)
copy(tmp, av)
(*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(*vals), int(*num),
int(unsafe.Sizeof(**vals))))).num = int32(txn)
(*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(*vals), int(*num),
int(unsafe.Sizeof(**vals))))).name.av_len = int32(len(av))
(*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(*vals), int(*num),
int(unsafe.Sizeof(**vals))))).name.av_val = &tmp[0]
meth := (*C_RTMP_METHOD)(incPtr(unsafe.Pointer(*vals), int(*num), int(unsafe.Sizeof(**vals))))
*meth = C_RTMP_METHOD{
name: av,
num: int32(txn),
}
*num++
}
@ -1185,17 +1173,15 @@ func C_HandleInvoke(r *C_RTMP, body *byte, nBodySize uint32) (ok bool) {
switch method {
case av__result:
var methodInvoked C_AVal
var methodInvoked string
for i := int32(0); i < r.m_numCalls; i++ {
if float64((*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(r.m_methodCalls), int(i),
int(unsafe.Sizeof(*r.m_methodCalls))))).num) == txn {
methodInvoked = (*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(r.m_methodCalls),
int(i), int(unsafe.Sizeof(*r.m_methodCalls))))).name
if float64((*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(r.m_methodCalls), int(i), int(unsafe.Sizeof(*r.m_methodCalls))))).num) == txn {
methodInvoked = (*C_RTMP_METHOD)(incPtr(unsafe.Pointer(r.m_methodCalls), int(i), int(unsafe.Sizeof(*r.m_methodCalls)))).name
C_AV_erase(r.m_methodCalls, (*int32)(&r.m_numCalls), int32(i), 0)
break
}
}
if methodInvoked.av_val == nil {
if methodInvoked == "" {
// TODO use new logger here
//RTMP_Log(RTMP_LOGDEBUG, "%s, received result id %f without matching request",
//__FUNCTION__, txn);
@ -1204,8 +1190,8 @@ func C_HandleInvoke(r *C_RTMP, body *byte, nBodySize uint32) (ok bool) {
// TODO use new logger here
//RTMP_Log(RTMP_LOGDEBUG, "%s, received result for method call <%s>", __FUNCTION__,
//methodInvoked.av_val);
switch {
case C_AVMATCH(&methodInvoked, &av_connect) != 0:
switch methodInvoked {
case av_connect:
if r.Link.token.av_len != 0 {
panic("No support for link token")
@ -1222,7 +1208,7 @@ func C_HandleInvoke(r *C_RTMP, body *byte, nBodySize uint32) (ok bool) {
panic("Link protocol has no RTMP_FEATURE_WRITE")
}
case C_AVMATCH(&methodInvoked, &av_createStream) != 0:
case av_createStream:
r.m_stream_id = int32(C_AMFProp_GetNumber(C_AMF_GetProp(&obj, "", 3)))
if r.Link.protocol&RTMP_FEATURE_WRITE != 0 {
@ -1231,8 +1217,7 @@ func C_HandleInvoke(r *C_RTMP, body *byte, nBodySize uint32) (ok bool) {
panic("Link protocol has no RTMP_FEATURE_WRITE")
}
case C_AVMATCH(&methodInvoked, &av_play) != 0 ||
C_AVMATCH(&methodInvoked, &av_publish) != 0:
case av_play, av_publish:
panic("Unsupported method av_play/av_publish")
}
//C.free(unsafe.Pointer(methodInvoked.av_val))
@ -1279,8 +1264,8 @@ func C_HandleInvoke(r *C_RTMP, body *byte, nBodySize uint32) (ok bool) {
case av_NetStream_Publish_Start:
r.m_bPlaying = true
for i := int32(0); i < r.m_numCalls; i++ {
if C_AVMATCH(&(*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(r.m_methodCalls), int(i),
int(unsafe.Sizeof(*r.m_methodCalls))))).name, &av_publish) != 0 {
method_name := (*C_RTMP_METHOD)(incPtr(unsafe.Pointer(r.m_methodCalls), int(i), int(unsafe.Sizeof(*r.m_methodCalls)))).name
if method_name == av_publish {
C_AV_erase(r.m_methodCalls, (*int32)(&r.m_numCalls), int32(i), 1)
break
}

View File

@ -205,7 +205,7 @@ type C_RTMP_READ struct {
// typedef struct RTMPMethod
// rtmp.h +231
type C_RTMP_METHOD struct {
name C_AVal
name string
num int32
}