Home | History | Annotate | Download | only in src
      1 /*--------------------------------------------------------------------------
      2 Copyright (c) 2012, The Linux Foundation. All rights reserved.
      3 
      4 Redistribution and use in source and binary forms, with or without
      5 modification, are permitted provided that the following conditions are met:
      6     * Redistributions of source code must retain the above copyright
      7       notice, this list of conditions and the following disclaimer.
      8     * Redistributions in binary form must reproduce the above copyright
      9       notice, this list of conditions and the following disclaimer in the
     10       documentation and/or other materials provided with the distribution.
     11     * Neither the name of Code Aurora nor
     12       the names of its contributors may be used to endorse or promote
     13       products derived from this software without specific prior written
     14       permission.
     15 
     16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18 IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
     19 NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     20 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     21 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     22 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     23 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     24 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     25 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     26 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 --------------------------------------------------------------------------*/
     28 #include <utils/Log.h>
     29 #include <gralloc_priv.h>
     30 #include "vidc_color_converter.h"
     31 #undef DEBUG_PRINT_LOW
     32 #undef DEBUG_PRINT_HIGH
     33 #undef DEBUG_PRINT_ERROR
     34 
     35 #define DEBUG_PRINT_LOW ALOGV
     36 #define DEBUG_PRINT_HIGH ALOGE
     37 #define DEBUG_PRINT_ERROR ALOGE
     38 
     39 omx_c2d_conv::omx_c2d_conv()
     40 {
     41   c2dcc = NULL;
     42   mLibHandle = NULL;
     43   mConvertOpen = NULL;
     44   mConvertClose = NULL;
     45   src_format = NV12_2K;
     46 }
     47 
     48 bool omx_c2d_conv::init() {
     49   bool status = true;
     50   if(mLibHandle || mConvertOpen || mConvertClose) {
     51     DEBUG_PRINT_ERROR("\n omx_c2d_conv::init called twice");
     52     status = false;
     53   }
     54   if(status) {
     55     mLibHandle = dlopen("libc2dcolorconvert.so", RTLD_LAZY);
     56     if(mLibHandle){
     57        mConvertOpen = (createC2DColorConverter_t *)
     58        dlsym(mLibHandle,"createC2DColorConverter");
     59        mConvertClose = (destroyC2DColorConverter_t *)
     60        dlsym(mLibHandle,"destroyC2DColorConverter");
     61        if(!mConvertOpen || !mConvertClose)
     62          status = false;
     63     } else
     64       status = false;
     65   }
     66   if(!status && mLibHandle){
     67     dlclose(mLibHandle);
     68     mLibHandle = NULL;
     69     mConvertOpen = NULL;
     70     mConvertClose = NULL;
     71   }
     72   return status;
     73 }
     74 
     75 bool omx_c2d_conv::convert(int src_fd, void *src_viraddr,
     76      int dest_fd,void *dest_viraddr)
     77 {
     78   int result;
     79   if(!src_viraddr || !dest_viraddr || !c2dcc){
     80     DEBUG_PRINT_ERROR("\n Invalid arguments omx_c2d_conv::convert");
     81     return false;
     82   }
     83   result =  c2dcc->convertC2D(src_fd,src_viraddr,
     84                               dest_fd,dest_viraddr);
     85   DEBUG_PRINT_LOW("\n Color convert status %d",result);
     86   return ((result < 0)?false:true);
     87 }
     88 
     89 bool omx_c2d_conv::open(unsigned int height,unsigned int width,
     90      ColorConvertFormat src, ColorConvertFormat dest)
     91 {
     92   bool status = false;
     93   if(!c2dcc) {
     94      c2dcc = mConvertOpen(width, height, width, height,
     95              src,dest,0);
     96      if(c2dcc) {
     97        src_format = src;
     98        status = true;
     99      } else
    100        DEBUG_PRINT_ERROR("\n mConvertOpen failed");
    101   }
    102    return status;
    103 }
    104 void omx_c2d_conv::close()
    105 {
    106   if(mLibHandle) {
    107     if(mConvertClose && c2dcc)
    108      mConvertClose(c2dcc);
    109     c2dcc = NULL;
    110   }
    111 }
    112 
    113 void omx_c2d_conv::destroy()
    114 {
    115   DEBUG_PRINT_ERROR("\n Destroy C2D instance");
    116   if(mLibHandle) {
    117     if(mConvertClose && c2dcc)
    118       mConvertClose(c2dcc);
    119     dlclose(mLibHandle);
    120   }
    121   c2dcc = NULL;
    122   mLibHandle = NULL;
    123   mConvertOpen = NULL;
    124   mConvertClose = NULL;
    125 }
    126 omx_c2d_conv::~omx_c2d_conv()
    127 {
    128   destroy();
    129 }
    130 int omx_c2d_conv::get_src_format()
    131 {
    132   int format = -1;
    133   if(src_format == NV12_2K) {
    134     format = HAL_PIXEL_FORMAT_NV12_ENCODEABLE;
    135   } else if(src_format == RGBA8888) {
    136     format = HAL_PIXEL_FORMAT_RGBA_8888;
    137   }
    138   return format;
    139 }
    140 bool omx_c2d_conv::get_buffer_size(int port,unsigned int &buf_size)
    141 {
    142   int cret = 0;
    143   bool ret = false;
    144   C2DBuffReq bufferreq;
    145   if(c2dcc){
    146     bufferreq.size = 0;
    147     cret = c2dcc->getBuffReq(port,&bufferreq);
    148     DEBUG_PRINT_LOW("\n Status of getbuffer is %d", cret);
    149     ret = (cret)?false:true;
    150     buf_size = bufferreq.size;
    151   }
    152   return ret;
    153 }
    154