Created
May 31, 2020 16:01
-
-
Save lu-zero/9bddd3ddf30e98e156afb108ccb98e9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static int get_stats(AVCodecContext *avctx) | |
{ | |
librav1eContext *ctx = avctx->priv_data; | |
RaData* buf = NULL; | |
// Summary | |
if (rav1e_rc_receive_pass_data(ctx->ctx, &buf) == RAV1E_RC_DATA_KIND_SUMMARY) { | |
size_t b64_size = AV_BASE64_SIZE(ctx->pass_pos); | |
AV_WB64(ctx->pass_data, buf->len); | |
memcpy(ctx->pass_data + 8, buf->data, buf->len); | |
avctx->stats_out = av_malloc(b64_size); | |
if (!avctx->stats_out) { | |
rav1e_data_unref(buf); | |
return AVERROR(ENOMEM); | |
} | |
av_base64_encode(avctx->stats_out, b64_size, ctx->pass_data, ctx->pass_pos); | |
av_freep(&ctx->pass_data); | |
} else { | |
uint8_t *tmp = av_fast_realloc(ctx->pass_data, &ctx->pass_size, | |
ctx->pass_pos + buf->len + 8); | |
if (!tmp) { | |
rav1e_data_unref(buf); | |
return AVERROR(ENOMEM); | |
} | |
ctx->pass_data = tmp; | |
AV_WB64(ctx->pass_data + ctx->pass_pos, buf->len); | |
memcpy(ctx->pass_data + ctx->pass_pos + 8, buf->data, buf->len); | |
ctx->pass_pos += buf->len + 8; | |
} | |
rav1e_data_unref(buf); | |
} | |
static int set_stats(AVCodecContext *avctx) | |
{ | |
librav1eContext *ctx = avctx->priv_data; | |
int req = rav1e_rc_second_pass_data_required(ctx->ctx); | |
while (req--) { | |
uint64_t len = AV_RB64(ctx->pass_data + ctx->pass_pos); | |
ret = rav1e_rc_send_pass_data(ctx->ctx, ctx->pass_data + ctx->pass_pos + 8, len); | |
if (ret < 0) | |
return AVERROR_EXTERNAL; | |
ctx->pass_pos += 8 + len; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment