klockwork: Fix libva klocwork scaning issues

Fix NULL pointer dereference risk issues and uninitialized variables

Signed-off-by: Elaine Wang <elaine.wang@intel.com>

Change-Id: I839a9def7b08c41c1f075e4cd1cc06e8bb0c8c9e
Fix va_fool.c klocwork issue

BZ: 83882

Fix klocwork issue that complaine array 'fool_context[idx].fool_buf'
of size 43 may use index value(s) 0..255

Change-Id: I196a36c0067e2b7e390567a203ef1520af5b873f
Signed-off-by: Elaine Wang <elaine.wang@intel.com>
va_trace_surface: dumpe surface content after vaEndPicture call

vaEndPicture will kick HW decode/encode, and at this time use CPU
to dump surface content can keep GPU/CPU in parallel.

Also for encode trace, don't need to wait current frame completions
but for decode, we must wait decode till it is completed

Signed-off-by: Austin Yuan <shengquan.yuan@intel.com>
(cherry picked from commit 0af365de4c03c12fc20183093a944f7513a1c7be)
va_trace: allow surface trace to dump part of surface content

To debug/isolate video record quality issue (blocky/corruption, etc),
we always need to dump the YUV image from camera. LibVA has such
functionality, but due to storage bandwidth issue (~10M Byte/second),
it is hard to write 1080P 30fps YUV data to disk (~88M Byte/second).
Now refine the functionality to only dump part of the image, and
won't need to modify the code in the default build.

The method is:
edit /etc/libva.conf to include bellow (all export them):
	LIBVA_TRACE_SURFACE=/data/enc-XXX.yuv
	LIBVA_TRACE_GEOMETRY=320x240+20+20

It will only save 320x240 from (20,20) of the source surface to file
/data/enc-XXX.yuv.

Signed-off-by: Austin Yuan <shengquan.yuan@intel.com>
(cherry picked from commit 5190a7465756a41808a562c8eccec521dbf77d8c)
vatrace: fix vatrace crash during video recording

Video recording crash when va trace is enabled. It's caused by
using wrong buffer type to trace slice buffer. This patch distinguish buffer
type VAEncSliceParameterBuffer from VAEncSliceParameterBufferH264 by
the buffer size.
Signed-off-by: Elaine Wang <elaine.wang@intel.com>

Change-Id: Ibc5c6a17b155e305151a25580b4e613702665ad1
(cherry picked from commit b5b1933f60dfec8cf2cff19082362accbe6fce1d)
vatrace: Fix encoded coded buffer dump function

libva trace can't dump coded buffer. It's caused by the wrong
decison in vaTraceEndPicture function which only dump coded buffer
when surface dumping is enabled.
Signed-off-by: Elaine Wang <elaine.wang@intel.com>

Change-Id: I8b0ec01e59faff3bfd5345d95cbf0e781f6f3706
(cherry picked from commit 202385430f29b3d3d356d86888a0f3979986b4e7)
va_trace: dump basic_unit_size/rc_flags in RateControl data struct

Signed-off-by: Austin Yuan <shengquan.yuan@intel.com>
(cherry picked from commit 4a78cb4e4a2d0e5c9231c7f532d2a733cf3bfce3)
vatrace: fix build issue

Change-Id: I1727528df6aaf48209774bada5cf136cfa1e4ee3
Signed-off-by: Austin Yuan <shengquan.yuan@intel.com>
(cherry picked from commit 1e0421f5ce01790e700940310aafb05e4c18d8f0)
va_parseConfig: still need to check env_value

env_value may be NULL which means the caller doens't
care the value of the environment variable, just check
if it is set.

Signed-off-by: Austin Yuan <shengquan.yuan@intel.com>
(cherry picked from commit 2e11d2273b2974a7d1959cbcaf8db5b8e9aedd9e)
vatrace: buffer_type_to_string: add missing VABufferType

sync with VABufferType in va/va.h.

Signed-off-by: Adrian Marius Negreanu <adrian.m.negreanu@intel.com>
(cherry picked from commit d5160173f9dd5a37c793518d1d483b09d278d90c)
[Remove unsupported types on master]
Signed-off-by: Xiang, Haihao <haihao.xiang@intel.com>
vatrace: print function name for vaMapBuffer trace with coded buffer

also fall into default va_TraceVABuffers if the buffer type falls into
"default"

Signed-off-by: Austin Yuan <shengquan.yuan@intel.com>
(cherry picked from commit acbf7d0c4830763e7c3be0e71c9da972f1aea7a5)
va_trace: refine the log format

Signed-off-by: Elaine Wang <elaine.wang@intel.com>
(cherry picked from commit 15a0fca64456d8c7de1f7aca2cb747c4929690cd)
LIBVA_DRIVER_NAME still needs va_getDriverName to open DRM device

va_getDriverName is bypassed when LIBVA_DRIVER_NAME is set, but driver
needs DRM device fd which is only opened in va_getDriverName

Change-Id: I4fe11edf9d8c328806255d4c93313cf99655a91d
Signed-off-by: Fei Jiang <fei.jiang@intel.com>
(cherry picked from commit 04706eb13ae410b53b6b38150413d544b7fdb524)
vatrace: dump flags of VAPictureH264

Signed-off-by: Elaine Wang <elaine.wang@intel.com>
(cherry picked from commit e1d86f000749d5fdbd6e36b55260d3fae096e457)
vatrace: only print info of valid reference frames

Signed-off-by: Austin Yuan <shengquan.yuan@intel.com>
(cherry picked from commit 67c489f323188df1370f8ba2d4063bc86153cce7)
libva: Add VABuffer dumping for JPEG parameters

BZ: 98966

Dump VABuffer of JPEG parameters in libva

Change-Id: I87450d92db402a4730e0c0433215c857bc5b494d
Signed-off-by: Cheng Yao <yao.cheng@intel.com>
(cherry picked from commit 40ffef8d1fcbbc709472dc1342d7e3e983ae5d96)
vatrace: print VAEncPackedHeaderParameterBufferType

Signed-off-by: Austin Yuan <shengquan.yuan@intel.com>
(cherry picked from commit 82ffa4b5bfb6cf59e90eedadbdfe3efdaced35e0)
vatrace: refine VAEncPackedHeaderParameterBufferType format

Change-Id: I1794a9c09a88b61d7abce970d7cb9a8f101162c6
Signed-off-by: Austin Yuan <shengquan.yuan@intel.com>
(cherry picked from commit 4853e4a3a6cc5218e032a19d729096862db82bc6)
vatrace: refine the format of buf data dump

Signed-off-by: Elaine Wang <elaine.wang@intel.com>
(cherry picked from commit 2292299fe00036eb6055a84846f63f36cbae27d9)
vatrace: remove the delimiter of every elements dump

Signed-off-by: Austin Yuan <shengquan.yuan@intel.com>
(cherry picked from commit 132f22ae9b42b4657361c87b5c7d5b14a26a52a9)