summaryrefslogtreecommitdiff
path: root/libavcodec/libx265.c
diff options
context:
space:
mode:
authorGopu Govindaswamy <gopu@multicorewareinc.com>2015-05-07 14:28:55 +0530
committerDerek Buitenhuis <derek.buitenhuis@gmail.com>2015-05-11 16:15:23 +0100
commit94c20de429420f541aba2d371c6175e8658f8353 (patch)
tree9a76be810b92154cbb8538d26784c3e52ab0f777 /libavcodec/libx265.c
parentab6dc863436361311eb2a2d3de692c7de4837d59 (diff)
avcodec/libx265: use x265 Multi-library Interface to query the API
ffmpeg can now use the x265 multi-library interface to make a runtime selection between a number of libx265 libraries (perhaps 8bpp and 16bpp). ffmpeg will link to one build of libx265 (statically or dynamically) and this linked version of libx265 will support one bit-depth (8 or 10 bits). At runtime, ffmpeg now has the option to request the encoder to use a different bit depth(8 or 10). If the requested bitdepth is zero, or if it matches the bitdepth of the system default libx265 (the currently linked library), then this library will be used for encode. If ffmpeg requests a different bit-depth, the linked libx265 will attempt to dynamically bind a shared library with the requested bit-depth from the install location (default or user-specified). new x265 API: const x265_api* api = x265_api_get(int bitDepth); x265_api - holds the libx265 public API functions bitDepth - requested API for 8bpp or 16bpp note: Use 0 to indicate native bit depth of the linked libx265 and x265_api_get(0) is guaranteed to return a non-null pointer Signed-off-by: Gopu Govindaswamy <gopu@multicorewareinc.com> Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Diffstat (limited to 'libavcodec/libx265.c')
-rw-r--r--libavcodec/libx265.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index 983b430bc1..7423e13ad0 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -39,6 +39,7 @@ typedef struct libx265Context {
x265_encoder *encoder;
x265_param *params;
+ const x265_api *api;
float crf;
char *preset;
@@ -67,10 +68,10 @@ static av_cold int libx265_encode_close(AVCodecContext *avctx)
av_frame_free(&avctx->coded_frame);
- x265_param_free(ctx->params);
+ ctx->api->param_free(ctx->params);
if (ctx->encoder)
- x265_encoder_close(ctx->encoder);
+ ctx->api->encoder_close(ctx->encoder);
return 0;
}
@@ -79,6 +80,10 @@ static av_cold int libx265_encode_init(AVCodecContext *avctx)
{
libx265Context *ctx = avctx->priv_data;
+ ctx->api = x265_api_get(av_pix_fmt_desc_get(avctx->pix_fmt)->comp[0].depth_minus1 + 1);
+ if (!ctx->api)
+ ctx->api = x265_api_get(0);
+
if (avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL &&
!av_pix_fmt_desc_get(avctx->pix_fmt)->log2_chroma_w) {
av_log(avctx, AV_LOG_ERROR,
@@ -93,13 +98,13 @@ static av_cold int libx265_encode_init(AVCodecContext *avctx)
return AVERROR(ENOMEM);
}
- ctx->params = x265_param_alloc();
+ ctx->params = ctx->api->param_alloc();
if (!ctx->params) {
av_log(avctx, AV_LOG_ERROR, "Could not allocate x265 param structure.\n");
return AVERROR(ENOMEM);
}
- if (x265_param_default_preset(ctx->params, ctx->preset, ctx->tune) < 0) {
+ if (ctx->api->param_default_preset(ctx->params, ctx->preset, ctx->tune) < 0) {
int i;
av_log(avctx, AV_LOG_ERROR, "Error setting preset/tune %s/%s.\n", ctx->preset, ctx->tune);
@@ -148,7 +153,7 @@ static av_cold int libx265_encode_init(AVCodecContext *avctx)
avctx->sample_aspect_ratio.num,
avctx->sample_aspect_ratio.den, 65535);
snprintf(sar, sizeof(sar), "%d:%d", sar_num, sar_den);
- if (x265_param_parse(ctx->params, "sar", sar) == X265_PARAM_BAD_VALUE) {
+ if (ctx->api->param_parse(ctx->params, "sar", sar) == X265_PARAM_BAD_VALUE) {
av_log(avctx, AV_LOG_ERROR, "Invalid SAR: %d:%d.\n", sar_num, sar_den);
return AVERROR_INVALIDDATA;
}
@@ -173,7 +178,7 @@ static av_cold int libx265_encode_init(AVCodecContext *avctx)
char crf[6];
snprintf(crf, sizeof(crf), "%2.2f", ctx->crf);
- if (x265_param_parse(ctx->params, "crf", crf) == X265_PARAM_BAD_VALUE) {
+ if (ctx->api->param_parse(ctx->params, "crf", crf) == X265_PARAM_BAD_VALUE) {
av_log(avctx, AV_LOG_ERROR, "Invalid crf: %2.2f.\n", ctx->crf);
return AVERROR(EINVAL);
}
@@ -191,7 +196,7 @@ static av_cold int libx265_encode_init(AVCodecContext *avctx)
if (!av_dict_parse_string(&dict, ctx->x265_opts, "=", ":", 0)) {
while ((en = av_dict_get(dict, "", en, AV_DICT_IGNORE_SUFFIX))) {
- int parse_ret = x265_param_parse(ctx->params, en->key, en->value);
+ int parse_ret = ctx->api->param_parse(ctx->params, en->key, en->value);
switch (parse_ret) {
case X265_PARAM_BAD_NAME:
@@ -210,7 +215,7 @@ static av_cold int libx265_encode_init(AVCodecContext *avctx)
}
}
- ctx->encoder = x265_encoder_open(ctx->params);
+ ctx->encoder = ctx->api->encoder_open(ctx->params);
if (!ctx->encoder) {
av_log(avctx, AV_LOG_ERROR, "Cannot open libx265 encoder.\n");
libx265_encode_close(avctx);
@@ -221,7 +226,7 @@ static av_cold int libx265_encode_init(AVCodecContext *avctx)
x265_nal *nal;
int nnal;
- avctx->extradata_size = x265_encoder_headers(ctx->encoder, &nal, &nnal);
+ avctx->extradata_size = ctx->api->encoder_headers(ctx->encoder, &nal, &nnal);
if (avctx->extradata_size <= 0) {
av_log(avctx, AV_LOG_ERROR, "Cannot encode headers.\n");
libx265_encode_close(avctx);
@@ -255,7 +260,7 @@ static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
int ret;
int i;
- x265_picture_init(ctx->params, &x265pic);
+ ctx->api->picture_init(ctx->params, &x265pic);
if (pic) {
for (i = 0; i < 3; i++) {
@@ -272,8 +277,8 @@ static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
X265_TYPE_AUTO;
}
- ret = x265_encoder_encode(ctx->encoder, &nal, &nnal,
- pic ? &x265pic : NULL, &x265pic_out);
+ ret = ctx->api->encoder_encode(ctx->encoder, &nal, &nnal,
+ pic ? &x265pic : NULL, &x265pic_out);
if (ret < 0)
return AVERROR_EXTERNAL;