From 7b20e8f76745bb5febbcdfeec3fd5e819d098030 Mon Sep 17 00:00:00 2001
From: saxon <saxon.milton@gmail.com>
Date: Fri, 13 Jul 2018 02:33:06 +0930
Subject: [PATCH] Just about to fix is I think

---
 rtmp/rtmp.go | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go
index 0788471c..15ffaed7 100644
--- a/rtmp/rtmp.go
+++ b/rtmp/rtmp.go
@@ -47,6 +47,7 @@ import (
 	"log"
 	"strconv"
 	"unsafe"
+	_"fmt"
 )
 
 const (
@@ -82,7 +83,7 @@ func NewSession(url string, connectTimeout uint) Session {
 func AVC(str string) C.AVal {
 	var aval C.AVal
 	aval.av_val = C.CString(str)
-	aval.av_len = C.int(len(str))
+	aval.av_len = C.int(unsafe.Sizeof(aval.av_val)-1)
 	return aval
 }
 
@@ -111,6 +112,7 @@ func (s *session) Write(data []byte) (int, error) {
 	if C.RTMP_IsConnected(s.rtmp) <= 0 {
 		return 0, Err(1)
 	}
+	//if C.RTMP_Write(s.rtmp,(*C.char)(unsafe.Pointer(&data[0])),C.int(len(data))) <= 0 {
 	if rtmpWrite(s.rtmp, data) <= 0 {
 		return 0, Err(2)
 	}
@@ -119,7 +121,7 @@ func (s *session) Write(data []byte) (int, error) {
 
 func rtmpWrite(r *C.RTMP, data []byte) int {
 	buf := (*C.char)(unsafe.Pointer(&data[0]))
-	var pkt *C.RTMPPacket = &r.m_write
+	var pkt = &r.m_write
 	var pend, enc *C.char
 	size := len(data)
 	s2 := size
@@ -127,15 +129,13 @@ func rtmpWrite(r *C.RTMP, data []byte) int {
 
 	pkt.m_nChannel = 0x04
 	pkt.m_nInfoField2 = r.m_stream_id
-
-	for s2 > 0 {
+	for s2 > 0 || s2 < 0{
 		if pkt.m_nBytesRead == 0 {
 			if size < minDataSize {
 				log.Printf("size: %d\n", size)
 				log.Printf("too small \n")
 				return 0
 			}
-
 			buf0 := *(*byte)(unsafe.Pointer(buf))
 			buf1 := *(*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(1)))
 			buf2 := *(*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(2)))