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) }