rtmp: uncommented usage of C_RTMP_Close - created todos in C_CloseInternal

This commit is contained in:
saxon 2018-08-25 23:49:54 +09:30
parent ba9ce9b37f
commit 7e6b2ee0b2
1 changed files with 80 additions and 74 deletions

View File

@ -158,7 +158,7 @@ func startSession(rtmp *C_RTMP, u string, timeout uint32) (*C_RTMP, error) {
rtmp.Link.timeout = connect_timeout
if C_RTMP_SetupURL(rtmp, u) == 0 {
// if C.RTMP_SetupURL(rtmp, C.CString(u)) == 0 {
//C.RTMP_Close(rtmp)
C_RTMP_Close(rtmp)
//C.RTMP_Free(rtmp)
return nil, errors.New("rtmp startSession: Failed to setup URL!")
}
@ -169,7 +169,7 @@ func startSession(rtmp *C_RTMP, u string, timeout uint32) (*C_RTMP, error) {
//C.RTMP_SetBufferMS(rtmp, 3600*1000)
if C_RTMP_Connect(rtmp, nil) == 0 {
//if C.RTMP_Connect(rtmp, nil) == 0 {
//C.RTMP_Close(rtmp)
C_RTMP_Close(rtmp)
//C.RTMP_Free(rtmp)
return nil, errors.New("rtmp startSession: Failed to connect!")
}
@ -177,7 +177,7 @@ func startSession(rtmp *C_RTMP, u string, timeout uint32) (*C_RTMP, error) {
// TODO: port this
if C_RTMP_ConnectStream(rtmp, 0) == 0 {
//if C.RTMP_ConnectStream(rtmp, 0) == 0 {
//C.RTMP_Close(rtmp)
C_RTMP_Close(rtmp)
//C.RTMP_Free(rtmp)
return nil, errors.New("rtmp startSession: Failed to connect stream!")
}
@ -190,7 +190,7 @@ func endSession(rtmp *C_RTMP) uint32 {
return 3
}
//C.RTMP_Close(rtmp)
C_RTMP_Close(rtmp)
//C.RTMP_Free(rtmp)
return 0
}
@ -382,89 +382,95 @@ func C_RTMP_SetupURL(r *C_RTMP, u string) int32 {
return 1
}
/*
func rtmpClose(r *C_RTMP) {
closeInternal(r, 0)
func C_RTMP_Close(r *C_RTMP) {
C_CloseInternal(r, 0)
}
func closeInternal(r *C_RTMP, reconnect int32) {
var i int32
func C_CloseInternal(r *C_RTMP, reconnect int32) {
// TODO: port SendFCUnpublish
// TODO: port SendDeleteStream
// TODO: port RTMPSockBuf_Close
// TODO: port AV_Clear
/*
var i int32
if C_RTMP_IsConnected(r) != 0 {
if r.m_stream_id > 0 {
i = int32(r.m_stream_id)
if r.Link.protocol&RTMP_FEATURE_WRITE != 0 {
C.SendFCUnpublish(r)
if C_RTMP_IsConnected(r) != 0 {
if r.m_stream_id > 0 {
i = int32(r.m_stream_id)
if r.Link.protocol&RTMP_FEATURE_WRITE != 0 {
C.SendFCUnpublish(r)
}
C.SendDeleteStream(r, float64(i))
}
C.SendDeleteStream(r, float64(i))
C.RTMPSockBuf_Close(&r.m_sb)
}
C.RTMPSockBuf_Close(&r.m_sb)
}
r.m_stream_id = -1
r.m_sb.sb_socket = -1
r.m_nBWCheckCounter = 0
r.m_nBytesIn = 0
r.m_nBytesInSent = 0
r.m_stream_id = -1
r.m_sb.sb_socket = -1
r.m_nBWCheckCounter = 0
r.m_nBytesIn = 0
r.m_nBytesInSent = 0
if r.m_read.flags&RTMP_READ_HEADER != 0 {
//C.free(unsafe.Pointer(r.m_read.buf))
r.m_read.buf = nil
}
r.m_read.dataType = 0
r.m_read.flags = 0
r.m_read.status = 0
r.m_read.nResumeTS = 0
r.m_read.nIgnoredFrameCounter = 0
r.m_read.nIgnoredFlvFrameCounter = 0
r.m_write.m_nBytesRead = 0
C.RTMPPacket_Free(&r.m_write)
for i := 0; i < int(r.m_channelsAllocatedIn); i++ {
if *(**C_RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsIn), i,
int(unsafe.Sizeof(&r.m_write)))) != nil {
C.RTMPPacket_Free(*(**C_RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsIn), i,
int(unsafe.Sizeof(&r.m_write)))))
//C.free(unsafe.Pointer(*(**C_RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsIn),
i, int(unsafe.Sizeof(&r.m_write))))))
*(**C_RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsIn),
i, int(unsafe.Sizeof(&r.m_write)))) = nil
if r.m_read.flags&RTMP_READ_HEADER != 0 {
//C.free(unsafe.Pointer(r.m_read.buf))
r.m_read.buf = nil
}
}
//C.free(unsafe.Pointer(r.m_vecChannelsOut))
r.m_vecChannelsOut = nil
r.m_channelsAllocatedOut = 0
C.AV_clear(r.m_methodCalls, r.m_numCalls)
r.m_read.dataType = 0
r.m_read.flags = 0
r.m_read.status = 0
r.m_read.nResumeTS = 0
r.m_read.nIgnoredFrameCounter = 0
r.m_read.nIgnoredFlvFrameCounter = 0
r.m_methodCalls = nil
r.m_numCalls = 0
r.m_numInvokes = 0
r.m_write.m_nBytesRead = 0
C.RTMPPacket_Free(&r.m_write)
r.m_bPlaying = C.uchar(0)
r.m_sb.sb_size = 0
// NOTE: C frees - not using in our case
for i := 0; i < int(r.m_channelsAllocatedIn); i++ {
if *(**C_RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsIn), i,
int(unsafe.Sizeof(&r.m_write)))) != nil {
r.m_msgCounter = 0
r.m_resplen = 0
r.m_unackd = 0
//C.RTMPPacket_Free(*(**C_RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsIn), i,
//int(unsafe.Sizeof(&r.m_write)))))
if ((r.Link.lFlags & RTMP_LF_FTCU) != 0) && (reconnect == 0) {
//C.free(unsafe.Pointer(r.Link.app.av_val))
r.Link.app.av_val = nil
r.Link.lFlags ^= RTMP_LF_FAPU
}
//C.free(unsafe.Pointer(*(**C_RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsIn),
//i, int(unsafe.Sizeof(&r.m_write))))))
if reconnect == 0 {
//C.free(unsafe.Pointer(r.Link.playpath0.av_val))
r.Link.playpath0.av_val = nil
}
*(**C_RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsIn),
i, int(unsafe.Sizeof(&r.m_write)))) = nil
}
}
//C.free(unsafe.Pointer(r.m_vecChannelsOut))
r.m_vecChannelsOut = nil
r.m_channelsAllocatedOut = 0
C.AV_clear(r.m_methodCalls, r.m_numCalls)
r.m_methodCalls = nil
r.m_numCalls = 0
r.m_numInvokes = 0
r.m_bPlaying = C.uchar(0)
r.m_sb.sb_size = 0
r.m_msgCounter = 0
r.m_resplen = 0
r.m_unackd = 0
if ((r.Link.lFlags & RTMP_LF_FTCU) != 0) && (reconnect == 0) {
//C.free(unsafe.Pointer(r.Link.app.av_val))
r.Link.app.av_val = nil
r.Link.lFlags ^= RTMP_LF_FAPU
}
if reconnect == 0 {
//C.free(unsafe.Pointer(r.Link.playpath0.av_val))
r.Link.playpath0.av_val = nil
}
*/
}
*/
// int RTMP_Connect0(RTMP *r, struct sockaddr* service);
// rtmp.c +906
@ -839,7 +845,7 @@ func C_ReadN(r *C_RTMP, buffer *byte, n int) int {
if nBytes == 0 {
log.Println("RTMP socket closed by peer")
// C.RTMP_Close(r)
C_RTMP_Close(r)
break
}
@ -865,7 +871,7 @@ func C_WriteN(r *C_RTMP, buffer unsafe.Pointer, n int) int {
}
// TODO: port this
//C.RTMP_Close(r)
C_RTMP_Close(r)
n = 1
break
}