Skip to content

Commit

Permalink
vpp: add opencl based alpha blending
Browse files Browse the repository at this point in the history
it's just a bare-bone application to test all base class works.
it waiting for opencl kernels.
  • Loading branch information
xuguangxin committed Jan 10, 2016
1 parent 8bedf1f commit 9db518b
Show file tree
Hide file tree
Showing 7 changed files with 249 additions and 0 deletions.
13 changes: 13 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,15 @@ fi
AM_CONDITIONAL(BUILD_GET_MV,
[test "x$enable_getmv" = "xyes"])

dnl ocl blender
AC_ARG_ENABLE(oclblender,
[AC_HELP_STRING([--enable-oclblender],
[build with opencl based alpha blend support @<:@default=no@:>@])],
[], [enable_oclblender="no"])

AM_CONDITIONAL(BUILD_OCL_BLENDER,
[test "x$enable_oclblender" = "xyes"])


# dnl Doxygen
AC_ARG_ENABLE(docs,
Expand Down Expand Up @@ -434,11 +443,15 @@ AS_IF([test x$enable_h264enc = xyes], [ENCODERS="$ENCODERS h264"])
AS_IF([test x$enable_jpegenc = xyes], [ENCODERS="$ENCODERS jpeg"])
AS_IF([test x$enable_vp8enc = xyes], [ENCODERS="$ENCODERS vp8"])

VPPS=" scaler"
AS_IF([test x$enable_oclblender = xyes], [VPPS="$VPPS oclblender"])

AC_MSG_RESULT([
libyami - libyami_version
Build decoders ................... :$DECODERS
Build encoders ....................:$ENCODERS
Build vpps ........................:$VPPS
Build documentation .............. : $enable_docs
Enable debug ......................: $enable_debug
Installation prefix .............. : $prefix
Expand Down
1 change: 1 addition & 0 deletions interface/VideoCommonDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ typedef struct VideoFrame {
#define YAMI_MIME_VP9 "video/x-vnd.on2.vp9"
#define YAMI_MIME_JPEG "image/jpeg"
#define YAMI_VPP_SCALER "vpp/scaler"
#define YAMI_VPP_OCL_BLENDER "vpp/ocl_blender"

#ifdef __cplusplus
}
Expand Down
21 changes: 21 additions & 0 deletions vpp/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ libyami_vpp_source_c = \
vaapivpppicture.cpp \
$(NULL)

if BUILD_OCL_BLENDER
libyami_vpp_source_c += ../ocl/oclcontext.cpp
libyami_vpp_source_c += oclpostprocess_base.cpp
endif

if BUILD_OCL_BLENDER
libyami_vpp_source_c += oclpostprocess_blender.cpp
endif

libyami_vpp_source_h = \
../interface/VideoCommonDefs.h \
Expand All @@ -24,6 +32,15 @@ libyami_vpp_source_h_priv = \
vaapivpppicture.h \
$(NULL)

if BUILD_OCL_BLENDER
libyami_vpp_source_h_priv += ../ocl/oclcontext.h
libyami_vpp_source_h_priv += oclpostprocess_base.h
endif

if BUILD_OCL_BLENDER
libyami_vpp_source_h_priv += oclpostprocess_blender.h
endif

libyami_vpp_la_LIBADD = \
$(top_builddir)/common/libyami_common.la \
$(top_builddir)/vaapi/libyami_vaapi.la \
Expand All @@ -41,6 +58,10 @@ libyami_vpp_cppflags = \
$(LIBVA_DRM_CFLAGS) \
$(NULL)

if BUILD_OCL_BLENDER
libyami_vpp_ldflags += -lOpenCL
endif

lib_LTLIBRARIES = libyami_vpp.la
libyami_vppincludedir = $(includedir)/libyami_vpp
libyami_vppinclude_HEADERS = $(libyami_vpp_source_h)
Expand Down
67 changes: 67 additions & 0 deletions vpp/oclpostprocess_base.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* oclpostprocess_base.cpp - base class for opencl based vpp
*
* Copyright (C) 2015 Intel Corporation
* Author: Xu Guangxin <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "oclpostprocess_base.h"
#include "common/log.h"
#include "ocl/oclcontext.h"

namespace YamiMediaCodec{

OclPostProcessBase::OclPostProcessBase()
:m_kernel(0)
{
}

YamiStatus OclPostProcessBase::setNativeDisplay(const NativeDisplay& display)
{
if (display.type != NATIVE_DISPLAY_VA
|| !display.handle) {
ERROR("vpp only support va display as NativeDisplay");
return YAMI_INVALID_PARAM;
}
m_display = (VADisplay)display.handle;
return YAMI_SUCCESS;
}

YamiStatus OclPostProcessBase::ensureContext(const char* kernalName)
{
if (m_kernel)
return YAMI_SUCCESS;
m_context = OclContext::create();
if (!m_context || !m_context->createKernel(kernalName,m_kernel))
return YAMI_DRIVER_FAIL;
return YAMI_SUCCESS;
}

OclPostProcessBase::~OclPostProcessBase()
{
if (m_kernel) {
checkOclStatus(clReleaseKernel(m_kernel), "ReleaseKernel");
}
}

}

55 changes: 55 additions & 0 deletions vpp/oclpostprocess_base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* oclpostprocess_base.h- base class for opencl based video post process
*
* Copyright (C) 2015 Intel Corporation
* Author: XuGuangxin<[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/

#ifndef vaapipostprocess_base_h
#define vaapipostprocess_base_h

#include "VideoPostProcessInterface.h"
#include <CL/opencl.h>
#include <va/va.h>

namespace YamiMediaCodec{
class OclContext;
/**
* \class OclPostProcessBase
* \brief Abstract video post process base on opencl
*
*/
class OclPostProcessBase : public IVideoPostProcess {
public:
// set native display
virtual YamiStatus setNativeDisplay(const NativeDisplay& display);

YamiStatus ensureContext(const char* kernalName);
//
virtual YamiStatus process(const SharedPtr<VideoFrame>& src,
const SharedPtr<VideoFrame>& dest) = 0;
OclPostProcessBase();
virtual ~OclPostProcessBase();
protected:
VADisplay m_display;
cl_kernel m_kernel;
SharedPtr<OclContext> m_context;
};
}
#endif /* vaapipostprocess_base_h */

47 changes: 47 additions & 0 deletions vpp/oclpostprocess_blender.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* oclpostprocess_blend.cpp - ocl based alpha blending
*
* Copyright (C) 2015 Intel Corporation
* Author: XuGuangxin<[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "oclpostprocess_blender.h"
#include "vaapipostprocess_factory.h"
#include "common/log.h"

namespace YamiMediaCodec{


YamiStatus
OclPostProcessBlender::process(const SharedPtr<VideoFrame>& src,
const SharedPtr<VideoFrame>& dest)
{
YamiStatus status = ensureContext("blend");
if (status != YAMI_SUCCESS)
return status;
return YAMI_SUCCESS;
}

const bool OclPostProcessBlender::s_registered =
VaapiPostProcessFactory::register_<OclPostProcessBlender>(YAMI_VPP_OCL_BLENDER);

}

45 changes: 45 additions & 0 deletions vpp/oclpostprocess_blender.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* oclpostprocess_blend.h - ocl based alpha blending
*
* Copyright (C) 2015 Intel Corporation
* Author: XuGuangxin<[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#ifndef oclpostprocess_blender_h
#define oclpostprocess_blender_h


#include "interface/VideoCommonDefs.h"
#include "oclpostprocess_base.h"

namespace YamiMediaCodec{

/**
* \class OclPostProcessBlend
* \brief alpha blending base on opencl
*/
class OclPostProcessBlender : public OclPostProcessBase {
public:
virtual YamiStatus process(const SharedPtr<VideoFrame>& src,
const SharedPtr<VideoFrame>& dest);

private:
static const bool s_registered; // VaapiPostProcessFactory registration result
};

}
#endif //oclpostprocess_blend_h

0 comments on commit 9db518b

Please sign in to comment.