av/rtmp/RTMPWrapper.c

86 lines
2.3 KiB
C

/*
NAME
RtpToTsConverter.go - provides utilities for the conversion of Rtp packets
to equivalent MpegTs packets.
DESCRIPTION
See Readme.md
AUTHOR
Saxon Nelson-Milton <saxon.milton@gmail.com>
LICENSE
RtpToTsConverter.go is Copyright (C) 2017 the Australian Ocean Lab (AusOcean)
It is free software: you can redistribute it and/or modify them
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
It is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with revid in gpl.txt. If not, see [GNU licenses](http://www.gnu.org/licenses).
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "rtmp_c/librtmp/rtmp_sys.h"
#include "rtmp_c/librtmp/log.h"
#include "rtmp_c/librtmp/rtmp.h"
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, url)) {
RTMP_Log(RTMP_LOGERROR, "SetupURL Err\n");
RTMP_Free(rtmp);
return 0;
}
RTMP_EnableWrite(rtmp);
RTMP_SetBufferMS(rtmp, 3600 * 1000);
if (!RTMP_Connect(rtmp, NULL)) {
RTMP_Log(RTMP_LOGERROR, "Connect Err\n");
RTMP_Free(rtmp);
return 0;
}
if (!RTMP_ConnectStream(rtmp, 0)) {
RTMP_Log(RTMP_LOGERROR, "ConnectStream Err\n");
RTMP_Close(rtmp);
RTMP_Free(rtmp);
return 0;
}
return 1;
}
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;
}
if (!RTMP_Write(rtmp, data, data_length)) {
RTMP_Log(RTMP_LOGERROR, "RTMP write error!\n");
return 0;
}
return 1;
}
unsigned int RTMP_end_session(RTMP* rtmp){
if (rtmp != NULL) {
RTMP_Close(rtmp);
RTMP_Free(rtmp);
rtmp = NULL;
return 1;
} else {
RTMP_Log(RTMP_LOGERROR, "Tried to end RTMP session, but not allocated yet!\n");
return 0;
}
}