Re: [libav-devel] [PATCH 6/9] lavf: VAAPI scale filter

2016-03-19 Thread Mark Thompson
On 19/03/16 08:47, Anton Khirnov wrote:
> Quoting Mark Thompson (2016-03-16 00:00:09)
>> +
>> +static int scale_vaapi_pipeline_uninit(ScaleVAAPIContext *ctx)
>> +{
>> +if (ctx->va_context != VA_INVALID_ID) {
> 
> Some tests reveal that these checks are not good, because this function
> can be called without the context/config ids ever being initialized.
> E.g. if the caller provides invalid filter options, init is never
> called, but uninit is.
> 

Oh, I wasn't expecting uninit to ever be called without init.  So just add an 
extra "init called" field to check there?

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 6/9] lavf: VAAPI scale filter

2016-03-19 Thread Anton Khirnov
Quoting Mark Thompson (2016-03-16 00:00:09)
> +
> +static int scale_vaapi_pipeline_uninit(ScaleVAAPIContext *ctx)
> +{
> +if (ctx->va_context != VA_INVALID_ID) {

Some tests reveal that these checks are not good, because this function
can be called without the context/config ids ever being initialized.
E.g. if the caller provides invalid filter options, init is never
called, but uninit is.

-- 
Anton Khirnov
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 6/9] lavf: VAAPI scale filter

2016-03-19 Thread Diego Biurrun
On Tue, Mar 15, 2016 at 11:00:09PM +, Mark Thompson wrote:
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -108,6 +108,7 @@ void avfilter_register_all(void)
>  REGISTER_FILTER(TRANSPOSE,  transpose,  vf);
>  REGISTER_FILTER(TRIM,   trim,   vf);
>  REGISTER_FILTER(UNSHARP,unsharp,vf);
> +REGISTER_FILTER(SCALE_VAAPI,scale_vaapi,vf);
>  REGISTER_FILTER(VFLIP,  vflip,  vf);
>  REGISTER_FILTER(YADIF,  yadif,  vf);

order

Diego
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 6/9] lavf: VAAPI scale filter

2016-03-15 Thread Mark Thompson
---
 configure|   3 +
 libavfilter/Makefile |   1 +
 libavfilter/allfilters.c |   1 +
 libavfilter/vf_scale_vaapi.c | 451 +++
 4 files changed, 456 insertions(+)
 create mode 100644 libavfilter/vf_scale_vaapi.c

diff --git a/configure b/configure
index 76d028d..b1aed3a 100755
--- a/configure
+++ b/configure
@@ -2360,6 +2360,7 @@ interlace_filter_deps="gpl"
 ocv_filter_deps="libopencv"
 resample_filter_deps="avresample"
 scale_filter_deps="swscale"
+scale_vaapi_filter_deps="vaapi VAProcPipelineParameterBuffer"

 # examples
 avcodec_example_deps="avcodec avutil"
@@ -4458,6 +4459,8 @@ check_type "windows.h dxva.h" "DXVA_PicParams_HEVC" 
-DWINAPI_FAMILY=WINAPI_FAMIL
 check_type "windows.h d3d11.h" "ID3D11VideoDecoder"
 check_type "d3d9.h dxva2api.h" DXVA2_ConfigPictureDecode -D_WIN32_WINNT=0x0602

+check_type "va/va.h va/va_vpp.h" "VAProcPipelineParameterBuffer"
+
 check_type "vdpau/vdpau.h" "VdpPictureInfoHEVC"

 if ! disabled w32threads && ! enabled pthreads; then
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index fa6647b..0f9643d 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -71,6 +71,7 @@ OBJS-$(CONFIG_OVERLAY_FILTER)+= vf_overlay.o
 OBJS-$(CONFIG_PAD_FILTER)+= vf_pad.o
 OBJS-$(CONFIG_PIXDESCTEST_FILTER)+= vf_pixdesctest.o
 OBJS-$(CONFIG_SCALE_FILTER)  += vf_scale.o
+OBJS-$(CONFIG_SCALE_VAAPI_FILTER)+= vf_scale_vaapi.o
 OBJS-$(CONFIG_SELECT_FILTER) += vf_select.o
 OBJS-$(CONFIG_SETDAR_FILTER) += vf_aspect.o
 OBJS-$(CONFIG_SETPTS_FILTER) += setpts.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 9461145..a2ff4d2 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -108,6 +108,7 @@ void avfilter_register_all(void)
 REGISTER_FILTER(TRANSPOSE,  transpose,  vf);
 REGISTER_FILTER(TRIM,   trim,   vf);
 REGISTER_FILTER(UNSHARP,unsharp,vf);
+REGISTER_FILTER(SCALE_VAAPI,scale_vaapi,vf);
 REGISTER_FILTER(VFLIP,  vflip,  vf);
 REGISTER_FILTER(YADIF,  yadif,  vf);

diff --git a/libavfilter/vf_scale_vaapi.c b/libavfilter/vf_scale_vaapi.c
new file mode 100644
index 000..fcf8348
--- /dev/null
+++ b/libavfilter/vf_scale_vaapi.c
@@ -0,0 +1,451 @@
+/*
+ * 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 
+
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext.h"
+#include "libavutil/hwcontext_vaapi.h"
+#include "libavutil/mem.h"
+#include "libavutil/opt.h"
+#include "libavutil/pixdesc.h"
+
+#include "avfilter.h"
+#include "formats.h"
+#include "internal.h"
+
+typedef struct ScaleVAAPIContext {
+const AVClass *class;
+
+AVVAAPIDeviceContext *hwctx;
+AVBufferRef *device_ref;
+
+VAConfigID  va_config;
+VAContextID va_context;
+
+AVBufferRef   *input_frames_ref;
+AVHWFramesContext *input_frames;
+
+AVBufferRef   *output_frames_ref;
+AVHWFramesContext *output_frames;
+
+char *output_format_string;
+enum AVPixelFormat output_format;
+int output_width;
+int output_height;
+
+} ScaleVAAPIContext;
+
+
+static int scale_vaapi_query_formats(AVFilterContext *avctx)
+{
+enum AVPixelFormat pix_fmts[] = {
+AV_PIX_FMT_VAAPI, AV_PIX_FMT_NONE,
+};
+
+ff_formats_ref(ff_make_format_list(pix_fmts),
+   >inputs[0]->out_formats);
+ff_formats_ref(ff_make_format_list(pix_fmts),
+   >outputs[0]->in_formats);
+
+return 0;
+}
+
+static int scale_vaapi_pipeline_uninit(ScaleVAAPIContext *ctx)
+{
+if (ctx->va_context != VA_INVALID_ID) {
+vaDestroyContext(ctx->hwctx->display, ctx->va_context);
+ctx->va_context = VA_INVALID_ID;
+}
+
+if (ctx->va_config != VA_INVALID_ID) {
+vaDestroyConfig(ctx->hwctx->display, ctx->va_config);
+ctx->va_config = VA_INVALID_ID;
+}
+
+av_buffer_unref(>output_frames_ref);
+av_buffer_unref(>device_ref);
+ctx->hwctx = 0;
+
+return 0;
+}
+
+static int scale_vaapi_config_input(AVFilterLink *inlink)
+{
+AVFilterContext *avctx =