From 6b4ece57e5ddce5b5e69f8287cce5fb2a5ec4c9d Mon Sep 17 00:00:00 2001 From: Saxon Milton Date: Thu, 28 Jun 2018 02:53:50 +0930 Subject: [PATCH] Started moving functionality to rtmp.go --- rtmp/rtmp.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index 33dec40b..7eaa2ad1 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -86,12 +86,22 @@ func (s *session) Open() error { return nil } +func (s *session) writeFrame(data []byte, dataLength uint) uint { + if !C.RTMP_IsConnected(rtmp) { + return 1 + } + if !C.RTMP_Write(s.rtmp, (const char*)(*C.char)(unsafe.Pointer(&data[0])), C.uint(dataLength)) { + return 2 + } + return 0 +} + // Write writes a frame (flv tag) to the rtmp connection func (s *session) Write(data []byte) (int, error) { if s.rtmp == nil { return 0, Err(3) } - ret := C.write_frame(s.rtmp, (*C.char)(unsafe.Pointer(&data[0])), C.uint(len(data))) + ret := s.writeFrame(data, len(data)) if ret != 0 { return 0, Err(ret) }