added consts and cleaned some things up

This commit is contained in:
saxon 2018-07-19 15:33:33 +09:30
parent b29debd3aa
commit 6fc7640b6b
1 changed files with 65 additions and 28 deletions

View File

@ -70,29 +70,60 @@ const (
) )
const ( const (
RTMP_PACKET_SIZE_LARGE = 0 RTMP_PACKET_TYPE_CHUNK_SIZE = 0x01
RTMP_PACKET_SIZE_MEDIUM = 1 RTMP_PACKET_TYPE_BYTES_READ_REPORT = 0x03
RTMP_PACKET_SIZE_SMALL = 2 RTMP_PACKET_TYPE_CONTROL = 0x04
RTMP_PACKET_TYPE_INFO = 0x12 RTMP_PACKET_TYPE_SERVER_BW = 0x05
RTMP_PACKET_TYPE_AUDIO = 0x08 RTMP_PACKET_TYPE_CLIENT_BW = 0x06
RTMP_PACKET_TYPE_VIDEO = 0x09 RTMP_PACKET_TYPE_AUDIO = 0x08
RTMP_READ_HEADER = 0x01 RTMP_PACKET_TYPE_VIDEO = 0x09
RTMP_READ_RESUME = 0x02 RTMP_PACKET_TYPE_FLEX_STREAM_SEND = 0x0F
RTMP_READ_NO_IGNORE = 0x04 RTMP_PACKET_TYPE_FLEX_SHARED_OBJECT = 0x10
RTMP_READ_GOTKF = 0x08 RTMP_PACKET_TYPE_FLEX_MESSAGE = 0x11
RTMP_READ_GOTFLVK = 0x10 RTMP_PACKET_TYPE_INFO = 0x12
RTMP_READ_SEEKING = 0x20 RTMP_PACKET_TYPE_SHARED_OBJECT = 0x13
RTMP_READ_COMPLETE = -3 RTMP_PACKET_TYPE_INVOKE = 0x14
RTMP_READ_ERROR = -2 RTMP_PACKET_TYPE_FLASH_VIDEO = 0x16
RTMP_READ_EOF = -1 RTMP_MAX_HEADER_SIZE = 18
RTMP_READ_IGNORE = 0 RTMP_PACKET_SIZE_LARGE = 0
RTMP_LF_AUTH = 0x0001 /* using auth param */ RTMP_PACKET_SIZE_MEDIUM = 1
RTMP_LF_LIVE = 0x0002 /* stream is live */ RTMP_PACKET_SIZE_SMALL = 2
RTMP_LF_SWFV = 0x0004 /* do SWF verification */ RTMP_PACKET_SIZE_MINIMUM = 3
RTMP_LF_PLST = 0x0008 /* send playlist before play */ RTMP_READ_HEADER = 0x01
RTMP_LF_BUFX = 0x0010 /* toggle stream on BufferEmpty msg */ RTMP_READ_RESUME = 0x02
RTMP_LF_FTCU = 0x0020 /* free tcUrl on close */ RTMP_READ_NO_IGNORE = 0x04
RTMP_LF_FAPU = 0x0040 /* free app on close */ RTMP_READ_GOTKF = 0x08
RTMP_READ_GOTFLVK = 0x10
RTMP_READ_SEEKING = 0x20
RTMP_READ_COMPLETE = -3
RTMP_READ_ERROR = -2
RTMP_READ_EOF = -1
RTMP_READ_IGNORE = 0
RTMP_LF_AUTH = 0x0001 /* using auth param */
RTMP_LF_LIVE = 0x0002 /* stream is live */
RTMP_LF_SWFV = 0x0004 /* do SWF verification */
RTMP_LF_PLST = 0x0008 /* send playlist before play */
RTMP_LF_BUFX = 0x0010 /* toggle stream on BufferEmpty msg */
RTMP_LF_FTCU = 0x0020 /* free tcUrl on close */
RTMP_LF_FAPU = 0x0040 /* free app on close */
RTMP_FEATURE_HTTP = 0x01
RTMP_FEATURE_ENC = 0x02
RTMP_FEATURE_SSL = 0x04
RTMP_FEATURE_MFP = 0x08 /* not yet supported */
RTMP_FEATURE_WRITE = 0x10 /* publish, not play */
RTMP_FEATURE_HTTP2 = 0x20 /* server-side rtmpt */
RTMP_PROTOCOL_UNDEFINED = -1
RTMP_PROTOCOL_RTMP = 0
RTMP_PROTOCOL_RTMPE = RTMP_FEATURE_ENC
RTMP_PROTOCOL_RTMPT = RTMP_FEATURE_HTTP
RTMP_PROTOCOL_RTMPS = RTMP_FEATURE_SSL
RTMP_PROTOCOL_RTMPTE = (RTMP_FEATURE_HTTP | RTMP_FEATURE_ENC)
RTMP_PROTOCOL_RTMPTS = (RTMP_FEATURE_HTTP | RTMP_FEATURE_SSL)
RTMP_PROTOCOL_RTMFP = RTMP_FEATURE_MFP
RTMP_DEFAULT_CHUNKSIZE = 128
RTMP_BUFFER_CACHE_SIZE = (16 * 1024)
RTMP_CHANNELS = 65600
RTMP_SWF_HASHLEN = 32
) )
const ( const (
@ -414,15 +445,19 @@ func afmDecodeInt24(data *byte) uint32 {
// TODO Understand logic and simplify // TODO Understand logic and simplify
c := (*uint8)(unsafe.Pointer(data)) c := (*uint8)(unsafe.Pointer(data))
dst := uint32(int32(*c) << 16) dst := uint32(int32(*c) << 16)
dst |= uint32(int32(*((*uint8)(unsafe.Pointer(uintptr(unsafe.Pointer(c)) + (uintptr)(int32(1))*unsafe.Sizeof(*c))))) << 8) dst |= uint32(int32(*((*uint8)(unsafe.Pointer(uintptr(unsafe.Pointer(c)) +
dst |= uint32(int32(*((*uint8)(unsafe.Pointer(uintptr(unsafe.Pointer(c)) + (uintptr)(int32(2))*unsafe.Sizeof(*c)))))) (uintptr)(int32(1))*unsafe.Sizeof(*c))))) << 8)
dst |= uint32(int32(*((*uint8)(unsafe.Pointer(uintptr(unsafe.Pointer(c)) +
(uintptr)(int32(2))*unsafe.Sizeof(*c))))))
return dst return dst
} }
func afmEncodeString(output *byte, outend *byte, bv *C.AVal) *byte { func afmEncodeString(output *byte, outend *byte, bv *C.AVal) *byte {
outputPtr := unsafe.Pointer(output) outputPtr := unsafe.Pointer(output)
outendPtr := unsafe.Pointer(outend) outendPtr := unsafe.Pointer(outend)
if (bv.av_len < 65536 && uintptr(incBytePtr(outputPtr, 1+2+int(bv.av_len))) > uintptr(outendPtr)) || uintptr(incBytePtr(outputPtr, 1+4+int(bv.av_len))) > uintptr(outendPtr) { if (bv.av_len < 65536 && uintptr(incBytePtr(outputPtr, 1+2+int(bv.av_len))) >
uintptr(outendPtr)) || uintptr(incBytePtr(outputPtr, 1+4+int(bv.av_len))) >
uintptr(outendPtr) {
return nil return nil
} }
@ -431,13 +466,15 @@ func afmEncodeString(output *byte, outend *byte, bv *C.AVal) *byte {
incBytePtr(outputPtr, 1) incBytePtr(outputPtr, 1)
// TODO Encode Int16 // TODO Encode Int16
outputPtr = unsafe.Pointer(C.AMF_EncodeInt16((*C.char)(outputPtr), (*C.char)(outendPtr), (C.short)(bv.av_len))) outputPtr = unsafe.Pointer(C.AMF_EncodeInt16((*C.char)(outputPtr),
(*C.char)(outendPtr), (C.short)(bv.av_len)))
} else { } else {
*(*C.char)(outputPtr) = C.AMF_LONG_STRING *(*C.char)(outputPtr) = C.AMF_LONG_STRING
incBytePtr(outputPtr, 1) incBytePtr(outputPtr, 1)
// TODO Encode Int16 // TODO Encode Int16
outputPtr = unsafe.Pointer(C.AMF_EncodeInt32((*C.char)(outputPtr), (*C.char)(outendPtr), bv.av_len)) outputPtr = unsafe.Pointer(C.AMF_EncodeInt32((*C.char)(outputPtr),
(*C.char)(outendPtr), bv.av_len))
} }
C.memcpy(unsafe.Pointer(outputPtr), unsafe.Pointer(bv.av_val), (C.size_t)(bv.av_len)) C.memcpy(unsafe.Pointer(outputPtr), unsafe.Pointer(bv.av_val), (C.size_t)(bv.av_len))
incBytePtr(outputPtr, int(bv.av_len)) incBytePtr(outputPtr, int(bv.av_len))