mirror of https://bitbucket.org/ausocean/av.git
Ported writeN, and tested with success
This commit is contained in:
parent
c7930e2cbe
commit
894a62716c
79
rtmp/rtmp.go
79
rtmp/rtmp.go
|
@ -36,12 +36,17 @@ package rtmp
|
|||
#include <string.h>
|
||||
#include <rtmp.h>
|
||||
|
||||
typedef enum {
|
||||
RTMPT_OPEN=0, RTMPT_SEND, RTMPT_IDLE, RTMPT_CLOSE
|
||||
} RTMPTCmd;
|
||||
|
||||
RTMP* start_session(RTMP* rtmp, char* url, uint connect_timeout);
|
||||
int write_frame(RTMP* rtmp, char* data, uint data_length);
|
||||
int end_session(RTMP* rtmp);
|
||||
void AV_queue(RTMP_METHOD **vals, int *num, AVal *av, int txn);
|
||||
int WriteN(RTMP *r, const char *buffer, int n);
|
||||
int EncodeInt32LE(char *output, int nVal);
|
||||
int HTTP_Post(RTMP *r, RTMPTCmd cmd, const char *buf, int len);
|
||||
*/
|
||||
import "C"
|
||||
|
||||
|
@ -67,6 +72,13 @@ const (
|
|||
int64Size = 8
|
||||
)
|
||||
|
||||
const (
|
||||
RTMPT_OPEN = iota
|
||||
RTMPT_SEND
|
||||
RTMPT_IDLE
|
||||
RTMPT_CLOSE
|
||||
)
|
||||
|
||||
const (
|
||||
RTMP_PACKET_SIZE_LARGE = 0
|
||||
RTMP_PACKET_SIZE_MEDIUM = 1
|
||||
|
@ -427,10 +439,6 @@ func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int {
|
|||
nChunkSize = nSize
|
||||
}
|
||||
|
||||
// TODO: figure out what's happening here:
|
||||
// RTMP_LogHexString(RTMP_LOGDEBUG2, (uint8_t *)header, hSize);
|
||||
// RTMP_LogHexString(RTMP_LOGDEBUG2, (uint8_t *)buffer, nChunkSize);
|
||||
|
||||
if tbuf != nil {
|
||||
//memmove(toff, header, uintptr(nChunkSize + hSize))
|
||||
copy(ptrToSlice(toff, int(nChunkSize+hSize)), ptrToSlice(header,
|
||||
|
@ -438,7 +446,7 @@ func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int {
|
|||
toff = incBytePtr(toff, nChunkSize + hSize)
|
||||
} else {
|
||||
// TODO: port this
|
||||
wrote = int(C.WriteN(r, (*C.char)(header), C.int(nChunkSize+hSize)))
|
||||
wrote = int(writeN(r, header, nChunkSize+hSize))
|
||||
|
||||
if wrote == 0 {
|
||||
return 0
|
||||
|
@ -484,7 +492,7 @@ func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int {
|
|||
|
||||
if tbuf != nil {
|
||||
// TODO: port C.writeN
|
||||
wrote := int(C.WriteN(r, (*C.char)(tbuf), C.int(uintptr(decBytePtr(toff,
|
||||
wrote := int(writeN(r, tbuf, int(uintptr(decBytePtr(toff,
|
||||
int(uintptr(unsafe.Pointer(tbuf))))))))
|
||||
C.free(tbuf)
|
||||
tbuf = nil
|
||||
|
@ -534,64 +542,22 @@ func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int {
|
|||
return 1
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue C.int ) C.int {
|
||||
prevPacket *C.RTMPPacket
|
||||
var last = 0 C.uint32_t
|
||||
var nSize C.int
|
||||
var hSize, cSize C.int
|
||||
var header, hptr, hend *C.char
|
||||
var hArr [C.RTMP_MAX_HEADER_SIZE]byte
|
||||
hbuf := (*C.char)(unsafe.Pointer(&hArr[0]))
|
||||
var c C.char
|
||||
var t C.uint32_t
|
||||
var buffer, tbuf, toff *C.char
|
||||
var nChunkSize C.int
|
||||
var tlen C.int
|
||||
|
||||
if packet.m_nChannel >= r.m_channelsAllocatedOut {
|
||||
n := packet.m_nChannel + 10
|
||||
packets := (**C.RTMPPacket)(C.realloc(r.m_vecChannelsOut, unsafe.Sizeof(packet) * n))
|
||||
|
||||
if packets != nil {
|
||||
C.free(r.m_vecChannelsOut)
|
||||
r.m_vecChannelsOut = nil
|
||||
r.m_channelsAllocatedOut = 0
|
||||
return 0
|
||||
}
|
||||
r.m_vecChannelsOut = packets
|
||||
C.memset(r.m_vecChannelsOut + r.m_channelsAllocatedOut, 0, unsafe.Sizeof(packet) * (n - r.m_channelsAllocatedOut))
|
||||
r.m_channelsAllocatedOut = n
|
||||
}
|
||||
|
||||
prePacket = r.m_vecChannelsOut[packet.m_nChannel]
|
||||
}
|
||||
*/
|
||||
/*
|
||||
func writeN(r *C.RTMP, buffer unsafe.Pointer, n int) int {
|
||||
ptr := buffer
|
||||
for n > 0 {
|
||||
var nBytes int
|
||||
|
||||
if r.Link.protocol & C.RTMP_FEATURE_HTTP {
|
||||
if (r.Link.protocol & C.RTMP_FEATURE_HTTP) != 0 {
|
||||
// TODO: port HTTP_POST
|
||||
nbytes = int(C.HTTP_POST(r, C.RTMPT_SEND, (*C.char)(ptr), C.int(n)))
|
||||
nBytes = int(C.HTTP_Post(r, RTMPT_SEND, (*C.char)(ptr), C.int(n)))
|
||||
} else {
|
||||
// TODO: port this if necessary
|
||||
nBytes = RTMPSockBuf_Send(&r.m_sb, (*C.char)(ptr), C.int(n))
|
||||
nBytes = int(C.RTMPSockBuf_Send(&r.m_sb, (*C.char)(ptr), C.int(n)))
|
||||
}
|
||||
|
||||
if nBytes < 0 {
|
||||
// TODO: port this
|
||||
sockerr := int(C.GetSockError())
|
||||
|
||||
if debugMode {
|
||||
log.Printf("WriteN, RTMP send error %v (%v bytes)",sockerr, n)
|
||||
}
|
||||
|
||||
if sockerr == C.EINTR && RTMP_ctrlC == 0 {
|
||||
continue
|
||||
log.Println("WriteN, RTMP send error")
|
||||
}
|
||||
|
||||
// TODO: port this
|
||||
|
@ -605,12 +571,17 @@ func writeN(r *C.RTMP, buffer unsafe.Pointer, n int) int {
|
|||
}
|
||||
|
||||
n -= nBytes
|
||||
ptr = incPtr(ptr, nBytes)
|
||||
ptr = incBytePtr(ptr, nBytes)
|
||||
}
|
||||
|
||||
return n == 0
|
||||
if n == 0 {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
// TODO: port RTMP_METHOD
|
||||
func avQueue(vals **C.RTMP_METHOD, num *int, av *AVal, txn int ) {
|
||||
var tmp unsafe.Pointer
|
||||
|
|
Loading…
Reference in New Issue