vaapidecode: don't try flushing the decoder instance if we didn't create one yet

This otherwise results in unnecessary error messages.

https://bugzilla.gnome.org/show_bug.cgi?id=734616
vaapidecode: reset decoder_finish variable after stopping the decoder thread

Otherwise the element is not usable again after draining/EOS.

https://bugzilla.gnome.org/show_bug.cgi?id=734616
vaapidecode: unlock condition variables before shutting down the element

Otherwise threads might wait for them, causing the shutdown of the element
to deadlock on the streaming thread.

https://bugzilla.gnome.org/show_bug.cgi?id=734616
vaapidecode: start the decoder task again after finishing

This allows the element to accept data again after draining without
a hard reset or caps change happening in between.

https://bugzilla.gnome.org/show_bug.cgi?id=734616
plugins: add helper for detecting VA surfaces in caps.

Introduce new gst_caps_has_vaapi_surface() helper function to detect
whether the supplied caps has VA surfaces. With GStreamer >= 1.2, this
implies a check for memory:VASurface caps features, and format=ENCODED
for earlier versions of GStreamer.
plugins: fix detection of raw video caps.

Use the new gst_caps_has_vaapi_surface() helper function to better
detect raw video caps, and in particular those from RGB colorspace.

https://bugzilla.gnome.org/show_bug.cgi?id=734665
vaapipostproc: fix heuristic for detecting discontinuity.

In order to make the discontinuity detection code useful, we need to
detect the lost frames in the history as early as the previous frame.
This is because some VA implementations only support one reference
frame for advanced deinterlacing.

In practice, turn the condition for detecting new frame that is beyond
the previous frame from field_duration*2 to field_duration*3, i.e.
nothing received for the past frame and a half because of possible
rounding errors when calculating the field-duration either in this
element (vaapipostproc), or from the upstream element (parser element).

This is a regression introduced with commit faefd62.

https://bugzilla.gnome.org/show_bug.cgi?id=734135
vaapipostproc: disable discontinuity detection code.

The "discontinuity" tracking code, whereby lost frames are tentatively
detected, is inoperant if the sink pad buffer timestamps are not right
to begin with.

This is a temporary workaround until the following bug is fixed:
https://bugzilla.gnome.org/show_bug.cgi?id=734386
vaapipostproc: improve heuristics for detecting native VA surfaces.

Use the new gst_caps_has_vaapi_surface() helper function to detect
whether the sink pad caps contain native VA surfaces, or not, i.e.
no raw video caps.

Also rename is_raw_yuv to get_va_surfaces to make the variable more
explicit as we just want a way to differentiate raw video caps from
VA surfaces actually.
vaapipostproc: fix construction of allowed sink pad caps.

Fix construction of the set of caps allowed on the sink pad to filter
out unsupported raw video caps with GStreamer >= 1.2.
vaapipostproc: fix detection of output surface format changes.

Default to I420 format for output surfaces so that to match the usual
GStreamer pipelines. Though, internally, we could still opt for NV12
surface formats, i.e. default format=ENCODED is a hint for that, thus
delegating the decision to the VA driver.
surfaceproxy: fix copy to propagate view_id.

Fix gst_vaapi_surface_proxy_copy() to copy the view-id element, thus
fixing random frames skipped when vaapipostproc element is used in
passthrough mode. In that mode, GstMemory is copied, thus including
the underlying GstVaapiVideoMeta and associated GstVaapiSurfaceProxy.
plugins: re-indent all GstVaapiVideo* related source code.
plugins: allow bufferpool to not allocate vaapi video meta.

Add GST_VAAPI_VIDEO_BUFFER_POOL_ACQUIRE_FLAG_NO_ALLOC params flag that
can be used to disable early allocations of vaapi video metas on buffers,
thus delagating that to the bufferpool user.
plugins: factor out decide_allocation() hook.

Add a default decide_allocation() hook to GstVaapiPluginBase. The caps
feature argument can be used to force a bufferpool with a specific kind
of memory.
plugins: fix memory leaks.
vaapivideomemory: avoid NULL pointer unref if GstVaapiImage creation failed.

https://bugzilla.gnome.org/show_bug.cgi?id=735156
vaapipostproc: enable advanced deinterlacing with same format.

If only advanced deinterlacing is requested, i.e. deinterlacing is
the only active algorithm to apply with source and output surface
formats being the same, then make sure to enable VPP processing.

Otherwise, allow fallback to bob-deinterlacing with simple rendering
flags alteration.
vaapipostproc: fix output buffer to have a GstVaapiVideoMemory.

https://bugzilla.gnome.org/show_bug.cgi?id=720311

[used new infrastructure through base decide_allocation() impl]
Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
vaapipostproc: fix passthrough mode.

If no explicit output surface format is supplied try to keep the one
supplied through the sink pad caps. This avoids a useless copy, even
if things are kept in GPU memory.

This is a performance regression from git commit dfa70b9.