Skip to content
This repository has been archived by the owner on Nov 9, 2022. It is now read-only.

Commit

Permalink
Merge branch 'pingfix'
Browse files Browse the repository at this point in the history
  • Loading branch information
sslivins committed Feb 27, 2017
2 parents bf229a2 + 178cfe5 commit d483cc9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 27 deletions.
45 changes: 29 additions & 16 deletions ftl_app/file_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int get_video_frame(h264_obj_t *handle, uint8_t *buf, uint32_t *length, int *get
return 0;
}

int init_audio(opus_obj_t *handle, const char *audio_file) {
int init_audio(opus_obj_t *handle, const char *audio_file, int raw_opus) {


if (audio_file == NULL) {
Expand All @@ -69,6 +69,8 @@ int get_video_frame(h264_obj_t *handle, uint8_t *buf, uint32_t *length, int *get
return 0;
}

handle->raw_opus = raw_opus;

handle->current_segment = 0;
handle->consumed = 0;
handle->page_len = 0;
Expand All @@ -95,22 +97,33 @@ int get_video_frame(h264_obj_t *handle, uint8_t *buf, uint32_t *length, int *get

*length = 0;

if (handle->consumed >= handle->page_len) {
if (get_ogg_page(handle) != 1) {
return 0;
}
}

int seg_len;
if (handle->raw_opus) {
if (feof(handle->fp)) {
return 0;
}

do {
seg_len = handle->seg_len_table[handle->current_segment];
memcpy(buf, handle->page_buf + handle->consumed, seg_len);
buf += seg_len;
*length += seg_len;
handle->consumed += seg_len;
handle->current_segment++;
} while (seg_len == 255);
fread(length, 1, 4, handle->fp);
fread(buf, 1, *length, handle->fp);
}
else {

if (handle->consumed >= handle->page_len) {
if (get_ogg_page(handle) != 1) {
return 0;
}
}

int seg_len;

do {
seg_len = handle->seg_len_table[handle->current_segment];
memcpy(buf, handle->page_buf + handle->consumed, seg_len);
buf += seg_len;
*length += seg_len;
handle->consumed += seg_len;
handle->current_segment++;
} while (seg_len == 255);
}

return 1;
}
Expand Down
3 changes: 2 additions & 1 deletion ftl_app/file_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ typedef struct {
uint8_t *page_buf;
int page_len;
int consumed;
int raw_opus;
uint8_t version;
uint8_t header_type;
uint8_t seg_length;
Expand All @@ -27,7 +28,7 @@ typedef struct {
int init_video(h264_obj_t *handle, const char *video_file);
int reset_video(h264_obj_t *handle);
int get_video_frame(h264_obj_t *handle, uint8_t *buf, uint32_t *length, int *end_of_frame);
int init_audio(opus_obj_t *handle, const char *audio_file);
int init_audio(opus_obj_t *handle, const char *audio_file, int raw_opus);
void close_audio(opus_obj_t *handle);
int reset_audio(opus_obj_t *handle);
int get_audio_packet(opus_obj_t *handle, uint8_t *buf, uint32_t *length);
Expand Down
27 changes: 17 additions & 10 deletions ftl_app/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ int main(int argc, char **argv)
char *stream_key = NULL;
int fps_num = 30;
int fps_den = 1;
int raw_opus = 0;
int speedtest_kbps = 1000;
int c;
int audio_pps = 50;
Expand All @@ -87,6 +88,7 @@ int main(int argc, char **argv)

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 All @@ -96,7 +98,7 @@ int main(int argc, char **argv)
printf("FTLSDK - version %d.%d\n", FTL_VERSION_MAJOR, FTL_VERSION_MINOR);
}

while ((c = getopt(argc, argv, "a:i:v:s:f:b:t:?")) != -1)
while ((c = getopt(argc, argv, "a:i:v:s:f:b:t:r:?")) != -1)
{
switch (c)
{
Expand All @@ -107,8 +109,13 @@ int main(int argc, char **argv)
video_input = optarg;
break;
case 'a':
audio_input = optarg;
audio_input = optarg;
break;
case 'r':
if (strcmp(optarg, "a") == 0) {
raw_opus = 1;
}
break;
case 's':
stream_key = optarg;
break;
Expand Down Expand Up @@ -164,7 +171,7 @@ int main(int argc, char **argv)
return -1;
}

if (!init_audio(&opus_handle, audio_input))
if (!init_audio(&opus_handle, audio_input, raw_opus))
{
printf("Failed to open audio file\n");
return -1;
Expand Down Expand Up @@ -248,12 +255,12 @@ int main(int argc, char **argv)
uint8_t nalu_type;
int audio_read_len;

if (feof(h264_handle.fp) || feof(opus_handle.fp))
{
printf("Restarting Stream\n");
reset_video(&h264_handle);
reset_audio(&opus_handle);
continue;
if (feof(h264_handle.fp) || feof(opus_handle.fp))
{
printf("Restarting Stream\n");
reset_video(&h264_handle);
reset_audio(&opus_handle);
continue;
}

if (get_video_frame(&h264_handle, h264_frame, &len, &end_of_frame) == 0)
Expand All @@ -271,7 +278,7 @@ int main(int argc, char **argv)
break;
}

ftl_ingest_send_media(&handle, FTL_AUDIO_DATA, audio_frame, len, 0);
ftl_ingest_send_media(&handle, FTL_AUDIO_DATA, audio_frame, len, 0);
audio_send_accumulator -= audio_time_step;
audio_pkts_sent++;
}
Expand Down

0 comments on commit d483cc9

Please sign in to comment.