From 4d7f6c6eb9501bfd1f58d4063cae050408b26552 Mon Sep 17 00:00:00 2001 From: Mark Feldman Date: Mon, 14 Oct 2019 16:56:37 -0700 Subject: [PATCH] Add --version to sample app (#65) - Added --help and --version to sample app - Updated .gitignore to ignore EbApiVersion.h - Changed version to v0.1.0 Signed-off-by: Mark Feldman --- .gitignore | 1 + CMakeLists.txt | 2 +- Source/App/EbAppConfig.c | 29 ++-- Source/App/EbAppConfig.h | 2 +- Source/App/EbAppMain.c | 303 ++++++++++++++++++++------------------- 5 files changed, 172 insertions(+), 165 deletions(-) diff --git a/.gitignore b/.gitignore index 4c54b85..42124f5 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ Bin Build !Build/linux/build.sh !Build/windows/generate_vs17.bat +Source/API/EbApiVersion.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 9805252..ae9ace3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,7 +39,7 @@ message(STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}") set(SVT_VP9_VERSION_MAJOR "0") set(SVT_VP9_VERSION_MINOR "1") -set(SVT_VP9_VERSION_PATCHLEVEL "1") +set(SVT_VP9_VERSION_PATCHLEVEL "0") configure_file(${PROJECT_SOURCE_DIR}/Source/API/EbApiVersion.h.in ${PROJECT_SOURCE_DIR}/Source/API/EbApiVersion.h @ONLY) diff --git a/Source/App/EbAppConfig.c b/Source/App/EbAppConfig.c index 12196d8..1174d89 100644 --- a/Source/App/EbAppConfig.c +++ b/Source/App/EbAppConfig.c @@ -6,7 +6,7 @@ #include #include #include - +#include "EbApiVersion.h" #include "EbAppConfig.h" #ifdef _WIN32 @@ -17,7 +17,8 @@ /********************************** * Defines **********************************/ -#define HELP_TOKEN "-help" +#define HELP_TOKEN "--help" +#define VERSION_TOKEN "--version" #define CHANNEL_NUMBER_TOKEN "-nch" #define COMMAND_LINE_MAX_SIZE 2048 #define CONFIG_FILE_TOKEN "-c" @@ -739,25 +740,29 @@ uint32_t get_help(int argc, char *const argv[]) char config_string[COMMAND_LINE_MAX_SIZE]; if (find_token(argc, argv, HELP_TOKEN, config_string) == 0) { int token_index = -1; - printf("\n%-25s\t%-25s\t%-25s\t\n\n" ,"TOKEN", "DESCRIPTION", "INPUT TYPE"); printf("%-25s\t%-25s\t%-25s\t\n" ,"-nch", "NumberOfChannels", "Single input"); while (config_entry[++token_index].token != NULL) { - printf("%-25s\t%-25s\t%-25s\t\n", config_entry[token_index].token, config_entry[token_index].name, config_entry[token_index].type ? "Array input": "Single input"); - } return 1; } - else { - return 0; - } - - - + return 0; } +uint32_t get_svt_version(int argc, char *const argv[]) +{ + char config_string[COMMAND_LINE_MAX_SIZE]; + if (find_token(argc, argv, VERSION_TOKEN, config_string) == 0) { + printf("SVT-VP9 version %d.%d.%d\n", SVT_VERSION_MAJOR, SVT_VERSION_MINOR, SVT_VERSION_PATCHLEVEL); + printf("Copyright(c) 2018 Intel Corporation\n"); + printf("BSD-2-Clause Plus Patent License\n"); + printf("https://github.com/OpenVisualCloud/SVT-VP9\n"); + return 1; + } + return 0; +} /****************************************************** * Get the number of channels and validate it with input @@ -952,4 +957,4 @@ EbErrorType read_command_line( } return return_error; -} \ No newline at end of file +} diff --git a/Source/App/EbAppConfig.h b/Source/App/EbAppConfig.h index 4cbedb3..a564e07 100644 --- a/Source/App/EbAppConfig.h +++ b/Source/App/EbAppConfig.h @@ -310,7 +310,7 @@ extern EbErrorType read_command_line( EbErrorType *return_errors); extern uint32_t get_help(int argc, char *const argv[]); - +extern uint32_t get_svt_version(int argc, char *const argv[]); extern uint32_t get_number_of_channels(int argc, char *const argv[]); #endif //EbAppConfig_h diff --git a/Source/App/EbAppMain.c b/Source/App/EbAppMain.c index cd2ae37..e8a6038 100644 --- a/Source/App/EbAppMain.c +++ b/Source/App/EbAppMain.c @@ -79,6 +79,9 @@ void AssignAppThreadGroup(uint8_t targetSocket) { ***************************************/ int32_t main(int32_t argc, char* argv[]) { + if (get_svt_version(argc, argv) || get_help(argc, argv)) + return EB_ErrorNone; + #ifdef _WIN32 _setmode(_fileno(stdin), _O_BINARY); _setmode(_fileno(stdout), _O_BINARY); @@ -105,162 +108,161 @@ int32_t main(int32_t argc, char* argv[]) printf("-------------------------------------\n"); printf("SVT-VP9 Encoder v0.1.0\n"); fflush(stdout); - if (!get_help(argc, argv)) { - // Get num_channels - num_channels = get_number_of_channels(argc, argv); - if (num_channels == 0) { - return EB_ErrorBadParameter; - } + // Get num_channels + num_channels = get_number_of_channels(argc, argv); + if (num_channels == 0) { + return EB_ErrorBadParameter; + } - // Initialize config - for (instance_count = 0; instance_count < num_channels; ++instance_count) { - configs[instance_count] = (EbConfig*)malloc(sizeof(EbConfig)); - if (!configs[instance_count]) - return EB_ErrorInsufficientResources; - eb_config_ctor(configs[instance_count]); - return_errors[instance_count] = EB_ErrorNone; - } + // Initialize config + for (instance_count = 0; instance_count < num_channels; ++instance_count) { + configs[instance_count] = (EbConfig*)malloc(sizeof(EbConfig)); + if (!configs[instance_count]) + return EB_ErrorInsufficientResources; + eb_config_ctor(configs[instance_count]); + return_errors[instance_count] = EB_ErrorNone; + } - // Initialize appCallback - for (instance_count = 0; instance_count < num_channels; ++instance_count) { - app_callbacks[instance_count] = (EbAppContext*)malloc(sizeof(EbAppContext)); - if (!app_callbacks[instance_count]) - return EB_ErrorInsufficientResources; - } + // Initialize appCallback + for (instance_count = 0; instance_count < num_channels; ++instance_count) { + app_callbacks[instance_count] = (EbAppContext*)malloc(sizeof(EbAppContext)); + if (!app_callbacks[instance_count]) + return EB_ErrorInsufficientResources; + } - for (instance_count = 0; instance_count < MAX_CHANNEL_NUMBER; ++instance_count) { - exit_conditions[instance_count] = APP_ExitConditionError; // Processing loop exit condition - exit_conditions_output[instance_count] = APP_ExitConditionError; // Processing loop exit condition - exit_conditions_recon[instance_count] = APP_ExitConditionError; // Processing loop exit condition - exit_conditions_input[instance_count] = APP_ExitConditionError; // Processing loop exit condition - channel_active[instance_count] = EB_FALSE; - } + for (instance_count = 0; instance_count < MAX_CHANNEL_NUMBER; ++instance_count) { + exit_conditions[instance_count] = APP_ExitConditionError; // Processing loop exit condition + exit_conditions_output[instance_count] = APP_ExitConditionError; // Processing loop exit condition + exit_conditions_recon[instance_count] = APP_ExitConditionError; // Processing loop exit condition + exit_conditions_input[instance_count] = APP_ExitConditionError; // Processing loop exit condition + channel_active[instance_count] = EB_FALSE; + } - // Read all configuration files. - return_error = read_command_line(argc, argv, configs, num_channels, return_errors); + // Read all configuration files. + return_error = read_command_line(argc, argv, configs, num_channels, return_errors); - // Process any command line options, including the configuration file - if (return_error == EB_ErrorNone) { + // Process any command line options, including the configuration file + if (return_error == EB_ErrorNone) { - // Set main thread affinity - if (configs[0]->target_socket != -1) - AssignAppThreadGroup(configs[0]->target_socket); + // Set main thread affinity + if (configs[0]->target_socket != -1) + AssignAppThreadGroup(configs[0]->target_socket); - // Init the Encoder + // Init the Encoder + for (instance_count = 0; instance_count < num_channels; ++instance_count) { + if (return_errors[instance_count] == EB_ErrorNone) { + + configs[instance_count]->active_channel_count = num_channels; + configs[instance_count]->channel_id = instance_count; + eb_start_time((uint64_t*)&configs[instance_count]->performance_context.lib_start_time[0], (uint64_t*)&configs[instance_count]->performance_context.lib_start_time[1]); + return_errors[instance_count] = init_encoder(configs[instance_count], app_callbacks[instance_count], instance_count); + return_error = (EbErrorType)(return_error | return_errors[instance_count]); + } + else { + channel_active[instance_count] = EB_FALSE; + } + } + + { + // Start the Encoder for (instance_count = 0; instance_count < num_channels; ++instance_count) { if (return_errors[instance_count] == EB_ErrorNone) { + return_error = (EbErrorType)(return_error & return_errors[instance_count]); + exit_conditions[instance_count] = APP_ExitConditionNone; + exit_conditions_output[instance_count] = APP_ExitConditionNone; + exit_conditions_recon[instance_count] = configs[instance_count]->recon_file ? APP_ExitConditionNone : APP_ExitConditionError; + exit_conditions_input[instance_count] = APP_ExitConditionNone; + channel_active[instance_count] = EB_TRUE; + eb_start_time((uint64_t*)&configs[instance_count]->performance_context.encode_start_time[0], (uint64_t*)&configs[instance_count]->performance_context.encode_start_time[1]); - configs[instance_count]->active_channel_count = num_channels; - configs[instance_count]->channel_id = instance_count; - eb_start_time((uint64_t*)&configs[instance_count]->performance_context.lib_start_time[0], (uint64_t*)&configs[instance_count]->performance_context.lib_start_time[1]); - return_errors[instance_count] = init_encoder(configs[instance_count], app_callbacks[instance_count], instance_count); - return_error = (EbErrorType)(return_error | return_errors[instance_count]); } else { - channel_active[instance_count] = EB_FALSE; + exit_conditions[instance_count] = APP_ExitConditionError; + exit_conditions_output[instance_count] = APP_ExitConditionError; + exit_conditions_recon[instance_count] = APP_ExitConditionError; + exit_conditions_input[instance_count] = APP_ExitConditionError; } - } - - { - // Start the Encoder - for (instance_count = 0; instance_count < num_channels; ++instance_count) { - if (return_errors[instance_count] == EB_ErrorNone) { - return_error = (EbErrorType)(return_error & return_errors[instance_count]); - exit_conditions[instance_count] = APP_ExitConditionNone; - exit_conditions_output[instance_count] = APP_ExitConditionNone; - exit_conditions_recon[instance_count] = configs[instance_count]->recon_file ? APP_ExitConditionNone : APP_ExitConditionError; - exit_conditions_input[instance_count] = APP_ExitConditionNone; - channel_active[instance_count] = EB_TRUE; - eb_start_time((uint64_t*)&configs[instance_count]->performance_context.encode_start_time[0], (uint64_t*)&configs[instance_count]->performance_context.encode_start_time[1]); - - } - else { - exit_conditions[instance_count] = APP_ExitConditionError; - exit_conditions_output[instance_count] = APP_ExitConditionError; - exit_conditions_recon[instance_count] = APP_ExitConditionError; - exit_conditions_input[instance_count] = APP_ExitConditionError; - } #if DISPLAY_MEMORY - EB_APP_MEMORY(); + EB_APP_MEMORY(); #endif - } - printf("Encoding "); - fflush(stdout); - - while (exit_condition == APP_ExitConditionNone) { - exit_condition = APP_ExitConditionFinished; - for (instance_count = 0; instance_count < num_channels; ++instance_count) { - if (channel_active[instance_count] == EB_TRUE) { - if (exit_conditions_input[instance_count] == APP_ExitConditionNone) - exit_conditions_input[instance_count] = process_input_buffer( - configs[instance_count], - app_callbacks[instance_count]); - if (exit_conditions_recon[instance_count] == APP_ExitConditionNone) - exit_conditions_recon[instance_count] = process_output_recon_buffer( - configs[instance_count], - app_callbacks[instance_count]); - if (exit_conditions_output[instance_count] == APP_ExitConditionNone) - exit_conditions_output[instance_count] = process_output_stream_buffer( - configs[instance_count], - app_callbacks[instance_count], - (exit_conditions_input[instance_count] == APP_ExitConditionNone) || (exit_conditions_recon[instance_count] == APP_ExitConditionNone)? 0 : 1); - if (((exit_conditions_recon[instance_count] == APP_ExitConditionFinished || !configs[instance_count]->recon_file) && exit_conditions_output[instance_count] == APP_ExitConditionFinished && exit_conditions_input[instance_count] == APP_ExitConditionFinished)|| + } + printf("Encoding "); + fflush(stdout); + + while (exit_condition == APP_ExitConditionNone) { + exit_condition = APP_ExitConditionFinished; + for (instance_count = 0; instance_count < num_channels; ++instance_count) { + if (channel_active[instance_count] == EB_TRUE) { + if (exit_conditions_input[instance_count] == APP_ExitConditionNone) + exit_conditions_input[instance_count] = process_input_buffer( + configs[instance_count], + app_callbacks[instance_count]); + if (exit_conditions_recon[instance_count] == APP_ExitConditionNone) + exit_conditions_recon[instance_count] = process_output_recon_buffer( + configs[instance_count], + app_callbacks[instance_count]); + if (exit_conditions_output[instance_count] == APP_ExitConditionNone) + exit_conditions_output[instance_count] = process_output_stream_buffer( + configs[instance_count], + app_callbacks[instance_count], + (exit_conditions_input[instance_count] == APP_ExitConditionNone) || (exit_conditions_recon[instance_count] == APP_ExitConditionNone)? 0 : 1); + if (((exit_conditions_recon[instance_count] == APP_ExitConditionFinished || !configs[instance_count]->recon_file) && exit_conditions_output[instance_count] == APP_ExitConditionFinished && exit_conditions_input[instance_count] == APP_ExitConditionFinished)|| ((exit_conditions_recon[instance_count] == APP_ExitConditionError && configs[instance_count]->recon_file) || exit_conditions_output[instance_count] == APP_ExitConditionError || exit_conditions_input[instance_count] == APP_ExitConditionError)){ - channel_active[instance_count] = EB_FALSE; - if (configs[instance_count]->recon_file) - exit_conditions[instance_count] = (AppExitConditionType)(exit_conditions_recon[instance_count] | exit_conditions_output[instance_count] | exit_conditions_input[instance_count]); - else - exit_conditions[instance_count] = (AppExitConditionType)(exit_conditions_output[instance_count] | exit_conditions_input[instance_count]); - } + channel_active[instance_count] = EB_FALSE; + if (configs[instance_count]->recon_file) + exit_conditions[instance_count] = (AppExitConditionType)(exit_conditions_recon[instance_count] | exit_conditions_output[instance_count] | exit_conditions_input[instance_count]); + else + exit_conditions[instance_count] = (AppExitConditionType)(exit_conditions_output[instance_count] | exit_conditions_input[instance_count]); } } - // check if all channels are inactive - for (instance_count = 0; instance_count < num_channels; ++instance_count) { - if (channel_active[instance_count] == EB_TRUE) - exit_condition = APP_ExitConditionNone; - } } - + // check if all channels are inactive for (instance_count = 0; instance_count < num_channels; ++instance_count) { - if (exit_conditions[instance_count] == APP_ExitConditionFinished && return_errors[instance_count] == EB_ErrorNone) { - double frame_rate; - - if ((configs[instance_count]->frame_rate_numerator != 0 && configs[instance_count]->frame_rate_denominator != 0) || configs[instance_count]->frame_rate != 0) { - - if (configs[instance_count]->frame_rate_numerator && configs[instance_count]->frame_rate_denominator && (configs[instance_count]->frame_rate_numerator != 0 && configs[instance_count]->frame_rate_denominator != 0)) { - frame_rate = ((double)configs[instance_count]->frame_rate_numerator) / ((double)configs[instance_count]->frame_rate_denominator); - } - else if (configs[instance_count]->frame_rate > 1000) { - // Correct for 16-bit fixed-point fractional precision - frame_rate = ((double)configs[instance_count]->frame_rate) / (1 << 16); - } - else { - frame_rate = (double)configs[instance_count]->frame_rate; - } - printf("\nSUMMARY --------------------------------- Channel %u --------------------------------\n", instance_count + 1); - - - printf("Total Frames\t\tFrame Rate\t\tByte Count\t\tBitrate\n"); - printf("%12d\t\t%4.2f fps\t\t%10.0f\t\t%5.2f kbps\n", + if (channel_active[instance_count] == EB_TRUE) + exit_condition = APP_ExitConditionNone; + } + } + + for (instance_count = 0; instance_count < num_channels; ++instance_count) { + if (exit_conditions[instance_count] == APP_ExitConditionFinished && return_errors[instance_count] == EB_ErrorNone) { + double frame_rate; + + if ((configs[instance_count]->frame_rate_numerator != 0 && configs[instance_count]->frame_rate_denominator != 0) || configs[instance_count]->frame_rate != 0) { + + if (configs[instance_count]->frame_rate_numerator && configs[instance_count]->frame_rate_denominator && (configs[instance_count]->frame_rate_numerator != 0 && configs[instance_count]->frame_rate_denominator != 0)) { + frame_rate = ((double)configs[instance_count]->frame_rate_numerator) / ((double)configs[instance_count]->frame_rate_denominator); + } + else if (configs[instance_count]->frame_rate > 1000) { + // Correct for 16-bit fixed-point fractional precision + frame_rate = ((double)configs[instance_count]->frame_rate) / (1 << 16); + } + else { + frame_rate = (double)configs[instance_count]->frame_rate; + } + printf("\nSUMMARY --------------------------------- Channel %u --------------------------------\n", instance_count + 1); + + + printf("Total Frames\t\tFrame Rate\t\tByte Count\t\tBitrate\n"); + printf("%12d\t\t%4.2f fps\t\t%10.0f\t\t%5.2f kbps\n", (int32_t)configs[instance_count]->performance_context.frame_count, (double)frame_rate, (double)configs[instance_count]->performance_context.byte_count, ((double)(configs[instance_count]->performance_context.byte_count << 3) * frame_rate / (configs[instance_count]->processed_frame_count * 1000))); - fflush(stdout); - } + fflush(stdout); } } - printf("\n"); - fflush(stdout); } - for (instance_count = 0; instance_count < num_channels; ++instance_count) { - if (exit_conditions[instance_count] == APP_ExitConditionFinished && return_errors[instance_count] == EB_ErrorNone) { + printf("\n"); + fflush(stdout); + } + for (instance_count = 0; instance_count < num_channels; ++instance_count) { + if (exit_conditions[instance_count] == APP_ExitConditionFinished && return_errors[instance_count] == EB_ErrorNone) { - if (configs[instance_count]->stop_encoder == EB_FALSE) { + if (configs[instance_count]->stop_encoder == EB_FALSE) { - printf("\nChannel %u\nAverage Speed:\t\t%.2f fps\nTotal Encoding Time:\t%.0f ms\nTotal Execution Time:\t%.0f ms\nAverage Latency:\t%.0f ms\nMax Latency:\t\t%u ms\n", + printf("\nChannel %u\nAverage Speed:\t\t%.2f fps\nTotal Encoding Time:\t%.0f ms\nTotal Execution Time:\t%.0f ms\nAverage Latency:\t%.0f ms\nMax Latency:\t\t%u ms\n", (uint32_t)(instance_count + 1), configs[instance_count]->performance_context.average_speed, configs[instance_count]->performance_context.total_encode_time * 1000, @@ -268,40 +270,39 @@ int32_t main(int32_t argc, char* argv[]) configs[instance_count]->performance_context.average_latency, (uint32_t)(configs[instance_count]->performance_context.max_latency)); - } - else { - printf("\nChannel %u Encoding Interrupted\n", (uint32_t)(instance_count + 1)); - } - } - else if (return_errors[instance_count] == EB_ErrorInsufficientResources) { - printf("Could not allocate enough memory for channel %u\n", instance_count + 1); } else { - printf("Error encoding at channel %u! Check error log file for more details ... \n", instance_count + 1); + printf("\nChannel %u Encoding Interrupted\n", (uint32_t)(instance_count + 1)); } } - - // DeInit Encoder - for (instance_count = num_channels; instance_count > 0; --instance_count) { - if (return_errors[instance_count - 1] == EB_ErrorNone) - return_errors[instance_count - 1] = de_init_encoder(app_callbacks[instance_count - 1], instance_count - 1); + else if (return_errors[instance_count] == EB_ErrorInsufficientResources) { + printf("Could not allocate enough memory for channel %u\n", instance_count + 1); + } + else { + printf("Error encoding at channel %u! Check error log file for more details ... \n", instance_count + 1); } - } - else { - printf("Error in configuration, could not begin encoding! ... \n"); - printf("Run %s -help for a list of options\n", argv[0]); - } - // Destruct the App memory variables - for (instance_count = 0; instance_count < num_channels; ++instance_count) { - eb_config_dtor(configs[instance_count]); - if (configs[instance_count]) - free(configs[instance_count]); - if (app_callbacks[instance_count]) - free(app_callbacks[instance_count]); } - printf("Encoder finished\n"); + // DeInit Encoder + for (instance_count = num_channels; instance_count > 0; --instance_count) { + if (return_errors[instance_count - 1] == EB_ErrorNone) + return_errors[instance_count - 1] = de_init_encoder(app_callbacks[instance_count - 1], instance_count - 1); + } } + else { + printf("Error in configuration, could not begin encoding! ... \n"); + printf("Run %s --help for a list of options\n", argv[0]); + } + // Destruct the App memory variables + for (instance_count = 0; instance_count < num_channels; ++instance_count) { + eb_config_dtor(configs[instance_count]); + if (configs[instance_count]) + free(configs[instance_count]); + if (app_callbacks[instance_count]) + free(app_callbacks[instance_count]); + } + + printf("Encoder finished\n"); return (return_error == 0) ? 0 : 1; }