Skip to content

Commit

Permalink
v9.14 (#3)
Browse files Browse the repository at this point in the history
* feat(ftl-sdk): updating to new best endpoint and docker builds

Added Docker Build
Added call to new Best v2 endpoint
Added more verbose logging and error handling
Added use of linter
Increase the length of vendor name and version

* adding execute into git for scripts

Co-authored-by: NathanielvonSprecken-MS <[email protected]>
  • Loading branch information
tyiki-badwell and NathanielvonSprecken-MS authored Feb 29, 2020
1 parent aad863d commit 8dfff5f
Show file tree
Hide file tree
Showing 21 changed files with 435 additions and 75 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.git
**/.git
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
build
.vscode/*
!.vscode/settings.json
*.orig
.vs/*
publish
build-output
46 changes: 46 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
FROM debian:9

RUN apt-get update -y
RUN apt-get install wget -y
RUN apt-get install -y cmake
RUN apt-get install git -y
RUN apt-get install build-essential -y
RUN apt-get install libssl-dev -y
RUN apt-get install libcurl4-openssl-dev -y
RUN apt-get upgrade ca-certificates -y

RUN apt-get install -y jq curl

RUN useradd ftl-user

RUN mkdir -p /opt/ftl-sdk/vid

RUN chown -R ftl-user:ftl-user /opt/ftl-sdk

WORKDIR /opt/ftl-sdk/vid

ARG VIDEO_URL=https://videotestmedia.blob.core.windows.net/ftl/sintel.h264
RUN wget ${VIDEO_URL}
ARG AUDIO_URL=https://videotestmedia.blob.core.windows.net/ftl/sintel.opus
RUN wget ${AUDIO_URL}

COPY --chown=ftl-user:ftl-user ./CMakeLists.txt /opt/ftl-sdk/CMakeLists.txt
COPY --chown=ftl-user:ftl-user ./libcurl /opt/ftl-sdk/libcurl
COPY --chown=ftl-user:ftl-user ./libjansson /opt/ftl-sdk/libjansson
COPY --chown=ftl-user:ftl-user ./libftl /opt/ftl-sdk/libftl
COPY --chown=ftl-user:ftl-user ./Doxyfile /opt/ftl-sdk/Doxyfile
COPY --chown=ftl-user:ftl-user ./ftl_app /opt/ftl-sdk/ftl_app
COPY --chown=ftl-user:ftl-user ./get-video /opt/ftl-sdk/get-video
COPY --chown=ftl-user:ftl-user ./get-audio /opt/ftl-sdk/get-audio
COPY --chown=ftl-user:ftl-user ./scripts /opt/ftl-sdk/scripts

USER ftl-user

WORKDIR /opt/ftl-sdk

RUN ./scripts/build

COPY --chown=ftl-user:ftl-user ./start-stream /opt/ftl-sdk/start-stream

ENTRYPOINT ["./start-stream"]

Empty file modified build.bat
100644 → 100755
Empty file.
22 changes: 11 additions & 11 deletions ftl_app/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ int main(int argc, char **argv)
int verbose = 0;

opterr = 0;

charon_install_ctrlc_handler();


if (FTL_VERSION_MAINTENANCE != 0)
{
printf("FTLSDK - version %d.%d.%d\n", FTL_VERSION_MAJOR, FTL_VERSION_MINOR, FTL_VERSION_MAINTENANCE);
Expand Down Expand Up @@ -158,7 +158,7 @@ int main(int argc, char **argv)

if (!init_video(&h264_handle, video_input))
{
printf("Faild to open video file\n");
printf("Failed to open video file\n");
return -1;
}
}
Expand Down Expand Up @@ -225,14 +225,14 @@ int main(int argc, char **argv)
if (speedtest_duration)
{
printf("Running Speed test: sending %d kbps for %d ms", speedtest_kbps, speedtest_duration);
speed_test_t results;
if ((status_code = ftl_ingest_speed_test_ex(&handle, speedtest_kbps, speedtest_duration, &results)) == FTL_SUCCESS) {
printf("Speed test completed: Peak kbps %d, initial rtt %d, final rtt %d, %3.2f lost packets\n",
speed_test_t results;
if ((status_code = ftl_ingest_speed_test_ex(&handle, speedtest_kbps, speedtest_duration, &results)) == FTL_SUCCESS) {
printf("Speed test completed: Peak kbps %d, initial rtt %d, final rtt %d, %3.2f lost packets\n",
results.peak_kbps, results.starting_rtt, results.ending_rtt, (float)results.lost_pkts * 100.f / (float)results.pkts_sent);
}
else {
printf("Speed test failed with: %s\n", ftl_status_code_to_string(status_code));
}
}
else {
printf("Speed test failed with: %s\n", ftl_status_code_to_string(status_code));
}

goto cleanup;
}
Expand Down
16 changes: 16 additions & 0 deletions get-audio
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
set -ue

OUTPUT=$1

curl 'https://www.dropbox.com/s/s2r6lggopt9ftw5/sintel.opus' \
-H 'authority: www.dropbox.com' \
-H 'cache-control: max-age=0' \
-H 'upgrade-insecure-requests: 1' \
-H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36' \
-H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8' \
-H 'accept-encoding: gzip, deflate, br' \
-H 'accept-language: en-US,en;q=0.9' \
-H 'cookie: __Host-ss=UsByWdIPus; locale=en; gvc=MjU4NzQxNzA3MDE4MjU3MDIzNDY0Nzc2NjAxNDg5MTU4MTg0MjYz; seen-sl-signup-modal=VHJ1ZQ%3D%3D; t=0-Hq7tZ1TDyj-aBNiWYv8YQl; __Host-js_csrf=0-Hq7tZ1TDyj-aBNiWYv8YQl; seen-sl-download-modal=VHJ1ZQ%3D%3D' \
--compressed > $OUTPUT

15 changes: 15 additions & 0 deletions get-video
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
set -ue

OUTPUT=$1

curl 'https://www.dropbox.com/s/ruijibs0lgjnq51/sintel.h264' \
-H 'authority: www.dropbox.com' \
-H 'cache-control: max-age=0' \
-H 'upgrade-insecure-requests: 1' \
-H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36' \
-H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8' \
-H 'accept-encoding: gzip, deflate, br' \
-H 'accept-language: en-US,en;q=0.9' \
-H 'cookie: __Host-ss=UsByWdIPus; locale=en; gvc=MjU4NzQxNzA3MDE4MjU3MDIzNDY0Nzc2NjAxNDg5MTU4MTg0MjYz; seen-sl-signup-modal=VHJ1ZQ%3D%3D; t=0-Hq7tZ1TDyj-aBNiWYv8YQl; __Host-js_csrf=0-Hq7tZ1TDyj-aBNiWYv8YQl; seen-sl-download-modal=VHJ1ZQ%3D%3D' \
--compressed > $OUTPUT
4 changes: 3 additions & 1 deletion libftl/ftl-sdk.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ 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 = 13;
FTL_API const int FTL_VERSION_MAINTENANCE = 14;

// Initializes all sublibraries used by FTL
FTL_API ftl_status_t ftl_init() {
Expand Down Expand Up @@ -408,6 +408,8 @@ FTL_API char* ftl_status_code_to_string(ftl_status_t status) {
return "the ingest socket was closed";
case FTL_INGEST_SOCKET_TIMEOUT:
return "the ingest socket was hit a timeout.";
case FTL_INGEST_SERVER_TERMINATE:
return "The server has terminated the stream.";
case FTL_UNKNOWN_ERROR_CODE:
default:
/* Unknown FTL error */
Expand Down
1 change: 1 addition & 0 deletions libftl/ftl.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ typedef enum {
FTL_SPEED_TEST_ABORTED,
FTL_INGEST_SOCKET_CLOSED,
FTL_INGEST_SOCKET_TIMEOUT,
FTL_INGEST_SERVER_TERMINATE,
} ftl_status_t;

typedef enum {
Expand Down
2 changes: 1 addition & 1 deletion libftl/ftl_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ ftl_status_t _set_ingest_hostname(ftl_stream_configuration_private_t *ftl) {
#endif
ftl->ingest_hostname = _strdup(ftl->param_ingest_hostname);
} while (0);

return ret_status;
}

Expand Down
11 changes: 5 additions & 6 deletions libftl/ftl_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
#define AUDIO_SAMPLE_RATE 48000
#define AUDIO_PACKET_DURATION_MS 20
#define IPVX_ADDR_ASCII_LEN INET6_ADDRSTRLEN
#define INGEST_LIST_URI "https://mixer.com/api/v1/ingests/best"
#define INGEST_LIST_URI "https://conductor.videosvc.mixer.com/api/video/v2/channels/%d/ingest"
#define INGEST_LOAD_PORT 8079
#define INGEST_PING_PORT 8079
#define PEAK_BITRATE_KBPS 10000 /*if not supplied this is the peak from the perspective of the send buffer*/
Expand Down Expand Up @@ -308,8 +308,6 @@ typedef struct {

typedef struct _ftl_ingest_t {
char *name;
char *ip;
char *hostname;
int rtt;
struct _ftl_ingest_t *next;
}ftl_ingest_t;
Expand Down Expand Up @@ -337,8 +335,8 @@ typedef struct {
char *key;
char hmacBuffer[512];
int video_kbps;
char vendor_name[20];
char vendor_version[20];
char vendor_name[50];
char vendor_version[50];
OS_THREAD_HANDLE connection_thread;
OS_THREAD_HANDLE keepalive_thread;
OS_THREAD_HANDLE bitrate_monitor_thread;
Expand Down Expand Up @@ -378,11 +376,12 @@ typedef enum {
FTL_INGEST_RESP_REGION_UNSUPPORTED = 407, // Streaming from this country or region is not authorized by local governments
FTL_INGEST_RESP_NO_MEDIA_TIMEOUT = 408,
FTL_INGEST_RESP_GAME_BLOCKED = 409, // The game the user account is set to can't be streamed.
FTL_INGEST_RESP_SERVER_TERMINATE = 410, // The sterver has terminated the stream.
FTL_INGEST_RESP_INTERNAL_SERVER_ERROR = 500,
FTL_INGEST_RESP_INTERNAL_MEMORY_ERROR = 900,
FTL_INGEST_RESP_INTERNAL_COMMAND_ERROR = 901,
FTL_INGEST_RESP_INTERNAL_SOCKET_CLOSED = 902,
FTL_INGEST_RESP_INTERNAL_SOCKET_TIMEOUT = 903,
FTL_INGEST_RESP_INTERNAL_SOCKET_TIMEOUT = 903
} ftl_response_code_t;

/**
Expand Down
38 changes: 20 additions & 18 deletions libftl/handshake.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ ftl_status_t _init_control_connection(ftl_stream_configuration_private_t *ftl) {
if ((retval = _set_ingest_hostname(ftl)) != FTL_SUCCESS) {
return retval;
}

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);
Expand All @@ -78,22 +78,22 @@ ftl_status_t _init_control_connection(ftl_stream_configuration_private_t *ftl) {
FTL_LOG(ftl, FTL_LOG_DEBUG, "failed to create socket. error: %s", get_socket_error());
continue;
}

if (p->ai_family == AF_INET) {
struct sockaddr_in *ipv4_addr = (struct sockaddr_in *)p->ai_addr;
inet_ntop(p->ai_family, &ipv4_addr->sin_addr, ingest_ip, sizeof(ingest_ip));
}
else if (p->ai_family == AF_INET6) {
struct sockaddr_in6 *ipv6_addr = (struct sockaddr_in6 *)p->ai_addr;
inet_ntop(p->ai_family, &ipv6_addr->sin6_addr, ingest_ip, sizeof(ingest_ip));
}
else {
continue;
}

if (p->ai_family == AF_INET) {
struct sockaddr_in *ipv4_addr = (struct sockaddr_in *)p->ai_addr;
inet_ntop(p->ai_family, &ipv4_addr->sin_addr, ingest_ip, sizeof(ingest_ip));
}
else if (p->ai_family == AF_INET6) {
struct sockaddr_in6 *ipv6_addr = (struct sockaddr_in6 *)p->ai_addr;
inet_ntop(p->ai_family, &ipv6_addr->sin6_addr, ingest_ip, sizeof(ingest_ip));
}
else {
continue;
}

FTL_LOG(ftl, FTL_LOG_DEBUG, "Got IP: %s\n", ingest_ip);
ftl->ingest_ip = _strdup(ingest_ip);
ftl->socket_family = p->ai_family;
FTL_LOG(ftl, FTL_LOG_DEBUG, "Got IP: %s\n", 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) {
Expand Down Expand Up @@ -592,11 +592,13 @@ ftl_status_t _log_response(ftl_stream_configuration_private_t *ftl, int response
case FTL_INGEST_RESP_INTERNAL_SOCKET_TIMEOUT:
FTL_LOG(ftl, FTL_LOG_ERROR, "Ingest socket timeout.");
return FTL_INGEST_SOCKET_TIMEOUT;
case FTL_INGEST_RESP_SERVER_TERMINATE:
FTL_LOG(ftl, FTL_LOG_ERROR, "The server has terminated the stream.");
return FTL_INGEST_SERVER_TERMINATE;
case FTL_INGEST_RESP_UNKNOWN:
FTL_LOG(ftl, FTL_LOG_ERROR, "Ingest unknown response.");
return FTL_INTERNAL_ERROR;
}

// TODO revert back
return 100 + response_code;
return FTL_UNKNOWN_ERROR_CODE;
}
Loading

0 comments on commit 8dfff5f

Please sign in to comment.