mirror of https://bitbucket.org/ausocean/av.git
Tried to make it more go like, but think I broke it
This commit is contained in:
parent
b0aa39c29b
commit
c2e1df170c
63
rtmp/rtmp.go
63
rtmp/rtmp.go
|
@ -55,6 +55,15 @@ const (
|
|||
minDataSize = 11
|
||||
)
|
||||
|
||||
const (
|
||||
RTMP_PACKET_SIZE_LARGE = 0
|
||||
RTMP_PACKET_SIZE_MEDIUM = 1
|
||||
RTMP_PACKET_SIZE_SMALL = 2
|
||||
RTMP_PACKET_TYPE_INFO = 0x12
|
||||
RTMP_PACKET_TYPE_AUDIO = 0x08
|
||||
RTMP_PACKET_TYPE_VIDEO = 0x09
|
||||
)
|
||||
|
||||
// Session provides an interface for sending flv tags over rtmp.
|
||||
type Session interface {
|
||||
Open() error
|
||||
|
@ -120,25 +129,17 @@ func (s *session) Write(data []byte) (int, error) {
|
|||
return len(data), nil
|
||||
}
|
||||
|
||||
const (
|
||||
RTMP_PACKET_SIZE_LARGE = 0
|
||||
RTMP_PACKET_SIZE_MEDIUM = 1
|
||||
RTMP_PACKET_SIZE_SMALL = 2
|
||||
RTMP_PACKET_TYPE_INFO = 0x12
|
||||
RTMP_PACKET_TYPE_AUDIO = 0x08
|
||||
RTMP_PACKET_TYPE_VIDEO = 0x09
|
||||
)
|
||||
func rtmpWrite(r *C.RTMP, data []byte) int {
|
||||
buf := (*C.char)(unsafe.Pointer(&data[0]))
|
||||
buf := unsafe.Pointer(&data[0])
|
||||
var pkt = &r.m_write
|
||||
var pend, enc *C.char
|
||||
var pend, enc unsafe.Pointer
|
||||
size := len(data)
|
||||
s2 := size
|
||||
var ret, num int
|
||||
|
||||
pkt.m_nChannel = 0x04
|
||||
pkt.m_nInfoField2 = r.m_stream_id
|
||||
for s2 > 0 || s2 < 0{
|
||||
for s2 != 0 {
|
||||
if pkt.m_nBytesRead == 0 {
|
||||
if size < minDataSize {
|
||||
log.Printf("size: %d\n", size)
|
||||
|
@ -149,18 +150,18 @@ func rtmpWrite(r *C.RTMP, data []byte) int {
|
|||
buf1 := *(*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(1)))
|
||||
buf2 := *(*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(2)))
|
||||
if buf0 == 'F' && buf1 == 'L' && buf2 == 'V' {
|
||||
buf = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(13)))
|
||||
buf = unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(13))
|
||||
s2 -= 13
|
||||
}
|
||||
|
||||
pkt.m_packetType = C.uchar(*(*byte)(unsafe.Pointer(buf)))
|
||||
buf = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(1)))
|
||||
pkt.m_nBodySize = C.AMF_DecodeInt24(buf)
|
||||
buf = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(3)))
|
||||
pkt.m_nTimeStamp = C.AMF_DecodeInt24(buf)
|
||||
buf = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(3)))
|
||||
pkt.m_nTimeStamp |= C.uint(*((*byte)(unsafe.Pointer(buf)))) << 24
|
||||
buf = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(4)))
|
||||
pkt.m_packetType = C.uchar(*(*byte)(buf))
|
||||
buf = unsafe.Pointer(uintptr(buf) + uintptr(1))
|
||||
pkt.m_nBodySize = C.AMF_DecodeInt24((*C.char)(buf))
|
||||
buf = unsafe.Pointer(uintptr(buf) + uintptr(3))
|
||||
pkt.m_nTimeStamp = C.AMF_DecodeInt24((*C.char)(buf))
|
||||
buf = unsafe.Pointer(uintptr(buf) + uintptr(3))
|
||||
pkt.m_nTimeStamp |= C.uint(*((*byte)(buf))) << 24
|
||||
buf = unsafe.Pointer(uintptr(buf) + uintptr(4))
|
||||
s2 -= 11
|
||||
|
||||
if ((pkt.m_packetType == RTMP_PACKET_TYPE_AUDIO ||
|
||||
|
@ -181,31 +182,31 @@ func rtmpWrite(r *C.RTMP, data []byte) int {
|
|||
return 0
|
||||
}
|
||||
|
||||
enc = pkt.m_body
|
||||
pend = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(enc)) +
|
||||
uintptr(pkt.m_nBodySize)))
|
||||
enc = unsafe.Pointer(pkt.m_body)
|
||||
pend = unsafe.Pointer(uintptr(enc) +
|
||||
uintptr(pkt.m_nBodySize))
|
||||
|
||||
if pkt.m_packetType == RTMP_PACKET_TYPE_INFO {
|
||||
enc = C.AMF_EncodeString(enc, pend, &setDataFrame)
|
||||
pkt.m_nBytesRead = C.uint(math.Abs(float64(uintptr(unsafe.Pointer(enc)) -
|
||||
enc = unsafe.Pointer(C.AMF_EncodeString((*C.char)(enc), (*C.char)(pend), &setDataFrame))
|
||||
pkt.m_nBytesRead = C.uint(math.Abs(float64(uintptr(enc) -
|
||||
uintptr(unsafe.Pointer(pkt.m_body)))))
|
||||
}
|
||||
|
||||
} else {
|
||||
enc = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(pkt.m_body)) +
|
||||
uintptr(pkt.m_nBytesRead)))
|
||||
enc = unsafe.Pointer(uintptr(unsafe.Pointer(pkt.m_body)) +
|
||||
uintptr(pkt.m_nBytesRead))
|
||||
}
|
||||
num = int(pkt.m_nBodySize - pkt.m_nBytesRead)
|
||||
if num > s2 {
|
||||
num = s2
|
||||
}
|
||||
// this will be a mem cpy func
|
||||
for i := 0; i < num; i++ {
|
||||
*(*byte)(unsafe.Pointer(enc)) = *(*byte)(unsafe.Pointer(buf))
|
||||
*(*byte)(enc) = *(*byte)(buf)
|
||||
}
|
||||
//C.memcpy(unsafe.Pointer(enc),unsafe.Pointer(buf),C.ulong(num))
|
||||
pkt.m_nBytesRead += C.uint(num)
|
||||
s2 -= num
|
||||
buf = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(num)))
|
||||
buf = unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(num))
|
||||
if pkt.m_nBytesRead == pkt.m_nBodySize {
|
||||
ret = int(C.RTMP_SendPacket(r, pkt, 0))
|
||||
C.RTMPPacket_Free(pkt)
|
||||
|
@ -213,7 +214,7 @@ func rtmpWrite(r *C.RTMP, data []byte) int {
|
|||
if ret == 0 {
|
||||
return -1
|
||||
}
|
||||
buf = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(4)))
|
||||
buf = unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(4))
|
||||
s2 -= 4
|
||||
if s2 < 0 {
|
||||
break
|
||||
|
|
Loading…
Reference in New Issue