Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: logs #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion ftl_app/dec_obj.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef __FTL_APP_DEC_OBJ
#define __FTL_APP_DEC_OBJ

#include "bitstream.h"

enum nalu_type_codes
Expand Down Expand Up @@ -244,4 +247,6 @@ typedef struct _h264_dec_obj_t
struct sequence_params_set_t *sps;
struct picture_params_set_t *pps;
struct slice_header_t slice;
}h264_dec_obj_t;
}h264_dec_obj_t;

#endif // __FTL_APP_DEC_OBJ
3 changes: 2 additions & 1 deletion ftl_app/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <Windows.h>
#include <WinSock2.h>
#else
#include <string.h>
#include <pthread.h>
#include <sys/time.h>
#endif
Expand Down Expand Up @@ -425,7 +426,7 @@ static void *ftl_status_thread(void *data)
{
ftl_packet_stats_msg_t *p = &status.msg.pkt_stats;

printf("Avg packet send per second %3.1f, total nack requests %d\n",
printf("Avg packet send per second %3.1f, total nack requests %lld\n",
(float)p->sent * 1000.f / p->period,
p->nack_reqs);
}
Expand Down
9 changes: 8 additions & 1 deletion ftl_app/utils.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#ifndef __FTL_APP_UTILS
#define __FTL_APP_UTILS

#include "dec_obj.h"

#define MIN(x,y) ((x < y) ? x : y)
#define MAX(x,y) ((x > y) ? x : y)

void store_sps(struct sequence_params_set_t *sps);
struct sequence_params_set_t * find_sps(int nal_unit_type, int seq_parameter_set_id);
void store_pps(struct picture_params_set_t *pps);
struct picture_params_set_t * find_pps(int pic_parameter_set_id);
struct picture_params_set_t * find_pps(int pic_parameter_set_id);

#endif // __FTL_APP_UTILS
14 changes: 6 additions & 8 deletions libftl/ftl-sdk.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
#endif

static BOOL _get_chan_id_and_key(const char *stream_key, uint32_t *chan_id, char *key);
static int _lookup_ingest_ip(const char *ingest_location, char *ingest_ip);

char error_message[1000];
FTL_API const int FTL_VERSION_MAJOR = 0;
FTL_API const int FTL_VERSION_MINOR = 9;
FTL_API const int FTL_VERSION_MAINTENANCE = 14;
Expand Down Expand Up @@ -171,7 +169,7 @@ FTL_API int ftl_ingest_speed_test(ftl_handle_t *ftl_handle, int speed_kbps, int

speed_test_t results;

FTL_LOG(ftl, FTL_LOG_WARN, "%s() is depricated, please use ftl_ingest_speed_test_ex()\n", __FUNCTION__);
FTL_LOG(ftl, FTL_LOG_WARN, "%s() is depricated, please use ftl_ingest_speed_test_ex()", __FUNCTION__);

if (media_speed_test(ftl, speed_kbps, duration_ms, &results) == FTL_SUCCESS) {
return results.peak_kbps;
Expand Down Expand Up @@ -259,11 +257,11 @@ ftl_status_t internal_ingest_disconnect(ftl_stream_configuration_private_t *ftl)
ftl_set_state(ftl, FTL_DISCONNECT_IN_PROGRESS);

if ((status_code = media_destroy(ftl)) != FTL_SUCCESS) {
FTL_LOG(ftl, FTL_LOG_ERROR, "failed to clean up media channel with error %d\n", status_code);
FTL_LOG(ftl, FTL_LOG_ERROR, "failed to clean up media channel with error %d", status_code);
}

if ((status_code = _ingest_disconnect(ftl)) != FTL_SUCCESS) {
FTL_LOG(ftl, FTL_LOG_ERROR, "Disconnect failed with error %d\n", status_code);
FTL_LOG(ftl, FTL_LOG_ERROR, "Disconnect failed with error %d", status_code);
}

ftl_clear_state(ftl, FTL_DISCONNECT_IN_PROGRESS);
Expand Down Expand Up @@ -323,9 +321,9 @@ ftl_status_t internal_ftl_ingest_destroy(ftl_stream_configuration_private_t *ftl
free(ftl->ingest_hostname);
}

if (ftl->param_ingest_hostname != NULL) {
free(ftl->param_ingest_hostname);
}
if (ftl->param_ingest_hostname != NULL) {
free(ftl->param_ingest_hostname);
}

free(ftl);
}
Expand Down
7 changes: 5 additions & 2 deletions libftl/ftl_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,13 @@ ftl_status_t _set_ingest_hostname(ftl_stream_configuration_private_t *ftl) {

do {
#ifndef DISABLE_AUTO_INGEST
if (strcmp(ftl->param_ingest_hostname, "auto") == 0) {
if (strcmp(ftl->param_ingest_hostname, "auto") == 0) {
ftl->ingest_hostname = ingest_find_best(ftl);
if (!ftl->ingest_hostname) {
ret_status = FTL_CONNECT_ERROR;
}
else
}
else
#endif
ftl->ingest_hostname = _strdup(ftl->param_ingest_hostname);
} while (0);
Expand Down
4 changes: 1 addition & 3 deletions libftl/ftl_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
#define SENDER_REPORT_TX_INTERVAL_MS 1000
#define PING_PTYPE 250
#define SENDER_REPORT_PTYPE 200
#define SOCKET_ERROR_MESSAGE_BUFFER 1024

// Adaptive bitrate constants

Expand Down Expand Up @@ -412,9 +413,6 @@ int ftl_read_media_port(const char *response_str);
* Platform abstractions
**/

// FIXME: make this less global
extern char error_message[1000];

ftl_status_t _log_response(ftl_stream_configuration_private_t *ftl, int response_code);
void ftl_set_state(ftl_stream_configuration_private_t *ftl, ftl_state_t state);
void ftl_clear_state(ftl_stream_configuration_private_t *ftl, ftl_state_t state);
Expand Down
36 changes: 20 additions & 16 deletions libftl/handshake.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ ftl_status_t _init_control_connection(ftl_stream_configuration_private_t *ftl) {
int err = 0;
SOCKET sock = 0;
struct addrinfo hints;
char socket_error_buffer[SOCKET_ERROR_MESSAGE_BUFFER];

memset(&hints, 0, sizeof(hints));
ftl_status_t retval = FTL_SUCCESS;

Expand Down Expand Up @@ -66,7 +68,8 @@ ftl_status_t _init_control_connection(ftl_stream_configuration_private_t *ftl) {
err = getaddrinfo(ftl->ingest_hostname, ingest_port_str, &hints, &resolved_names);
if (err != 0) {
FTL_LOG(ftl, FTL_LOG_ERROR, "getaddrinfo failed to look up ingest address %s.", ftl->ingest_hostname);
FTL_LOG(ftl, FTL_LOG_ERROR, "gai error was: %s", gai_strerror(err));
//TODO: gai_strerror: not thread safe in windows.
FTL_LOG(ftl, FTL_LOG_ERROR, "getaddrinfo error was: %s", gai_strerror(err));
return FTL_DNS_FAILURE;
}

Expand All @@ -75,7 +78,7 @@ ftl_status_t _init_control_connection(ftl_stream_configuration_private_t *ftl) {
sock = socket(p->ai_family, p->ai_socktype, p->ai_protocol);
if (sock == -1) {
/* try the next candidate */
FTL_LOG(ftl, FTL_LOG_DEBUG, "failed to create socket. error: %s", get_socket_error());
FTL_LOG(ftl, FTL_LOG_DEBUG, "failed to create socket. error: %s", get_socket_error(socket_error_buffer, sizeof(socket_error_buffer)));
continue;
}

Expand All @@ -91,29 +94,29 @@ ftl_status_t _init_control_connection(ftl_stream_configuration_private_t *ftl) {
continue;
}

FTL_LOG(ftl, FTL_LOG_DEBUG, "Got IP: %s\n", ingest_ip);
FTL_LOG(ftl, FTL_LOG_DEBUG, "Got IP: %s", ingest_ip);
ftl->ingest_ip = _strdup(ingest_ip);
ftl->socket_family = p->ai_family;

/* Go for broke */
if (connect(sock, p->ai_addr, (int)p->ai_addrlen) == -1) {
FTL_LOG(ftl, FTL_LOG_DEBUG, "failed to connect on candidate, error: %s", get_socket_error());
FTL_LOG(ftl, FTL_LOG_DEBUG, "failed to connect on candidate, error: %s", get_socket_error(socket_error_buffer, sizeof(socket_error_buffer)));
close_socket(sock);
sock = 0;
continue;
}

/* If we got here, we successfully connected */
if (set_socket_enable_keepalive(sock) != 0) {
FTL_LOG(ftl, FTL_LOG_DEBUG, "failed to enable keep alives. error: %s", get_socket_error());
FTL_LOG(ftl, FTL_LOG_DEBUG, "failed to enable keep alives. error: %s", get_socket_error(socket_error_buffer, sizeof(socket_error_buffer)));
}

if (set_socket_recv_timeout(sock, SOCKET_RECV_TIMEOUT_MS) != 0) {
FTL_LOG(ftl, FTL_LOG_DEBUG, "failed to set recv timeout. error: %s", get_socket_error());
FTL_LOG(ftl, FTL_LOG_DEBUG, "failed to set recv timeout. error: %s", get_socket_error(socket_error_buffer, sizeof(socket_error_buffer)));
}

if (set_socket_send_timeout(sock, SOCKET_SEND_TIMEOUT_MS) != 0) {
FTL_LOG(ftl, FTL_LOG_DEBUG, "failed to set send timeout. error: %s", get_socket_error());
FTL_LOG(ftl, FTL_LOG_DEBUG, "failed to set send timeout. error: %s", get_socket_error(socket_error_buffer, sizeof(socket_error_buffer)));
}

break;
Expand All @@ -124,8 +127,7 @@ ftl_status_t _init_control_connection(ftl_stream_configuration_private_t *ftl) {

/* Check to see if we actually connected */
if (sock <= 0) {
FTL_LOG(ftl, FTL_LOG_ERROR, "failed to connect to ingest. Last error was: %s",
get_socket_error());
FTL_LOG(ftl, FTL_LOG_ERROR, "failed to connect to ingest. Last error was: %s", get_socket_error(socket_error_buffer, sizeof(socket_error_buffer)));
return FTL_CONNECT_ERROR;
}

Expand Down Expand Up @@ -251,7 +253,7 @@ ftl_status_t _ingest_connect(ftl_stream_configuration_private_t *ftl) {
break;
}

FTL_LOG(ftl, FTL_LOG_INFO, "Successfully connected to ingest. Media will be sent to port %d\n", ftl->media.assigned_port);
FTL_LOG(ftl, FTL_LOG_INFO, "Successfully connected to ingest. Media will be sent to port %d", ftl->media.assigned_port);

return FTL_SUCCESS;
} while (0);
Expand Down Expand Up @@ -295,9 +297,9 @@ ftl_status_t _ingest_disconnect(ftl_stream_configuration_private_t *ftl) {

ftl_clear_state(ftl, FTL_CONNECTED);

FTL_LOG(ftl, FTL_LOG_INFO, "light-saber disconnect\n");
FTL_LOG(ftl, FTL_LOG_INFO, "light-saber disconnect");
if ((response_code = _ftl_send_command(ftl, FALSE, response, sizeof(response), "DISCONNECT", ftl->channel_id)) != FTL_INGEST_RESP_OK) {
FTL_LOG(ftl, FTL_LOG_ERROR, "Ingest Disconnect failed with %d (%s)\n", response_code, response);
FTL_LOG(ftl, FTL_LOG_ERROR, "Ingest Disconnect failed with %d (%s)", response_code, response);
}
}

Expand Down Expand Up @@ -376,6 +378,7 @@ static ftl_response_code_t _ftl_send_command(ftl_stream_configuration_private_t
}

send(ftl->ingest_socket, buf, len, 0);
FTL_LOG(ftl, FTL_LOG_DEBUG, "send[%s]", buf);

if (need_response) {
resp_code = _ftl_get_response(ftl, response_buf, response_len);
Expand Down Expand Up @@ -421,11 +424,11 @@ OS_THREAD_ROUTINE control_keepalive_thread(void *data)

// Send the ping to ingest now.
if ((response_code = _ftl_send_command(ftl, FALSE, NULL, 0, "PING %d", ftl->channel_id)) != FTL_INGEST_RESP_OK) {
FTL_LOG(ftl, FTL_LOG_ERROR, "Ingest ping failed with %d\n", response_code);
FTL_LOG(ftl, FTL_LOG_ERROR, "Ingest ping failed with %d", response_code);
}
}

FTL_LOG(ftl, FTL_LOG_INFO, "Exited control_keepalive_thread\n");
FTL_LOG(ftl, FTL_LOG_INFO, "Exited control_keepalive_thread");

return 0;
}
Expand All @@ -437,6 +440,7 @@ OS_THREAD_ROUTINE connection_status_thread(void *data)
ftl_status_msg_t status;
struct timeval last_ping, now;
int64_t ms_since_ping = 0;
char socket_error_buffer[SOCKET_ERROR_MESSAGE_BUFFER];

// We ping every 5 seconds, but don't timeout the connection until 30 seconds has passed
// without hearing anything back from the ingest. This time is high, but some some poor networks
Expand All @@ -462,7 +466,7 @@ OS_THREAD_ROUTINE connection_status_thread(void *data)
int ret = get_socket_bytes_available(ftl->ingest_socket, &bytesAvailable);
if (ret < 0)
{
FTL_LOG(ftl, FTL_LOG_ERROR, "Failed to call get_socket_bytes_available, %s", get_socket_error());
FTL_LOG(ftl, FTL_LOG_ERROR, "Failed to call get_socket_bytes_available, %s", get_socket_error(socket_error_buffer, sizeof(socket_error_buffer)));
error_code = FTL_UNKNOWN_ERROR_CODE;
}
else
Expand Down Expand Up @@ -504,7 +508,7 @@ OS_THREAD_ROUTINE connection_status_thread(void *data)
{
break;
}
FTL_LOG(ftl, FTL_LOG_ERROR, "Ingest connection has dropped: error code %d\n", error_code);
FTL_LOG(ftl, FTL_LOG_ERROR, "Ingest connection has dropped: error code %d", error_code);

// Clear the state that this thread is running. If we don't do this we will dead lock
// in the internal_ingest_disconnect.
Expand Down
Loading