[x265] [PATCH 2 of 2] cli: use multi-lib APIs as a (weak) demonstration
Steve Borho
steve at borho.org
Thu Apr 2 19:19:48 CEST 2015
# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1427994917 18000
# Thu Apr 02 12:15:17 2015 -0500
# Node ID eddbf09aa388d55c18ea96d8fec05470fc07dea7
# Parent a9c4d2446c9f5b44ca875d4433a2121f4ec3f860
cli: use multi-lib APIs as a (weak) demonstration
it is a weak demonstration because the CLI uses internal methods which are
not exported from shared libraries on many platforms, so this will never be
particularly functional.
diff -r a9c4d2446c9f -r eddbf09aa388 source/x265.cpp
--- a/source/x265.cpp Thu Apr 02 11:48:34 2015 -0500
+++ b/source/x265.cpp Thu Apr 02 12:15:17 2015 -0500
@@ -470,28 +470,36 @@
GetConsoleTitle(orgConsoleTitle, CONSOLE_TITLE_SIZE);
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_AWAYMODE_REQUIRED);
- x265_param *param = x265_param_alloc();
+ const x265_api* api = x265_api_get(X265_DEPTH); /* prefer what the cli was compiled against */
+ if (!api)
+ api = x265_api_get(0);
+
+ x265_param *param = api->param_alloc();
CLIOptions cliopt;
if (cliopt.parse(argc, argv, param))
{
cliopt.destroy();
- x265_param_free(param);
+ api->param_free(param);
exit(1);
}
- x265_encoder *encoder = x265_encoder_open(param);
+ /* note: we could try to acquire a different libx265 API here based on
+ * the profile found during option parsing, but it must be done before
+ * opening an encoder */
+
+ x265_encoder *encoder = api->encoder_open(param);
if (!encoder)
{
x265_log(param, X265_LOG_ERROR, "failed to open encoder\n");
cliopt.destroy();
- x265_param_free(param);
- x265_cleanup();
+ api->param_free(param);
+ api->cleanup();
exit(2);
}
/* get the encoder parameters post-initialization */
- x265_encoder_parameters(encoder, param);
+ api->encoder_parameters(encoder, param);
/* Control-C handler */
if (signal(SIGINT, sigint_handler) == SIG_ERR)
@@ -511,7 +519,7 @@
if (!param->bRepeatHeaders)
{
- if (x265_encoder_headers(encoder, &p_nal, &nal) < 0)
+ if (api->encoder_headers(encoder, &p_nal, &nal) < 0)
{
x265_log(param, X265_LOG_ERROR, "Failure generating stream headers\n");
ret = 3;
@@ -521,7 +529,7 @@
cliopt.writeNALs(p_nal, nal);
}
- x265_picture_init(param, pic_in);
+ api->picture_init(param, pic_in);
if (cliopt.bDither)
{
@@ -562,7 +570,7 @@
}
}
- int numEncoded = x265_encoder_encode(encoder, &p_nal, &nal, pic_in, pic_recon);
+ int numEncoded = api->encoder_encode(encoder, &p_nal, &nal, pic_in, pic_recon);
if (numEncoded < 0)
{
b_ctrl_c = 1;
@@ -582,7 +590,7 @@
/* Flush the encoder */
while (!b_ctrl_c)
{
- int numEncoded = x265_encoder_encode(encoder, &p_nal, &nal, NULL, pic_recon);
+ int numEncoded = api->encoder_encode(encoder, &p_nal, &nal, NULL, pic_recon);
if (numEncoded < 0)
{
ret = 4;
@@ -605,10 +613,10 @@
fprintf(stderr, "%*s\r", 80, " ");
fail:
- x265_encoder_get_stats(encoder, &stats, sizeof(stats));
+ api->encoder_get_stats(encoder, &stats, sizeof(stats));
if (param->csvfn && !b_ctrl_c)
- x265_encoder_log(encoder, argc, argv);
- x265_encoder_close(encoder);
+ api->encoder_log(encoder, argc, argv);
+ api->encoder_close(encoder);
cliopt.bitstreamFile.close();
if (b_ctrl_c)
@@ -633,11 +641,11 @@
printf("\nencoded 0 frames\n");
}
- x265_cleanup(); /* Free library singletons */
+ api->cleanup(); /* Free library singletons */
cliopt.destroy();
- x265_param_free(param);
+ api->param_free(param);
X265_FREE(errorBuf);
More information about the x265-devel
mailing list