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
|
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.
|
// Session provides an interface for sending flv tags over rtmp.
|
||||||
type Session interface {
|
type Session interface {
|
||||||
Open() error
|
Open() error
|
||||||
|
@ -120,25 +129,17 @@ func (s *session) Write(data []byte) (int, error) {
|
||||||
return len(data), nil
|
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 {
|
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 pkt = &r.m_write
|
||||||
var pend, enc *C.char
|
var pend, enc unsafe.Pointer
|
||||||
size := len(data)
|
size := len(data)
|
||||||
s2 := size
|
s2 := size
|
||||||
var ret, num int
|
var ret, num int
|
||||||
|
|
||||||
pkt.m_nChannel = 0x04
|
pkt.m_nChannel = 0x04
|
||||||
pkt.m_nInfoField2 = r.m_stream_id
|
pkt.m_nInfoField2 = r.m_stream_id
|
||||||
for s2 > 0 || s2 < 0{
|
for s2 != 0 {
|
||||||
if pkt.m_nBytesRead == 0 {
|
if pkt.m_nBytesRead == 0 {
|
||||||
if size < minDataSize {
|
if size < minDataSize {
|
||||||
log.Printf("size: %d\n", size)
|
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)))
|
buf1 := *(*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(1)))
|
||||||
buf2 := *(*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(2)))
|
buf2 := *(*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(2)))
|
||||||
if buf0 == 'F' && buf1 == 'L' && buf2 == 'V' {
|
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
|
s2 -= 13
|
||||||
}
|
}
|
||||||
|
|
||||||
pkt.m_packetType = C.uchar(*(*byte)(unsafe.Pointer(buf)))
|
pkt.m_packetType = C.uchar(*(*byte)(buf))
|
||||||
buf = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(1)))
|
buf = unsafe.Pointer(uintptr(buf) + uintptr(1))
|
||||||
pkt.m_nBodySize = C.AMF_DecodeInt24(buf)
|
pkt.m_nBodySize = C.AMF_DecodeInt24((*C.char)(buf))
|
||||||
buf = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(3)))
|
buf = unsafe.Pointer(uintptr(buf) + uintptr(3))
|
||||||
pkt.m_nTimeStamp = C.AMF_DecodeInt24(buf)
|
pkt.m_nTimeStamp = C.AMF_DecodeInt24((*C.char)(buf))
|
||||||
buf = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(3)))
|
buf = unsafe.Pointer(uintptr(buf) + uintptr(3))
|
||||||
pkt.m_nTimeStamp |= C.uint(*((*byte)(unsafe.Pointer(buf)))) << 24
|
pkt.m_nTimeStamp |= C.uint(*((*byte)(buf))) << 24
|
||||||
buf = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(4)))
|
buf = unsafe.Pointer(uintptr(buf) + uintptr(4))
|
||||||
s2 -= 11
|
s2 -= 11
|
||||||
|
|
||||||
if ((pkt.m_packetType == RTMP_PACKET_TYPE_AUDIO ||
|
if ((pkt.m_packetType == RTMP_PACKET_TYPE_AUDIO ||
|
||||||
|
@ -181,31 +182,31 @@ func rtmpWrite(r *C.RTMP, data []byte) int {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
enc = pkt.m_body
|
enc = unsafe.Pointer(pkt.m_body)
|
||||||
pend = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(enc)) +
|
pend = unsafe.Pointer(uintptr(enc) +
|
||||||
uintptr(pkt.m_nBodySize)))
|
uintptr(pkt.m_nBodySize))
|
||||||
|
|
||||||
if pkt.m_packetType == RTMP_PACKET_TYPE_INFO {
|
if pkt.m_packetType == RTMP_PACKET_TYPE_INFO {
|
||||||
enc = C.AMF_EncodeString(enc, pend, &setDataFrame)
|
enc = unsafe.Pointer(C.AMF_EncodeString((*C.char)(enc), (*C.char)(pend), &setDataFrame))
|
||||||
pkt.m_nBytesRead = C.uint(math.Abs(float64(uintptr(unsafe.Pointer(enc)) -
|
pkt.m_nBytesRead = C.uint(math.Abs(float64(uintptr(enc) -
|
||||||
uintptr(unsafe.Pointer(pkt.m_body)))))
|
uintptr(unsafe.Pointer(pkt.m_body)))))
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
enc = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(pkt.m_body)) +
|
enc = unsafe.Pointer(uintptr(unsafe.Pointer(pkt.m_body)) +
|
||||||
uintptr(pkt.m_nBytesRead)))
|
uintptr(pkt.m_nBytesRead))
|
||||||
}
|
}
|
||||||
num = int(pkt.m_nBodySize - pkt.m_nBytesRead)
|
num = int(pkt.m_nBodySize - pkt.m_nBytesRead)
|
||||||
if num > s2 {
|
if num > s2 {
|
||||||
num = s2
|
num = s2
|
||||||
}
|
}
|
||||||
|
// this will be a mem cpy func
|
||||||
for i := 0; i < num; i++ {
|
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)
|
pkt.m_nBytesRead += C.uint(num)
|
||||||
s2 -= 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 {
|
if pkt.m_nBytesRead == pkt.m_nBodySize {
|
||||||
ret = int(C.RTMP_SendPacket(r, pkt, 0))
|
ret = int(C.RTMP_SendPacket(r, pkt, 0))
|
||||||
C.RTMPPacket_Free(pkt)
|
C.RTMPPacket_Free(pkt)
|
||||||
|
@ -213,7 +214,7 @@ func rtmpWrite(r *C.RTMP, data []byte) int {
|
||||||
if ret == 0 {
|
if ret == 0 {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
buf = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(4)))
|
buf = unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(4))
|
||||||
s2 -= 4
|
s2 -= 4
|
||||||
if s2 < 0 {
|
if s2 < 0 {
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in New Issue