diff options
Diffstat (limited to 'libavcodec/vaapi_encode_vp8.c')
-rw-r--r-- | libavcodec/vaapi_encode_vp8.c | 91 |
1 files changed, 41 insertions, 50 deletions
diff --git a/libavcodec/vaapi_encode_vp8.c b/libavcodec/vaapi_encode_vp8.c index 857054dc64..166636cd84 100644 --- a/libavcodec/vaapi_encode_vp8.c +++ b/libavcodec/vaapi_encode_vp8.c @@ -1,18 +1,18 @@ /* - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * Libav is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -28,17 +28,20 @@ #include "avcodec.h" #include "internal.h" #include "vaapi_encode.h" +#include "vp8.h" typedef struct VAAPIEncodeVP8Context { - int q_index_i; - int q_index_p; -} VAAPIEncodeVP8Context; + VAAPIEncodeContext common; -typedef struct VAAPIEncodeVP8Options { + // User options. int loop_filter_level; int loop_filter_sharpness; -} VAAPIEncodeVP8Options; + + // Derived settings. + int q_index_i; + int q_index_p; +} VAAPIEncodeVP8Context; #define vseq_var(name) vseq->name, name @@ -62,8 +65,8 @@ static int vaapi_encode_vp8_init_sequence_params(AVCodecContext *avctx) vseq->kf_auto = 0; if (!(ctx->va_rc_mode & VA_RC_CQP)) { - vseq->bits_per_second = avctx->bit_rate; - vseq->intra_period = avctx->gop_size; + vseq->bits_per_second = ctx->va_bit_rate; + vseq->intra_period = ctx->gop_size; } return 0; @@ -72,9 +75,8 @@ static int vaapi_encode_vp8_init_sequence_params(AVCodecContext *avctx) static int vaapi_encode_vp8_init_picture_params(AVCodecContext *avctx, VAAPIEncodePicture *pic) { - VAAPIEncodeContext *ctx = avctx->priv_data; + VAAPIEncodeVP8Context *priv = avctx->priv_data; VAEncPictureParameterBufferVP8 *vpic = pic->codec_picture_params; - VAAPIEncodeVP8Options *opt = ctx->codec_options; int i; vpic->reconstructed_frame = pic->recon_surface; @@ -115,8 +117,8 @@ static int vaapi_encode_vp8_init_picture_params(AVCodecContext *avctx, vpic->pic_flags.bits.version = 0; vpic->pic_flags.bits.loop_filter_type = 0; for (i = 0; i < 4; i++) - vpic->loop_filter_level[i] = opt->loop_filter_level; - vpic->sharpness_level = opt->loop_filter_sharpness; + vpic->loop_filter_level[i] = priv->loop_filter_level; + vpic->sharpness_level = priv->loop_filter_sharpness; vpic->clamp_qindex_low = 0; vpic->clamp_qindex_high = 127; @@ -129,8 +131,7 @@ static int vaapi_encode_vp8_write_quant_table(AVCodecContext *avctx, int index, int *type, char *data, size_t *data_len) { - VAAPIEncodeContext *ctx = avctx->priv_data; - VAAPIEncodeVP8Context *priv = ctx->priv_data; + VAAPIEncodeVP8Context *priv = avctx->priv_data; VAQMatrixBufferVP8 quant; int i, q; @@ -142,6 +143,8 @@ static int vaapi_encode_vp8_write_quant_table(AVCodecContext *avctx, *type = VAQMatrixBufferType; *data_len = sizeof(quant); + memset(&quant, 0, sizeof(quant)); + if (pic->type == PICTURE_TYPE_P) q = priv->q_index_p; else @@ -158,25 +161,29 @@ static int vaapi_encode_vp8_write_quant_table(AVCodecContext *avctx, static av_cold int vaapi_encode_vp8_configure(AVCodecContext *avctx) { - VAAPIEncodeContext *ctx = avctx->priv_data; - VAAPIEncodeVP8Context *priv = ctx->priv_data; + VAAPIEncodeVP8Context *priv = avctx->priv_data; - priv->q_index_p = av_clip(avctx->global_quality, 0, 127); + priv->q_index_p = av_clip(avctx->global_quality, 0, VP8_MAX_QUANT); if (avctx->i_quant_factor > 0.0) priv->q_index_i = av_clip((avctx->global_quality * avctx->i_quant_factor + avctx->i_quant_offset) + 0.5, - 0, 127); + 0, VP8_MAX_QUANT); else priv->q_index_i = priv->q_index_p; return 0; } +static const VAAPIEncodeProfile vaapi_encode_vp8_profiles[] = { + { 0 /* VP8 has no profiles */, 8, 3, 1, 1, VAProfileVP8Version0_3 }, + { FF_PROFILE_UNKNOWN } +}; + static const VAAPIEncodeType vaapi_encode_type_vp8 = { - .configure = &vaapi_encode_vp8_configure, + .profiles = vaapi_encode_vp8_profiles, - .priv_data_size = sizeof(VAAPIEncodeVP8Context), + .configure = &vaapi_encode_vp8_configure, .sequence_params_size = sizeof(VAEncSequenceParameterBufferVP8), .init_sequence_params = &vaapi_encode_vp8_init_sequence_params, @@ -191,30 +198,12 @@ static av_cold int vaapi_encode_vp8_init(AVCodecContext *avctx) { VAAPIEncodeContext *ctx = avctx->priv_data; - if (avctx->max_b_frames > 0) { - av_log(avctx, AV_LOG_ERROR, "B-frames are not supported.\n"); - return AVERROR_PATCHWELCOME; - } - ctx->codec = &vaapi_encode_type_vp8; - ctx->va_profile = VAProfileVP8Version0_3; - ctx->va_entrypoint = VAEntrypointEncSlice; - ctx->va_rt_format = VA_RT_FORMAT_YUV420; - - if (avctx->flags & AV_CODEC_FLAG_QSCALE) { - ctx->va_rc_mode = VA_RC_CQP; - } else if (avctx->bit_rate > 0) { - if (avctx->rc_max_rate == avctx->bit_rate) - ctx->va_rc_mode = VA_RC_CBR; - else - ctx->va_rc_mode = VA_RC_VBR; - } else { - ctx->va_rc_mode = VA_RC_CQP; - } - - // Packed headers are not currently supported. - ctx->va_packed_headers = 0; + // No packed headers are currently desired. VP8 has no metadata + // which would be useful to write, and no existing driver supports + // adding them anyway. + ctx->desired_packed_headers = 0; ctx->surface_width = FFALIGN(avctx->width, 16); ctx->surface_height = FFALIGN(avctx->height, 16); @@ -222,10 +211,10 @@ static av_cold int vaapi_encode_vp8_init(AVCodecContext *avctx) return ff_vaapi_encode_init(avctx); } -#define OFFSET(x) (offsetof(VAAPIEncodeContext, codec_options_data) + \ - offsetof(VAAPIEncodeVP8Options, x)) +#define OFFSET(x) offsetof(VAAPIEncodeVP8Context, x) #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM) static const AVOption vaapi_encode_vp8_options[] = { + VAAPI_ENCODE_COMMON_OPTIONS, { "loop_filter_level", "Loop filter level", OFFSET(loop_filter_level), AV_OPT_TYPE_INT, { .i64 = 16 }, 0, 63, FLAGS }, { "loop_filter_sharpness", "Loop filter sharpness", @@ -238,6 +227,8 @@ static const AVCodecDefault vaapi_encode_vp8_defaults[] = { { "bf", "0" }, { "g", "120" }, { "global_quality", "40" }, + { "qmin", "-1" }, + { "qmax", "-1" }, { NULL }, }; @@ -253,10 +244,10 @@ AVCodec ff_vp8_vaapi_encoder = { .long_name = NULL_IF_CONFIG_SMALL("VP8 (VAAPI)"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_VP8, - .priv_data_size = (sizeof(VAAPIEncodeContext) + - sizeof(VAAPIEncodeVP8Options)), + .priv_data_size = sizeof(VAAPIEncodeVP8Context), .init = &vaapi_encode_vp8_init, - .encode2 = &ff_vaapi_encode2, + .send_frame = &ff_vaapi_encode_send_frame, + .receive_packet = &ff_vaapi_encode_receive_packet, .close = &ff_vaapi_encode_close, .priv_class = &vaapi_encode_vp8_class, .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE, |