2018-02-13 11:39:26 +03:00
|
|
|
/*
|
|
|
|
NAME
|
2018-03-13 04:14:43 +03:00
|
|
|
RTMPWrapper.c
|
2018-02-13 11:39:26 +03:00
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
See Readme.md
|
|
|
|
|
|
|
|
AUTHOR
|
2018-03-13 04:14:43 +03:00
|
|
|
Saxon Nelson-Milton <saxon@ausocean.org>
|
2018-02-13 11:39:26 +03:00
|
|
|
|
|
|
|
LICENSE
|
2018-03-13 04:14:43 +03:00
|
|
|
RTMPWrapper.c is Copyright (C) 2017 the Australian Ocean Lab (AusOcean)
|
2018-02-13 11:39:26 +03:00
|
|
|
|
|
|
|
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).
|
|
|
|
*/
|
2018-02-12 16:31:19 +03:00
|
|
|
#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"
|
2018-02-14 09:00:44 +03:00
|
|
|
#include "rtmp_c/librtmp/rtmp.h"
|
2018-02-12 16:31:19 +03:00
|
|
|
|
2018-05-05 17:12:29 +03:00
|
|
|
RTMP* rtmp = NULL;
|
2018-02-15 10:02:04 +03:00
|
|
|
|
|
|
|
unsigned int RTMP_start_session(char* url, uint connect_timeout){
|
|
|
|
printf("RTMP url: %s\n", url);
|
2018-02-13 11:39:26 +03:00
|
|
|
rtmp = RTMP_Alloc();
|
|
|
|
RTMP_Init(rtmp);
|
|
|
|
rtmp->Link.timeout = connect_timeout;
|
2018-02-14 09:00:44 +03:00
|
|
|
if (!RTMP_SetupURL(rtmp, url)) {
|
2018-02-15 10:02:04 +03:00
|
|
|
printf("Can't setup url!\n");
|
2018-05-03 08:56:09 +03:00
|
|
|
RTMP_Close(rtmp);
|
2018-02-13 11:39:26 +03:00
|
|
|
RTMP_Free(rtmp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
RTMP_EnableWrite(rtmp);
|
|
|
|
RTMP_SetBufferMS(rtmp, 3600 * 1000);
|
|
|
|
if (!RTMP_Connect(rtmp, NULL)) {
|
2018-02-15 10:02:04 +03:00
|
|
|
printf("RTMP can't connect!\n");
|
2018-05-03 08:56:09 +03:00
|
|
|
RTMP_Close(rtmp);
|
2018-02-13 11:39:26 +03:00
|
|
|
RTMP_Free(rtmp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!RTMP_ConnectStream(rtmp, 0)) {
|
2018-02-15 10:02:04 +03:00
|
|
|
printf("RTMP can't connect stream!\n");
|
2018-02-13 11:39:26 +03:00
|
|
|
RTMP_Close(rtmp);
|
|
|
|
RTMP_Free(rtmp);
|
|
|
|
return 0;
|
|
|
|
}
|
2018-02-14 09:00:44 +03:00
|
|
|
return 1;
|
2018-02-12 16:31:19 +03:00
|
|
|
}
|
|
|
|
|
2018-02-15 10:02:04 +03:00
|
|
|
unsigned int RTMP_write_frame(char* data, uint data_length){
|
2018-05-05 17:29:51 +03:00
|
|
|
char* dataForC = malloc(data_length);
|
2018-05-05 17:28:26 +03:00
|
|
|
memcpy(dataForC,data,data_length);
|
2018-02-13 11:39:26 +03:00
|
|
|
if (!RTMP_IsConnected(rtmp)) {
|
2018-02-15 10:02:04 +03:00
|
|
|
printf("RTMP is not connected!\n");
|
2018-05-05 17:28:26 +03:00
|
|
|
free(dataForC);
|
2018-02-13 11:39:26 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2018-02-15 10:02:04 +03:00
|
|
|
if (!RTMP_Write(rtmp, (const char*)data, data_length)) {
|
|
|
|
printf("RTMP write error!\n");
|
2018-05-05 17:28:26 +03:00
|
|
|
free(dataForC);
|
2018-02-13 11:39:26 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2018-05-05 17:34:07 +03:00
|
|
|
free(dataForC);
|
2018-02-13 11:39:26 +03:00
|
|
|
return 1;
|
2018-02-12 16:31:19 +03:00
|
|
|
}
|
|
|
|
|
2018-02-15 10:02:04 +03:00
|
|
|
unsigned int RTMP_end_session(){
|
2018-02-13 11:39:26 +03:00
|
|
|
if (rtmp != NULL) {
|
|
|
|
RTMP_Close(rtmp);
|
|
|
|
RTMP_Free(rtmp);
|
|
|
|
rtmp = NULL;
|
|
|
|
return 1;
|
|
|
|
} else {
|
2018-02-15 10:02:04 +03:00
|
|
|
printf("Tried to end RTMP session, but not allocated yet!\n");
|
2018-02-12 16:31:19 +03:00
|
|
|
return 0;
|
2018-02-13 11:39:26 +03:00
|
|
|
}
|
2018-02-12 16:31:19 +03:00
|
|
|
}
|