From 10cd22d02ad60e254b4371dd1ab4dd8b937a9875 Mon Sep 17 00:00:00 2001
From: saxon <saxon.milton@gmail.com>
Date: Thu, 19 Jul 2018 00:54:36 +0930
Subject: [PATCH] Created go RTMP_READ struct

---
 rtmp/rtmp.go | 75 +++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 51 insertions(+), 24 deletions(-)

diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go
index 50214dca..a8f94a24 100644
--- a/rtmp/rtmp.go
+++ b/rtmp/rtmp.go
@@ -61,18 +61,6 @@ import (
 	"unsafe"
 )
 
-const (
-	minDataSize = 11
-	debugMode   = false
-	nullChar    = "golang\000"
-)
-
-const (
-	byteSize  = 1
-	int32Size = 4
-	int64Size = 8
-)
-
 const (
 	RTMPT_OPEN = iota
 	RTMPT_SEND
@@ -87,21 +75,33 @@ const (
 	RTMP_PACKET_TYPE_INFO   = 0x12
 	RTMP_PACKET_TYPE_AUDIO  = 0x08
 	RTMP_PACKET_TYPE_VIDEO  = 0x09
+	RTMP_READ_HEADER        = 0x01
+	RTMP_READ_RESUME        = 0x02
+	RTMP_READ_NO_IGNORE     = 0x04
+	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
+)
+
+const (
+	minDataSize = 11
+	debugMode   = false
+)
+
+const (
+	byteSize  = 1
+	int32Size = 4
+	int64Size = 8
 )
 
 // memmove copies n bytes from "from" to "to".
 //go:linkname memmove runtime.memmove
 //func memmove(to, from unsafe.Pointer, n uintptr)
 
-// C.AVal is in amf.h
-// See #define AVC(str) {str, sizeof(str)-1} in amf.h
-func AVC(str string) C.AVal {
-	var aval C.AVal
-	aval.av_val = C.CString(str)
-	aval.av_len = C.int(len(str))
-	return aval
-}
-
 // av_setDataFrame is a static const global in rtmp.c
 var setDataFrame = AVC("@setDataFrame")
 
@@ -141,7 +141,7 @@ type RTMP struct {
 	m_bSendCounter         uint8
 	m_numInvokes           int
 	m_numCalls             int
-	m_methodCalls          *C.RTMP_METHOD
+	m_methodCalls          *RTMP_METHOD
 	m_channelsAllocatedIn  int
 	m_channelsAllocatedOut int
 	m_vecChannelsIn        **RTMPPacket
@@ -155,7 +155,7 @@ type RTMP struct {
 	m_polling              int
 	m_resplen              int
 	m_unackd               int
-	m_clientID             C.AVal
+	m_clientID             AVal
 	m_read                 C.RTMP_READ
 	m_write                C.RTMPPacket
 	m_sb                   C.RTMPSockBuf
@@ -176,7 +176,7 @@ type RTMPPacket struct {
 }
 
 type RTMP_METHOD struct {
-	name C.AVal
+	name AVal
 	num  int
 }
 
@@ -185,6 +185,24 @@ type AVal struct {
 	av_len int
 }
 
+type RTMP_READ struct {
+	buf                     *byte
+	bufpos                  *byte
+	buflen                  uint
+	timestamp               uint32
+	dataType                uint8
+	flags                   uint8
+	status                  int8
+	initialFrameType        uint8
+	nResumeTS               uint32
+	metaHeader              *byte
+	initialFrame            *byte
+	nMetaHeaderSize         uint32
+	nInitialFrameSize       uint32
+	nIgnoredFrameCounter    uint32
+	nIgnoredFlvFrameCounter uint32
+}
+
 var _ Session = (*session)(nil)
 
 // NewSession returns a new session.
@@ -814,6 +832,15 @@ func ptrToSlice(data unsafe.Pointer, size int) []byte {
 	return ret
 }
 
+// C.AVal is in amf.h
+// See  AVC(str) {str, sizeof(str)-1} in amf.h
+func AVC(str string) C.AVal {
+	var aval C.AVal
+	aval.av_val = C.CString(str)
+	aval.av_len = C.int(len(str))
+	return aval
+}
+
 var rtmpErrs = [...]string{
 	1: "rtmp: not connected",
 	2: "rtmp: write error",