mirror of https://github.com/intel/libva-utils.git
libva-utils: initial commit
libva-utils is a new git repository that will host sample applications for libva, conformance tests and others relevant to libva It is using the same version as libva and it should follow libva version. It is intended to be released together with libva It has the same license as libva Initial functionality ports the vainfo application from libva repository. The git history for it will remain on libva. To port vainfo, also the a common libva-display library was ported. The original tests for encoder and decoder are also ported to this repository. debian folder for vainfo was also ported The basic tests are going to be substituted by a new set of tests based on Gtest framework. libva-utils will dynamically link libva, use pkg-config to compile and link properly. Signed-off-by: Daniel Charles <daniel.charles@intel.com>
This commit is contained in:
commit
c9af683d6c
|
@ -0,0 +1,19 @@
|
|||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sub license, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the
|
||||
next paragraph) shall be included in all copies or substantial portions
|
||||
of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
|
||||
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,47 @@
|
|||
# Copyright (c) 2007 Intel Corporation. All Rights Reserved.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a
|
||||
# copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sub license, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice (including the
|
||||
# next paragraph) shall be included in all copies or substantial portions
|
||||
# of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
# IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
|
||||
# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
|
||||
|
||||
AUTOMAKE_OPTIONS = foreign
|
||||
|
||||
SUBDIRS = common decode encode vainfo
|
||||
|
||||
# Extra clean files so that maintainer-clean removes *everything*
|
||||
MAINTAINERCLEANFILES = \
|
||||
aclocal.m4 compile config.guess config.sub \
|
||||
configure depcomp install-sh ltmain.sh \
|
||||
Makefile.in missing
|
||||
|
||||
DEB_BUILDDIR = debian.build
|
||||
|
||||
deb:
|
||||
@[ -d debian ] || ln -s debian.upstream debian
|
||||
dpkg-buildpackage -rfakeroot -uc -us
|
||||
|
||||
deb.upstream: dist
|
||||
-mkdir -p $(DEB_BUILDDIR)
|
||||
cd $(DEB_BUILDDIR) && \
|
||||
rm -rf $(PACKAGE)-$(VERSION) && \
|
||||
tar zxvf ../$(PACKAGE)-$(VERSION).tar.gz && \
|
||||
cd $(PACKAGE)-$(VERSION) && \
|
||||
$(MAKE) deb -f Makefile.am
|
|
@ -0,0 +1,51 @@
|
|||
#!/bin/sh
|
||||
# Copyright (c) 2007 Intel Corporation. All Rights Reserved.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a
|
||||
# copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sub license, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice (including the
|
||||
# next paragraph) shall be included in all copies or substantial portions
|
||||
# of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
# IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
|
||||
# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
PROJECT="libva-utils"
|
||||
|
||||
test -n "$srcdir" || srcdir="`dirname \"$0\"`"
|
||||
test -n "$srcdir" || srcdir=.
|
||||
|
||||
if ! test -f "$srcdir/configure.ac"; then
|
||||
echo "Failed to find the top-level $PROJECT directory"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
olddir="`pwd`"
|
||||
cd "$srcdir"
|
||||
|
||||
mkdir -p m4
|
||||
|
||||
AUTORECONF=`which autoreconf`
|
||||
if test -z $AUTORECONF; then
|
||||
echo "*** No autoreconf found ***"
|
||||
exit 1
|
||||
else
|
||||
autoreconf -v --install || exit $?
|
||||
fi
|
||||
|
||||
cd "$olddir"
|
||||
|
||||
if test -z "$NOCONFIGURE"; then
|
||||
$srcdir/configure "$@" && echo "Now type 'make' to compile $PROJECT."
|
||||
fi
|
|
@ -0,0 +1,60 @@
|
|||
# Copyright (c) 2012 Intel Corporation. All Rights Reserved.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a
|
||||
# copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sub license, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice (including the
|
||||
# next paragraph) shall be included in all copies or substantial portions
|
||||
# of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
# IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
|
||||
# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
noinst_LTLIBRARIES = libva-display.la
|
||||
|
||||
libva_display_cflags = \
|
||||
$(LIBVA_CFLAGS) \
|
||||
$(NULL)
|
||||
|
||||
libva_display_libs = \
|
||||
$(LIBVA_LDFLAGS) \
|
||||
$(NULL)
|
||||
|
||||
source_c = va_display.c
|
||||
source_h = va_display.h
|
||||
|
||||
if USE_X11
|
||||
source_c += va_display_x11.c
|
||||
libva_display_cflags += $(X11_CFLAGS) $(LIBVA_X11_CFLAGS)
|
||||
libva_display_libs += $(X11_LIBS) $(LIBVA_X11_LIBS)
|
||||
endif
|
||||
|
||||
if USE_DRM
|
||||
source_c += va_display_drm.c
|
||||
libva_display_cflags += $(DRM_CFLAGS) $(LIBVA_DRM_CFLAGS)
|
||||
libva_display_libs += $(DRM_LIBS) $(LIBVA_DRM_LIBS)
|
||||
endif
|
||||
|
||||
if USE_WAYLAND
|
||||
source_c += va_display_wayland.c
|
||||
libva_display_cflags += $(WAYLAND_CFLAGS) $(LIBVA_WAYLAND_CFLAGS)
|
||||
libva_display_libs += $(WAYLAND_LIBS) $(LIBVA_WAYLAND_LIBS)
|
||||
endif
|
||||
|
||||
libva_display_la_SOURCES= $(source_c)
|
||||
noinst_HEADERS = $(source_h)
|
||||
libva_display_la_CFLAGS = $(libva_display_cflags)
|
||||
libva_display_la_LIBADD = $(libva_display_libs)
|
||||
|
||||
# Extra clean files so that maintainer-clean removes *everything*
|
||||
MAINTAINERCLEANFILES = Makefile.in
|
|
@ -0,0 +1,489 @@
|
|||
/*
|
||||
* Copyright (c) 2008-2009 Intel Corporation. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sub license, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the
|
||||
* next paragraph) shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
|
||||
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#include "loadsurface_yuv.h"
|
||||
|
||||
static int scale_2dimage(unsigned char *src_img, int src_imgw, int src_imgh,
|
||||
unsigned char *dst_img, int dst_imgw, int dst_imgh)
|
||||
{
|
||||
int row=0, col=0;
|
||||
|
||||
for (row=0; row<dst_imgh; row++) {
|
||||
for (col=0; col<dst_imgw; col++) {
|
||||
*(dst_img + row * dst_imgw + col) = *(src_img + (row * src_imgh/dst_imgh) * src_imgw + col * src_imgw/dst_imgw);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int YUV_blend_with_pic(int width, int height,
|
||||
unsigned char *Y_start, int Y_pitch,
|
||||
unsigned char *U_start, int U_pitch,
|
||||
unsigned char *V_start, int V_pitch,
|
||||
unsigned int fourcc, int fixed_alpha)
|
||||
{
|
||||
/* PIC YUV format */
|
||||
unsigned char *pic_y_old = yuvga_pic;
|
||||
unsigned char *pic_u_old = pic_y_old + 640*480;
|
||||
unsigned char *pic_v_old = pic_u_old + 640*480/4;
|
||||
unsigned char *pic_y, *pic_u, *pic_v;
|
||||
|
||||
int alpha_values[] = {100,90,80,70,60,50,40,30,20,30,40,50,60,70,80,90};
|
||||
|
||||
static int alpha_idx = 0;
|
||||
int alpha;
|
||||
int allocated = 0;
|
||||
|
||||
int row, col;
|
||||
|
||||
if (fixed_alpha == 0) {
|
||||
alpha = alpha_values[alpha_idx % 16 ];
|
||||
alpha_idx ++;
|
||||
} else
|
||||
alpha = fixed_alpha;
|
||||
|
||||
//alpha = 0;
|
||||
|
||||
pic_y = pic_y_old;
|
||||
pic_u = pic_u_old;
|
||||
pic_v = pic_v_old;
|
||||
|
||||
if (width != 640 || height != 480) { /* need to scale the pic */
|
||||
pic_y = (unsigned char *)malloc(width * height);
|
||||
if(pic_y == NULL) {
|
||||
printf("Failed to allocate memory for pic_y\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
pic_u = (unsigned char *)malloc(width * height/4);
|
||||
if(pic_u == NULL) {
|
||||
printf("Failed to allocate memory for pic_u\n");
|
||||
free(pic_y);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pic_v = (unsigned char *)malloc(width * height/4);
|
||||
if(pic_v == NULL) {
|
||||
printf("Failed to allocate memory for pic_v\n");
|
||||
free(pic_y);
|
||||
free(pic_u);
|
||||
return -1;
|
||||
}
|
||||
allocated = 1;
|
||||
|
||||
memset(pic_y, 0, width * height);
|
||||
memset(pic_u, 0, width * height /4);
|
||||
memset(pic_v, 0, width * height /4);
|
||||
|
||||
scale_2dimage(pic_y_old, 640, 480,
|
||||
pic_y, width, height);
|
||||
scale_2dimage(pic_u_old, 320, 240,
|
||||
pic_u, width/2, height/2);
|
||||
scale_2dimage(pic_v_old, 320, 240,
|
||||
pic_v, width/2, height/2);
|
||||
}
|
||||
|
||||
/* begin blend */
|
||||
|
||||
/* Y plane */
|
||||
int Y_pixel_stride = 1;
|
||||
if (fourcc == VA_FOURCC_YUY2)
|
||||
Y_pixel_stride = 2;
|
||||
|
||||
for (row=0; row<height; row++) {
|
||||
unsigned char *p = Y_start + row * Y_pitch;
|
||||
unsigned char *q = pic_y + row * width;
|
||||
for (col=0; col<width; col++, q++) {
|
||||
*p = *p * (100 - alpha) / 100 + *q * alpha/100;
|
||||
p += Y_pixel_stride;
|
||||
}
|
||||
}
|
||||
|
||||
/* U/V plane */
|
||||
int U_pixel_stride = 0, V_pixel_stride = 0;
|
||||
int v_factor_to_nv12 = 1;
|
||||
switch (fourcc) {
|
||||
case VA_FOURCC_YV12:
|
||||
U_pixel_stride = V_pixel_stride = 1;
|
||||
break;
|
||||
case VA_FOURCC_NV12:
|
||||
U_pixel_stride = V_pixel_stride = 2;
|
||||
break;
|
||||
case VA_FOURCC_YUY2:
|
||||
U_pixel_stride = V_pixel_stride = 4;
|
||||
v_factor_to_nv12 = 2;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
for (row=0; row<height/2*v_factor_to_nv12; row++) {
|
||||
unsigned char *pU = U_start + row * U_pitch;
|
||||
unsigned char *pV = V_start + row * V_pitch;
|
||||
unsigned char *qU = pic_u + row/v_factor_to_nv12 * width/2;
|
||||
unsigned char *qV = pic_v + row/v_factor_to_nv12 * width/2;
|
||||
|
||||
for (col=0; col<width/2; col++, qU++, qV++) {
|
||||
*pU = *pU * (100 - alpha) / 100 + *qU * alpha/100;
|
||||
*pV = *pV * (100 - alpha) / 100 + *qV * alpha/100;
|
||||
|
||||
pU += U_pixel_stride;
|
||||
pV += V_pixel_stride;
|
||||
}
|
||||
}
|
||||
|
||||
if (allocated) {
|
||||
free(pic_y);
|
||||
free(pic_u);
|
||||
free(pic_v);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int yuvgen_planar(int width, int height,
|
||||
unsigned char *Y_start, int Y_pitch,
|
||||
unsigned char *U_start, int U_pitch,
|
||||
unsigned char *V_start, int V_pitch,
|
||||
unsigned int fourcc, int box_width, int row_shift,
|
||||
int field)
|
||||
{
|
||||
int row, alpha;
|
||||
unsigned char uv_value = 0x80;
|
||||
|
||||
/* copy Y plane */
|
||||
int y_factor = 1;
|
||||
if (fourcc == VA_FOURCC_YUY2) y_factor = 2;
|
||||
for (row=0;row<height;row++) {
|
||||
unsigned char *Y_row = Y_start + row * Y_pitch;
|
||||
int jj, xpos, ypos;
|
||||
|
||||
ypos = (row / box_width) & 0x1;
|
||||
|
||||
/* fill garbage data into the other field */
|
||||
if (((field == VA_TOP_FIELD) && (row &1))
|
||||
|| ((field == VA_BOTTOM_FIELD) && ((row &1)==0))) {
|
||||
memset(Y_row, 0xff, width);
|
||||
continue;
|
||||
}
|
||||
|
||||
for (jj=0; jj<width; jj++) {
|
||||
xpos = ((row_shift + jj) / box_width) & 0x1;
|
||||
if (xpos == ypos)
|
||||
Y_row[jj*y_factor] = 0xeb;
|
||||
else
|
||||
Y_row[jj*y_factor] = 0x10;
|
||||
|
||||
if (fourcc == VA_FOURCC_YUY2) {
|
||||
Y_row[jj*y_factor+1] = uv_value; // it is for UV
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* copy UV data */
|
||||
for( row =0; row < height/2; row++) {
|
||||
|
||||
/* fill garbage data into the other field */
|
||||
if (((field == VA_TOP_FIELD) && (row &1))
|
||||
|| ((field == VA_BOTTOM_FIELD) && ((row &1)==0))) {
|
||||
uv_value = 0xff;
|
||||
}
|
||||
|
||||
unsigned char *U_row = U_start + row * U_pitch;
|
||||
unsigned char *V_row = V_start + row * V_pitch;
|
||||
switch (fourcc) {
|
||||
case VA_FOURCC_NV12:
|
||||
memset(U_row, uv_value, width);
|
||||
break;
|
||||
case VA_FOURCC_YV12:
|
||||
memset (U_row,uv_value,width/2);
|
||||
memset (V_row,uv_value,width/2);
|
||||
break;
|
||||
case VA_FOURCC_YUY2:
|
||||
// see above. it is set with Y update.
|
||||
break;
|
||||
default:
|
||||
printf("unsupported fourcc in loadsurface.h\n");
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (getenv("AUTO_NOUV"))
|
||||
return 0;
|
||||
|
||||
if (getenv("AUTO_ALPHA"))
|
||||
alpha = 0;
|
||||
else
|
||||
alpha = 70;
|
||||
|
||||
YUV_blend_with_pic(width,height,
|
||||
Y_start, Y_pitch,
|
||||
U_start, U_pitch,
|
||||
V_start, V_pitch,
|
||||
fourcc, alpha);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int upload_surface(VADisplay va_dpy, VASurfaceID surface_id,
|
||||
int box_width, int row_shift,
|
||||
int field)
|
||||
{
|
||||
VAImage surface_image;
|
||||
void *surface_p=NULL, *U_start = NULL,*V_start = NULL;
|
||||
VAStatus va_status;
|
||||
unsigned int pitches[3]={0,0,0};
|
||||
|
||||
va_status = vaDeriveImage(va_dpy,surface_id,&surface_image);
|
||||
CHECK_VASTATUS(va_status,"vaDeriveImage");
|
||||
|
||||
vaMapBuffer(va_dpy,surface_image.buf,&surface_p);
|
||||
assert(VA_STATUS_SUCCESS == va_status);
|
||||
|
||||
pitches[0] = surface_image.pitches[0];
|
||||
switch (surface_image.format.fourcc) {
|
||||
case VA_FOURCC_NV12:
|
||||
U_start = (char *)surface_p + surface_image.offsets[1];
|
||||
V_start = (char *)U_start + 1;
|
||||
pitches[1] = surface_image.pitches[1];
|
||||
pitches[2] = surface_image.pitches[1];
|
||||
break;
|
||||
case VA_FOURCC_IYUV:
|
||||
U_start = (char *)surface_p + surface_image.offsets[1];
|
||||
V_start = (char *)surface_p + surface_image.offsets[2];
|
||||
pitches[1] = surface_image.pitches[1];
|
||||
pitches[2] = surface_image.pitches[2];
|
||||
break;
|
||||
case VA_FOURCC_YV12:
|
||||
U_start = (char *)surface_p + surface_image.offsets[2];
|
||||
V_start = (char *)surface_p + surface_image.offsets[1];
|
||||
pitches[1] = surface_image.pitches[2];
|
||||
pitches[2] = surface_image.pitches[1];
|
||||
break;
|
||||
case VA_FOURCC_YUY2:
|
||||
U_start = (char *)surface_p + 1;
|
||||
V_start = (char *)surface_p + 3;
|
||||
pitches[1] = surface_image.pitches[0];
|
||||
pitches[2] = surface_image.pitches[0];
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
|
||||
/* assume surface is planar format */
|
||||
yuvgen_planar(surface_image.width, surface_image.height,
|
||||
(unsigned char *)surface_p, pitches[0],
|
||||
(unsigned char *)U_start, pitches[1],
|
||||
(unsigned char *)V_start, pitches[2],
|
||||
surface_image.format.fourcc,
|
||||
box_width, row_shift, field);
|
||||
|
||||
vaUnmapBuffer(va_dpy,surface_image.buf);
|
||||
|
||||
vaDestroyImage(va_dpy,surface_image.image_id);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Upload YUV data from memory into a surface
|
||||
* if src_fourcc == NV12, assume the buffer pointed by src_U
|
||||
* is UV interleaved (src_V is ignored)
|
||||
*/
|
||||
static int upload_surface_yuv(VADisplay va_dpy, VASurfaceID surface_id,
|
||||
int src_fourcc, int src_width, int src_height,
|
||||
unsigned char *src_Y, unsigned char *src_U, unsigned char *src_V)
|
||||
{
|
||||
VAImage surface_image;
|
||||
unsigned char *surface_p=NULL, *Y_start=NULL, *U_start=NULL;
|
||||
int Y_pitch=0, U_pitch=0, row;
|
||||
VAStatus va_status;
|
||||
|
||||
va_status = vaDeriveImage(va_dpy,surface_id, &surface_image);
|
||||
CHECK_VASTATUS(va_status,"vaDeriveImage");
|
||||
|
||||
vaMapBuffer(va_dpy,surface_image.buf,(void **)&surface_p);
|
||||
assert(VA_STATUS_SUCCESS == va_status);
|
||||
|
||||
Y_start = surface_p;
|
||||
Y_pitch = surface_image.pitches[0];
|
||||
switch (surface_image.format.fourcc) {
|
||||
case VA_FOURCC_NV12:
|
||||
U_start = (unsigned char *)surface_p + surface_image.offsets[1];
|
||||
U_pitch = surface_image.pitches[1];
|
||||
break;
|
||||
case VA_FOURCC_IYUV:
|
||||
U_start = (unsigned char *)surface_p + surface_image.offsets[1];
|
||||
U_pitch = surface_image.pitches[1];
|
||||
break;
|
||||
case VA_FOURCC_YV12:
|
||||
U_start = (unsigned char *)surface_p + surface_image.offsets[2];
|
||||
U_pitch = surface_image.pitches[2];
|
||||
break;
|
||||
case VA_FOURCC_YUY2:
|
||||
U_start = surface_p + 1;
|
||||
U_pitch = surface_image.pitches[0];
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
|
||||
/* copy Y plane */
|
||||
for (row=0;row<src_height;row++) {
|
||||
unsigned char *Y_row = Y_start + row * Y_pitch;
|
||||
memcpy(Y_row, src_Y + row*src_width, src_width);
|
||||
}
|
||||
|
||||
for (row =0; row < src_height/2; row++) {
|
||||
unsigned char *U_row = U_start + row * U_pitch;
|
||||
unsigned char *u_ptr = NULL, *v_ptr=NULL;
|
||||
int j;
|
||||
switch (surface_image.format.fourcc) {
|
||||
case VA_FOURCC_NV12:
|
||||
if (src_fourcc == VA_FOURCC_NV12) {
|
||||
memcpy(U_row, src_U + row * src_width, src_width);
|
||||
break;
|
||||
} else if (src_fourcc == VA_FOURCC_IYUV) {
|
||||
u_ptr = src_U + row * (src_width/2);
|
||||
v_ptr = src_V + row * (src_width/2);
|
||||
} else if (src_fourcc == VA_FOURCC_YV12) {
|
||||
v_ptr = src_U + row * (src_width/2);
|
||||
u_ptr = src_V + row * (src_width/2);
|
||||
}
|
||||
if ((src_fourcc == VA_FOURCC_IYUV) ||
|
||||
(src_fourcc == VA_FOURCC_YV12)) {
|
||||
for(j = 0; j < src_width/2; j++) {
|
||||
U_row[2*j] = u_ptr[j];
|
||||
U_row[2*j+1] = v_ptr[j];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case VA_FOURCC_IYUV:
|
||||
case VA_FOURCC_YV12:
|
||||
case VA_FOURCC_YUY2:
|
||||
default:
|
||||
printf("unsupported fourcc in load_surface_yuv\n");
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
vaUnmapBuffer(va_dpy,surface_image.buf);
|
||||
|
||||
vaDestroyImage(va_dpy,surface_image.image_id);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Download YUV data from a surface into memory
|
||||
* Some hardward doesn't have a aperture for linear access of
|
||||
* tiled surface, thus use vaGetImage to expect the implemnetion
|
||||
* to do tile to linear convert
|
||||
*
|
||||
* if dst_fourcc == NV12, assume the buffer pointed by dst_U
|
||||
* is UV interleaved (src_V is ignored)
|
||||
*/
|
||||
static int download_surface_yuv(VADisplay va_dpy, VASurfaceID surface_id,
|
||||
int dst_fourcc, int dst_width, int dst_height,
|
||||
unsigned char *dst_Y, unsigned char *dst_U, unsigned char *dst_V)
|
||||
{
|
||||
VAImage surface_image;
|
||||
unsigned char *surface_p=NULL, *Y_start=NULL, *U_start=NULL;
|
||||
int Y_pitch=0, U_pitch=0, row;
|
||||
VAStatus va_status;
|
||||
|
||||
va_status = vaDeriveImage(va_dpy,surface_id, &surface_image);
|
||||
CHECK_VASTATUS(va_status,"vaDeriveImage");
|
||||
|
||||
vaMapBuffer(va_dpy,surface_image.buf,(void **)&surface_p);
|
||||
assert(VA_STATUS_SUCCESS == va_status);
|
||||
|
||||
Y_start = surface_p;
|
||||
Y_pitch = surface_image.pitches[0];
|
||||
switch (surface_image.format.fourcc) {
|
||||
case VA_FOURCC_NV12:
|
||||
U_start = (unsigned char *)surface_p + surface_image.offsets[1];
|
||||
U_pitch = surface_image.pitches[1];
|
||||
break;
|
||||
case VA_FOURCC_IYUV:
|
||||
U_start = (unsigned char *)surface_p + surface_image.offsets[1];
|
||||
U_pitch = surface_image.pitches[1];
|
||||
break;
|
||||
case VA_FOURCC_YV12:
|
||||
U_start = (unsigned char *)surface_p + surface_image.offsets[2];
|
||||
U_pitch = surface_image.pitches[2];
|
||||
break;
|
||||
case VA_FOURCC_YUY2:
|
||||
U_start = surface_p + 1;
|
||||
U_pitch = surface_image.pitches[0];
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
|
||||
/* copy Y plane */
|
||||
for (row=0;row<dst_height;row++) {
|
||||
unsigned char *Y_row = Y_start + row * Y_pitch;
|
||||
memcpy(dst_Y + row*dst_width, Y_row, dst_width);
|
||||
}
|
||||
|
||||
for (row =0; row < dst_height/2; row++) {
|
||||
unsigned char *U_row = U_start + row * U_pitch;
|
||||
unsigned char *u_ptr = NULL, *v_ptr = NULL;
|
||||
int j;
|
||||
switch (surface_image.format.fourcc) {
|
||||
case VA_FOURCC_NV12:
|
||||
if (dst_fourcc == VA_FOURCC_NV12) {
|
||||
memcpy(dst_U + row * dst_width, U_row, dst_width);
|
||||
break;
|
||||
} else if (dst_fourcc == VA_FOURCC_IYUV) {
|
||||
u_ptr = dst_U + row * (dst_width/2);
|
||||
v_ptr = dst_V + row * (dst_width/2);
|
||||
} else if (dst_fourcc == VA_FOURCC_YV12) {
|
||||
v_ptr = dst_U + row * (dst_width/2);
|
||||
u_ptr = dst_V + row * (dst_width/2);
|
||||
}
|
||||
if ((dst_fourcc == VA_FOURCC_IYUV) ||
|
||||
(dst_fourcc == VA_FOURCC_YV12)) {
|
||||
for(j = 0; j < dst_width/2; j++) {
|
||||
u_ptr[j] = U_row[2*j];
|
||||
v_ptr[j] = U_row[2*j+1];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case VA_FOURCC_IYUV:
|
||||
case VA_FOURCC_YV12:
|
||||
case VA_FOURCC_YUY2:
|
||||
default:
|
||||
printf("unsupported fourcc in load_surface_yuv\n");
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
vaUnmapBuffer(va_dpy,surface_image.buf);
|
||||
|
||||
vaDestroyImage(va_dpy,surface_image.image_id);
|
||||
|
||||
return 0;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,168 @@
|
|||
/*
|
||||
* Copyright (c) 2012 Intel Corporation. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sub license, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the
|
||||
* next paragraph) shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
|
||||
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <va/va.h>
|
||||
#include "va_display.h"
|
||||
|
||||
extern const VADisplayHooks va_display_hooks_android;
|
||||
extern const VADisplayHooks va_display_hooks_wayland;
|
||||
extern const VADisplayHooks va_display_hooks_x11;
|
||||
extern const VADisplayHooks va_display_hooks_drm;
|
||||
|
||||
static const VADisplayHooks *g_display_hooks;
|
||||
static const VADisplayHooks *g_display_hooks_available[] = {
|
||||
#ifdef ANDROID
|
||||
&va_display_hooks_android,
|
||||
#else
|
||||
#ifdef HAVE_VA_WAYLAND
|
||||
&va_display_hooks_wayland,
|
||||
#endif
|
||||
#ifdef HAVE_VA_X11
|
||||
&va_display_hooks_x11,
|
||||
#endif
|
||||
#ifdef HAVE_VA_DRM
|
||||
&va_display_hooks_drm,
|
||||
#endif
|
||||
#endif
|
||||
NULL
|
||||
};
|
||||
|
||||
static const char *g_display_name;
|
||||
|
||||
static const char *
|
||||
get_display_name(int argc, char *argv[])
|
||||
{
|
||||
const char *display_name = NULL;
|
||||
int i;
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (strcmp(argv[i], "--display") != 0)
|
||||
continue;
|
||||
argv[i] = NULL;
|
||||
|
||||
if (++i < argc) {
|
||||
display_name = argv[i];
|
||||
argv[i] = NULL;
|
||||
}
|
||||
}
|
||||
return display_name;
|
||||
}
|
||||
|
||||
static void
|
||||
print_display_names(void)
|
||||
{
|
||||
const VADisplayHooks **h;
|
||||
|
||||
printf("Available displays:\n");
|
||||
for (h = g_display_hooks_available; *h != NULL; h++)
|
||||
printf(" %s\n", (*h)->name);
|
||||
}
|
||||
|
||||
static void
|
||||
sanitize_args(int *argc, char *argv[])
|
||||
{
|
||||
char **out_args = argv;
|
||||
int i, n = *argc;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
if (argv[i])
|
||||
*out_args++ = argv[i];
|
||||
}
|
||||
*out_args = NULL;
|
||||
*argc = out_args - argv;
|
||||
}
|
||||
|
||||
void
|
||||
va_init_display_args(int *argc, char *argv[])
|
||||
{
|
||||
const char *display_name;
|
||||
|
||||
display_name = get_display_name(*argc, argv);
|
||||
if (display_name && strcmp(display_name, "help") == 0) {
|
||||
print_display_names();
|
||||
exit(0);
|
||||
}
|
||||
g_display_name = display_name;
|
||||
|
||||
sanitize_args(argc, argv);
|
||||
}
|
||||
|
||||
VADisplay
|
||||
va_open_display(void)
|
||||
{
|
||||
VADisplay va_dpy = NULL;
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; !va_dpy && g_display_hooks_available[i]; i++) {
|
||||
g_display_hooks = g_display_hooks_available[i];
|
||||
if (g_display_name &&
|
||||
strcmp(g_display_name, g_display_hooks->name) != 0)
|
||||
continue;
|
||||
if (!g_display_hooks->open_display)
|
||||
continue;
|
||||
va_dpy = g_display_hooks->open_display();
|
||||
}
|
||||
|
||||
if (!va_dpy) {
|
||||
fprintf(stderr, "error: failed to initialize display");
|
||||
if (g_display_name)
|
||||
fprintf(stderr, " '%s'", g_display_name);
|
||||
fprintf(stderr, "\n");
|
||||
abort();
|
||||
}
|
||||
return va_dpy;
|
||||
}
|
||||
|
||||
void
|
||||
va_close_display(VADisplay va_dpy)
|
||||
{
|
||||
if (!va_dpy)
|
||||
return;
|
||||
|
||||
if (g_display_hooks && g_display_hooks->close_display)
|
||||
g_display_hooks->close_display(va_dpy);
|
||||
}
|
||||
|
||||
VAStatus
|
||||
va_put_surface(
|
||||
VADisplay va_dpy,
|
||||
VASurfaceID surface,
|
||||
const VARectangle *src_rect,
|
||||
const VARectangle *dst_rect
|
||||
)
|
||||
{
|
||||
if (!va_dpy)
|
||||
return VA_STATUS_ERROR_INVALID_DISPLAY;
|
||||
|
||||
if (g_display_hooks && g_display_hooks->put_surface)
|
||||
return g_display_hooks->put_surface(va_dpy, surface, src_rect, dst_rect);
|
||||
return VA_STATUS_ERROR_UNIMPLEMENTED;
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright (c) 2012 Intel Corporation. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sub license, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the
|
||||
* next paragraph) shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
|
||||
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef VA_DISPLAY_H
|
||||
#define VA_DISPLAY_H
|
||||
|
||||
#include <va/va.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
VADisplay (*open_display) (void);
|
||||
void (*close_display) (VADisplay va_dpy);
|
||||
VAStatus (*put_surface) (VADisplay va_dpy, VASurfaceID surface,
|
||||
const VARectangle *src_rect,
|
||||
const VARectangle *dst_rect);
|
||||
} VADisplayHooks;
|
||||
|
||||
void
|
||||
va_init_display_args(int *argc, char *argv[]);
|
||||
|
||||
VADisplay
|
||||
va_open_display(void);
|
||||
|
||||
void
|
||||
va_close_display(VADisplay va_dpy);
|
||||
|
||||
VAStatus
|
||||
va_put_surface(
|
||||
VADisplay va_dpy,
|
||||
VASurfaceID surface,
|
||||
const VARectangle *src_rect,
|
||||
const VARectangle *dst_rect
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* VA_DISPLAY_H */
|
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
* Copyright (c) 2012 Intel Corporation. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sub license, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the
|
||||
* next paragraph) shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
|
||||
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <va/va_android.h>
|
||||
#include "va_display.h"
|
||||
|
||||
#include <gui/Surface.h>
|
||||
#include <gui/SurfaceComposerClient.h>
|
||||
#include <gui/ISurfaceComposer.h>
|
||||
|
||||
static unsigned int fake_display = 0xdeada01d;
|
||||
|
||||
using namespace android;
|
||||
|
||||
static sp<SurfaceComposerClient> client = NULL;
|
||||
static sp<SurfaceControl> surface_ctr = NULL;
|
||||
static sp<ANativeWindow> anw = NULL;
|
||||
|
||||
static VADisplay
|
||||
va_open_display_android(void)
|
||||
{
|
||||
return vaGetDisplay(&fake_display);
|
||||
}
|
||||
|
||||
static void
|
||||
va_close_display_android(VADisplay va_dpy)
|
||||
{
|
||||
}
|
||||
|
||||
static int create_window(int x, int y, int width, int height)
|
||||
{
|
||||
client = new SurfaceComposerClient();
|
||||
|
||||
surface_ctr = client->createSurface(
|
||||
String8("Test Surface"),
|
||||
width, height,
|
||||
PIXEL_FORMAT_RGB_888, 0);
|
||||
|
||||
SurfaceComposerClient::openGlobalTransaction();
|
||||
surface_ctr->setLayer(0x7FFFFFFF);
|
||||
surface_ctr->show();
|
||||
SurfaceComposerClient::closeGlobalTransaction();
|
||||
|
||||
SurfaceComposerClient::openGlobalTransaction();
|
||||
surface_ctr->setPosition(x, y);
|
||||
SurfaceComposerClient::closeGlobalTransaction();
|
||||
|
||||
SurfaceComposerClient::openGlobalTransaction();
|
||||
surface_ctr->setSize(width, height);
|
||||
SurfaceComposerClient::closeGlobalTransaction();
|
||||
|
||||
anw = surface_ctr->getSurface();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static VAStatus
|
||||
va_put_surface_android(
|
||||
VADisplay va_dpy,
|
||||
VASurfaceID surface,
|
||||
const VARectangle *src_rect,
|
||||
const VARectangle *dst_rect
|
||||
)
|
||||
{
|
||||
if (anw == NULL)
|
||||
create_window(dst_rect->x, dst_rect->y, dst_rect->width, dst_rect->height);
|
||||
|
||||
return vaPutSurface(va_dpy, surface, anw,
|
||||
src_rect->x, src_rect->y,
|
||||
src_rect->width, src_rect->height,
|
||||
dst_rect->x, dst_rect->y,
|
||||
dst_rect->width, dst_rect->height,
|
||||
NULL, 0,
|
||||
VA_FRAME_PICTURE);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
const VADisplayHooks va_display_hooks_android = {
|
||||
"android",
|
||||
va_open_display_android,
|
||||
va_close_display_android,
|
||||
va_put_surface_android
|
||||
};
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* Copyright (c) 2012 Intel Corporation. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sub license, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the
|
||||
* next paragraph) shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
|
||||
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#ifdef IN_LIBVA
|
||||
# include "va/drm/va_drm.h"
|
||||
#else
|
||||
# include <va/va_drm.h>
|
||||
#endif
|
||||
#include "va_display.h"
|
||||
|
||||
static int drm_fd = -1;
|
||||
|
||||
static VADisplay
|
||||
va_open_display_drm(void)
|
||||
{
|
||||
VADisplay va_dpy;
|
||||
int i;
|
||||
|
||||
static const char *drm_device_paths[] = {
|
||||
"/dev/dri/renderD128",
|
||||
"/dev/dri/card0",
|
||||
NULL
|
||||
};
|
||||
|
||||
for (i = 0; drm_device_paths[i]; i++) {
|
||||
drm_fd = open(drm_device_paths[i], O_RDWR);
|
||||
if (drm_fd < 0)
|
||||
continue;
|
||||
|
||||
va_dpy = vaGetDisplayDRM(drm_fd);
|
||||
if (va_dpy)
|
||||
return va_dpy;
|
||||
|
||||
close(drm_fd);
|
||||
drm_fd = -1;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
va_close_display_drm(VADisplay va_dpy)
|
||||
{
|
||||
if (drm_fd < 0)
|
||||
return;
|
||||
|
||||
close(drm_fd);
|
||||
drm_fd = -1;
|
||||
}
|
||||
|
||||
|
||||
static VAStatus
|
||||
va_put_surface_drm(
|
||||
VADisplay va_dpy,
|
||||
VASurfaceID surface,
|
||||
const VARectangle *src_rect,
|
||||
const VARectangle *dst_rect
|
||||
)
|
||||
{
|
||||
return VA_STATUS_ERROR_OPERATION_FAILED;
|
||||
}
|
||||
|
||||
const VADisplayHooks va_display_hooks_drm = {
|
||||
"drm",
|
||||
va_open_display_drm,
|
||||
va_close_display_drm,
|
||||
va_put_surface_drm,
|
||||
};
|
|
@ -0,0 +1,193 @@
|
|||
/*
|
||||
* Copyright (c) 2012 Intel Corporation. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sub license, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the
|
||||
* next paragraph) shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
|
||||
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef IN_LIBVA
|
||||
# include "va/wayland/va_wayland.h"
|
||||
#else
|
||||
# include <va/va_wayland.h>
|
||||
#endif
|
||||
#include "va_display.h"
|
||||
|
||||
struct display {
|
||||
struct wl_display *display;
|
||||
struct wl_registry *registry;
|
||||
struct wl_compositor *compositor;
|
||||
struct wl_shell *shell;
|
||||
struct wl_shell_surface *shell_surface;
|
||||
struct wl_surface *surface;
|
||||
unsigned int ref_count;
|
||||
int event_fd;
|
||||
};
|
||||
|
||||
static struct display *g_display;
|
||||
|
||||
static void
|
||||
registry_handle_global(
|
||||
void *data,
|
||||
struct wl_registry *registry,
|
||||
uint32_t id,
|
||||
const char *interface,
|
||||
uint32_t version
|
||||
)
|
||||
{
|
||||
struct display * const d = data;
|
||||
|
||||
if (strcmp(interface, "wl_compositor") == 0)
|
||||
d->compositor =
|
||||
wl_registry_bind(registry, id, &wl_compositor_interface, 1);
|
||||
else if (strcmp(interface, "wl_shell") == 0)
|
||||
d->shell = wl_registry_bind(registry, id, &wl_shell_interface, 1);
|
||||
}
|
||||
|
||||
static const struct wl_registry_listener registry_listener = {
|
||||
registry_handle_global,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static VADisplay
|
||||
va_open_display_wayland(void)
|
||||
{
|
||||
struct display *d;
|
||||
|
||||
if (g_display) {
|
||||
d = g_display;
|
||||
d->ref_count++;
|
||||
}
|
||||
else {
|
||||
d = calloc(1, sizeof(*d));
|
||||
if (!d)
|
||||
return NULL;
|
||||
d->event_fd = -1;
|
||||
|
||||
d->display = wl_display_connect(NULL);
|
||||
if (!d->display) {
|
||||
free(d);
|
||||
return NULL;
|
||||
}
|
||||
wl_display_set_user_data(d->display, d);
|
||||
d->registry = wl_display_get_registry(d->display);
|
||||
wl_registry_add_listener(d->registry, ®istry_listener, d);
|
||||
d->event_fd = wl_display_get_fd(d->display);
|
||||
wl_display_dispatch(d->display);
|
||||
|
||||
d->ref_count = 1;
|
||||
g_display = d;
|
||||
}
|
||||
return vaGetDisplayWl(d->display);
|
||||
}
|
||||
|
||||
static void
|
||||
va_close_display_wayland(VADisplay va_dpy)
|
||||
{
|
||||
struct display * const d = g_display;
|
||||
|
||||
if (!d || --d->ref_count > 0)
|
||||
return;
|
||||
|
||||
if (d->surface) {
|
||||
wl_surface_destroy(d->surface);
|
||||
d->surface = NULL;
|
||||
}
|
||||
|
||||
if (d->shell_surface) {
|
||||
wl_shell_surface_destroy(d->shell_surface);
|
||||
d->shell_surface = NULL;
|
||||
}
|
||||
|
||||
if (d->shell) {
|
||||
wl_shell_destroy(d->shell);
|
||||
d->shell = NULL;
|
||||
}
|
||||
|
||||
if (d->compositor) {
|
||||
wl_compositor_destroy(d->compositor);
|
||||
d->compositor = NULL;
|
||||
}
|
||||
|
||||
if (d->display) {
|
||||
wl_display_disconnect(d->display);
|
||||
d->display = NULL;
|
||||
}
|
||||
free(g_display);
|
||||
g_display = NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
ensure_window(VADisplay va_dpy, unsigned int width, unsigned int height)
|
||||
{
|
||||
struct display * const d = g_display;
|
||||
|
||||
if (!d->surface) {
|
||||
d->surface = wl_compositor_create_surface(d->compositor);
|
||||
if (!d->surface)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!d->shell_surface) {
|
||||
d->shell_surface = wl_shell_get_shell_surface(d->shell, d->surface);
|
||||
if (!d->shell_surface)
|
||||
return 0;
|
||||
wl_shell_surface_set_toplevel(d->shell_surface);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static VAStatus
|
||||
va_put_surface_wayland(
|
||||
VADisplay va_dpy,
|
||||
VASurfaceID surface,
|
||||
const VARectangle *src_rect,
|
||||
const VARectangle *dst_rect
|
||||
)
|
||||
{
|
||||
struct display * const d = g_display;
|
||||
VAStatus va_status;
|
||||
struct wl_buffer *buffer;
|
||||
|
||||
if (!ensure_window(va_dpy, dst_rect->width, dst_rect->height))
|
||||
return VA_STATUS_ERROR_ALLOCATION_FAILED;
|
||||
|
||||
va_status = vaGetSurfaceBufferWl(va_dpy, surface, VA_FRAME_PICTURE, &buffer);
|
||||
if (va_status != VA_STATUS_SUCCESS)
|
||||
return va_status;
|
||||
|
||||
wl_surface_attach(d->surface, buffer, 0, 0);
|
||||
wl_surface_damage(
|
||||
d->surface,
|
||||
dst_rect->x, dst_rect->y, dst_rect->width, dst_rect->height
|
||||
);
|
||||
|
||||
wl_surface_commit(d->surface);
|
||||
wl_display_flush(d->display);
|
||||
return VA_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
const VADisplayHooks va_display_hooks_wayland = {
|
||||
"wayland",
|
||||
va_open_display_wayland,
|
||||
va_close_display_wayland,
|
||||
va_put_surface_wayland,
|
||||
};
|
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* Copyright (c) 2012 Intel Corporation. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sub license, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the
|
||||
* next paragraph) shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
|
||||
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <va/va_x11.h>
|
||||
#include "va_display.h"
|
||||
|
||||
static Display *x11_display;
|
||||
static Window x11_window;
|
||||
|
||||
static VADisplay
|
||||
va_open_display_x11(void)
|
||||
{
|
||||
x11_display = XOpenDisplay(NULL);
|
||||
if (!x11_display) {
|
||||
fprintf(stderr, "error: can't connect to X server!\n");
|
||||
return NULL;
|
||||
}
|
||||
return vaGetDisplay(x11_display);
|
||||
}
|
||||
|
||||
static void
|
||||
va_close_display_x11(VADisplay va_dpy)
|
||||
{
|
||||
if (!x11_display)
|
||||
return;
|
||||
|
||||
if (x11_window) {
|
||||
XUnmapWindow(x11_display, x11_window);
|
||||
XDestroyWindow(x11_display, x11_window);
|
||||
x11_window = None;
|
||||
}
|
||||
XCloseDisplay(x11_display);
|
||||
x11_display = NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
ensure_window(unsigned int width, unsigned int height)
|
||||
{
|
||||
Window win, rootwin;
|
||||
unsigned int black_pixel, white_pixel;
|
||||
int screen;
|
||||
|
||||
if (!x11_display)
|
||||
return 0;
|
||||
|
||||
if (x11_window) {
|
||||
XResizeWindow(x11_display, x11_window, width, height);
|
||||
return 1;
|
||||
}
|
||||
|
||||
screen = DefaultScreen(x11_display);
|
||||
rootwin = RootWindow(x11_display, screen);
|
||||
black_pixel = BlackPixel(x11_display, screen);
|
||||
white_pixel = WhitePixel(x11_display, screen);
|
||||
|
||||
win = XCreateSimpleWindow(
|
||||
x11_display,
|
||||
rootwin,
|
||||
0, 0, width, height,
|
||||
1, black_pixel, white_pixel
|
||||
);
|
||||
if (!win)
|
||||
return 0;
|
||||
x11_window = win;
|
||||
|
||||
XMapWindow(x11_display, x11_window);
|
||||
XSync(x11_display, False);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
validate_rect(const VARectangle *rect)
|
||||
{
|
||||
return (rect &&
|
||||
rect->x >= 0 &&
|
||||
rect->y >= 0 &&
|
||||
rect->width > 0 &&
|
||||
rect->height > 0);
|
||||
}
|
||||
|
||||
static VAStatus
|
||||
va_put_surface_x11(
|
||||
VADisplay va_dpy,
|
||||
VASurfaceID surface,
|
||||
const VARectangle *src_rect,
|
||||
const VARectangle *dst_rect
|
||||
)
|
||||
{
|
||||
unsigned int win_width, win_height;
|
||||
|
||||
if (!va_dpy)
|
||||
return VA_STATUS_ERROR_INVALID_DISPLAY;
|
||||
if (surface == VA_INVALID_SURFACE)
|
||||
return VA_STATUS_ERROR_INVALID_SURFACE;
|
||||
if (!validate_rect(src_rect) || !validate_rect(dst_rect))
|
||||
return VA_STATUS_ERROR_INVALID_PARAMETER;
|
||||
|
||||
win_width = dst_rect->x + dst_rect->width;
|
||||
win_height = dst_rect->y + dst_rect->height;
|
||||
if (!ensure_window(win_width, win_height))
|
||||
return VA_STATUS_ERROR_ALLOCATION_FAILED;
|
||||
return vaPutSurface(va_dpy, surface, x11_window,
|
||||
src_rect->x, src_rect->y,
|
||||
src_rect->width, src_rect->height,
|
||||
dst_rect->x, dst_rect->y,
|
||||
dst_rect->width, dst_rect->height,
|
||||
NULL, 0,
|
||||
VA_FRAME_PICTURE);
|
||||
}
|
||||
|
||||
const VADisplayHooks va_display_hooks_x11 = {
|
||||
"x11",
|
||||
va_open_display_x11,
|
||||
va_close_display_x11,
|
||||
va_put_surface_x11,
|
||||
};
|
|
@ -0,0 +1,277 @@
|
|||
# Copyright (c) 2007 Intel Corporation. All Rights Reserved.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a
|
||||
# copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sub license, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice (including the
|
||||
# next paragraph) shall be included in all copies or substantial portions
|
||||
# of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
# IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
|
||||
# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
# libva-utils package version number
|
||||
# package version number follows libva package version number to
|
||||
# comply with the same version used for released
|
||||
#
|
||||
# - major version is libva_major_version
|
||||
# - minor version is libva_minor_version
|
||||
# - micro version is libva_micro_version
|
||||
# - pre version is libva_pre_version, usually development version
|
||||
m4_define([libva_utils_major_version], [1])
|
||||
m4_define([libva_utils_minor_version], [7])
|
||||
m4_define([libva_utils_micro_version], [3])
|
||||
m4_define([libva_utils_pre_version], [1])
|
||||
|
||||
m4_define([libva_utils_version],
|
||||
[libva_utils_major_version.libva_utils_minor_version.libva_utils_micro_version])
|
||||
m4_if(libva_utils_pre_version, [0], [], [
|
||||
m4_append([libva_utils_version], libva_utils_pre_version, [.pre])
|
||||
])
|
||||
|
||||
# libva minimum version requirement, at this released version
|
||||
# libva-utils was created
|
||||
m4_define([libva_api_min_version], [0.39.4])
|
||||
|
||||
# libdrm minimun version requirement
|
||||
m4_define([libdrm_version], [2.4])
|
||||
|
||||
# Wayland minimum version number
|
||||
m4_define([wayland_api_version], [1.0.0])
|
||||
|
||||
AC_PREREQ(2.57)
|
||||
AC_INIT([libva_utils],
|
||||
[libva_utils_version],
|
||||
[https://github.com/01org/libva-utils/issues/new],
|
||||
[libyamiutils],
|
||||
[https://github.com/01org/libva-utils])
|
||||
AC_CONFIG_SRCDIR([Makefile.am])
|
||||
AC_CONFIG_MACRO_DIR([m4])
|
||||
AM_INIT_AUTOMAKE([dist-bzip2])
|
||||
|
||||
AC_CONFIG_HEADERS([config.h])
|
||||
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
|
||||
|
||||
TODAY="`LC_ALL=C date +'%a, %d %b %Y %X %z'`"
|
||||
AC_SUBST(TODAY)
|
||||
|
||||
LIBVA_UTILS_MAJOR_VERSION=libva_utils_major_version
|
||||
LIBVA_UTILS_MINOR_VERSION=libva_utils_minor_version
|
||||
LIBVA_UTILS_MICRO_VERSION=libva_utils_micro_version
|
||||
LIBVA_UTILS_VERSION=libva_utils_version
|
||||
AC_SUBST(LIBVA_UTILS_MAJOR_VERSION)
|
||||
AC_SUBST(LIBVA_UTILS_MINOR_VERSION)
|
||||
AC_SUBST(LIBVA_UTILS_MICRO_VERSION)
|
||||
AC_SUBST(LIBVA_UTILS_VERSION)
|
||||
|
||||
AC_ARG_ENABLE(drm,
|
||||
[AC_HELP_STRING([--enable-drm],
|
||||
[build with VA/DRM API support @<:@default=yes@:>@])],
|
||||
[], [enable_drm="yes"])
|
||||
|
||||
AC_ARG_ENABLE(x11,
|
||||
[AC_HELP_STRING([--enable-x11],
|
||||
[build with VA/X11 API support @<:@default=yes@:>@])],
|
||||
[], [enable_x11="yes"])
|
||||
|
||||
AC_ARG_ENABLE(glx,
|
||||
[AC_HELP_STRING([--enable-glx],
|
||||
[build with VA/GLX API support @<:@default=yes@:>@])],
|
||||
[], [enable_glx="yes"])
|
||||
|
||||
AC_ARG_ENABLE(egl,
|
||||
[AC_HELP_STRING([--enable-egl],
|
||||
[build with VA/EGL API support @<:@default=yes@:>@])],
|
||||
[], [enable_egl="yes"])
|
||||
|
||||
AC_ARG_ENABLE([wayland],
|
||||
[AC_HELP_STRING([--enable-wayland],
|
||||
[build with VA/Wayland API support @<:@default=yes@:>@])],
|
||||
[], [enable_wayland="yes"])
|
||||
|
||||
AC_ARG_ENABLE([gtests],
|
||||
[AC_HELP_STRING([--enable-gtests],
|
||||
[build gtests @<:@default=no@:>@])],
|
||||
[], [enable_gtests="no"])
|
||||
|
||||
AC_ARG_WITH(drivers-path,
|
||||
[AC_HELP_STRING([--with-drivers-path=[[path]]],
|
||||
[drivers path])],
|
||||
[], [with_drivers_path="$libdir/dri"])
|
||||
|
||||
LIBVA_DRIVERS_PATH="$with_drivers_path"
|
||||
AC_SUBST(LIBVA_DRIVERS_PATH)
|
||||
|
||||
AC_DISABLE_STATIC
|
||||
AC_PROG_LIBTOOL
|
||||
AC_PROG_CC
|
||||
AC_PROG_CXX
|
||||
AM_PROG_CC_C_O
|
||||
PKG_PROG_PKG_CONFIG
|
||||
|
||||
AC_HEADER_STDC
|
||||
AC_SYS_LARGEFILE
|
||||
|
||||
# Check for __attribute__((visibility()))
|
||||
AC_CACHE_CHECK([whether __attribute__((visibility())) is supported],
|
||||
ac_cv_have_gnuc_visibility_attribute,
|
||||
[cat > conftest.c <<EOF
|
||||
int foo __attribute__ ((visibility ("hidden"))) = 1;
|
||||
int bar __attribute__ ((visibility ("protected"))) = 1;
|
||||
EOF
|
||||
ac_cv_have_gnuc_visibility_attribute="no"
|
||||
if ${CC-cc} -Werror -S conftest.c -o conftest.s >/dev/null 2>&1; then
|
||||
if grep '\.hidden.*foo' conftest.s >/dev/null; then
|
||||
if grep '\.protected.*bar' conftest.s >/dev/null; then
|
||||
ac_cv_have_gnuc_visibility_attribute="yes"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
rm -f conftest.[cs]
|
||||
])
|
||||
if test "$ac_cv_have_gnuc_visibility_attribute" = "yes"; then
|
||||
AC_DEFINE([HAVE_GNUC_VISIBILITY_ATTRIBUTE], [1],
|
||||
[Defined to 1 if GCC visibility attribute is supported])
|
||||
fi
|
||||
|
||||
# Check for DRM (mandatory)
|
||||
LIBDRM_VERSION=libdrm_version
|
||||
PKG_CHECK_MODULES([DRM], [libdrm >= $LIBDRM_VERSION])
|
||||
PKG_CHECK_MODULES([LIBVA_DRM], [libva-drm])
|
||||
AC_SUBST(LIBDRM_VERSION)
|
||||
|
||||
# Check for libva (for dynamic linking)
|
||||
LIBVA_API_MIN_VERSION=libva_api_min_version
|
||||
PKG_CHECK_MODULES([LIBVA], [libva >= $LIBVA_API_MIN_VERSION])
|
||||
AC_SUBST(LIBVA_VERSION)
|
||||
LIBVA_API_VERSION=`$PKG_CONFIG --modversion libva`
|
||||
|
||||
USE_DRM="no"
|
||||
if test "$enable_drm" = "yes"; then
|
||||
USE_DRM="yes"
|
||||
AC_DEFINE([HAVE_VA_DRM], [1], [Defined to 1 if VA/DRM API is supported])
|
||||
fi
|
||||
AM_CONDITIONAL(USE_DRM, test "$USE_DRM" = "yes")
|
||||
|
||||
# Check for X11
|
||||
USE_X11="no"
|
||||
if test "$enable_x11" = "yes"; then
|
||||
USE_X11="yes"
|
||||
PKG_CHECK_MODULES([X11], [x11], [:], [USE_X11="no"])
|
||||
PKG_CHECK_MODULES([XEXT], [xext], [:], [USE_X11="no"])
|
||||
PKG_CHECK_MODULES([XFIXES], [xfixes], [:], [USE_X11="no"])
|
||||
if test "$USE_X11" = "yes"; then
|
||||
PKG_CHECK_MODULES([LIBVA_X11], [libva-x11], [:], [USE_X11="no"])
|
||||
AC_DEFINE([HAVE_VA_X11], [1], [Defined to 1 if VA/X11 API is supported])
|
||||
fi
|
||||
fi
|
||||
AM_CONDITIONAL(USE_X11, test "$USE_X11" = "yes")
|
||||
|
||||
# Check for GLX
|
||||
USE_GLX="no"
|
||||
if test "$USE_X11:$enable_glx" = "yes:yes"; then
|
||||
PKG_CHECK_MODULES([GLX], [gl x11], [USE_GLX="yes"], [:])
|
||||
saved_CPPFLAGS="$CPPFLAGS"
|
||||
saved_LIBS="$LIBS"
|
||||
CPPFLAGS="$CPPFLAGS $GLX_CFLAGS"
|
||||
LIBS="$LIBS $GLX_LIBS"
|
||||
AC_CHECK_HEADERS([GL/gl.h GL/glx.h], [:], [USE_GLX="no"])
|
||||
AC_CHECK_LIB([GL], [glXCreateContext], [:] [USE_GLX="no"])
|
||||
CPPFLAGS="$saved_CPPFLAGS"
|
||||
LIBS="$saved_LIBS"
|
||||
if test "$USE_GLX" = "yes"; then
|
||||
AC_DEFINE([HAVE_VA_GLX], [1], [Defined to 1 if VA/GLX API is built])
|
||||
fi
|
||||
fi
|
||||
AM_CONDITIONAL(USE_GLX, test "$USE_GLX" = "yes")
|
||||
|
||||
# Check for EGL
|
||||
USE_EGL="no"
|
||||
if test "$enable_egl" = "yes"; then
|
||||
PKG_CHECK_MODULES([EGL], [egl], [USE_EGL="yes"], [:])
|
||||
saved_CPPFLAGS="$CPPFLAGS"
|
||||
saved_LIBS="$LIBS"
|
||||
CPPFLAGS="$CPPFLAGS $EGL_CFLAGS"
|
||||
LIBS="$LIBS $EGL_LIBS"
|
||||
AC_CHECK_HEADERS([EGL/egl.h], [:], [USE_EGL="no"])
|
||||
AC_CHECK_LIB([EGL], [eglGetDisplay], [:], [USE_EGL="no"])
|
||||
CPPFLAGS="$saved_CPPFLAGS"
|
||||
LIBS="$saved_LIBS"
|
||||
if test "$USE_EGL" = "yes"; then
|
||||
AC_DEFINE([HAVE_VA_EGL], [1], [Defined to 1 if VA/EGL API is built])
|
||||
fi
|
||||
fi
|
||||
AM_CONDITIONAL(USE_EGL, test "$USE_EGL" = "yes")
|
||||
|
||||
dnl Check for Wayland
|
||||
WAYLAND_API_VERSION=wayland_api_version
|
||||
AC_SUBST(WAYLAND_API_VERSION)
|
||||
|
||||
USE_WAYLAND="no"
|
||||
if test "$enable_wayland" = "yes"; then
|
||||
PKG_CHECK_MODULES([WAYLAND], [wayland-client >= wayland_api_version],
|
||||
[USE_WAYLAND="yes"], [:])
|
||||
if test "$USE_WAYLAND" = "yes"; then
|
||||
|
||||
WAYLAND_PREFIX=`$PKG_CONFIG --variable=prefix wayland-client`
|
||||
AC_PATH_PROG([WAYLAND_SCANNER], [wayland-scanner],,
|
||||
[${WAYLAND_PREFIX}/bin$PATH_SEPARATOR$PATH])
|
||||
|
||||
AC_DEFINE([HAVE_VA_WAYLAND], [1],
|
||||
[Defined to 1 if VA/Wayland API is supported])
|
||||
PKG_CHECK_MODULES([LIBVA_WAYLAND], [libva-wayland], [:], [USE_WAYLAND="no"])
|
||||
fi
|
||||
fi
|
||||
|
||||
AM_CONDITIONAL(USE_WAYLAND, test "$USE_WAYLAND" = "yes")
|
||||
|
||||
pkgconfigdir=${libdir}/pkgconfig
|
||||
AC_SUBST(pkgconfigdir)
|
||||
|
||||
dnl Check for builds without backend
|
||||
if test "$USE_DRM:$USE_X11:$USE_WAYLAND" = "no:no:no"; then
|
||||
AC_MSG_ERROR([Please select at least one backend (DRM, X11, Wayland)])
|
||||
fi
|
||||
|
||||
AM_CONDITIONAL(ENABLE_GTESTS, test "$enable_gtests" = "yes")
|
||||
|
||||
AC_OUTPUT([
|
||||
Makefile
|
||||
common/Makefile
|
||||
test/Makefile
|
||||
vainfo/Makefile
|
||||
encode/Makefile
|
||||
decode/Makefile
|
||||
debian.upstream/Makefile
|
||||
debian.upstream/changelog
|
||||
debian.upstream/control
|
||||
])
|
||||
|
||||
|
||||
# Print a small summary
|
||||
BACKENDS=""
|
||||
AS_IF([test x$USE_DRM = xyes], [BACKENDS="$BACKENDS drm"])
|
||||
AS_IF([test x$USE_X11 = xyes], [BACKENDS="$BACKENDS x11"])
|
||||
AS_IF([test x$USE_GLX = xyes], [BACKENDS="$BACKENDS glx"])
|
||||
AS_IF([test x$USE_EGL = xyes], [BACKENDS="$BACKENDS egl"])
|
||||
AS_IF([test x$USE_WAYLAND = xyes], [BACKENDS="$BACKENDS wayland"])
|
||||
|
||||
echo
|
||||
echo "libva-utils - ${LIBVA_UTILS_VERSION}"
|
||||
echo
|
||||
echo Libva VA-API version ............. : $LIBVA_API_VERSION
|
||||
echo Installation prefix .............. : $prefix
|
||||
echo Default driver path .............. : $LIBVA_DRIVERS_PATH
|
||||
echo Extra window systems ............. : $BACKENDS
|
||||
echo Enable Gtests .................... : $enable_gtests
|
||||
echo
|
|
@ -0,0 +1,23 @@
|
|||
DEBIANFILES = \
|
||||
README.Debian \
|
||||
changelog.in \
|
||||
compat \
|
||||
control.in \
|
||||
copyright \
|
||||
rules \
|
||||
vainfo.install \
|
||||
$(NULL)
|
||||
|
||||
DEBIANGENFILES = \
|
||||
changelog \
|
||||
control \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DIST = $(DEBIANFILES)
|
||||
|
||||
DISTCLEANFILES = $(DEBIANGENFILES)
|
||||
|
||||
dist_noinst_DATA = $(DEBIANGENFILES)
|
||||
|
||||
# Extra clean files so that maintainer-clean removes *everything*
|
||||
MAINTAINERCLEANFILES = Makefile.in
|
|
@ -0,0 +1,7 @@
|
|||
libva for Debian
|
||||
----------------
|
||||
|
||||
This library implements tests for the Video Acceleration (VA) API for Linux.
|
||||
It will load a hardware dependendent video acceleration driver.
|
||||
|
||||
-- Waldo Bastian <waldo.bastian@intel.com> Mon, 18 Jun 2007 21:35:31 -0700
|
|
@ -0,0 +1,5 @@
|
|||
libva-utils (@PACKAGE_VERSION@-1) unstable; urgency=low
|
||||
|
||||
* Autogenerated package, see NEWS file for ChangeLog.
|
||||
|
||||
-- Daniel Charles <daniel.charles@intel.com> @TODAY@
|
|
@ -0,0 +1 @@
|
|||
5
|
|
@ -0,0 +1,27 @@
|
|||
Source: libva
|
||||
Priority: extra
|
||||
Maintainer: Daniel Charles <daniel.charles@intel.com>
|
||||
Build-Depends: automake,
|
||||
autotools-dev,
|
||||
cdbs,
|
||||
debhelper (>= 5),
|
||||
libdrm-dev (>= @LIBDRM_VERSION@),
|
||||
libva-dev (>= @LIBVA_VERSION@),
|
||||
@USE_X11_TRUE@ libx11-dev, libxext-dev, libxfixes-dev,
|
||||
@USE_GLX_TRUE@ libgl-dev,
|
||||
@USE_WAYLAND_TRUE@ libwayland-dev (>= @WAYLAND_API_VERSION@),
|
||||
libtool,
|
||||
pkg-config
|
||||
Standards-Version: 3.7.2
|
||||
Section: libs
|
||||
|
||||
Package: vainfo
|
||||
Architecture: any
|
||||
Depends: libva@LIBVA_MAJOR_VERSION@ (= ${Source-Version})
|
||||
Description: Video Acceleration (VA) API for Linux -- info program
|
||||
The libva library implements the Video Acceleration (VA) API for Linux.
|
||||
The library loads a hardware dependendent driver.
|
||||
|
||||
The libva-utils project hosts the tests for libva library.
|
||||
.
|
||||
This package contains the `vainfo' program.
|
|
@ -0,0 +1,44 @@
|
|||
This package was debianized by Waldo Bastian <waldo.bastian@intel.com> on
|
||||
Mon, 18 Jun 2007 21:35:31 -0700.
|
||||
|
||||
It was downloaded from <url://example.com>
|
||||
|
||||
Upstream Author(s):
|
||||
|
||||
Waldo Bastian <waldo.bastian@intel.com>
|
||||
Jonathan Bian <jonathan.bian@intel.com>
|
||||
|
||||
Copyright:
|
||||
|
||||
(C) Copyright IBM Corporation 2004
|
||||
Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
|
||||
Copyright 2000 VA Linux Systems, Inc.
|
||||
Copyright 2007 Intel Corportation
|
||||
|
||||
License:
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sub license, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the
|
||||
next paragraph) shall be included in all copies or substantial portions
|
||||
of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
|
||||
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
The Debian packaging is (C) 2007, Intel Corporation and
|
||||
is licensed under the GPL, see `/usr/share/common-licenses/GPL'.
|
||||
|
||||
# Please also look if there are files or directories which have a
|
||||
# different copyright/license attached and list them here.
|
|
@ -0,0 +1,14 @@
|
|||
#!/usr/bin/make -f
|
||||
|
||||
include /usr/share/cdbs/1/rules/debhelper.mk
|
||||
include /usr/share/cdbs/1/class/autotools.mk
|
||||
include /usr/share/cdbs/1/rules/utils.mk
|
||||
|
||||
# Allow SMP build
|
||||
ifeq ($(DEBIAN_BUILD_NCPUS),)
|
||||
DEBIAN_BUILD_NCPUS = $(shell /usr/bin/getconf _NPROCESSORS_ONLN)
|
||||
endif
|
||||
ifneq ($(DEBIAN_BUILD_NCPUS),)
|
||||
EXTRA_MAKE_FLAGS += -j$(DEBIAN_BUILD_NCPUS)
|
||||
endif
|
||||
MAKE += $(EXTRA_MAKE_FLAGS)
|
|
@ -0,0 +1 @@
|
|||
debian/tmp/usr/bin/vainfo
|
|
@ -0,0 +1,27 @@
|
|||
# For test_01
|
||||
# =====================================================
|
||||
|
||||
LOCAL_PATH:= $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_SRC_FILES := \
|
||||
mpeg2vldemo.cpp \
|
||||
../common/va_display.c \
|
||||
../common/va_display_android.cpp
|
||||
|
||||
LOCAL_CFLAGS += \
|
||||
-DANDROID
|
||||
|
||||
LOCAL_C_INCLUDES += \
|
||||
$(LOCAL_PATH)/../../va \
|
||||
$(LOCAL_PATH)/../common \
|
||||
$(TARGET_OUT_HEADERS)/libva
|
||||
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
LOCAL_MODULE := mpeg2vldemo
|
||||
|
||||
LOCAL_SHARED_LIBRARIES := libva libva-android libdl libdrm libcutils libutils libgui
|
||||
|
||||
include $(BUILD_EXECUTABLE)
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
# Copyright (c) 2007 Intel Corporation. All Rights Reserved.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a
|
||||
# copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sub license, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice (including the
|
||||
# next paragraph) shall be included in all copies or substantial portions
|
||||
# of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
# IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
|
||||
# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
bin_PROGRAMS = mpeg2vldemo loadjpeg
|
||||
|
||||
AM_CPPFLAGS = \
|
||||
$(LIBVA_CFLAGS) \
|
||||
-I$(top_srcdir)/common \
|
||||
$(NULL)
|
||||
|
||||
TEST_LIBS = \
|
||||
$(LIBVA_LIBS) \
|
||||
$(top_builddir)/common/libva-display.la \
|
||||
$(NULL)
|
||||
|
||||
mpeg2vldemo_LDADD = $(TEST_LIBS)
|
||||
mpeg2vldemo_SOURCES = mpeg2vldemo.cpp
|
||||
|
||||
loadjpeg_LDADD = $(TEST_LIBS)
|
||||
loadjpeg_SOURCES = loadjpeg.c tinyjpeg.c
|
||||
|
||||
valgrind: $(bin_PROGRAMS)
|
||||
for a in $(bin_PROGRAMS); do \
|
||||
valgrind --leak-check=full --show-reachable=yes .libs/$$a; \
|
||||
done
|
||||
|
||||
EXTRA_DIST = \
|
||||
tinyjpeg.h \
|
||||
tinyjpeg-internal.h \
|
||||
$(NULL)
|
|
@ -0,0 +1,137 @@
|
|||
/*
|
||||
* Small jpeg decoder library - testing application
|
||||
*
|
||||
* Copyright (c) 2006, Luc Saillard <luc@saillard.org>
|
||||
* Copyright (c) 2012 Intel Corporation.
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* - Neither the name of the author nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "tinyjpeg.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include "va_display.h"
|
||||
|
||||
static void exitmessage(const char *message) __attribute__((noreturn));
|
||||
static void exitmessage(const char *message)
|
||||
{
|
||||
printf("%s\n", message);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static int filesize(FILE *fp)
|
||||
{
|
||||
long pos;
|
||||
fseek(fp, 0, SEEK_END);
|
||||
pos = ftell(fp);
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
return pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load one jpeg image, and decompress it, and save the result.
|
||||
*/
|
||||
int convert_one_image(const char *infilename)
|
||||
{
|
||||
FILE *fp;
|
||||
unsigned int length_of_file;
|
||||
unsigned int width, height;
|
||||
unsigned char *buf;
|
||||
struct jdec_private *jdec;
|
||||
|
||||
/* Load the Jpeg into memory */
|
||||
fp = fopen(infilename, "rb");
|
||||
if (fp == NULL)
|
||||
exitmessage("Cannot open filename\n");
|
||||
length_of_file = filesize(fp);
|
||||
buf = (unsigned char *)malloc(length_of_file + 4);
|
||||
if (buf == NULL)
|
||||
exitmessage("Not enough memory for loading file\n");
|
||||
fread(buf, length_of_file, 1, fp);
|
||||
fclose(fp);
|
||||
|
||||
/* Decompress it */
|
||||
jdec = tinyjpeg_init();
|
||||
if (jdec == NULL)
|
||||
exitmessage("Not enough memory to alloc the structure need for decompressing\n");
|
||||
|
||||
if (tinyjpeg_parse_header(jdec, buf, length_of_file)<0)
|
||||
exitmessage(tinyjpeg_get_errorstring(jdec));
|
||||
|
||||
/* Get the size of the image */
|
||||
tinyjpeg_get_size(jdec, &width, &height);
|
||||
|
||||
printf("Decoding JPEG image %dx%d...\n", width, height);
|
||||
if (tinyjpeg_decode(jdec) < 0)
|
||||
exitmessage(tinyjpeg_get_errorstring(jdec));
|
||||
|
||||
tinyjpeg_free(jdec);
|
||||
|
||||
free(buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
fprintf(stderr, "Usage: loadjpeg <input_filename.jpeg> \n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* main
|
||||
*
|
||||
*/
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char *input_filename;
|
||||
clock_t start_time, finish_time;
|
||||
unsigned int duration;
|
||||
int current_argument;
|
||||
|
||||
va_init_display_args(&argc, argv);
|
||||
|
||||
if (argc < 2)
|
||||
usage();
|
||||
|
||||
current_argument = 1;
|
||||
input_filename = argv[current_argument];
|
||||
|
||||
start_time = clock();
|
||||
convert_one_image(input_filename);
|
||||
finish_time = clock();
|
||||
duration = finish_time - start_time;
|
||||
printf("Decoding finished in %u ticks\n", duration);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 101 KiB |
Binary file not shown.
|
@ -0,0 +1,282 @@
|
|||
/*
|
||||
* Copyright (c) 2007-2008 Intel Corporation. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sub license, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the
|
||||
* next paragraph) shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
|
||||
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* it is a real program to show how VAAPI decode work,
|
||||
* It does VLD decode for a simple MPEG2 clip "mpeg2-I.m2v"
|
||||
* "mpeg2-I.m2v" and VA parameters are hardcoded into mpeg2vldemo.c,
|
||||
* See mpeg2-I.jif to know how those VA parameters come from
|
||||
*
|
||||
* gcc -o mpeg2vldemo mpeg2vldemo.c -lva -lva-x11 -I/usr/include/va
|
||||
* ./mpeg2vldemo : only do decode
|
||||
* ./mpeg2vldemo <any parameter >: decode+display
|
||||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <getopt.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <assert.h>
|
||||
#include <va/va.h>
|
||||
#include "va_display.h"
|
||||
|
||||
#define CHECK_VASTATUS(va_status,func) \
|
||||
if (va_status != VA_STATUS_SUCCESS) { \
|
||||
fprintf(stderr,"%s:%s (%d) failed,exit\n", __func__, func, __LINE__); \
|
||||
exit(1); \
|
||||
}
|
||||
|
||||
/* Data dump of a 16x16 MPEG2 video clip,it has one I frame
|
||||
*/
|
||||
static unsigned char mpeg2_clip[]={
|
||||
0x00,0x00,0x01,0xb3,0x01,0x00,0x10,0x13,0xff,0xff,0xe0,0x18,0x00,0x00,0x01,0xb5,
|
||||
0x14,0x8a,0x00,0x01,0x00,0x00,0x00,0x00,0x01,0xb8,0x00,0x08,0x00,0x00,0x00,0x00,
|
||||
0x01,0x00,0x00,0x0f,0xff,0xf8,0x00,0x00,0x01,0xb5,0x8f,0xff,0xf3,0x41,0x80,0x00,
|
||||
0x00,0x01,0x01,0x13,0xe1,0x00,0x15,0x81,0x54,0xe0,0x2a,0x05,0x43,0x00,0x2d,0x60,
|
||||
0x18,0x01,0x4e,0x82,0xb9,0x58,0xb1,0x83,0x49,0xa4,0xa0,0x2e,0x05,0x80,0x4b,0x7a,
|
||||
0x00,0x01,0x38,0x20,0x80,0xe8,0x05,0xff,0x60,0x18,0xe0,0x1d,0x80,0x98,0x01,0xf8,
|
||||
0x06,0x00,0x54,0x02,0xc0,0x18,0x14,0x03,0xb2,0x92,0x80,0xc0,0x18,0x94,0x42,0x2c,
|
||||
0xb2,0x11,0x64,0xa0,0x12,0x5e,0x78,0x03,0x3c,0x01,0x80,0x0e,0x80,0x18,0x80,0x6b,
|
||||
0xca,0x4e,0x01,0x0f,0xe4,0x32,0xc9,0xbf,0x01,0x42,0x69,0x43,0x50,0x4b,0x01,0xc9,
|
||||
0x45,0x80,0x50,0x01,0x38,0x65,0xe8,0x01,0x03,0xf3,0xc0,0x76,0x00,0xe0,0x03,0x20,
|
||||
0x28,0x18,0x01,0xa9,0x34,0x04,0xc5,0xe0,0x0b,0x0b,0x04,0x20,0x06,0xc0,0x89,0xff,
|
||||
0x60,0x12,0x12,0x8a,0x2c,0x34,0x11,0xff,0xf6,0xe2,0x40,0xc0,0x30,0x1b,0x7a,0x01,
|
||||
0xa9,0x0d,0x00,0xac,0x64
|
||||
};
|
||||
|
||||
/* hardcoded here without a bitstream parser helper
|
||||
* please see picture mpeg2-I.jpg for bitstream details
|
||||
*/
|
||||
static VAPictureParameterBufferMPEG2 pic_param={
|
||||
horizontal_size:16,
|
||||
vertical_size:16,
|
||||
forward_reference_picture:0xffffffff,
|
||||
backward_reference_picture:0xffffffff,
|
||||
picture_coding_type:1,
|
||||
f_code:0xffff,
|
||||
{
|
||||
{
|
||||
intra_dc_precision:0,
|
||||
picture_structure:3,
|
||||
top_field_first:0,
|
||||
frame_pred_frame_dct:1,
|
||||
concealment_motion_vectors:0,
|
||||
q_scale_type:0,
|
||||
intra_vlc_format:0,
|
||||
alternate_scan:0,
|
||||
repeat_first_field:0,
|
||||
progressive_frame:1 ,
|
||||
is_first_field:1
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
/* see MPEG2 spec65 for the defines of matrix */
|
||||
static VAIQMatrixBufferMPEG2 iq_matrix = {
|
||||
load_intra_quantiser_matrix:1,
|
||||
load_non_intra_quantiser_matrix:1,
|
||||
load_chroma_intra_quantiser_matrix:0,
|
||||
load_chroma_non_intra_quantiser_matrix:0,
|
||||
intra_quantiser_matrix:{
|
||||
8, 16, 16, 19, 16, 19, 22, 22,
|
||||
22, 22, 22, 22, 26, 24, 26, 27,
|
||||
27, 27, 26, 26, 26, 26, 27, 27,
|
||||
27, 29, 29, 29, 34, 34, 34, 29,
|
||||
29, 29, 27, 27, 29, 29, 32, 32,
|
||||
34, 34, 37, 38, 37, 35, 35, 34,
|
||||
35, 38, 38, 40, 40, 40, 48, 48,
|
||||
46, 46, 56, 56, 58, 69, 69, 83
|
||||
},
|
||||
non_intra_quantiser_matrix:{16},
|
||||
chroma_intra_quantiser_matrix:{0},
|
||||
chroma_non_intra_quantiser_matrix:{0}
|
||||
};
|
||||
|
||||
#if 1
|
||||
static VASliceParameterBufferMPEG2 slice_param={
|
||||
slice_data_size:150,
|
||||
slice_data_offset:0,
|
||||
slice_data_flag:0,
|
||||
macroblock_offset:38, /* 4byte + 6bits=38bits */
|
||||
slice_horizontal_position:0,
|
||||
slice_vertical_position:0,
|
||||
quantiser_scale_code:2,
|
||||
intra_slice_flag:0
|
||||
};
|
||||
#endif
|
||||
|
||||
#define CLIP_WIDTH 16
|
||||
#define CLIP_HEIGHT 16
|
||||
|
||||
#define WIN_WIDTH (CLIP_WIDTH<<1)
|
||||
#define WIN_HEIGHT (CLIP_HEIGHT<<1)
|
||||
|
||||
int main(int argc,char **argv)
|
||||
{
|
||||
VAEntrypoint entrypoints[5];
|
||||
int num_entrypoints,vld_entrypoint;
|
||||
VAConfigAttrib attrib;
|
||||
VAConfigID config_id;
|
||||
VASurfaceID surface_id;
|
||||
VAContextID context_id;
|
||||
VABufferID pic_param_buf,iqmatrix_buf,slice_param_buf,slice_data_buf;
|
||||
int major_ver, minor_ver;
|
||||
VADisplay va_dpy;
|
||||
VAStatus va_status;
|
||||
int putsurface=0;
|
||||
|
||||
va_init_display_args(&argc, argv);
|
||||
|
||||
if (argc > 1)
|
||||
putsurface=1;
|
||||
|
||||
va_dpy = va_open_display();
|
||||
va_status = vaInitialize(va_dpy, &major_ver, &minor_ver);
|
||||
assert(va_status == VA_STATUS_SUCCESS);
|
||||
|
||||
va_status = vaQueryConfigEntrypoints(va_dpy, VAProfileMPEG2Main, entrypoints,
|
||||
&num_entrypoints);
|
||||
CHECK_VASTATUS(va_status, "vaQueryConfigEntrypoints");
|
||||
|
||||
for (vld_entrypoint = 0; vld_entrypoint < num_entrypoints; vld_entrypoint++) {
|
||||
if (entrypoints[vld_entrypoint] == VAEntrypointVLD)
|
||||
break;
|
||||
}
|
||||
if (vld_entrypoint == num_entrypoints) {
|
||||
/* not find VLD entry point */
|
||||
assert(0);
|
||||
}
|
||||
|
||||
/* Assuming finding VLD, find out the format for the render target */
|
||||
attrib.type = VAConfigAttribRTFormat;
|
||||
vaGetConfigAttributes(va_dpy, VAProfileMPEG2Main, VAEntrypointVLD,
|
||||
&attrib, 1);
|
||||
if ((attrib.value & VA_RT_FORMAT_YUV420) == 0) {
|
||||
/* not find desired YUV420 RT format */
|
||||
assert(0);
|
||||
}
|
||||
|
||||
va_status = vaCreateConfig(va_dpy, VAProfileMPEG2Main, VAEntrypointVLD,
|
||||
&attrib, 1,&config_id);
|
||||
CHECK_VASTATUS(va_status, "vaQueryConfigEntrypoints");
|
||||
|
||||
va_status = vaCreateSurfaces(
|
||||
va_dpy,
|
||||
VA_RT_FORMAT_YUV420, CLIP_WIDTH, CLIP_HEIGHT,
|
||||
&surface_id, 1,
|
||||
NULL, 0
|
||||
);
|
||||
CHECK_VASTATUS(va_status, "vaCreateSurfaces");
|
||||
|
||||
/* Create a context for this decode pipe */
|
||||
va_status = vaCreateContext(va_dpy, config_id,
|
||||
CLIP_WIDTH,
|
||||
((CLIP_HEIGHT+15)/16)*16,
|
||||
VA_PROGRESSIVE,
|
||||
&surface_id,
|
||||
1,
|
||||
&context_id);
|
||||
CHECK_VASTATUS(va_status, "vaCreateContext");
|
||||
|
||||
va_status = vaCreateBuffer(va_dpy, context_id,
|
||||
VAPictureParameterBufferType,
|
||||
sizeof(VAPictureParameterBufferMPEG2),
|
||||
1, &pic_param,
|
||||
&pic_param_buf);
|
||||
CHECK_VASTATUS(va_status, "vaCreateBuffer");
|
||||
|
||||
va_status = vaCreateBuffer(va_dpy, context_id,
|
||||
VAIQMatrixBufferType,
|
||||
sizeof(VAIQMatrixBufferMPEG2),
|
||||
1, &iq_matrix,
|
||||
&iqmatrix_buf );
|
||||
CHECK_VASTATUS(va_status, "vaCreateBuffer");
|
||||
|
||||
va_status = vaCreateBuffer(va_dpy, context_id,
|
||||
VASliceParameterBufferType,
|
||||
sizeof(VASliceParameterBufferMPEG2),
|
||||
1,
|
||||
&slice_param, &slice_param_buf);
|
||||
CHECK_VASTATUS(va_status, "vaCreateBuffer");
|
||||
|
||||
va_status = vaCreateBuffer(va_dpy, context_id,
|
||||
VASliceDataBufferType,
|
||||
0xc4-0x2f+1,
|
||||
1,
|
||||
mpeg2_clip+0x2f,
|
||||
&slice_data_buf);
|
||||
CHECK_VASTATUS(va_status, "vaCreateBuffer");
|
||||
|
||||
va_status = vaBeginPicture(va_dpy, context_id, surface_id);
|
||||
CHECK_VASTATUS(va_status, "vaBeginPicture");
|
||||
|
||||
va_status = vaRenderPicture(va_dpy,context_id, &pic_param_buf, 1);
|
||||
CHECK_VASTATUS(va_status, "vaRenderPicture");
|
||||
|
||||
va_status = vaRenderPicture(va_dpy,context_id, &iqmatrix_buf, 1);
|
||||
CHECK_VASTATUS(va_status, "vaRenderPicture");
|
||||
|
||||
va_status = vaRenderPicture(va_dpy,context_id, &slice_param_buf, 1);
|
||||
CHECK_VASTATUS(va_status, "vaRenderPicture");
|
||||
|
||||
va_status = vaRenderPicture(va_dpy,context_id, &slice_data_buf, 1);
|
||||
CHECK_VASTATUS(va_status, "vaRenderPicture");
|
||||
|
||||
va_status = vaEndPicture(va_dpy,context_id);
|
||||
CHECK_VASTATUS(va_status, "vaEndPicture");
|
||||
|
||||
va_status = vaSyncSurface(va_dpy, surface_id);
|
||||
CHECK_VASTATUS(va_status, "vaSyncSurface");
|
||||
|
||||
if (putsurface) {
|
||||
VARectangle src_rect, dst_rect;
|
||||
|
||||
src_rect.x = 0;
|
||||
src_rect.y = 0;
|
||||
src_rect.width = CLIP_WIDTH;
|
||||
src_rect.height = CLIP_HEIGHT;
|
||||
|
||||
dst_rect.x = 0;
|
||||
dst_rect.y = 0;
|
||||
dst_rect.width = WIN_WIDTH;
|
||||
dst_rect.height = WIN_HEIGHT;
|
||||
|
||||
va_status = va_put_surface(va_dpy, surface_id, &src_rect, &dst_rect);
|
||||
CHECK_VASTATUS(va_status, "vaPutSurface");
|
||||
}
|
||||
printf("press any key to exit\n");
|
||||
getchar();
|
||||
|
||||
vaDestroySurfaces(va_dpy,&surface_id,1);
|
||||
vaDestroyConfig(va_dpy,config_id);
|
||||
vaDestroyContext(va_dpy,context_id);
|
||||
|
||||
vaTerminate(va_dpy);
|
||||
va_close_display(va_dpy);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,121 @@
|
|||
/*
|
||||
* Small jpeg decoder library (Internal header)
|
||||
*
|
||||
* Copyright (c) 2006, Luc Saillard <luc@saillard.org>
|
||||
* Copyright (c) 2012 Intel Corporation.
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* - Neither the name of the author nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __TINYJPEG_INTERNAL_H_
|
||||
#define __TINYJPEG_INTERNAL_H_
|
||||
|
||||
#include <setjmp.h>
|
||||
|
||||
#define SANITY_CHECK 1
|
||||
|
||||
struct jdec_private;
|
||||
|
||||
#define HUFFMAN_BITS_SIZE 256
|
||||
|
||||
#define HUFFMAN_TABLES 4
|
||||
#define COMPONENTS 4
|
||||
#define JPEG_MAX_WIDTH 2048
|
||||
#define JPEG_MAX_HEIGHT 2048
|
||||
#define JPEG_SCAN_MAX 4
|
||||
|
||||
enum std_markers {
|
||||
DQT = 0xDB, /* Define Quantization Table */
|
||||
SOF = 0xC0, /* Start of Frame (size information) */
|
||||
DHT = 0xC4, /* Huffman Table */
|
||||
SOI = 0xD8, /* Start of Image */
|
||||
SOS = 0xDA, /* Start of Scan */
|
||||
RST = 0xD0, /* Reset Marker d0 -> .. */
|
||||
RST7 = 0xD7, /* Reset Marker .. -> d7 */
|
||||
EOI = 0xD9, /* End of Image */
|
||||
DRI = 0xDD, /* Define Restart Interval */
|
||||
APP0 = 0xE0,
|
||||
};
|
||||
|
||||
|
||||
struct huffman_table
|
||||
{
|
||||
/*bits and values*/
|
||||
unsigned char bits[16];
|
||||
unsigned char values[256];
|
||||
};
|
||||
|
||||
struct component
|
||||
{
|
||||
unsigned int Hfactor;
|
||||
unsigned int Vfactor;
|
||||
unsigned char quant_table_index;
|
||||
unsigned int cid;
|
||||
};
|
||||
|
||||
|
||||
typedef void (*decode_MCU_fct) (struct jdec_private *priv);
|
||||
typedef void (*convert_colorspace_fct) (struct jdec_private *priv);
|
||||
|
||||
struct jpeg_sos
|
||||
{
|
||||
unsigned int nr_components;
|
||||
struct {
|
||||
unsigned int component_id;
|
||||
unsigned int dc_selector;
|
||||
unsigned int ac_selector;
|
||||
}components[4];
|
||||
};
|
||||
|
||||
struct jdec_private
|
||||
{
|
||||
/* Public variables */
|
||||
unsigned int width[JPEG_SCAN_MAX], height[JPEG_SCAN_MAX]; /* Size of the image */
|
||||
|
||||
/* Private variables */
|
||||
const unsigned char *stream_begin, *stream_end,*stream_scan;
|
||||
unsigned int stream_length;
|
||||
|
||||
const unsigned char *stream; /* Pointer to the current stream */
|
||||
|
||||
struct component component_infos[COMPONENTS];
|
||||
unsigned int nf_components;
|
||||
unsigned char Q_tables[COMPONENTS][64]; /* quantization tables, zigzag*/
|
||||
unsigned char Q_tables_valid[COMPONENTS];
|
||||
struct huffman_table HTDC[HUFFMAN_TABLES]; /* DC huffman tables */
|
||||
unsigned char HTDC_valid[HUFFMAN_TABLES];
|
||||
struct huffman_table HTAC[HUFFMAN_TABLES]; /* AC huffman tables */
|
||||
unsigned char HTAC_valid[HUFFMAN_TABLES];
|
||||
struct jpeg_sos cur_sos; /* current sos values*/
|
||||
int default_huffman_table_initialized;
|
||||
int restart_interval;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,873 @@
|
|||
/*
|
||||
* Small jpeg decoder library
|
||||
*
|
||||
* Copyright (c) 2006, Luc Saillard <luc@saillard.org>
|
||||
* Copyright (c) 2012 Intel Corporation.
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* - Neither the name of the author nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "tinyjpeg.h"
|
||||
#include "tinyjpeg-internal.h"
|
||||
|
||||
// for libva
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <assert.h>
|
||||
#include <va/va.h>
|
||||
#include "va_display.h"
|
||||
|
||||
|
||||
#define cY 0
|
||||
#define cCb 1
|
||||
#define cCr 2
|
||||
|
||||
#define BLACK_Y 0
|
||||
#define BLACK_U 127
|
||||
#define BLACK_V 127
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
#endif
|
||||
#ifndef MAX
|
||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
#endif
|
||||
#define ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0]))
|
||||
|
||||
#if DEBUG
|
||||
#define trace(fmt, args...) do { \
|
||||
fprintf(stderr, fmt, ## args); \
|
||||
fflush(stderr); \
|
||||
} while(0)
|
||||
#else
|
||||
#define trace(fmt, args...) do { } while (0)
|
||||
#endif
|
||||
#define error(fmt, args...) do { \
|
||||
snprintf(error_string, sizeof(error_string), fmt, ## args); \
|
||||
return -1; \
|
||||
} while(0)
|
||||
/* The variables for different image scans */
|
||||
static int scan_num=0;
|
||||
static int next_image_found=0;
|
||||
/* Global variable to return the last error found while deconding */
|
||||
static char error_string[256];
|
||||
static VAHuffmanTableBufferJPEGBaseline default_huffman_table_param={
|
||||
huffman_table:
|
||||
{
|
||||
// lumiance component
|
||||
{
|
||||
num_dc_codes:{0,1,5,1,1,1,1,1,1,0,0,0}, // 12 bits is ok for baseline profile
|
||||
dc_values:{0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b},
|
||||
num_ac_codes:{0,2,1,3,3,2,4,3,5,5,4,4,0,0,1,125},
|
||||
ac_values:{
|
||||
0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
|
||||
0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
|
||||
0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
|
||||
0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
|
||||
0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
|
||||
0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
|
||||
0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
|
||||
0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
|
||||
0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
|
||||
0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
|
||||
0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
|
||||
0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
|
||||
0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
|
||||
0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
|
||||
0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
|
||||
0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
|
||||
0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
|
||||
0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
|
||||
0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
|
||||
0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
|
||||
0xf9, 0xfa
|
||||
},/*,0xonly,0xthe,0xfirst,0x162,0xbytes,0xare,0xavailable,0x*/
|
||||
},
|
||||
// chrom component
|
||||
{
|
||||
num_dc_codes:{0,3,1,1,1,1,1,1,1,1,1,0}, // 12 bits is ok for baseline profile
|
||||
dc_values:{0,1,2,3,4,5,6,7,8,9,0xa,0xb},
|
||||
num_ac_codes:{0,2,1,2,4,4,3,4,7,5,4,4,0,1,2,119},
|
||||
ac_values:{
|
||||
0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
|
||||
0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
|
||||
0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
|
||||
0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
|
||||
0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
|
||||
0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
|
||||
0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
|
||||
0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
|
||||
0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
|
||||
0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
|
||||
0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
|
||||
0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
|
||||
0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
|
||||
0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
|
||||
0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
|
||||
0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
|
||||
0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
|
||||
0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
|
||||
0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
|
||||
0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
|
||||
0xf9, 0xfa
|
||||
},/*,0xonly,0xthe,0xfirst,0x162,0xbytes,0xare,0xavailable,0x*/
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
#define be16_to_cpu(x) (((x)[0]<<8)|(x)[1])
|
||||
|
||||
|
||||
static int build_default_huffman_tables(struct jdec_private *priv)
|
||||
{
|
||||
int i = 0;
|
||||
if (priv->default_huffman_table_initialized)
|
||||
return 0;
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
priv->HTDC_valid[i] = 1;
|
||||
memcpy(priv->HTDC[i].bits, default_huffman_table_param.huffman_table[i%2].num_dc_codes,
|
||||
sizeof(default_huffman_table_param.huffman_table[i%2].num_dc_codes));
|
||||
memcpy(priv->HTDC[i].values, default_huffman_table_param.huffman_table[i%2].dc_values,
|
||||
sizeof(default_huffman_table_param.huffman_table[i%2].dc_values));
|
||||
priv->HTAC_valid[i] = 1;
|
||||
memcpy(priv->HTAC[i].bits, default_huffman_table_param.huffman_table[i%2].num_ac_codes,
|
||||
sizeof(default_huffman_table_param.huffman_table[i%2].num_ac_codes));
|
||||
memcpy(priv->HTAC[i].values, default_huffman_table_param.huffman_table[i%2].ac_values,
|
||||
sizeof(default_huffman_table_param.huffman_table[i%2].ac_values));
|
||||
}
|
||||
priv->default_huffman_table_initialized = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void print_SOF(const unsigned char *stream)
|
||||
{
|
||||
int width, height, nr_components, precision;
|
||||
#if DEBUG
|
||||
const char *nr_components_to_string[] = {
|
||||
"????",
|
||||
"Grayscale",
|
||||
"????",
|
||||
"YCbCr",
|
||||
"CYMK"
|
||||
};
|
||||
#endif
|
||||
|
||||
precision = stream[2];
|
||||
height = be16_to_cpu(stream+3);
|
||||
width = be16_to_cpu(stream+5);
|
||||
nr_components = stream[7];
|
||||
|
||||
trace("> SOF marker\n");
|
||||
trace("Size:%dx%d nr_components:%d (%s) precision:%d\n",
|
||||
width, height,
|
||||
nr_components, nr_components_to_string[nr_components],
|
||||
precision);
|
||||
}
|
||||
|
||||
static int parse_DQT(struct jdec_private *priv, const unsigned char *stream)
|
||||
{
|
||||
int qi;
|
||||
const unsigned char *dqt_block_end;
|
||||
|
||||
trace("> DQT marker\n");
|
||||
dqt_block_end = stream + be16_to_cpu(stream);
|
||||
stream += 2; /* Skip length */
|
||||
|
||||
while (stream < dqt_block_end)
|
||||
{
|
||||
qi = *stream++;
|
||||
#if SANITY_CHECK
|
||||
if (qi>>4)
|
||||
error("16 bits quantization table is not supported\n");
|
||||
if (qi>4)
|
||||
error("No more 4 quantization table is supported (got %d)\n", qi);
|
||||
#endif
|
||||
memcpy(priv->Q_tables[qi&0x0F], stream, 64);
|
||||
priv->Q_tables_valid[qi & 0x0f] = 1;
|
||||
stream += 64;
|
||||
}
|
||||
trace("< DQT marker\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_SOF(struct jdec_private *priv, const unsigned char *stream)
|
||||
{
|
||||
int i, width, height, nr_components, cid, sampling_factor;
|
||||
unsigned char Q_table;
|
||||
struct component *c;
|
||||
|
||||
trace("> SOF marker\n");
|
||||
print_SOF(stream);
|
||||
|
||||
height = be16_to_cpu(stream+3);
|
||||
width = be16_to_cpu(stream+5);
|
||||
nr_components = stream[7];
|
||||
priv->nf_components = nr_components;
|
||||
#if SANITY_CHECK
|
||||
if (stream[2] != 8)
|
||||
error("Precision other than 8 is not supported\n");
|
||||
if (width>JPEG_MAX_WIDTH || height>JPEG_MAX_HEIGHT)
|
||||
printf("WARNING:Width and Height (%dx%d) seems suspicious\n", width, height);
|
||||
if (nr_components != 3)
|
||||
printf("ERROR:We only support YUV images\n");
|
||||
if (height%16)
|
||||
printf("WARNING:Height need to be a multiple of 16 (current height is %d)\n", height);
|
||||
if (width%16)
|
||||
printf("WARNING:Width need to be a multiple of 16 (current Width is %d)\n", width);
|
||||
#endif
|
||||
stream += 8;
|
||||
for (i=0; i<nr_components; i++) {
|
||||
cid = *stream++;
|
||||
sampling_factor = *stream++;
|
||||
Q_table = *stream++;
|
||||
c = &priv->component_infos[i];
|
||||
c->cid = cid;
|
||||
if (Q_table >= COMPONENTS)
|
||||
error("Bad Quantization table index (got %d, max allowed %d)\n", Q_table, COMPONENTS-1);
|
||||
c->Vfactor = sampling_factor&0xf;
|
||||
c->Hfactor = sampling_factor>>4;
|
||||
c->quant_table_index = Q_table;
|
||||
trace("Component:%d factor:%dx%d Quantization table:%d\n",
|
||||
cid, c->Hfactor, c->Vfactor, Q_table );
|
||||
|
||||
}
|
||||
priv->width[scan_num] = width;
|
||||
priv->height[scan_num] = height;
|
||||
|
||||
trace("< SOF marker\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_SOS(struct jdec_private *priv, const unsigned char *stream)
|
||||
{
|
||||
unsigned int i, cid, table;
|
||||
unsigned int nr_components = stream[2];
|
||||
|
||||
trace("> SOS marker\n");
|
||||
|
||||
priv->cur_sos.nr_components= nr_components;
|
||||
|
||||
stream += 3;
|
||||
for (i=0;i<nr_components;i++) {
|
||||
cid = *stream++;
|
||||
table = *stream++;
|
||||
priv->cur_sos.components[i].component_id = cid;
|
||||
priv->cur_sos.components[i].dc_selector = ((table>>4)&0x0F);
|
||||
priv->cur_sos.components[i].ac_selector = (table&0x0F);
|
||||
#if SANITY_CHECK
|
||||
if ((table&0xf)>=4)
|
||||
error("We do not support more than 2 AC Huffman table\n");
|
||||
if ((table>>4)>=4)
|
||||
error("We do not support more than 2 DC Huffman table\n");
|
||||
if (cid != priv->component_infos[i].cid)
|
||||
error("SOS cid order (%d:%d) isn't compatible with the SOF marker (%d:%d)\n",
|
||||
i, cid, i, priv->component_infos[i].cid);
|
||||
trace("ComponentId:%d tableAC:%d tableDC:%d\n", cid, table&0xf, table>>4);
|
||||
#endif
|
||||
}
|
||||
priv->stream = stream+3;
|
||||
trace("< SOS marker\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tinyjpeg_parse_SOS(struct jdec_private *priv, const unsigned char *stream)
|
||||
{
|
||||
return parse_SOS(priv, stream);
|
||||
}
|
||||
|
||||
|
||||
static int parse_DHT(struct jdec_private *priv, const unsigned char *stream)
|
||||
{
|
||||
unsigned int count, i;
|
||||
int length, index;
|
||||
unsigned char Tc, Th;
|
||||
|
||||
length = be16_to_cpu(stream) - 2;
|
||||
stream += 2; /* Skip length */
|
||||
|
||||
trace("> DHT marker (length=%d)\n", length);
|
||||
|
||||
while (length>0) {
|
||||
index = *stream++;
|
||||
|
||||
Tc = index & 0xf0; // it is not important to <<4
|
||||
Th = index & 0x0f;
|
||||
if (Tc) {
|
||||
memcpy(priv->HTAC[index & 0xf].bits, stream, 16);
|
||||
}
|
||||
else {
|
||||
memcpy(priv->HTDC[index & 0xf].bits, stream, 16);
|
||||
}
|
||||
|
||||
count = 0;
|
||||
for (i=0; i<16; i++) {
|
||||
count += *stream++;
|
||||
}
|
||||
|
||||
#if SANITY_CHECK
|
||||
if (count >= HUFFMAN_BITS_SIZE)
|
||||
error("No more than %d bytes is allowed to describe a huffman table", HUFFMAN_BITS_SIZE);
|
||||
if ( (index &0xf) >= HUFFMAN_TABLES)
|
||||
error("No more than %d Huffman tables is supported (got %d)\n", HUFFMAN_TABLES, index&0xf);
|
||||
trace("Huffman table %s[%d] length=%d\n", (index&0xf0)?"AC":"DC", index&0xf, count);
|
||||
#endif
|
||||
|
||||
if (Tc) {
|
||||
memcpy(priv->HTAC[index & 0xf].values, stream, count);
|
||||
priv->HTAC_valid[index & 0xf] = 1;
|
||||
}
|
||||
else {
|
||||
memcpy(priv->HTDC[index & 0xf].values, stream, count);
|
||||
priv->HTDC_valid[index & 0xf] = 1;
|
||||
}
|
||||
|
||||
length -= 1;
|
||||
length -= 16;
|
||||
length -= count;
|
||||
stream += count;
|
||||
}
|
||||
trace("< DHT marker\n");
|
||||
return 0;
|
||||
}
|
||||
static int parse_DRI(struct jdec_private *priv, const unsigned char *stream)
|
||||
{
|
||||
unsigned int length;
|
||||
|
||||
trace("> DRI marker\n");
|
||||
|
||||
length = be16_to_cpu(stream);
|
||||
|
||||
#if SANITY_CHECK
|
||||
if (length != 4)
|
||||
error("Length of DRI marker need to be 4\n");
|
||||
#endif
|
||||
|
||||
priv->restart_interval = be16_to_cpu(stream+2);
|
||||
|
||||
#if DEBUG
|
||||
trace("Restart interval = %d\n", priv->restart_interval);
|
||||
#endif
|
||||
|
||||
trace("< DRI marker\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int findEOI(struct jdec_private *priv,const unsigned char *stream)
|
||||
{
|
||||
while (stream<=priv->stream_end&& !(*stream == 0xff && *(stream+1) == 0xd9 )) //searching for the end of image marker
|
||||
{
|
||||
stream++;
|
||||
continue;
|
||||
}
|
||||
priv->stream_scan=stream;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int findSOI(struct jdec_private *priv,const unsigned char *stream)
|
||||
{
|
||||
while (!(*stream == 0xff && *(stream+1) == 0xd8 ) ) //searching for the start of image marker
|
||||
{
|
||||
if(stream<=priv->stream_end)
|
||||
{
|
||||
stream++;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
return 0; // No more images in the file.
|
||||
}
|
||||
priv->stream=stream+2;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int parse_JFIF(struct jdec_private *priv, const unsigned char *stream)
|
||||
{
|
||||
int chuck_len;
|
||||
int marker;
|
||||
int sos_marker_found = 0;
|
||||
int dht_marker_found = 0;
|
||||
int dqt_marker_found = 0;
|
||||
const unsigned char *next_chunck;
|
||||
|
||||
next_image_found = findSOI(priv,stream);
|
||||
stream=priv->stream;
|
||||
|
||||
while (!sos_marker_found && stream<=priv->stream_end)
|
||||
{
|
||||
while((*stream == 0xff))
|
||||
stream++;
|
||||
|
||||
marker = *stream++;
|
||||
chuck_len = be16_to_cpu(stream);
|
||||
next_chunck = stream + chuck_len;
|
||||
switch (marker)
|
||||
{
|
||||
case SOF:
|
||||
if (parse_SOF(priv, stream) < 0)
|
||||
return -1;
|
||||
break;
|
||||
case DQT:
|
||||
if (parse_DQT(priv, stream) < 0)
|
||||
return -1;
|
||||
dqt_marker_found = 1;
|
||||
break;
|
||||
case SOS:
|
||||
if (parse_SOS(priv, stream) < 0)
|
||||
return -1;
|
||||
sos_marker_found = 1;
|
||||
break;
|
||||
case DHT:
|
||||
if (parse_DHT(priv, stream) < 0)
|
||||
return -1;
|
||||
dht_marker_found = 1;
|
||||
break;
|
||||
case DRI:
|
||||
if (parse_DRI(priv, stream) < 0)
|
||||
return -1;
|
||||
break;
|
||||
default:
|
||||
trace("> Unknown marker %2.2x\n", marker);
|
||||
break;
|
||||
}
|
||||
|
||||
stream = next_chunck;
|
||||
}
|
||||
|
||||
if(next_image_found){
|
||||
if (!dht_marker_found) {
|
||||
trace("No Huffman table loaded, using the default one\n");
|
||||
build_default_huffman_tables(priv);
|
||||
}
|
||||
if (!dqt_marker_found) {
|
||||
error("ERROR:No Quantization table loaded, using the default one\n");
|
||||
}
|
||||
}
|
||||
#ifdef SANITY_CHECK
|
||||
if ( (priv->component_infos[cY].Hfactor < priv->component_infos[cCb].Hfactor)
|
||||
|| (priv->component_infos[cY].Hfactor < priv->component_infos[cCr].Hfactor))
|
||||
error("Horizontal sampling factor for Y should be greater than horitontal sampling factor for Cb or Cr\n");
|
||||
if ( (priv->component_infos[cY].Vfactor < priv->component_infos[cCb].Vfactor)
|
||||
|| (priv->component_infos[cY].Vfactor < priv->component_infos[cCr].Vfactor))
|
||||
error("Vertical sampling factor for Y should be greater than vertical sampling factor for Cb or Cr\n");
|
||||
if ( (priv->component_infos[cCb].Hfactor!=1)
|
||||
|| (priv->component_infos[cCr].Hfactor!=1)
|
||||
|| (priv->component_infos[cCb].Vfactor!=1)
|
||||
|| (priv->component_infos[cCr].Vfactor!=1))
|
||||
printf("ERROR:Sampling other than 1x1 for Cr and Cb is not supported");
|
||||
#endif
|
||||
findEOI(priv,stream);
|
||||
return next_image_found;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
*
|
||||
* Functions exported of the library.
|
||||
*
|
||||
* Note: Some applications can access directly to internal pointer of the
|
||||
* structure. It's is not recommended, but if you have many images to
|
||||
* uncompress with the same parameters, some functions can be called to speedup
|
||||
* the decoding.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* Allocate a new tinyjpeg decoder object.
|
||||
*
|
||||
* Before calling any other functions, an object need to be called.
|
||||
*/
|
||||
struct jdec_private *tinyjpeg_init(void)
|
||||
{
|
||||
struct jdec_private *priv;
|
||||
|
||||
priv = (struct jdec_private *)calloc(1, sizeof(struct jdec_private));
|
||||
if (priv == NULL)
|
||||
return NULL;
|
||||
return priv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Free a tinyjpeg object.
|
||||
*
|
||||
* No others function can be called after this one.
|
||||
*/
|
||||
void tinyjpeg_free(struct jdec_private *priv)
|
||||
{
|
||||
free(priv);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the tinyjpeg object and prepare the decoding of the stream.
|
||||
*
|
||||
* Check if the jpeg can be decoded with this jpeg decoder.
|
||||
* Fill some table used for preprocessing.
|
||||
*/
|
||||
int tinyjpeg_parse_header(struct jdec_private *priv, const unsigned char *buf, unsigned int size)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Identify the file */
|
||||
if ((buf[0] != 0xFF) || (buf[1] != SOI))
|
||||
error("Not a JPG file ?\n");
|
||||
|
||||
priv->stream_begin = buf;
|
||||
priv->stream_length = size;
|
||||
priv->stream_end = priv->stream_begin + priv->stream_length;
|
||||
|
||||
priv->stream = priv->stream_begin;
|
||||
ret = parse_JFIF(priv, priv->stream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int tinyjpeg_decode(struct jdec_private *priv)
|
||||
{
|
||||
#define CHECK_VASTATUS(va_status,func) \
|
||||
if (va_status != VA_STATUS_SUCCESS) { \
|
||||
fprintf(stderr,"%s:%s (%d) failed,exit\n", __func__, func, __LINE__); \
|
||||
exit(1); \
|
||||
}
|
||||
|
||||
VAEntrypoint entrypoints[5];
|
||||
int num_entrypoints,vld_entrypoint;
|
||||
VAConfigAttrib attrib;
|
||||
VAConfigID config_id;
|
||||
VASurfaceID surface_id;
|
||||
VAContextID context_id;
|
||||
VABufferID pic_param_buf,iqmatrix_buf,huffmantable_buf,slice_param_buf,slice_data_buf;
|
||||
int major_ver, minor_ver;
|
||||
VADisplay va_dpy;
|
||||
VAStatus va_status;
|
||||
int max_h_factor, max_v_factor;
|
||||
int putsurface=1;
|
||||
unsigned int i, j;
|
||||
|
||||
int surface_type;
|
||||
char *type;
|
||||
int ChromaTypeIndex;
|
||||
|
||||
VASurfaceAttrib forcc;
|
||||
forcc.type =VASurfaceAttribPixelFormat;
|
||||
forcc.flags=VA_SURFACE_ATTRIB_SETTABLE;
|
||||
forcc.value.type=VAGenericValueTypeInteger;
|
||||
|
||||
|
||||
va_dpy = va_open_display();
|
||||
va_status = vaInitialize(va_dpy, &major_ver, &minor_ver);
|
||||
assert(va_status == VA_STATUS_SUCCESS);
|
||||
|
||||
va_status = vaQueryConfigEntrypoints(va_dpy, VAProfileJPEGBaseline, entrypoints,
|
||||
&num_entrypoints);
|
||||
CHECK_VASTATUS(va_status, "vaQueryConfigEntrypoints");
|
||||
|
||||
for (vld_entrypoint = 0; vld_entrypoint < num_entrypoints; vld_entrypoint++) {
|
||||
if (entrypoints[vld_entrypoint] == VAEntrypointVLD)
|
||||
break;
|
||||
}
|
||||
if (vld_entrypoint == num_entrypoints) {
|
||||
/* not find VLD entry point */
|
||||
assert(0);
|
||||
}
|
||||
|
||||
/* Assuming finding VLD, find out the format for the render target */
|
||||
attrib.type = VAConfigAttribRTFormat;
|
||||
vaGetConfigAttributes(va_dpy, VAProfileJPEGBaseline, VAEntrypointVLD,
|
||||
&attrib, 1);
|
||||
if ((attrib.value & VA_RT_FORMAT_YUV420) == 0) {
|
||||
/* not find desired YUV420 RT format */
|
||||
assert(0);
|
||||
}
|
||||
|
||||
va_status = vaCreateConfig(va_dpy, VAProfileJPEGBaseline, VAEntrypointVLD,
|
||||
&attrib, 1,&config_id);
|
||||
CHECK_VASTATUS(va_status, "vaQueryConfigEntrypoints");
|
||||
|
||||
while (next_image_found){
|
||||
VAPictureParameterBufferJPEGBaseline pic_param;
|
||||
memset(&pic_param, 0, sizeof(pic_param));
|
||||
pic_param.picture_width = priv->width[scan_num];
|
||||
pic_param.picture_height = priv->height[scan_num];
|
||||
pic_param.num_components = priv->nf_components;
|
||||
|
||||
|
||||
for (i=0; i<pic_param.num_components; i++) { // tinyjpeg support 3 components only, does it match va?
|
||||
pic_param.components[i].component_id = priv->component_infos[i].cid;
|
||||
pic_param.components[i].h_sampling_factor = priv->component_infos[i].Hfactor;
|
||||
pic_param.components[i].v_sampling_factor = priv->component_infos[i].Vfactor;
|
||||
pic_param.components[i].quantiser_table_selector = priv->component_infos[i].quant_table_index;
|
||||
}
|
||||
int h1, h2, h3, v1, v2, v3;
|
||||
h1 = pic_param.components[0].h_sampling_factor;
|
||||
h2 = pic_param.components[1].h_sampling_factor;
|
||||
h3 = pic_param.components[2].h_sampling_factor;
|
||||
v1 = pic_param.components[0].v_sampling_factor;
|
||||
v2 = pic_param.components[1].v_sampling_factor;
|
||||
v3 = pic_param.components[2].v_sampling_factor;
|
||||
|
||||
if (h1 == 2 && h2 == 1 && h3 == 1 &&
|
||||
v1 == 2 && v2 == 1 && v3 == 1) {
|
||||
//surface_type = VA_RT_FORMAT_IMC3;
|
||||
surface_type = VA_RT_FORMAT_YUV420;
|
||||
forcc.value.value.i = VA_FOURCC_IMC3;
|
||||
ChromaTypeIndex = 1;
|
||||
type = "VA_FOURCC_IMC3";
|
||||
}
|
||||
else if (h1 == 2 && h2 == 1 && h3 == 1 &&
|
||||
v1 == 1 && v2 == 1 && v3 == 1) {
|
||||
//surface_type = VA_RT_FORMAT_YUV422H;
|
||||
surface_type = VA_RT_FORMAT_YUV422;
|
||||
forcc.value.value.i = VA_FOURCC_422H;
|
||||
ChromaTypeIndex = 2;
|
||||
type = "VA_FOURCC_422H";
|
||||
}
|
||||
else if (h1 == 1 && h2 == 1 && h3 == 1 &&
|
||||
v1 == 1 && v2 == 1 && v3 == 1) {
|
||||
surface_type = VA_RT_FORMAT_YUV444;
|
||||
forcc.value.value.i = VA_FOURCC_444P;
|
||||
//forcc.value.value.i = VA_FOURCC_RGBP;
|
||||
ChromaTypeIndex = 3;
|
||||
type = "VA_FOURCC_444P";
|
||||
}
|
||||
else if (h1 == 4 && h2 == 1 && h3 == 1 &&
|
||||
v1 == 1 && v2 == 1 && v3 == 1) {
|
||||
surface_type = VA_RT_FORMAT_YUV411;
|
||||
forcc.value.value.i = VA_FOURCC_411P;
|
||||
ChromaTypeIndex = 4;
|
||||
type = "VA_FOURCC_411P";
|
||||
}
|
||||
else if (h1 == 1 && h2 == 1 && h3 == 1 &&
|
||||
v1 == 2 && v2 == 1 && v3 == 1) {
|
||||
//surface_type = VA_RT_FORMAT_YUV422V;
|
||||
surface_type = VA_RT_FORMAT_YUV422;
|
||||
forcc.value.value.i = VA_FOURCC_422V;
|
||||
ChromaTypeIndex = 5;
|
||||
type = "VA_FOURCC_422V";
|
||||
}
|
||||
else if (h1 == 2 && h2 == 1 && h3 == 1 &&
|
||||
v1 == 2 && v2 == 2 && v3 == 2) {
|
||||
//surface_type = VA_RT_FORMAT_YUV422H;
|
||||
surface_type = VA_RT_FORMAT_YUV422;
|
||||
forcc.value.value.i = VA_FOURCC_422H;
|
||||
ChromaTypeIndex = 6;
|
||||
type = "VA_FOURCC_422H";
|
||||
}
|
||||
else if (h2 == 2 && h2 == 2 && h3 == 2 &&
|
||||
v1 == 2 && v2 == 1 && v3 == 1) {
|
||||
//surface_type = VA_RT_FORMAT_YUV422V;
|
||||
surface_type = VA_RT_FORMAT_YUV422;
|
||||
forcc.value.value.i = VA_FOURCC_422V;
|
||||
ChromaTypeIndex = 7;
|
||||
type = "VA_FOURCC_422V";
|
||||
}
|
||||
else
|
||||
{
|
||||
surface_type = VA_RT_FORMAT_YUV400;
|
||||
forcc.value.value.i = VA_FOURCC('Y','8','0','0');
|
||||
ChromaTypeIndex = 0;
|
||||
type = "Format_400P";
|
||||
}
|
||||
|
||||
va_status = vaCreateSurfaces(va_dpy,surface_type,
|
||||
priv->width[scan_num],priv->height[scan_num], //alignment?
|
||||
&surface_id, 1, &forcc, 1);
|
||||
CHECK_VASTATUS(va_status, "vaCreateSurfaces");
|
||||
|
||||
/* Create a context for this decode pipe */
|
||||
va_status = vaCreateContext(va_dpy, config_id,
|
||||
priv->width[scan_num], priv->height[scan_num], // alignment?
|
||||
VA_PROGRESSIVE,
|
||||
&surface_id,
|
||||
1,
|
||||
&context_id);
|
||||
CHECK_VASTATUS(va_status, "vaCreateContext");
|
||||
|
||||
va_status = vaCreateBuffer(va_dpy, context_id,
|
||||
VAPictureParameterBufferType, // VAPictureParameterBufferJPEGBaseline?
|
||||
sizeof(VAPictureParameterBufferJPEGBaseline),
|
||||
1, &pic_param,
|
||||
&pic_param_buf);
|
||||
CHECK_VASTATUS(va_status, "vaCreateBuffer");
|
||||
|
||||
VAIQMatrixBufferJPEGBaseline iq_matrix;
|
||||
const unsigned int num_quant_tables =
|
||||
MIN(COMPONENTS, ARRAY_ELEMS(iq_matrix.load_quantiser_table));
|
||||
// todo, only mask it if non-default quant matrix is used. do we need build default quant matrix?
|
||||
memset(&iq_matrix, 0, sizeof(VAIQMatrixBufferJPEGBaseline));
|
||||
for (i = 0; i < num_quant_tables; i++) {
|
||||
if (!priv->Q_tables_valid[i])
|
||||
continue;
|
||||
iq_matrix.load_quantiser_table[i] = 1;
|
||||
for (j = 0; j < 64; j++)
|
||||
iq_matrix.quantiser_table[i][j] = priv->Q_tables[i][j];
|
||||
}
|
||||
va_status = vaCreateBuffer(va_dpy, context_id,
|
||||
VAIQMatrixBufferType, // VAIQMatrixBufferJPEGBaseline?
|
||||
sizeof(VAIQMatrixBufferJPEGBaseline),
|
||||
1, &iq_matrix,
|
||||
&iqmatrix_buf );
|
||||
CHECK_VASTATUS(va_status, "vaCreateBuffer");
|
||||
|
||||
VAHuffmanTableBufferJPEGBaseline huffman_table;
|
||||
const unsigned int num_huffman_tables =
|
||||
MIN(COMPONENTS, ARRAY_ELEMS(huffman_table.load_huffman_table));
|
||||
memset(&huffman_table, 0, sizeof(VAHuffmanTableBufferJPEGBaseline));
|
||||
assert(sizeof(huffman_table.huffman_table[0].num_dc_codes) ==
|
||||
sizeof(priv->HTDC[0].bits));
|
||||
assert(sizeof(huffman_table.huffman_table[0].dc_values[0]) ==
|
||||
sizeof(priv->HTDC[0].values[0]));
|
||||
for (i = 0; i < num_huffman_tables; i++) {
|
||||
if (!priv->HTDC_valid[i] || !priv->HTAC_valid[i])
|
||||
continue;
|
||||
huffman_table.load_huffman_table[i] = 1;
|
||||
memcpy(huffman_table.huffman_table[i].num_dc_codes, priv->HTDC[i].bits,
|
||||
sizeof(huffman_table.huffman_table[i].num_dc_codes));
|
||||
memcpy(huffman_table.huffman_table[i].dc_values, priv->HTDC[i].values,
|
||||
sizeof(huffman_table.huffman_table[i].dc_values));
|
||||
memcpy(huffman_table.huffman_table[i].num_ac_codes, priv->HTAC[i].bits,
|
||||
sizeof(huffman_table.huffman_table[i].num_ac_codes));
|
||||
memcpy(huffman_table.huffman_table[i].ac_values, priv->HTAC[i].values,
|
||||
sizeof(huffman_table.huffman_table[i].ac_values));
|
||||
memset(huffman_table.huffman_table[i].pad, 0,
|
||||
sizeof(huffman_table.huffman_table[i].pad));
|
||||
}
|
||||
va_status = vaCreateBuffer(va_dpy, context_id,
|
||||
VAHuffmanTableBufferType, // VAHuffmanTableBufferJPEGBaseline?
|
||||
sizeof(VAHuffmanTableBufferJPEGBaseline),
|
||||
1, &huffman_table,
|
||||
&huffmantable_buf );
|
||||
CHECK_VASTATUS(va_status, "vaCreateBuffer");
|
||||
|
||||
// one slice for whole image?
|
||||
max_h_factor = priv->component_infos[0].Hfactor;
|
||||
max_v_factor = priv->component_infos[0].Vfactor;
|
||||
static VASliceParameterBufferJPEGBaseline slice_param;
|
||||
slice_param.slice_data_size = (priv->stream_scan - priv->stream);
|
||||
slice_param.slice_data_offset = 0;
|
||||
slice_param.slice_data_flag = VA_SLICE_DATA_FLAG_ALL;
|
||||
slice_param.slice_horizontal_position = 0;
|
||||
slice_param.slice_vertical_position = 0;
|
||||
slice_param.num_components = priv->cur_sos.nr_components;
|
||||
for (i = 0; i < slice_param.num_components; i++) {
|
||||
slice_param.components[i].component_selector = priv->cur_sos.components[i].component_id; /* FIXME: set to values specified in SOS */
|
||||
slice_param.components[i].dc_table_selector = priv->cur_sos.components[i].dc_selector; /* FIXME: set to values specified in SOS */
|
||||
slice_param.components[i].ac_table_selector = priv->cur_sos.components[i].ac_selector; /* FIXME: set to values specified in SOS */
|
||||
}
|
||||
slice_param.restart_interval = priv->restart_interval;
|
||||
slice_param.num_mcus = ((priv->width[scan_num]+max_h_factor*8-1)/(max_h_factor*8))*
|
||||
((priv->height[scan_num]+max_v_factor*8-1)/(max_v_factor*8)); // ?? 720/16?
|
||||
|
||||
va_status = vaCreateBuffer(va_dpy, context_id,
|
||||
VASliceParameterBufferType, // VASliceParameterBufferJPEGBaseline?
|
||||
sizeof(VASliceParameterBufferJPEGBaseline),
|
||||
1,
|
||||
&slice_param, &slice_param_buf);
|
||||
CHECK_VASTATUS(va_status, "vaCreateBuffer");
|
||||
|
||||
va_status = vaCreateBuffer(va_dpy, context_id,
|
||||
VASliceDataBufferType,
|
||||
priv->stream_scan - priv->stream,
|
||||
1,
|
||||
(void*)priv->stream, // jpeg_clip,
|
||||
&slice_data_buf);
|
||||
CHECK_VASTATUS(va_status, "vaCreateBuffer");
|
||||
|
||||
va_status = vaBeginPicture(va_dpy, context_id, surface_id);
|
||||
CHECK_VASTATUS(va_status, "vaBeginPicture");
|
||||
|
||||
va_status = vaRenderPicture(va_dpy,context_id, &pic_param_buf, 1);
|
||||
CHECK_VASTATUS(va_status, "vaRenderPicture");
|
||||
|
||||
va_status = vaRenderPicture(va_dpy,context_id, &iqmatrix_buf, 1);
|
||||
CHECK_VASTATUS(va_status, "vaRenderPicture");
|
||||
|
||||
va_status = vaRenderPicture(va_dpy,context_id, &huffmantable_buf, 1);
|
||||
CHECK_VASTATUS(va_status, "vaRenderPicture");
|
||||
|
||||
va_status = vaRenderPicture(va_dpy,context_id, &slice_param_buf, 1);
|
||||
CHECK_VASTATUS(va_status, "vaRenderPicture");
|
||||
|
||||
va_status = vaRenderPicture(va_dpy,context_id, &slice_data_buf, 1);
|
||||
CHECK_VASTATUS(va_status, "vaRenderPicture");
|
||||
|
||||
va_status = vaEndPicture(va_dpy,context_id);
|
||||
CHECK_VASTATUS(va_status, "vaEndPicture");
|
||||
|
||||
va_status = vaSyncSurface(va_dpy, surface_id);
|
||||
CHECK_VASTATUS(va_status, "vaSyncSurface");
|
||||
|
||||
if (putsurface) {
|
||||
VARectangle src_rect, dst_rect;
|
||||
|
||||
src_rect.x = 0;
|
||||
src_rect.y = 0;
|
||||
src_rect.width = priv->width[scan_num];
|
||||
src_rect.height = priv->height[scan_num];
|
||||
dst_rect = src_rect;
|
||||
|
||||
va_status = va_put_surface(va_dpy, surface_id, &src_rect, &dst_rect);
|
||||
CHECK_VASTATUS(va_status, "vaPutSurface");
|
||||
}
|
||||
scan_num++;
|
||||
|
||||
vaDestroySurfaces(va_dpy,&surface_id,1);
|
||||
vaDestroyConfig(va_dpy,config_id);
|
||||
vaDestroyContext(va_dpy,context_id);
|
||||
|
||||
parse_JFIF(priv,priv->stream);
|
||||
if(priv->width[scan_num] == 0 && priv->height[scan_num] == 0)
|
||||
break;
|
||||
}
|
||||
// va_close_display(va_dpy);
|
||||
vaTerminate(va_dpy);
|
||||
printf("press any key to exit23\n");
|
||||
getchar();
|
||||
return 0;
|
||||
}
|
||||
const char *tinyjpeg_get_errorstring(struct jdec_private *priv)
|
||||
{
|
||||
/* FIXME: the error string must be store in the context */
|
||||
priv = priv;
|
||||
return error_string;
|
||||
}
|
||||
void tinyjpeg_get_size(struct jdec_private *priv, unsigned int *width, unsigned int *height)
|
||||
{
|
||||
*width = priv->width[scan_num];
|
||||
*height = priv->height[scan_num];
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Small jpeg decoder library (header file)
|
||||
*
|
||||
* Copyright (c) 2006, Luc Saillard <luc@saillard.org>
|
||||
* Copyright (c) 2012 Intel Corporation.
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* - Neither the name of the author nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __JPEGDEC_H__
|
||||
#define __JPEGDEC_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct jdec_private;
|
||||
|
||||
/* Flags that can be set by any applications */
|
||||
#define TINYJPEG_FLAGS_MJPEG_TABLE (1<<1)
|
||||
|
||||
/* Format accepted in outout */
|
||||
enum tinyjpeg_fmt {
|
||||
TINYJPEG_FMT_GREY = 1,
|
||||
TINYJPEG_FMT_BGR24,
|
||||
TINYJPEG_FMT_RGB24,
|
||||
TINYJPEG_FMT_YUV420P,
|
||||
};
|
||||
|
||||
struct jdec_private *tinyjpeg_init(void);
|
||||
void tinyjpeg_free(struct jdec_private *priv);
|
||||
|
||||
int tinyjpeg_parse_header(struct jdec_private *priv, const unsigned char *buf, unsigned int size);
|
||||
int tinyjpeg_decode(struct jdec_private *priv);
|
||||
const char *tinyjpeg_get_errorstring(struct jdec_private *priv);
|
||||
void tinyjpeg_get_size(struct jdec_private *priv, unsigned int *width, unsigned int *height);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
# For test_01
|
||||
# =====================================================
|
||||
|
||||
LOCAL_PATH:= $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_SRC_FILES := \
|
||||
../common/va_display.c \
|
||||
../common/va_display_android.cpp \
|
||||
h264encode.c
|
||||
|
||||
LOCAL_CFLAGS += \
|
||||
-DANDROID
|
||||
|
||||
LOCAL_C_INCLUDES += \
|
||||
$(LOCAL_PATH)/../../va \
|
||||
$(LOCAL_PATH)/../common \
|
||||
$(TARGET_OUT_HEADERS)/libva
|
||||
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
LOCAL_MODULE := h264encode
|
||||
|
||||
LOCAL_SHARED_LIBRARIES := libva-android libva libdl libdrm libcutils libutils libgui libm
|
||||
|
||||
include $(BUILD_EXECUTABLE)
|
||||
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_SRC_FILES := \
|
||||
../common/va_display.c \
|
||||
../common/va_display_android.cpp \
|
||||
avcenc.c
|
||||
|
||||
LOCAL_CFLAGS += \
|
||||
-DANDROID
|
||||
|
||||
LOCAL_C_INCLUDES += \
|
||||
$(LOCAL_PATH)/../../va \
|
||||
$(LOCAL_PATH)/../common \
|
||||
$(TARGET_OUT_HEADERS)/libva
|
||||
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
LOCAL_MODULE := avcenc
|
||||
|
||||
LOCAL_SHARED_LIBRARIES := libva-android libva libdl libdrm libcutils libutils libgui
|
||||
|
||||
include $(BUILD_EXECUTABLE)
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
# Copyright (c) 2007 Intel Corporation. All Rights Reserved.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a
|
||||
# copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sub license, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice (including the
|
||||
# next paragraph) shall be included in all copies or substantial portions
|
||||
# of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
# IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
|
||||
# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
bin_PROGRAMS = avcenc mpeg2vaenc h264encode jpegenc
|
||||
noinst_PROGRAMS = svctenc
|
||||
|
||||
AM_CPPFLAGS = \
|
||||
-Wall \
|
||||
$(LIBVA_CFLAGS) \
|
||||
$(NULL)
|
||||
|
||||
h264encode_SOURCES = h264encode.c
|
||||
h264encode_CFLAGS = -I$(top_srcdir)/common -g
|
||||
h264encode_LDADD = \
|
||||
$(LIBVA_LIBS) \
|
||||
$(top_builddir)/common/libva-display.la \
|
||||
-lpthread -lm
|
||||
|
||||
avcenc_SOURCES = avcenc.c
|
||||
avcenc_CFLAGS = -I$(top_srcdir)/common -g
|
||||
avcenc_LDADD = \
|
||||
$(LIBVA_LIBS) \
|
||||
$(top_builddir)/common/libva-display.la \
|
||||
-lpthread
|
||||
|
||||
mpeg2vaenc_SOURCES = mpeg2vaenc.c
|
||||
mpeg2vaenc_CFLAGS = -I$(top_srcdir)/common
|
||||
mpeg2vaenc_LDADD = \
|
||||
$(LIBVA_LIBS) \
|
||||
$(top_builddir)/common/libva-display.la \
|
||||
-lpthread
|
||||
|
||||
jpegenc_SOURCES = jpegenc.c
|
||||
jpegenc_CFLAGS = -I$(top_srcdir)/common -g
|
||||
jpegenc_LDADD = \
|
||||
$(LIBVA_LIBS) \
|
||||
$(top_builddir)/common/libva-display.la \
|
||||
-lpthread
|
||||
|
||||
svctenc_SOURCES = svctenc.c
|
||||
svctenc_CFLAGS = -I$(top_srcdir)/common -g
|
||||
svctenc_LDADD = \
|
||||
$(LIBVA_LIBS) \
|
||||
$(top_builddir)/common/libva-display.la \
|
||||
-lpthread -lm
|
||||
|
||||
valgrind: $(bin_PROGRAMS) $(noinst_PROGRAMS)
|
||||
for a in $(bin_PROGRAMS) $(noinst_PROGRAMS); do \
|
||||
valgrind --leak-check=full --show-reachable=yes .libs/$$a; \
|
||||
done
|
||||
|
||||
EXTRA_DIST = \
|
||||
jpegenc_utils.h \
|
||||
$(NULL)
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,355 @@
|
|||
/*
|
||||
* Copyright (c) 2014 Intel Corporation. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sub license, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the
|
||||
* next paragraph) shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
|
||||
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
/*
|
||||
* This file is a utilities file which supports JPEG Encode process
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define MAX_JPEG_COMPONENTS 3 //only for Y, U and V
|
||||
#define JPEG_Y 0
|
||||
#define JPEG_U 1
|
||||
#define JPEG_V 2
|
||||
#define NUM_QUANT_ELEMENTS 64
|
||||
#define NUM_MAX_HUFFTABLE 2
|
||||
#define NUM_AC_RUN_SIZE_BITS 16
|
||||
#define NUM_AC_CODE_WORDS_HUFFVAL 162
|
||||
#define NUM_DC_RUN_SIZE_BITS 16
|
||||
#define NUM_DC_CODE_WORDS_HUFFVAL 12
|
||||
|
||||
#define BITSTREAM_ALLOCATE_STEPPING 4096
|
||||
|
||||
struct __bitstream {
|
||||
unsigned int *buffer;
|
||||
int bit_offset;
|
||||
int max_size_in_dword;
|
||||
};
|
||||
|
||||
typedef struct __bitstream bitstream;
|
||||
|
||||
static unsigned int
|
||||
swap32(unsigned int val)
|
||||
{
|
||||
unsigned char *pval = (unsigned char *)&val;
|
||||
|
||||
return ((pval[0] << 24) |
|
||||
(pval[1] << 16) |
|
||||
(pval[2] << 8) |
|
||||
(pval[3] << 0));
|
||||
}
|
||||
|
||||
static void
|
||||
bitstream_start(bitstream *bs)
|
||||
{
|
||||
bs->max_size_in_dword = BITSTREAM_ALLOCATE_STEPPING;
|
||||
bs->buffer = calloc(bs->max_size_in_dword * sizeof(int), 1);
|
||||
assert(bs->buffer);
|
||||
bs->bit_offset = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
bitstream_end(bitstream *bs)
|
||||
{
|
||||
int pos = (bs->bit_offset >> 5);
|
||||
int bit_offset = (bs->bit_offset & 0x1f);
|
||||
int bit_left = 32 - bit_offset;
|
||||
|
||||
if (bit_offset) {
|
||||
bs->buffer[pos] = swap32((bs->buffer[pos] << bit_left));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
bitstream_put_ui(bitstream *bs, unsigned int val, int size_in_bits)
|
||||
{
|
||||
int pos = (bs->bit_offset >> 5);
|
||||
int bit_offset = (bs->bit_offset & 0x1f);
|
||||
int bit_left = 32 - bit_offset;
|
||||
|
||||
if (!size_in_bits)
|
||||
return;
|
||||
|
||||
if (size_in_bits < 32)
|
||||
val &= ((1 << size_in_bits) - 1);
|
||||
|
||||
bs->bit_offset += size_in_bits;
|
||||
|
||||
if (bit_left > size_in_bits) {
|
||||
bs->buffer[pos] = (bs->buffer[pos] << size_in_bits | val);
|
||||
} else {
|
||||
size_in_bits -= bit_left;
|
||||
bs->buffer[pos] = (bs->buffer[pos] << bit_left) | (val >> size_in_bits);
|
||||
bs->buffer[pos] = swap32(bs->buffer[pos]);
|
||||
|
||||
if (pos + 1 == bs->max_size_in_dword) {
|
||||
bs->max_size_in_dword += BITSTREAM_ALLOCATE_STEPPING;
|
||||
bs->buffer = realloc(bs->buffer, bs->max_size_in_dword * sizeof(unsigned int));
|
||||
assert(bs->buffer);
|
||||
}
|
||||
|
||||
bs->buffer[pos + 1] = val;
|
||||
}
|
||||
}
|
||||
|
||||
//As per Jpeg Spec ISO/IEC 10918-1, below values are assigned
|
||||
enum jpeg_markers {
|
||||
|
||||
//Define JPEG markers as 0xFFXX if you are adding the value directly to the buffer
|
||||
//Else define marker as 0xXXFF if you are assigning the marker to a structure variable.
|
||||
//This is needed because of the little-endedness of the IA
|
||||
|
||||
SOI = 0xFFD8, //Start of Image
|
||||
EOI = 0xFFD9, //End of Image
|
||||
SOS = 0xFFDA, //Start of Scan
|
||||
DQT = 0xFFDB, //Define Quantization Table
|
||||
DRI = 0xFFDD, //Define restart interval
|
||||
RST0 = 0xFFD0, //Restart interval termination
|
||||
DHT = 0xFFC4, //Huffman table
|
||||
SOF0 = 0xFFC0, //Baseline DCT
|
||||
APP0 = 0xFFE0, //Application Segment
|
||||
COM = 0xFFFE //Comment segment
|
||||
};
|
||||
|
||||
typedef struct _JPEGFrameHeader {
|
||||
|
||||
uint16_t SOF; //Start of Frame Header
|
||||
uint16_t Lf; //Length of Frame Header
|
||||
uint8_t P; //Sample precision
|
||||
uint16_t Y; //Number of lines
|
||||
uint16_t X; //Number of samples per line
|
||||
uint8_t Nf; //Number of image components in frame
|
||||
|
||||
struct _JPEGComponent {
|
||||
uint8_t Ci; //Component identifier
|
||||
uint8_t Hi:4; //Horizontal sampling factor
|
||||
uint8_t Vi:4; //Vertical sampling factor
|
||||
uint8_t Tqi; //Quantization table destination selector
|
||||
} JPEGComponent[MAX_JPEG_COMPONENTS];
|
||||
|
||||
} JPEGFrameHeader;
|
||||
|
||||
|
||||
typedef struct _JPEGScanHeader {
|
||||
|
||||
uint16_t SOS; //Start of Scan
|
||||
uint16_t Ls; //Length of Scan
|
||||
uint8_t Ns; //Number of image components in the scan
|
||||
|
||||
struct _ScanComponent {
|
||||
uint8_t Csj; //Scan component selector
|
||||
uint8_t Tdj:4; //DC Entropy coding table destination selector(Tdj:4 bits)
|
||||
uint8_t Taj:4; //AC Entropy coding table destination selector(Taj:4 bits)
|
||||
} ScanComponent[MAX_JPEG_COMPONENTS];
|
||||
|
||||
uint8_t Ss; //Start of spectral or predictor selection, 0 for Baseline
|
||||
uint8_t Se; //End of spectral or predictor selection, 63 for Baseline
|
||||
uint8_t Ah:4; //Successive approximation bit position high, 0 for Baseline
|
||||
uint8_t Al:4; //Successive approximation bit position low, 0 for Baseline
|
||||
|
||||
} JPEGScanHeader;
|
||||
|
||||
|
||||
typedef struct _JPEGQuantSection {
|
||||
|
||||
uint16_t DQT; //Quantization table marker
|
||||
uint16_t Lq; //Length of Quantization table definition
|
||||
uint8_t Tq:4; //Quantization table destination identifier
|
||||
uint8_t Pq:4; //Quatization table precision. Should be 0 for 8-bit samples
|
||||
uint8_t Qk[NUM_QUANT_ELEMENTS]; //Quantization table elements
|
||||
|
||||
} JPEGQuantSection;
|
||||
|
||||
typedef struct _JPEGHuffSection {
|
||||
|
||||
uint16_t DHT; //Huffman table marker
|
||||
uint16_t Lh; //Huffman table definition length
|
||||
uint8_t Tc:4; //Table class- 0:DC, 1:AC
|
||||
uint8_t Th:4; //Huffman table destination identifier
|
||||
uint8_t Li[NUM_AC_RUN_SIZE_BITS]; //Number of Huffman codes of length i
|
||||
uint8_t Vij[NUM_AC_CODE_WORDS_HUFFVAL]; //Value associated with each Huffman code
|
||||
|
||||
} JPEGHuffSection;
|
||||
|
||||
|
||||
typedef struct _JPEGRestartSection {
|
||||
|
||||
uint16_t DRI; //Restart interval marker
|
||||
uint16_t Lr; //Legth of restart interval segment
|
||||
uint16_t Ri; //Restart interval
|
||||
|
||||
} JPEGRestartSection;
|
||||
|
||||
|
||||
typedef struct _JPEGCommentSection {
|
||||
|
||||
uint16_t COM; //Comment marker
|
||||
uint16_t Lc; //Comment segment length
|
||||
uint8_t Cmi; //Comment byte
|
||||
|
||||
} JPEGCommentSection;
|
||||
|
||||
|
||||
typedef struct _JPEGAppSection {
|
||||
|
||||
uint16_t APPn; //Application data marker
|
||||
uint16_t Lp; //Application data segment length
|
||||
uint8_t Api; //Application data byte
|
||||
|
||||
} JPEGAppSection;
|
||||
|
||||
//Luminance quantization table
|
||||
//Source: Jpeg Spec ISO/IEC 10918-1, Annex K, Table K.1
|
||||
uint8_t jpeg_luma_quant[NUM_QUANT_ELEMENTS] = {
|
||||
16, 11, 10, 16, 24, 40, 51, 61,
|
||||
12, 12, 14, 19, 26, 58, 60, 55,
|
||||
14, 13, 16, 24, 40, 57, 69, 56,
|
||||
14, 17, 22, 29, 51, 87, 80, 62,
|
||||
18, 22, 37, 56, 68, 109, 103, 77,
|
||||
24, 35, 55, 64, 81, 104, 113, 92,
|
||||
49, 64, 78, 87, 103, 121, 120, 101,
|
||||
72, 92, 95, 98, 112, 100, 103, 99
|
||||
};
|
||||
|
||||
//Luminance quantization table
|
||||
//Source: Jpeg Spec ISO/IEC 10918-1, Annex K, Table K.2
|
||||
uint8_t jpeg_chroma_quant[NUM_QUANT_ELEMENTS] = {
|
||||
17, 18, 24, 47, 99, 99, 99, 99,
|
||||
18, 21, 26, 66, 99, 99, 99, 99,
|
||||
24, 26, 56, 99, 99, 99, 99, 99,
|
||||
47, 66, 99, 99, 99, 99, 99, 99,
|
||||
99, 99, 99, 99, 99, 99, 99, 99,
|
||||
99, 99, 99, 99, 99, 99, 99, 99,
|
||||
99, 99, 99, 99, 99, 99, 99, 99,
|
||||
99, 99, 99, 99, 99, 99, 99, 99
|
||||
};
|
||||
|
||||
|
||||
//Zigzag scan order of the the Luma and Chroma components
|
||||
//Note: Jpeg Spec ISO/IEC 10918-1, Figure A.6 shows the zigzag order differently.
|
||||
//The Spec is trying to show the zigzag pattern with number positions. The below
|
||||
//table will use the patter shown by A.6 and map the postion of the elements in the array
|
||||
uint8_t jpeg_zigzag[] = {
|
||||
0, 1, 8, 16, 9, 2, 3, 10,
|
||||
17, 24, 32, 25, 18, 11, 4, 5,
|
||||
12, 19, 26, 33, 40, 48, 41, 34,
|
||||
27, 20, 13, 6, 7, 14, 21, 28,
|
||||
35, 42, 49, 56, 57, 50, 43, 36,
|
||||
29, 22, 15, 23, 30, 37, 44, 51,
|
||||
58, 59, 52, 45, 38, 31, 39, 46,
|
||||
53, 60, 61, 54, 47, 55, 62, 63
|
||||
};
|
||||
|
||||
|
||||
//Huffman table for Luminance DC Coefficients
|
||||
//Reference Jpeg Spec ISO/IEC 10918-1, K.3.3.1
|
||||
//K.3.3.1 is the summarized version of Table K.3
|
||||
uint8_t jpeg_hufftable_luma_dc[] = {
|
||||
//TcTh (Tc=0 since 0:DC, 1:AC; Th=0)
|
||||
0x00,
|
||||
//Li
|
||||
0x00, 0x01, 0x05, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
//Vi
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B
|
||||
};
|
||||
|
||||
//Huffman table for Chrominance DC Coefficients
|
||||
//Reference Jpeg Spec ISO/IEC 10918-1, K.3.3.1
|
||||
//K.3.3.1 is the summarized version of Table K.4
|
||||
uint8_t jpeg_hufftable_chroma_dc[] = {
|
||||
//TcTh (Tc=0 since 0:DC, 1:AC; Th=1)
|
||||
0x01,
|
||||
//Li
|
||||
0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
//Vi
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B
|
||||
};
|
||||
|
||||
|
||||
//Huffman table for Luminance AC Coefficients
|
||||
//Reference Jpeg Spec ISO/IEC 10918-1, K.3.3.2
|
||||
//K.3.3.2 is the summarized version of Table K.5
|
||||
uint8_t jpeg_hufftable_luma_ac[] = {
|
||||
//TcTh (Tc=1 since 0:DC, 1:AC; Th=0)
|
||||
0x10,
|
||||
//Li
|
||||
0x00, 0x02, 0x01, 0x03, 0x03, 0x02, 0x04, 0x03, 0x05, 0x05, 0x04, 0x04, 0x00, 0x00, 0x01, 0x7D,
|
||||
//Vi
|
||||
0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
|
||||
0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xA1, 0x08, 0x23, 0x42, 0xB1, 0xC1, 0x15, 0x52, 0xD1, 0xF0,
|
||||
0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0A, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x25, 0x26, 0x27, 0x28,
|
||||
0x29, 0x2A, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
|
||||
0x4A, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
|
||||
0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
|
||||
0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7,
|
||||
0xA8, 0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5,
|
||||
0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xE1, 0xE2,
|
||||
0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8,
|
||||
0xF9, 0xFA
|
||||
};
|
||||
|
||||
//Huffman table for Chrominance AC Coefficients
|
||||
//Reference Jpeg Spec ISO/IEC 10918-1, K.3.3.2
|
||||
//K.3.3.2 is the summarized version of Table K.6
|
||||
uint8_t jpeg_hufftable_chroma_ac[] = {
|
||||
//TcTh (Tc=1 since 0:DC, 1:AC; Th=1)
|
||||
0x11,
|
||||
//Li
|
||||
0x00, 0x02, 0x01, 0x02, 0x04, 0x04, 0x03, 0x04, 0x07, 0x05, 0x04, 0x04, 0x00, 0x01, 0x02, 0x77,
|
||||
//Vi
|
||||
0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
|
||||
0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, 0xA1, 0xB1, 0xC1, 0x09, 0x23, 0x33, 0x52, 0xF0,
|
||||
0x15, 0x62, 0x72, 0xD1, 0x0A, 0x16, 0x24, 0x34, 0xE1, 0x25, 0xF1, 0x17, 0x18, 0x19, 0x1A, 0x26,
|
||||
0x27, 0x28, 0x29, 0x2A, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
|
||||
0x49, 0x4A, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
|
||||
0x69, 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
|
||||
0x88, 0x89, 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0xA2, 0xA3, 0xA4, 0xA5,
|
||||
0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xC2, 0xC3,
|
||||
0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA,
|
||||
0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8,
|
||||
0xF9, 0xFA
|
||||
};
|
||||
|
||||
typedef struct _YUVComponentSpecs {
|
||||
//One of 0(I420)/1(NV12)/2(UYVY)/3(YUY2)/4(Y8)/5(RGBA)>
|
||||
unsigned int yuv_type;
|
||||
// One of VA_RT_FORMAT_YUV420, VA_RT_FORMAT_YUV422, VA_RT_FORMAT_YUV400, VA_RT_FORMAT_YUV444, VA_RT_FORMAT_RGB32
|
||||
unsigned int va_surface_format;
|
||||
//One of VA_FOURCC_I420, VA_FOURCC_NV12, VA_FOURCC_UYVY, VA_FOURCC_YUY2, VA_FOURCC_Y800, VA_FOURCC_444P, VA_FOURCC_RGBA
|
||||
unsigned int fourcc_val; //Using this field to evaluate the input file type.
|
||||
//no.of. components
|
||||
unsigned int num_components;
|
||||
//Y horizontal subsample
|
||||
unsigned int y_h_subsample;
|
||||
//Y vertical subsample
|
||||
unsigned int y_v_subsample;
|
||||
//U horizontal subsample
|
||||
unsigned int u_h_subsample;
|
||||
//U vertical subsample
|
||||
unsigned int u_v_subsample;
|
||||
//V horizontal subsample
|
||||
unsigned int v_h_subsample;
|
||||
//V vertical subsample
|
||||
unsigned int v_v_subsample;
|
||||
} YUVComponentSpecs;
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,42 @@
|
|||
# Copyright (c) 2007 Intel Corporation. All Rights Reserved.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a
|
||||
# copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sub license, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice (including the
|
||||
# next paragraph) shall be included in all copies or substantial portions
|
||||
# of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
# IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
|
||||
# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
bin_PROGRAMS = vainfo
|
||||
|
||||
vainfo_cflags = \
|
||||
-I$(top_srcdir)/common \
|
||||
$(LIBVA_CFLAGS) \
|
||||
-DLIBVA_VERSION_S="\"$(LIBVA_VERSION)\"" \
|
||||
$(NULL)
|
||||
|
||||
vainfo_libs = \
|
||||
$(LIBVA_LIBS) \
|
||||
$(top_builddir)/common/libva-display.la \
|
||||
$(NULL)
|
||||
|
||||
vainfo_SOURCES = vainfo.c
|
||||
noinst_HEADERS = $(source_h)
|
||||
vainfo_CFLAGS = $(vainfo_cflags)
|
||||
vainfo_LDADD = $(vainfo_libs)
|
||||
|
||||
valgrind: vainfo
|
||||
valgrind --leak-check=full --show-reachable=yes .libs/vainfo;
|
|
@ -0,0 +1,162 @@
|
|||
/*
|
||||
* Copyright (c) 2007 Intel Corporation. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sub license, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the
|
||||
* next paragraph) shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
|
||||
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "va_display.h"
|
||||
|
||||
#define CHECK_VASTATUS(va_status,func, ret) \
|
||||
if (va_status != VA_STATUS_SUCCESS) { \
|
||||
fprintf(stderr,"%s failed with error code %d (%s),exit\n",func, va_status, vaErrorStr(va_status)); \
|
||||
ret_val = ret; \
|
||||
goto error; \
|
||||
}
|
||||
|
||||
static char * profile_string(VAProfile profile)
|
||||
{
|
||||
switch (profile) {
|
||||
case VAProfileNone: return "VAProfileNone";
|
||||
case VAProfileMPEG2Simple: return "VAProfileMPEG2Simple";
|
||||
case VAProfileMPEG2Main: return "VAProfileMPEG2Main";
|
||||
case VAProfileMPEG4Simple: return "VAProfileMPEG4Simple";
|
||||
case VAProfileMPEG4AdvancedSimple: return "VAProfileMPEG4AdvancedSimple";
|
||||
case VAProfileMPEG4Main: return "VAProfileMPEG4Main";
|
||||
case VAProfileH264Baseline: return "VAProfileH264Baseline";
|
||||
case VAProfileH264Main: return "VAProfileH264Main";
|
||||
case VAProfileH264High: return "VAProfileH264High";
|
||||
case VAProfileVC1Simple: return "VAProfileVC1Simple";
|
||||
case VAProfileVC1Main: return "VAProfileVC1Main";
|
||||
case VAProfileVC1Advanced: return "VAProfileVC1Advanced";
|
||||
case VAProfileH263Baseline: return "VAProfileH263Baseline";
|
||||
case VAProfileH264ConstrainedBaseline: return "VAProfileH264ConstrainedBaseline";
|
||||
case VAProfileJPEGBaseline: return "VAProfileJPEGBaseline";
|
||||
case VAProfileVP8Version0_3: return "VAProfileVP8Version0_3";
|
||||
case VAProfileH264MultiviewHigh: return "VAProfileH264MultiviewHigh";
|
||||
case VAProfileH264StereoHigh: return "VAProfileH264StereoHigh";
|
||||
case VAProfileHEVCMain: return "VAProfileHEVCMain";
|
||||
case VAProfileHEVCMain10: return "VAProfileHEVCMain10";
|
||||
case VAProfileVP9Profile0: return "VAProfileVP9Profile0";
|
||||
case VAProfileVP9Profile1: return "VAProfileVP9Profile1";
|
||||
case VAProfileVP9Profile2: return "VAProfileVP9Profile2";
|
||||
case VAProfileVP9Profile3: return "VAProfileVP9Profile3";
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return "<unknown profile>";
|
||||
}
|
||||
|
||||
|
||||
static char * entrypoint_string(VAEntrypoint entrypoint)
|
||||
{
|
||||
switch (entrypoint) {
|
||||
case VAEntrypointVLD:return "VAEntrypointVLD";
|
||||
case VAEntrypointIZZ:return "VAEntrypointIZZ";
|
||||
case VAEntrypointIDCT:return "VAEntrypointIDCT";
|
||||
case VAEntrypointMoComp:return "VAEntrypointMoComp";
|
||||
case VAEntrypointDeblocking:return "VAEntrypointDeblocking";
|
||||
case VAEntrypointEncSlice:return "VAEntrypointEncSlice";
|
||||
case VAEntrypointEncPicture:return "VAEntrypointEncPicture";
|
||||
case VAEntrypointEncSliceLP:return "VAEntrypointEncSliceLP";
|
||||
case VAEntrypointVideoProc:return "VAEntrypointVideoProc";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return "<unknown entrypoint>";
|
||||
}
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
VADisplay va_dpy;
|
||||
VAStatus va_status;
|
||||
int major_version, minor_version;
|
||||
const char *driver;
|
||||
const char *name = strrchr(argv[0], '/');
|
||||
VAProfile profile, *profile_list = NULL;
|
||||
int num_profiles, max_num_profiles, i;
|
||||
VAEntrypoint entrypoint, entrypoints[10];
|
||||
int num_entrypoint;
|
||||
int ret_val = 0;
|
||||
|
||||
if (name)
|
||||
name++;
|
||||
else
|
||||
name = argv[0];
|
||||
|
||||
va_init_display_args(&argc, (char **)argv);
|
||||
|
||||
va_dpy = va_open_display();
|
||||
if (NULL == va_dpy)
|
||||
{
|
||||
fprintf(stderr, "%s: vaGetDisplay() failed\n", name);
|
||||
return 2;
|
||||
}
|
||||
|
||||
va_status = vaInitialize(va_dpy, &major_version, &minor_version);
|
||||
CHECK_VASTATUS(va_status, "vaInitialize", 3);
|
||||
|
||||
printf("%s: VA-API version: %d.%d (libva %s)\n",
|
||||
name, major_version, minor_version, LIBVA_VERSION_S);
|
||||
|
||||
driver = vaQueryVendorString(va_dpy);
|
||||
printf("%s: Driver version: %s\n", name, driver ? driver : "<unknown>");
|
||||
|
||||
printf("%s: Supported profile and entrypoints\n", name);
|
||||
max_num_profiles = vaMaxNumProfiles(va_dpy);
|
||||
profile_list = malloc(max_num_profiles * sizeof(VAProfile));
|
||||
|
||||
if (!profile_list) {
|
||||
printf("Failed to allocate memory for profile list\n");
|
||||
ret_val = 5;
|
||||
goto error;
|
||||
}
|
||||
|
||||
va_status = vaQueryConfigProfiles(va_dpy, profile_list, &num_profiles);
|
||||
CHECK_VASTATUS(va_status, "vaQueryConfigProfiles", 6);
|
||||
|
||||
for (i = 0; i < num_profiles; i++) {
|
||||
char *profile_str;
|
||||
|
||||
profile = profile_list[i];
|
||||
va_status = vaQueryConfigEntrypoints(va_dpy, profile, entrypoints,
|
||||
&num_entrypoint);
|
||||
if (va_status == VA_STATUS_ERROR_UNSUPPORTED_PROFILE)
|
||||
continue;
|
||||
|
||||
CHECK_VASTATUS(va_status, "vaQueryConfigEntrypoints", 4);
|
||||
|
||||
profile_str = profile_string(profile);
|
||||
for (entrypoint = 0; entrypoint < num_entrypoint; entrypoint++)
|
||||
printf(" %-32s: %s\n", profile_str, entrypoint_string(entrypoints[entrypoint]));
|
||||
}
|
||||
|
||||
error:
|
||||
free(profile_list);
|
||||
vaTerminate(va_dpy);
|
||||
va_close_display(va_dpy);
|
||||
|
||||
return ret_val;
|
||||
}
|
Loading…
Reference in New Issue