mirror of https://bitbucket.org/ausocean/av.git
Getting rid of errors
This commit is contained in:
parent
e4a1583583
commit
a4349bd013
49
rtmp/rtmp.go
49
rtmp/rtmp.go
|
@ -75,6 +75,15 @@ func NewSession(url string, connectTimeout uint) Session {
|
|||
}
|
||||
}
|
||||
|
||||
// C.AVal is in amf.h
|
||||
// See #define AVC(str) {str, sizeof(str)-1} in amf.h
|
||||
func AVC(str string) C.AVal {
|
||||
var aval C.AVal
|
||||
aval.av_val = (*C.char)([]byte(str)[0])
|
||||
aval.av_len = (C.int)(int(unsafe.Sizeof([]byte(str))-1))
|
||||
return aval
|
||||
}
|
||||
|
||||
// Open establishes an rtmp connection with the url passed into the
|
||||
// constructor
|
||||
func (s *session) Open() error {
|
||||
|
@ -89,22 +98,19 @@ func (s *session) Open() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func AVC(str string) *C.char {
|
||||
slice := [2]byte{str, C.sizeof(str)-1}
|
||||
return (*C.char)(unsafe.Pointer(&slice[0]))
|
||||
}
|
||||
|
||||
func (s *session) rtmpWrite(r *C.RTMP, buf []byte) int {
|
||||
var pkt *C.RTMPPacket = &rtmp.m_write
|
||||
var pkt *C.RTMPPacket = &r.m_write
|
||||
var pend, enc *C.char
|
||||
s2 := len(buf)
|
||||
size := len(buf)
|
||||
s2 := size
|
||||
var ret, num int
|
||||
|
||||
pkt.m_nChannel = 0x04
|
||||
pkt.m_nInfoField2 = r.m_stream_id
|
||||
|
||||
for s2 > 0 {
|
||||
if !pkt.m_nBytesRead {
|
||||
if pkt.m_nBytesRead == 0 {
|
||||
if size < 11 {
|
||||
log.Printf("size: %d\n", size)
|
||||
log.Printf("too small \n")
|
||||
|
@ -112,13 +118,14 @@ func (s *session) rtmpWrite(r *C.RTMP, buf []byte) int {
|
|||
}
|
||||
|
||||
if buf[0] == 'F' && buf[1] == 'L' && buf[2] == 'V' {
|
||||
buf += 13
|
||||
// buf += 13
|
||||
buf = buf[13:]
|
||||
s2 -= 13
|
||||
}
|
||||
|
||||
// pkt.m_packetType = *buf++
|
||||
buf = buf[1:]
|
||||
pkt.m_packetType = buf[0]
|
||||
pkt.m_packetType = C.uchar(buf[0])
|
||||
|
||||
cChar := (*C.char)(unsafe.Pointer(&buf[0]))
|
||||
pkt.m_nBodySize = C.AMF_DecodeInt24(cChar)
|
||||
|
@ -134,7 +141,7 @@ func (s *session) rtmpWrite(r *C.RTMP, buf []byte) int {
|
|||
|
||||
// C: pkt->m_nTimeStamp |= *buf++ << 24;
|
||||
buf = buf[1:]
|
||||
pkt.m_nTimeStamp |= ( buf[0] << 24 )
|
||||
pkt.m_nTimeStamp |= C.uint( buf[0] << 24 )
|
||||
|
||||
// C: buf+=3
|
||||
buf = buf[3:]
|
||||
|
@ -143,7 +150,7 @@ func (s *session) rtmpWrite(r *C.RTMP, buf []byte) int {
|
|||
|
||||
if ((pkt.m_packetType == C.RTMP_PACKET_TYPE_AUDIO ||
|
||||
pkt.m_packetType == C.RTMP_PACKET_TYPE_VIDEO) &&
|
||||
!pkt.m_nTimeStamp) || pkt.m_packetType == C.RTMP_PACKET_TYPE_INFO {
|
||||
pkt.m_nTimeStamp == 0) || pkt.m_packetType == C.RTMP_PACKET_TYPE_INFO {
|
||||
|
||||
pkt.m_headerType = C.RTMP_PACKET_SIZE_LARGE
|
||||
if pkt.m_packetType == C.RTMP_PACKET_TYPE_INFO {
|
||||
|
@ -154,19 +161,20 @@ func (s *session) rtmpWrite(r *C.RTMP, buf []byte) int {
|
|||
}
|
||||
|
||||
// C: if (!RTMPPacket_Alloc(pkt, pkt->m_nBodySize))
|
||||
if !helpers.UintToBool(uint( C.RTMPPacket_Alloc(pkt, pkt.m_nBodySize))) {
|
||||
if !tools.UintToBool(uint( C.RTMPPacket_Alloc(pkt, pkt.m_nBodySize))) {
|
||||
log.Println("Failed to allocated packet")
|
||||
return 0
|
||||
}
|
||||
|
||||
// Note this is pointer arithmatic
|
||||
enc = pkt.m_body
|
||||
pend = enc + pkt.m_nBodySize
|
||||
|
||||
// pend = enc + pkt.m_nBodySize
|
||||
pend = (*C.char)(unsafe.Pointer( uintptr(unsafe.Pointer(enc)) + ( unsafe.Sizeof(C.int(0)) *
|
||||
(uintptr(pkt.m_nBodySize)) ) ))
|
||||
if pkt.m_packetType == C.RTMP_PACKET_TYPE_INFO {
|
||||
// av_setDataFrame is a static const global in rtmp.c
|
||||
av_setDataFram := AVC("@setDataFrame")
|
||||
enc = C.AMF_EncodeString(enc, pend, &av_setDataFrame )
|
||||
av_setDataFrame := AVC("@setDataFrame")
|
||||
enc = C.AMF_EncodeString(enc, pend, unsafe.Pointer&av_setDataFrame )
|
||||
pkt.m_nBytesRead = enc - pkt.m_body
|
||||
}
|
||||
} else {
|
||||
|
@ -208,17 +216,10 @@ func (s *session) writeFrame(data []byte) uint {
|
|||
if C.RTMP_IsConnected(s.rtmp) <= 0 {
|
||||
return 1
|
||||
}
|
||||
/*
|
||||
// If RTMP_Write returns less than or equal to zero then something is wrong
|
||||
if C.RTMP_Write(s.rtmp, (*C.char)(unsafe.Pointer(&data[0])), C.int(len(data))) <= 0 {
|
||||
return 2
|
||||
}
|
||||
*/
|
||||
|
||||
// This is where C.RTMP_Write would be used
|
||||
if rtmpWrite(s.rtmp, data) <= 0 {
|
||||
return 2
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue