28
28
#include <ftl/ftl.h>
29
29
30
30
#ifdef _WIN32
31
+ #include <winsock2.h>
32
+ #include <ws2tcpip.h>
33
+ #pragma comment(lib, "ws2_32.lib")
31
34
#include <windows.h>
32
35
#include <process.h>
33
36
#include <Shellapi.h>
@@ -66,6 +69,7 @@ struct ffmpeg_cfg {
66
69
67
70
/* FTL specific fields */
68
71
const char * ingest_location ;
72
+ char ingest_ip [20 ];
69
73
uint32_t channel_id ;
70
74
char stream_key [2048 ];
71
75
uint32_t audio_ssrc ;
@@ -180,10 +184,39 @@ int map_ftl_error_to_obs_error(int status) {
180
184
return ftl_to_obs_error_code ;
181
185
}
182
186
187
+ static int lookup_ingest_ip (const char * ingest_location , char * ingest_ip ){
188
+ struct hostent * remoteHost ;
189
+ struct in_addr addr ;
190
+ int retval = -1 ;
191
+ ingest_ip [0 ] = '\0' ;
192
+
193
+ remoteHost = gethostbyname (ingest_location );
194
+
195
+ if (remoteHost ) {
196
+ int i = 0 ;
197
+ if (remoteHost -> h_addrtype == AF_INET )
198
+ {
199
+ while (remoteHost -> h_addr_list [i ] != 0 ) {
200
+ addr .s_addr = * (u_long * ) remoteHost -> h_addr_list [i ++ ];
201
+ blog (LOG_INFO , "IP Address #%d of ingest is: %s\n" , i , inet_ntoa (addr ));
202
+
203
+ /*only use the first ip found*/
204
+ if (strlen (ingest_ip ) == 0 ){
205
+ strcpy (ingest_ip , inet_ntoa (addr ));
206
+ retval = 0 ;
207
+ }
208
+ }
209
+ }
210
+ }
211
+
212
+ return retval ;
213
+ }
214
+
183
215
ftl_status_t attempt_ftl_connection (struct ffmpeg_output * output , struct ffmpeg_cfg config )
184
216
{
185
217
ftl_status_t status_code ;
186
218
219
+
187
220
/* Use Charon to autheticate and configure muxer settings */
188
221
ftl_init ();
189
222
ftl_register_log_handler (log_libftl_messages );
@@ -192,9 +225,9 @@ ftl_status_t attempt_ftl_connection(struct ffmpeg_output *output, struct ffmpeg_
192
225
if (status_code != FTL_SUCCESS ) {
193
226
blog (LOG_WARNING , "Failed to initialize stream configuration: errno %d\n" , status_code );
194
227
return OBS_OUTPUT_ERROR ;
195
- }
228
+ }
196
229
197
- ftl_set_ingest_location (output -> stream_config , config .ingest_location );
230
+ ftl_set_ingest_location (output -> stream_config , config .ingest_ip );
198
231
ftl_set_authetication_key (output -> stream_config , config .channel_id , config .stream_key );
199
232
200
233
#ifdef _FTL_USE_H264
@@ -1176,6 +1209,7 @@ static int try_connect(struct ffmpeg_output *output)
1176
1209
settings = obs_output_get_settings (output -> output );
1177
1210
memset (& config , 0 , sizeof (config ));
1178
1211
config .ingest_location = get_string_or_null (settings , "url" );
1212
+ lookup_ingest_ip (config .ingest_location , config .ingest_ip );
1179
1213
config .format_name = get_string_or_null (settings , "format_name" );
1180
1214
config .format_mime_type = get_string_or_null (settings ,
1181
1215
"format_mime_type" );
@@ -1189,7 +1223,7 @@ static int try_connect(struct ffmpeg_output *output)
1189
1223
full_streamkey = get_string_or_null (settings , "ftl_stream_key" );
1190
1224
1191
1225
/* Build the RTP command line */
1192
- if (config .ingest_location == NULL ) {
1226
+ if (config .ingest_location == NULL || strlen ( config . ingest_ip ) == 0 ) {
1193
1227
blog (LOG_WARNING , "ingest location blank" );
1194
1228
return OBS_OUTPUT_ERROR ;
1195
1229
}
@@ -1305,7 +1339,7 @@ static int try_connect(struct ffmpeg_output *output)
1305
1339
/* Glue together the ingest URL */
1306
1340
1307
1341
#ifdef _WIN32
1308
- swprintf (ftl_ingest_arg , sizeof (ftl_ingest_arg )/sizeof (wchar_t ), L"-rtpingestaddr=%hs:8082" , config .ingest_location );
1342
+ swprintf (ftl_ingest_arg , sizeof (ftl_ingest_arg )/sizeof (wchar_t ), L"-rtpingestaddr=%hs:8082" , config .ingest_ip );
1309
1343
blog (LOG_WARNING , "FTL ingest args are: %S\n" , ftl_ingest_arg );
1310
1344
ZeroMemory ( & output -> ShExecInfo , sizeof (output -> ShExecInfo ) );
1311
1345
output -> ShExecInfo .cbSize = sizeof (SHELLEXECUTEINFO );
@@ -1320,7 +1354,7 @@ static int try_connect(struct ffmpeg_output *output)
1320
1354
ShellExecuteEx (& output -> ShExecInfo );
1321
1355
SetPriorityClass (output -> ShExecInfo .hProcess , HIGH_PRIORITY_CLASS );
1322
1356
#else
1323
- snprintf (ftl_ingest_arg , sizeof (ftl_ingest_arg ), "-rtpingestaddr=%s:8082" , config .ingest_location );
1357
+ snprintf (ftl_ingest_arg , sizeof (ftl_ingest_arg ), "-rtpingestaddr=%s:8082" , config .ingest_ip );
1324
1358
blog (LOG_WARNING , "FTL ingest args are: %s\n" , ftl_ingest_arg );
1325
1359
/* print error message if fork() fails */
1326
1360
blog (LOG_WARNING , "Forking Process\n" );
0 commit comments