New upstream version 0.15.4+dfsg1
This commit is contained in:
parent
55d5047af0
commit
67704ac59c
359 changed files with 8423 additions and 1050 deletions
|
|
@ -62,6 +62,7 @@ endif()
|
|||
set(obs-outputs_HEADERS
|
||||
obs-output-ver.h
|
||||
rtmp-helpers.h
|
||||
net-if.h
|
||||
flv-mux.h
|
||||
flv-output.h
|
||||
librtmp)
|
||||
|
|
@ -69,7 +70,8 @@ set(obs-outputs_SOURCES
|
|||
obs-outputs.c
|
||||
rtmp-stream.c
|
||||
flv-output.c
|
||||
flv-mux.c)
|
||||
flv-mux.c
|
||||
net-if.c)
|
||||
|
||||
add_library(obs-outputs MODULE
|
||||
${obs-outputs_SOURCES}
|
||||
|
|
|
|||
|
|
@ -2,3 +2,4 @@ RTMPStream="RTMP Stream"
|
|||
RTMPStream.DropThreshold="Drop Threshold (milliseconds)"
|
||||
FLVOutput="FLV File Output"
|
||||
FLVOutput.FilePath="File Path"
|
||||
Default="Default"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
RTMPStream="RTMP-virtaus"
|
||||
RTMPStream.DropThreshold="Pudotuskynnys (ms)"
|
||||
RTMPStream.DropThreshold="Pudotuskynnys (millisekuntia)"
|
||||
FLVOutput="FLV-tiedosto ulostulo"
|
||||
FLVOutput.FilePath="Tiedostopolku"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
RTMPStream="RTMP 串流"
|
||||
RTMPStream.DropThreshold="丟失阈值(毫秒)"
|
||||
RTMPStream.DropThreshold="丟棄閾值 (毫秒)"
|
||||
FLVOutput="FLV 檔案輸出"
|
||||
FLVOutput.FilePath="檔案路徑"
|
||||
|
||||
|
|
|
|||
|
|
@ -46,14 +46,14 @@ static const char *flv_output_getname(void *unused)
|
|||
return obs_module_text("FLVOutput");
|
||||
}
|
||||
|
||||
static void flv_output_stop(void *data);
|
||||
static void flv_output_stop(void *data, uint64_t ts);
|
||||
|
||||
static void flv_output_destroy(void *data)
|
||||
{
|
||||
struct flv_output *stream = data;
|
||||
|
||||
if (stream->active)
|
||||
flv_output_stop(data);
|
||||
flv_output_stop(data, 0);
|
||||
|
||||
dstr_free(&stream->path);
|
||||
bfree(stream);
|
||||
|
|
@ -68,7 +68,7 @@ static void *flv_output_create(obs_data_t *settings, obs_output_t *output)
|
|||
return stream;
|
||||
}
|
||||
|
||||
static void flv_output_stop(void *data)
|
||||
static void flv_output_stop(void *data, uint64_t ts)
|
||||
{
|
||||
struct flv_output *stream = data;
|
||||
|
||||
|
|
@ -84,6 +84,8 @@ static void flv_output_stop(void *data)
|
|||
|
||||
info("FLV file output complete");
|
||||
}
|
||||
|
||||
UNUSED_PARAMETER(ts);
|
||||
}
|
||||
|
||||
static int write_packet(struct flv_output *stream,
|
||||
|
|
|
|||
270
plugins/obs-outputs/net-if.c
Normal file
270
plugins/obs-outputs/net-if.c
Normal file
|
|
@ -0,0 +1,270 @@
|
|||
/******************************************************************************
|
||||
Copyright (C) 2016 B. Lee <bl4@postpile.net>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
|
||||
#include "net-if.h"
|
||||
#include <util/platform.h>
|
||||
#include <util/dstr.h>
|
||||
|
||||
#define do_log(level, format, ...) \
|
||||
blog(level, "[net if] " format, ##__VA_ARGS__)
|
||||
|
||||
#define warn(format, ...) do_log(LOG_WARNING, format, ##__VA_ARGS__)
|
||||
#define info(format, ...) do_log(LOG_INFO, format, ##__VA_ARGS__)
|
||||
#define debug(format, ...) do_log(LOG_DEBUG, format, ##__VA_ARGS__)
|
||||
|
||||
static inline void netif_saddr_data_push_back(struct netif_saddr_data *sd,
|
||||
const char *ip, const char *adapter)
|
||||
{
|
||||
struct netif_saddr_item item;
|
||||
struct dstr full_name = {0};
|
||||
char *ip_dup = bstrdup(ip);
|
||||
|
||||
if (adapter && *adapter)
|
||||
dstr_printf(&full_name, "[%s] %s", adapter, ip);
|
||||
else
|
||||
dstr_copy(&full_name, ip);
|
||||
|
||||
item.name = full_name.array;
|
||||
item.addr = ip_dup;
|
||||
|
||||
da_push_back(sd->addrs, &item);
|
||||
}
|
||||
|
||||
static void netif_convert_to_string(char *dest,
|
||||
struct sockaddr_storage *byte_address)
|
||||
{
|
||||
int family = byte_address->ss_family;
|
||||
char temp_char[INET6_ADDRSTRLEN] = {0};
|
||||
|
||||
#ifndef _WIN32
|
||||
if (family == AF_INET)
|
||||
inet_ntop(family, &(((struct sockaddr_in*)byte_address)->sin_addr),
|
||||
temp_char, INET6_ADDRSTRLEN);
|
||||
else if (family == AF_INET6)
|
||||
inet_ntop(family, &(((struct sockaddr_in*)byte_address)->sin_addr),
|
||||
temp_char, INET6_ADDRSTRLEN);
|
||||
#else
|
||||
if (family == AF_INET)
|
||||
InetNtopA(family, &(((SOCKADDR_IN *)byte_address)->sin_addr),
|
||||
temp_char, INET6_ADDRSTRLEN);
|
||||
else if (family == AF_INET6)
|
||||
InetNtopA(family, &(((SOCKADDR_IN6 *)byte_address)->sin6_addr),
|
||||
temp_char, INET6_ADDRSTRLEN);
|
||||
#endif
|
||||
strncpy(dest, temp_char, INET6_ADDRSTRLEN);
|
||||
}
|
||||
|
||||
static void netif_push(struct sockaddr *copy_source,
|
||||
struct netif_saddr_data *saddr_d,
|
||||
const char *adapter)
|
||||
{
|
||||
char temp_char[INET6_ADDRSTRLEN] = {0};
|
||||
struct sockaddr_storage sa = {0};
|
||||
|
||||
if (copy_source->sa_family == AF_INET)
|
||||
memcpy(&sa, copy_source, sizeof(struct sockaddr_in));
|
||||
else if (copy_source->sa_family == AF_INET6)
|
||||
memcpy(&sa, copy_source, sizeof(struct sockaddr_in6));
|
||||
|
||||
netif_convert_to_string(temp_char, &sa);
|
||||
netif_saddr_data_push_back(saddr_d, temp_char, adapter);
|
||||
}
|
||||
|
||||
void netif_log_saddrs(struct netif_saddr_data *sd)
|
||||
{
|
||||
for(size_t i = 0; i < sd->addrs.num; i++)
|
||||
info("\t\t%s", sd->addrs.array[i].name);
|
||||
}
|
||||
|
||||
bool netif_str_to_addr(struct sockaddr_storage *out, int *addr_len,
|
||||
const char *addr)
|
||||
{
|
||||
bool ipv6;
|
||||
|
||||
memset(out, 0, sizeof(*out));
|
||||
*addr_len = 0;
|
||||
|
||||
if (!addr)
|
||||
return false;
|
||||
|
||||
ipv6 = (strchr(addr, ':') != NULL);
|
||||
out->ss_family = ipv6 ? AF_INET6 : AF_INET;
|
||||
*addr_len = sizeof(*out);
|
||||
|
||||
#ifdef _WIN32
|
||||
int ret = WSAStringToAddressA((LPSTR)addr, out->ss_family, NULL,
|
||||
(LPSOCKADDR)out, addr_len);
|
||||
if (ret == SOCKET_ERROR)
|
||||
warn("Could not parse address, error code: %d", GetLastError());
|
||||
return ret != SOCKET_ERROR;
|
||||
#else
|
||||
struct sockaddr_in *sin = (struct sockaddr_in *)out;
|
||||
if (inet_pton(out->ss_family, addr, &sin->sin_addr)) {
|
||||
*addr_len = ipv6 ?
|
||||
sizeof(struct sockaddr_in6) :
|
||||
sizeof(struct sockaddr_in);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
static inline bool is_loopback(struct ifaddrs *ifa)
|
||||
{
|
||||
const char *n = ifa->ifa_name;
|
||||
return n && (strcmp(n, "lo") == 0 || strcmp(n, "lo0") == 0);
|
||||
}
|
||||
|
||||
static inline void netif_get_addrs_nix(struct netif_saddr_data *ifaddrs)
|
||||
{
|
||||
struct ifaddrs *ifaddr, *ifa;
|
||||
unsigned int family, s;
|
||||
char host[NI_MAXHOST];
|
||||
|
||||
if (getifaddrs(&ifaddr) == -1) {
|
||||
warn("getifaddrs() failed");
|
||||
return;
|
||||
}
|
||||
|
||||
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
|
||||
if (ifa->ifa_addr == NULL || is_loopback(ifa))
|
||||
continue;
|
||||
|
||||
family = ifa->ifa_addr->sa_family;
|
||||
|
||||
if ((family == AF_INET) || (family == AF_INET6)) {
|
||||
s = getnameinfo(ifa->ifa_addr,
|
||||
(family == AF_INET) ?
|
||||
sizeof(struct sockaddr_in) :
|
||||
sizeof(struct sockaddr_in6),
|
||||
host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
|
||||
if (s != 0) {
|
||||
warn("getnameinfo() failed: %s",
|
||||
gai_strerror(s));
|
||||
continue;
|
||||
}
|
||||
|
||||
netif_push(ifa->ifa_addr, ifaddrs, ifa->ifa_name);
|
||||
}
|
||||
}
|
||||
|
||||
freeifaddrs(ifaddr);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static inline PIP_ADAPTER_ADDRESSES get_adapters(void)
|
||||
{
|
||||
PIP_ADAPTER_ADDRESSES adapter = NULL;
|
||||
unsigned long ret = 0;
|
||||
unsigned long out_buf_len = 4096;
|
||||
unsigned long flags =
|
||||
GAA_FLAG_SKIP_ANYCAST |
|
||||
GAA_FLAG_SKIP_MULTICAST |
|
||||
GAA_FLAG_SKIP_DNS_SERVER;
|
||||
const int max_tries = 3;
|
||||
int i = 0;
|
||||
|
||||
do {
|
||||
adapter = (IP_ADAPTER_ADDRESSES*)bmalloc(out_buf_len);
|
||||
if (!adapter)
|
||||
return NULL;
|
||||
|
||||
ret = GetAdaptersAddresses(AF_UNSPEC, flags, NULL, adapter,
|
||||
&out_buf_len);
|
||||
if (ret == ERROR_BUFFER_OVERFLOW) {
|
||||
bfree(adapter);
|
||||
adapter = NULL;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
} while ((ret == ERROR_BUFFER_OVERFLOW) && (i < max_tries));
|
||||
|
||||
if (ret != NO_ERROR && ret != ERROR_NO_DATA) {
|
||||
LPSTR msg_buf = NULL;
|
||||
|
||||
bfree(adapter);
|
||||
adapter = NULL;
|
||||
|
||||
FormatMessageA(
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, ret,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
msg_buf, 0, NULL);
|
||||
if (msg_buf) {
|
||||
warn("Call to GetAdaptersAddresses failed: %s (%d)",
|
||||
msg_buf, ret);
|
||||
LocalFree(msg_buf);
|
||||
}
|
||||
}
|
||||
|
||||
return adapter;
|
||||
}
|
||||
|
||||
static inline void netif_get_addrs_win32(struct netif_saddr_data *ifaddrs)
|
||||
{
|
||||
PIP_ADAPTER_ADDRESSES adapter = get_adapters();
|
||||
PIP_ADAPTER_UNICAST_ADDRESS unicast = NULL;
|
||||
PIP_ADAPTER_ADDRESSES cur_adap = NULL;
|
||||
SOCKET_ADDRESS socket_addr;
|
||||
int family;
|
||||
|
||||
if (!adapter)
|
||||
return;
|
||||
|
||||
for (cur_adap = adapter; !!cur_adap; cur_adap = cur_adap->Next) {
|
||||
char *adap_name = NULL;
|
||||
|
||||
if (cur_adap->OperStatus != IfOperStatusUp ||
|
||||
cur_adap->IfType == IF_TYPE_SOFTWARE_LOOPBACK)
|
||||
continue;
|
||||
|
||||
os_wcs_to_utf8_ptr(cur_adap->FriendlyName, 0, &adap_name);
|
||||
|
||||
unicast = cur_adap->FirstUnicastAddress;
|
||||
|
||||
for (; !!unicast; unicast = unicast->Next) {
|
||||
socket_addr = unicast->Address;
|
||||
|
||||
family = socket_addr.lpSockaddr->sa_family;
|
||||
if (family == AF_INET || family == AF_INET6)
|
||||
netif_push(socket_addr.lpSockaddr, ifaddrs,
|
||||
adap_name);
|
||||
}
|
||||
|
||||
bfree(adap_name);
|
||||
}
|
||||
|
||||
bfree(adapter);
|
||||
}
|
||||
#endif
|
||||
|
||||
void netif_get_addrs(struct netif_saddr_data *ifaddrs)
|
||||
{
|
||||
da_init(ifaddrs->addrs);
|
||||
|
||||
#ifdef _WIN32
|
||||
netif_get_addrs_win32(ifaddrs);
|
||||
#else
|
||||
netif_get_addrs_nix(ifaddrs);
|
||||
#endif
|
||||
}
|
||||
76
plugins/obs-outputs/net-if.h
Normal file
76
plugins/obs-outputs/net-if.h
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
/******************************************************************************
|
||||
Copyright (C) 2016 B. Lee <bl4@postpile.net>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <util/darray.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <ws2tcpip.h>
|
||||
# include <winsock2.h>
|
||||
# include <ws2ipdef.h>
|
||||
# include <iphlpapi.h>
|
||||
#else
|
||||
|
||||
# ifdef __linux__
|
||||
# include <linux/if_link.h>
|
||||
# elif __FreeBSD__
|
||||
# ifndef _GNU_SOURCE
|
||||
# define _GNU_SOURCE
|
||||
# define __NET_IF_GNU_SOURCE__
|
||||
# endif //_GNU_SOURCE
|
||||
# endif //__FreeBSD__
|
||||
|
||||
# include <ifaddrs.h>
|
||||
# include <netdb.h>
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
# include <unistd.h>
|
||||
# include <arpa/inet.h>
|
||||
# include <sys/socket.h>
|
||||
|
||||
# ifdef __FreeBSD__
|
||||
# ifdef ___NET_IF_GNU_SOURCE__
|
||||
# undef ___NET_IF_GNU_SOURCE__
|
||||
# undef _GNU_SOURCE
|
||||
# endif
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
struct netif_saddr_item {
|
||||
char *name;
|
||||
char *addr;
|
||||
};
|
||||
|
||||
struct netif_saddr_data {
|
||||
DARRAY(struct netif_saddr_item) addrs;
|
||||
};
|
||||
|
||||
static inline void netif_saddr_data_free(struct netif_saddr_data *data)
|
||||
{
|
||||
for (size_t i = 0; i < data->addrs.num; i++) {
|
||||
bfree(data->addrs.array[i].name);
|
||||
bfree(data->addrs.array[i].addr);
|
||||
}
|
||||
da_free(data->addrs);
|
||||
}
|
||||
|
||||
extern bool netif_str_to_addr(struct sockaddr_storage *out, int *addr_len,
|
||||
const char *addr);
|
||||
extern void netif_get_addrs(struct netif_saddr_data *ifaddrs);
|
||||
extern void netif_log_saddrs(struct netif_saddr_data *sd);
|
||||
|
|
@ -25,6 +25,7 @@
|
|||
#include "librtmp/rtmp.h"
|
||||
#include "librtmp/log.h"
|
||||
#include "flv-mux.h"
|
||||
#include "net-if.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <Iphlpapi.h>
|
||||
|
|
@ -42,6 +43,7 @@
|
|||
|
||||
#define OPT_DROP_THRESHOLD "drop_threshold_ms"
|
||||
#define OPT_MAX_SHUTDOWN_TIME_SEC "max_shutdown_time_sec"
|
||||
#define OPT_BIND_IP "bind_ip"
|
||||
|
||||
//#define TEST_FRAMEDROPS
|
||||
|
||||
|
|
@ -63,10 +65,12 @@ struct rtmp_stream {
|
|||
|
||||
os_sem_t *send_sem;
|
||||
os_event_t *stop_event;
|
||||
uint64_t stop_ts;
|
||||
|
||||
struct dstr path, key;
|
||||
struct dstr username, password;
|
||||
struct dstr encoder_name;
|
||||
struct dstr bind_ip;
|
||||
|
||||
/* frame drop variables */
|
||||
int64_t drop_threshold_usec;
|
||||
|
|
@ -146,6 +150,7 @@ static void rtmp_stream_destroy(void *data)
|
|||
if (stream->connecting)
|
||||
pthread_join(stream->connect_thread, NULL);
|
||||
|
||||
stream->stop_ts = 0;
|
||||
os_event_signal(stream->stop_event);
|
||||
|
||||
if (active(stream)) {
|
||||
|
|
@ -162,6 +167,7 @@ static void rtmp_stream_destroy(void *data)
|
|||
dstr_free(&stream->username);
|
||||
dstr_free(&stream->password);
|
||||
dstr_free(&stream->encoder_name);
|
||||
dstr_free(&stream->bind_ip);
|
||||
os_event_destroy(stream->stop_event);
|
||||
os_sem_destroy(stream->send_sem);
|
||||
pthread_mutex_destroy(&stream->packets_mutex);
|
||||
|
|
@ -193,7 +199,7 @@ fail:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static void rtmp_stream_stop(void *data)
|
||||
static void rtmp_stream_stop(void *data, uint64_t ts)
|
||||
{
|
||||
struct rtmp_stream *stream = data;
|
||||
|
||||
|
|
@ -203,11 +209,12 @@ static void rtmp_stream_stop(void *data)
|
|||
if (connecting(stream))
|
||||
pthread_join(stream->connect_thread, NULL);
|
||||
|
||||
stream->stop_ts = ts / 1000ULL;
|
||||
os_event_signal(stream->stop_event);
|
||||
|
||||
if (active(stream)) {
|
||||
os_sem_post(stream->send_sem);
|
||||
obs_output_end_data_capture(stream->output);
|
||||
if (stream->stop_ts == 0)
|
||||
os_sem_post(stream->send_sem);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -313,33 +320,6 @@ static int send_packet(struct rtmp_stream *stream,
|
|||
|
||||
static inline bool send_headers(struct rtmp_stream *stream);
|
||||
|
||||
static bool send_remaining_packets(struct rtmp_stream *stream)
|
||||
{
|
||||
struct encoder_packet packet;
|
||||
uint64_t max_ns = (uint64_t)stream->max_shutdown_time_sec * 1000000000;
|
||||
uint64_t begin_time_ns = os_gettime_ns();
|
||||
|
||||
if (!stream->sent_headers) {
|
||||
if (!send_headers(stream))
|
||||
return false;
|
||||
}
|
||||
|
||||
while (get_next_packet(stream, &packet)) {
|
||||
if (send_packet(stream, &packet, false, packet.track_idx) < 0)
|
||||
return false;
|
||||
|
||||
/* Just disconnect if it takes too long to shut down */
|
||||
if ((os_gettime_ns() - begin_time_ns) > max_ns) {
|
||||
info("Took longer than %d second(s) to shut down, "
|
||||
"automatically stopping connection",
|
||||
stream->max_shutdown_time_sec);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void *send_thread(void *data)
|
||||
{
|
||||
struct rtmp_stream *stream = data;
|
||||
|
|
@ -349,11 +329,20 @@ static void *send_thread(void *data)
|
|||
while (os_sem_wait(stream->send_sem) == 0) {
|
||||
struct encoder_packet packet;
|
||||
|
||||
if (stopping(stream))
|
||||
if (stopping(stream) && stream->stop_ts == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!get_next_packet(stream, &packet))
|
||||
continue;
|
||||
|
||||
if (stopping(stream)) {
|
||||
if (packet.sys_dts_usec >= (int64_t)stream->stop_ts) {
|
||||
obs_free_encoder_packet(&packet);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!stream->sent_headers) {
|
||||
if (!send_headers(stream)) {
|
||||
os_atomic_set_bool(&stream->disconnected, true);
|
||||
|
|
@ -367,12 +356,8 @@ static void *send_thread(void *data)
|
|||
}
|
||||
}
|
||||
|
||||
if (!disconnected(stream) && !send_remaining_packets(stream))
|
||||
os_atomic_set_bool(&stream->disconnected, true);
|
||||
|
||||
if (disconnected(stream)) {
|
||||
info("Disconnected from %s", stream->path.array);
|
||||
free_packets(stream);
|
||||
} else {
|
||||
info("User stopped the stream");
|
||||
}
|
||||
|
|
@ -382,8 +367,11 @@ static void *send_thread(void *data)
|
|||
if (!stopping(stream)) {
|
||||
pthread_detach(stream->send_thread);
|
||||
obs_output_signal_stop(stream->output, OBS_OUTPUT_DISCONNECTED);
|
||||
} else {
|
||||
obs_output_end_data_capture(stream->output);
|
||||
}
|
||||
|
||||
free_packets(stream);
|
||||
os_event_reset(stream->stop_event);
|
||||
os_atomic_set_bool(&stream->active, false);
|
||||
stream->sent_headers = false;
|
||||
|
|
@ -453,7 +441,6 @@ static inline bool send_headers(struct rtmp_stream *stream)
|
|||
stream->sent_headers = true;
|
||||
size_t i = 0;
|
||||
bool next = true;
|
||||
bool fail = false;
|
||||
|
||||
if (!send_audio_header(stream, i++, &next))
|
||||
return false;
|
||||
|
|
@ -617,6 +604,17 @@ static int try_connect(struct rtmp_stream *stream)
|
|||
set_rtmp_dstr(&stream->rtmp.Link.flashVer, &stream->encoder_name);
|
||||
stream->rtmp.Link.swfUrl = stream->rtmp.Link.tcUrl;
|
||||
|
||||
if (dstr_is_empty(&stream->bind_ip) ||
|
||||
dstr_cmp(&stream->bind_ip, "default") == 0) {
|
||||
memset(&stream->rtmp.m_bindIP, 0, sizeof(stream->rtmp.m_bindIP));
|
||||
} else {
|
||||
bool success = netif_str_to_addr(&stream->rtmp.m_bindIP.addr,
|
||||
&stream->rtmp.m_bindIP.addrLen,
|
||||
stream->bind_ip.array);
|
||||
if (success)
|
||||
info("Binding to IP");
|
||||
}
|
||||
|
||||
RTMP_AddStream(&stream->rtmp, stream->key.array);
|
||||
|
||||
for (size_t idx = 1;; idx++) {
|
||||
|
|
@ -653,6 +651,7 @@ static bool init_connect(struct rtmp_stream *stream)
|
|||
{
|
||||
obs_service_t *service;
|
||||
obs_data_t *settings;
|
||||
const char *bind_ip;
|
||||
|
||||
if (stopping(stream))
|
||||
pthread_join(stream->send_thread, NULL);
|
||||
|
|
@ -680,6 +679,10 @@ static bool init_connect(struct rtmp_stream *stream)
|
|||
(int64_t)obs_data_get_int(settings, OPT_DROP_THRESHOLD) * 1000;
|
||||
stream->max_shutdown_time_sec =
|
||||
(int)obs_data_get_int(settings, OPT_MAX_SHUTDOWN_TIME_SEC);
|
||||
|
||||
bind_ip = obs_data_get_string(settings, OPT_BIND_IP);
|
||||
dstr_copy(&stream->bind_ip, bind_ip);
|
||||
|
||||
obs_data_release(settings);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -826,7 +829,7 @@ static void rtmp_stream_data(void *data, struct encoder_packet *packet)
|
|||
struct encoder_packet new_packet;
|
||||
bool added_packet = false;
|
||||
|
||||
if (disconnected(stream))
|
||||
if (disconnected(stream) || !active(stream))
|
||||
return;
|
||||
|
||||
if (packet->type == OBS_ENCODER_VIDEO)
|
||||
|
|
@ -854,6 +857,7 @@ static void rtmp_stream_defaults(obs_data_t *defaults)
|
|||
{
|
||||
obs_data_set_default_int(defaults, OPT_DROP_THRESHOLD, 600);
|
||||
obs_data_set_default_int(defaults, OPT_MAX_SHUTDOWN_TIME_SEC, 5);
|
||||
obs_data_set_default_string(defaults, OPT_BIND_IP, "default");
|
||||
}
|
||||
|
||||
static obs_properties_t *rtmp_stream_properties(void *unused)
|
||||
|
|
@ -861,11 +865,26 @@ static obs_properties_t *rtmp_stream_properties(void *unused)
|
|||
UNUSED_PARAMETER(unused);
|
||||
|
||||
obs_properties_t *props = obs_properties_create();
|
||||
struct netif_saddr_data addrs = {0};
|
||||
obs_property_t *p;
|
||||
|
||||
obs_properties_add_int(props, OPT_DROP_THRESHOLD,
|
||||
obs_module_text("RTMPStream.DropThreshold"),
|
||||
200, 10000, 100);
|
||||
|
||||
p = obs_properties_add_list(props, OPT_BIND_IP,
|
||||
obs_module_text("RTMPStream.BindIP"),
|
||||
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING);
|
||||
|
||||
obs_property_list_add_string(p, obs_module_text("Default"), "default");
|
||||
|
||||
netif_get_addrs(&addrs);
|
||||
for (size_t i = 0; i < addrs.addrs.num; i++) {
|
||||
struct netif_saddr_item item = addrs.addrs.array[i];
|
||||
obs_property_list_add_string(p, item.name, item.addr);
|
||||
}
|
||||
netif_saddr_data_free(&addrs);
|
||||
|
||||
return props;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue