Managed to link c code with cgo :)

This commit is contained in:
Unknown 2018-02-14 16:30:44 +10:30
parent a276809ec9
commit 400f909dd4
12 changed files with 19 additions and 13 deletions

View File

@ -41,8 +41,7 @@ import (
"os/exec"
"strconv"
"time"
"rtmp"
//"bitbucket.org/ausocean/av/parser"
//"bitbucket.org/ausocean/av/tsgenerator"
"../generator"

View File

@ -154,6 +154,7 @@ func TestRtmpOutputUsingLibRtmp(t *testing.T){
Output: Rtmp,
RtmpMethod: LibRtmp,
RtmpUrl: "",
FramesPerClip: 1,
Packetization: Flv,
FrameRate: "25",
}

BIN
revid/testOutput.flv Normal file

Binary file not shown.

View File

@ -26,12 +26,13 @@ LICENSE
along with revid in gpl.txt. If not, see [GNU licenses](http://www.gnu.org/licenses).
*/
package rtmp
// #cgo LDFLAGS: rtmp_c/librtmp/amf.o rtmp_c/librtmp/hashswf.o rtmp_c/librtmp/log.o rtmp_c/librtmp/parseurl.o rtmp_c/librtmp/rtmp.o -lssl -lcrypto -lz
// #include "RTMPWrapper.h"
import "C"
import (
"errors"
"unsafe"
)
type RTMPSession interface {
@ -54,22 +55,26 @@ func NewRTMPSession(url string, connectTimeout uint) (session *rtmpSession){
}
func (s *rtmpSession) StartSession() error {
if !bool(C.RTMP_start_session(s.rtmp, C.CString(s.url), C.uint(connect_timeout))) {
if !uintToBool(uint(C.RTMP_start_session(s.rtmp, C.CString(s.url), C.uint(s.timeout)))) {
return errors.New("RTMP start error! Check rtmp log for details!")
}
return nil
}
func (s *rtmpSession) WriteFrame(data []byte, dataLength uint) error {
if !bool(C.RTMP_write_frame(s.rtmp, (*C.char)(unsafe.Pointer(&data[0])), C.uint(data_length))) {
if !uintToBool(uint(C.RTMP_write_frame(s.rtmp, (*C.char)(unsafe.Pointer(&data[0])), C.uint(dataLength)))) {
return errors.New("RTMP write error! Check rtmp log for details!")
}
return nil
}
func (s *rtmpSession) EndSession() error {
if !bool(C.RTMP_end_session(s.rtmp)) {
if !uintToBool(uint(C.RTMP_end_session(s.rtmp))) {
return errors.New("RTMP end session error! Check rtmp log for details!")
}
return nil
}
func uintToBool(x uint) bool {
return x != 0
}

View File

@ -31,13 +31,13 @@ LICENSE
#include <unistd.h>
#include "rtmp_c/librtmp/rtmp_sys.h"
#include "rtmp_c/librtmp/log.h"
#include "lwlog/lwlog.h"
#include "rtmp_c/librtmp/rtmp.h"
int RTMP_start_session(RTMP* rtmp, char* url, uint connect_timeout){
unsigned int RTMP_start_session(RTMP* rtmp, char* url, uint connect_timeout){
rtmp = RTMP_Alloc();
RTMP_Init(rtmp);
rtmp->Link.timeout = connect_timeout;
if (!RTMP_SetupURL(rtmp, (const char*)url)) {
if (!RTMP_SetupURL(rtmp, url)) {
RTMP_Log(RTMP_LOGERROR, "SetupURL Err\n");
RTMP_Free(rtmp);
return 0;
@ -57,10 +57,10 @@ int RTMP_start_session(RTMP* rtmp, char* url, uint connect_timeout){
RTMP_Free(rtmp);
return 0;
}
return 1
return 1;
}
int RTMP_write_frame(RTMP* rtmp, char* data, uint data_length){
unsigned int RTMP_write_frame(RTMP* rtmp, char* data, uint data_length){
if (!RTMP_IsConnected(rtmp)) {
RTMP_Log(RTMP_LOGERROR, "RTMP is not connected!\n");
return 0;
@ -72,7 +72,7 @@ int RTMP_write_frame(RTMP* rtmp, char* data, uint data_length){
return 1;
}
int RTMP_end_session(RTMP* rtmp){
unsigned int RTMP_end_session(RTMP* rtmp){
if (rtmp != NULL) {
RTMP_Close(rtmp);
RTMP_Free(rtmp);

View File

@ -31,7 +31,8 @@ LICENSE
#include <unistd.h>
#include "rtmp_c/librtmp/rtmp_sys.h"
#include "rtmp_c/librtmp/log.h"
#include "lwlog/lwlog.h"
#include "rtmp_c/librtmp/rtmp.h"
int RTMP_start_session(RTMP* rtmp, char* url, uint connect_timeout);
int RTMP_write_frame(RTMP* rtmp, char* data, uint data_length);

BIN
rtmp/rtmp_c/librtmp/amf.o Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
rtmp/rtmp_c/librtmp/log.o Normal file

Binary file not shown.

Binary file not shown.

BIN
rtmp/rtmp_c/librtmp/rtmp.o Normal file

Binary file not shown.