[FFmpeg-cvslog] vaapi_encode: Add VP9 support

2017-10-26 Thread Mark Thompson
ffmpeg | branch: master | Mark Thompson  | Mon Nov 28 23:54:57 
2016 +| [0fd91e4bfc00a6609b59d1ce3a9f152184e62601] | committer: Mark 
Thompson

vaapi_encode: Add VP9 support

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0fd91e4bfc00a6609b59d1ce3a9f152184e62601
---

 configure |   3 +
 libavcodec/Makefile   |   1 +
 libavcodec/allcodecs.c|   1 +
 libavcodec/vaapi_encode_vp9.c | 311 ++
 libavcodec/version.h  |   2 +-
 5 files changed, 317 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index f1488cf494..30eba73c21 100755
--- a/configure
+++ b/configure
@@ -2273,6 +2273,8 @@ vp8_qsv_decoder_deps="libmfx"
 vp8_qsv_decoder_select="qsvdec vp8_qsv_hwaccel vp8_parser"
 vp8_vaapi_encoder_deps="VAEncPictureParameterBufferVP8"
 vp8_vaapi_encoder_select="vaapi_encode"
+vp9_vaapi_encoder_deps="VAEncPictureParameterBufferVP9"
+vp9_vaapi_encoder_select="vaapi_encode"
 
 nvenc_h264_encoder_select="h264_nvenc_encoder"
 nvenc_hevc_encoder_select="hevc_nvenc_encoder"
@@ -4666,6 +4668,7 @@ check_type "va/va.h va/va_enc_hevc.h" 
"VAEncPictureParameterBufferHEVC"
 check_type "va/va.h va/va_enc_jpeg.h" "VAEncPictureParameterBufferJPEG"
 check_type "va/va.h va/va_enc_mpeg2.h" "VAEncPictureParameterBufferMPEG2"
 check_type "va/va.h va/va_enc_vp8.h"  "VAEncPictureParameterBufferVP8"
+check_type "va/va.h va/va_enc_vp9.h"  "VAEncPictureParameterBufferVP9"
 
 check_type "vdpau/vdpau.h" "VdpPictureInfoHEVC"
 
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 674c8d0445..ec62f514a7 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -485,6 +485,7 @@ OBJS-$(CONFIG_VP8_QSV_DECODER) += qsvdec_other.o
 OBJS-$(CONFIG_VP8_VAAPI_ENCODER)   += vaapi_encode_vp8.o
 OBJS-$(CONFIG_VP9_DECODER) += vp9.o vp9data.o vp9dsp.o \
   vp9block.o vp9prob.o vp9mvs.o 
vp56rac.o
+OBJS-$(CONFIG_VP9_VAAPI_ENCODER)   += vaapi_encode_vp9.o
 OBJS-$(CONFIG_VQA_DECODER) += vqavideo.o
 OBJS-$(CONFIG_WAVPACK_DECODER) += wavpack.o
 OBJS-$(CONFIG_WEBP_DECODER)+= webp.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 556bdb43f3..36f839c852 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -511,6 +511,7 @@ void avcodec_register_all(void)
 REGISTER_ENCODER(NVENC_HEVC,nvenc_hevc);
 #endif
 REGISTER_ENCODER(VP8_VAAPI, vp8_vaapi);
+REGISTER_ENCODER(VP9_VAAPI, vp9_vaapi);
 
 /* parsers */
 REGISTER_PARSER(AAC,aac);
diff --git a/libavcodec/vaapi_encode_vp9.c b/libavcodec/vaapi_encode_vp9.c
new file mode 100644
index 00..5d3eec1775
--- /dev/null
+++ b/libavcodec/vaapi_encode_vp9.c
@@ -0,0 +1,311 @@
+/*
+ * This file is part of Libav.
+ *
+ * Libav 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,
+ * 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+#include 
+
+#include "libavutil/avassert.h"
+#include "libavutil/common.h"
+#include "libavutil/internal.h"
+#include "libavutil/opt.h"
+#include "libavutil/pixfmt.h"
+
+#include "avcodec.h"
+#include "internal.h"
+#include "vaapi_encode.h"
+
+
+typedef struct VAAPIEncodeVP9Context {
+int q_idx_idr;
+int q_idx_p;
+int q_idx_b;
+
+// Reference direction for B-like frames:
+// 0 - most recent P/IDR frame is last.
+// 1 - most recent P frame is golden.
+int last_ref_dir;
+} VAAPIEncodeVP9Context;
+
+typedef struct VAAPIEncodeVP9Options {
+int loop_filter_level;
+int loop_filter_sharpness;
+} VAAPIEncodeVP9Options;
+
+
+#define vseq_var(name) vseq->name, name
+#define vseq_field(name)   vseq->seq_fields.bits.name, name
+#define vpic_var(name) vpic->name, name
+#define vpic_field(name)   vpic->pic_fields.bits.name, name
+
+
+static int vaapi_encode_vp9_init_sequence_params(AVCodecContext *avctx)
+{
+VAAPIEncodeContext   *ctx = avctx->priv_data;
+VAEncSequenceParameterBufferVP9 *vseq = ctx->codec_sequence_params;
+VAEncPictureParameterBufferVP9  *vpic = ctx->codec_picture_params;
+
+vseq->max_frame_width  = avctx->width;
+vseq->max_frame_height = avctx->height;
+
+vseq->kf_auto = 0;
+
+if (!(ctx->va_rc_mode & VA_RC_CQP)) {
+vseq->bits_per_second = avctx->bit_rate;
+  

[FFmpeg-cvslog] vaapi_encode: Add VP9 support

2017-06-24 Thread Mark Thompson
ffmpeg | branch: master | Mark Thompson  | Mon Nov 28 23:54:57 
2016 +| [bde04604065db565373c315ad13d9c3c5db4d7c9] | committer: Mark 
Thompson

vaapi_encode: Add VP9 support

(cherry picked from commit 0fd91e4bfc00a6609b59d1ce3a9f152184e62601)

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=bde04604065db565373c315ad13d9c3c5db4d7c9
---

 configure |   3 +
 libavcodec/Makefile   |   1 +
 libavcodec/allcodecs.c|   1 +
 libavcodec/vaapi_encode_vp9.c | 313 ++
 libavcodec/version.h  |   2 +-
 5 files changed, 319 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index 2817746ce5..6ca919be4a 100755
--- a/configure
+++ b/configure
@@ -2797,6 +2797,8 @@ vp8_vaapi_encoder_deps="VAEncPictureParameterBufferVP8"
 vp8_vaapi_encoder_select="vaapi_encode"
 vp9_cuvid_decoder_deps="cuda cuvid"
 vp9_mediacodec_decoder_deps="mediacodec"
+vp9_vaapi_encoder_deps="VAEncPictureParameterBufferVP9"
+vp9_vaapi_encoder_select="vaapi_encode"
 wmv3_crystalhd_decoder_select="crystalhd"
 wmv3_vdpau_decoder_select="vc1_vdpau_decoder"
 
@@ -5725,6 +5727,7 @@ check_type "va/va.h va/va_enc_hevc.h" 
"VAEncPictureParameterBufferHEVC"
 check_type "va/va.h va/va_enc_jpeg.h" "VAEncPictureParameterBufferJPEG"
 check_type "va/va.h va/va_enc_mpeg2.h" "VAEncPictureParameterBufferMPEG2"
 check_type "va/va.h va/va_enc_vp8.h"  "VAEncPictureParameterBufferVP8"
+check_type "va/va.h va/va_enc_vp9.h"  "VAEncPictureParameterBufferVP9"
 
 check_type "vdpau/vdpau.h" "VdpPictureInfoHEVC"
 
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index b5cc748e19..f0cba8843d 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -627,6 +627,7 @@ OBJS-$(CONFIG_VP9_DECODER) += vp9.o vp9data.o 
vp9dsp.o vp9lpf.o vp9r
   vp9dsp_8bpp.o vp9dsp_10bpp.o 
vp9dsp_12bpp.o
 OBJS-$(CONFIG_VP9_CUVID_DECODER)   += cuvid.o
 OBJS-$(CONFIG_VP9_MEDIACODEC_DECODER)  += mediacodecdec.o
+OBJS-$(CONFIG_VP9_VAAPI_ENCODER)   += vaapi_encode_vp9.o
 OBJS-$(CONFIG_VPLAYER_DECODER) += textdec.o ass.o
 OBJS-$(CONFIG_VQA_DECODER) += vqavideo.o
 OBJS-$(CONFIG_WAVPACK_DECODER) += wavpack.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 27110e1cfd..54a9e8c42e 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -680,6 +680,7 @@ static void register_all(void)
 REGISTER_ENCODER(VP8_VAAPI, vp8_vaapi);
 REGISTER_DECODER(VP9_CUVID, vp9_cuvid);
 REGISTER_DECODER(VP9_MEDIACODEC,vp9_mediacodec);
+REGISTER_ENCODER(VP9_VAAPI, vp9_vaapi);
 
 /* parsers */
 REGISTER_PARSER(AAC,aac);
diff --git a/libavcodec/vaapi_encode_vp9.c b/libavcodec/vaapi_encode_vp9.c
new file mode 100644
index 00..a987d1cd71
--- /dev/null
+++ b/libavcodec/vaapi_encode_vp9.c
@@ -0,0 +1,313 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * 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.
+ *
+ * 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+#include 
+
+#include "libavutil/avassert.h"
+#include "libavutil/common.h"
+#include "libavutil/internal.h"
+#include "libavutil/opt.h"
+#include "libavutil/pixfmt.h"
+
+#include "avcodec.h"
+#include "internal.h"
+#include "vaapi_encode.h"
+
+#define VP9_MAX_QUANT 255
+
+
+typedef struct VAAPIEncodeVP9Context {
+int q_idx_idr;
+int q_idx_p;
+int q_idx_b;
+
+// Reference direction for B-like frames:
+// 0 - most recent P/IDR frame is last.
+// 1 - most recent P frame is golden.
+int last_ref_dir;
+} VAAPIEncodeVP9Context;
+
+typedef struct VAAPIEncodeVP9Options {
+int loop_filter_level;
+int loop_filter_sharpness;
+} VAAPIEncodeVP9Options;
+
+
+#define vseq_var(name) vseq->name, name
+#define vseq_field(name)   vseq->seq_fields.bits.name, name
+#define vpic_var(name) vpic->name, name
+#define vpic_field(name)   vpic->pic_fields.bits.name, name
+
+
+static int vaapi_encode_vp9_init_sequence_params(AVCodecContext *avctx)
+{
+VAAPIEncodeContext   *ctx = avctx->priv_data;
+VAEncSequenceParameterBufferVP9 *vseq = ctx->codec_sequence_params;
+VAEncPictureParameterBufferVP9  *vpic = ctx->codec_picture_params;
+
+vseq->max_frame_width  = avctx->width;
+