From 69ff0bbad5d9e2661f508903351c05099187e2e4 Mon Sep 17 00:00:00 2001 From: saxon Date: Sat, 28 Jul 2018 15:08:09 +0930 Subject: [PATCH] Back to working order - now we will slowly go through changing to my funcs making sure it works --- rtmp/rtmp.go | 40 ++++++++++++++++++++++++-------------- rtmp/rtmp_c/librtmp/rtmp.c | 4 ++-- rtmp/rtmp_c/librtmp/rtmp.h | 2 ++ 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index 1c220025..fa1dd842 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -372,10 +372,13 @@ func (s *session) Write(data []byte) (int, error) { return 0, Err(3) } - if rtmpIsConnected(s.rtmp) == 0 { + // if rtmpIsConnected(s.rtmp) == 0 { + if C.RTMP_IsConnected(s.rtmp) == 0 { return 0, Err(1) } - if rtmpWrite(s.rtmp, data) == 0 { + + // if rtmpWrite(s.rtmp, data) == 0 { + if C.RTMP_Write(s.rtmp, (*C.char)(unsafe.Pointer(&data[0])), C.int(len(data))) == 0 { return 0, Err(2) } return len(data), nil @@ -390,27 +393,34 @@ func rtmpIsConnected(r *C.RTMP) int { func startSession(rtmp *C.RTMP, u string, timeout uint32) (*C.RTMP, error) { connect_timeout := C.int(timeout) - rtmp = rtmpAlloc() - rtmpInit(rtmp) + // rtmp = rtmpAlloc() + rtmp = C.RTMP_Alloc() + // rtmpInit(rtmp) + C.RTMP_Init(rtmp) rtmp.Link.timeout = connect_timeout - if rtmpSetupUrl(rtmp, u) == 0 { - //C.RTMP_Clos(rtmp) - //C.RTMP_Free(rtmp) + // if rtmpSetupUrl(rtmp, u) == 0 { + if C.RTMP_SetupURL(rtmp, C.CString(u)) == 0 { + C.RTMP_Close(rtmp) + C.RTMP_Free(rtmp) return nil, errors.New("rtmp startSession: Failed to setup URL!") } - rtmpEnableWrite(rtmp) - rtmpSetBufferMS(rtmp, 3600*1000) - if rtmpConnect(rtmp, nil) == 0 { - //C.RTMP_Close(rtmp) - //C.RTMP_Free(rtmp) + // rtmpEnableWrite(rtmp) + C.RTMP_EnableWrite(rtmp) + // rtmpSetBufferMS(rtmp, 3600*1000) + C.RTMP_SetBufferMS(rtmp, 3600*1000) + // if rtmpConnect(rtmp, nil) == 0 { + if C.RTMP_Connect(rtmp, nil) == 0 { + C.RTMP_Close(rtmp) + C.RTMP_Free(rtmp) return nil, errors.New("rtmp startSession: Failed to connect!") } // TODO: port this - if rtmpConnectStream(rtmp, 0) == 0 { - //C.RTMP_Close(rtmp) - //C.RTMP_Free(rtmp) + // if rtmpConnectStream(rtmp, 0) == 0 { + if C.RTMP_ConnectStream(rtmp, 0) == 0 { + C.RTMP_Close(rtmp) + C.RTMP_Free(rtmp) return nil, errors.New("rtmp startSession: Failed to connect stream!") } diff --git a/rtmp/rtmp_c/librtmp/rtmp.c b/rtmp/rtmp_c/librtmp/rtmp.c index 15fb8ada..59927b28 100644 --- a/rtmp/rtmp_c/librtmp/rtmp.c +++ b/rtmp/rtmp_c/librtmp/rtmp.c @@ -118,7 +118,7 @@ static int SendCheckBWResult(RTMP *r, double txn); int SendDeleteStream(RTMP *r, double dStreamId); static int SendFCSubscribe(RTMP *r, AVal *subscribepath); static int SendPlay(RTMP *r); -static int SendBytesReceived(RTMP *r); +int SendBytesReceived(RTMP *r); static int SendUsherToken(RTMP *r, AVal *usherToken); #if 0 /* unused */ @@ -2076,7 +2076,7 @@ RTMP_SendClientBW(RTMP *r) return RTMP_SendPacket(r, &packet, FALSE); } -static int +int SendBytesReceived(RTMP *r) { RTMPPacket packet; diff --git a/rtmp/rtmp_c/librtmp/rtmp.h b/rtmp/rtmp_c/librtmp/rtmp.h index dd06e783..8cbf2986 100644 --- a/rtmp/rtmp_c/librtmp/rtmp.h +++ b/rtmp/rtmp_c/librtmp/rtmp.h @@ -299,6 +299,8 @@ extern "C" int HandShake(RTMP *r, int FP9HandShake); + int SendBytesReceived(RTMP *r); + int SendConnectPacket(RTMP *r, RTMPPacket *cp); int SendDeleteStream(RTMP *r, double dStreamId);