mirror of https://bitbucket.org/ausocean/av.git
Still can't find the bug
This commit is contained in:
parent
4819cc92ec
commit
137d60bde6
rtmp
31
rtmp/rtmp.go
31
rtmp/rtmp.go
|
@ -48,6 +48,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
_"fmt"
|
_"fmt"
|
||||||
|
"math"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -83,7 +84,7 @@ func NewSession(url string, connectTimeout uint) Session {
|
||||||
func AVC(str string) C.AVal {
|
func AVC(str string) C.AVal {
|
||||||
var aval C.AVal
|
var aval C.AVal
|
||||||
aval.av_val = C.CString(str)
|
aval.av_val = C.CString(str)
|
||||||
aval.av_len = C.int(unsafe.Sizeof(aval.av_val)-1)
|
aval.av_len = C.int(len(str))
|
||||||
return aval
|
return aval
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,6 +120,14 @@ 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 := (*C.char)(unsafe.Pointer(&data[0]))
|
||||||
var pkt = &r.m_write
|
var pkt = &r.m_write
|
||||||
|
@ -150,21 +159,21 @@ func rtmpWrite(r *C.RTMP, data []byte) int {
|
||||||
buf = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(3)))
|
buf = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(3)))
|
||||||
pkt.m_nTimeStamp = C.AMF_DecodeInt24(buf)
|
pkt.m_nTimeStamp = C.AMF_DecodeInt24(buf)
|
||||||
buf = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(3)))
|
buf = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(3)))
|
||||||
pkt.m_nTimeStamp |= C.uint(*(*byte)(unsafe.Pointer(buf)) << 24)
|
pkt.m_nTimeStamp |= C.uint(*((*byte)(unsafe.Pointer(buf)))) << 24
|
||||||
buf = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(4)))
|
buf = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(4)))
|
||||||
s2 -= 11
|
s2 -= 11
|
||||||
|
|
||||||
if ((pkt.m_packetType == C.RTMP_PACKET_TYPE_AUDIO ||
|
if ((pkt.m_packetType == RTMP_PACKET_TYPE_AUDIO ||
|
||||||
pkt.m_packetType == C.RTMP_PACKET_TYPE_VIDEO) &&
|
pkt.m_packetType == RTMP_PACKET_TYPE_VIDEO) &&
|
||||||
pkt.m_nTimeStamp == 0) || pkt.m_packetType == C.RTMP_PACKET_TYPE_INFO {
|
pkt.m_nTimeStamp == 0) || pkt.m_packetType == RTMP_PACKET_TYPE_INFO {
|
||||||
|
|
||||||
pkt.m_headerType = C.RTMP_PACKET_SIZE_LARGE
|
pkt.m_headerType = RTMP_PACKET_SIZE_LARGE
|
||||||
|
|
||||||
if pkt.m_packetType == C.RTMP_PACKET_TYPE_INFO {
|
if pkt.m_packetType == RTMP_PACKET_TYPE_INFO {
|
||||||
pkt.m_nBodySize += 16
|
pkt.m_nBodySize += 16
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pkt.m_headerType = C.RTMP_PACKET_SIZE_MEDIUM
|
pkt.m_headerType = RTMP_PACKET_SIZE_MEDIUM
|
||||||
}
|
}
|
||||||
|
|
||||||
if int(C.RTMPPacket_Alloc(pkt, pkt.m_nBodySize)) == 0 {
|
if int(C.RTMPPacket_Alloc(pkt, pkt.m_nBodySize)) == 0 {
|
||||||
|
@ -176,10 +185,10 @@ func rtmpWrite(r *C.RTMP, data []byte) int {
|
||||||
pend = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(enc)) +
|
pend = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(enc)) +
|
||||||
uintptr(pkt.m_nBodySize)))
|
uintptr(pkt.m_nBodySize)))
|
||||||
|
|
||||||
if pkt.m_packetType == C.RTMP_PACKET_TYPE_INFO {
|
if pkt.m_packetType == RTMP_PACKET_TYPE_INFO {
|
||||||
enc = C.AMF_EncodeString(enc, pend, &av_setDataFrame)
|
enc = C.AMF_EncodeString(enc, pend, &av_setDataFrame)
|
||||||
pkt.m_nBytesRead = (C.uint)(uintptr(unsafe.Pointer(enc)) -
|
pkt.m_nBytesRead = C.uint(math.Abs(float64(uintptr(unsafe.Pointer(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 = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(pkt.m_body)) +
|
||||||
|
|
Loading…
Reference in New Issue