/* * Copyright Samsung Electronics Co.,LTD. * Copyright (C) 2011 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "SecJpegCodecHal.h" #define JPEG_ERROR_ALOG(fmt,...) #define NUM_PLANES (1) #define NUM_BUFFERS (1) SecJpegDecoderHal::SecJpegDecoderHal() { t_iJpegFd = -1; t_bFlagCreate = false; } SecJpegDecoderHal::~SecJpegDecoderHal() { if (t_bFlagCreate == true) { this->destroy(); } } int SecJpegDecoderHal::create(void) { if (t_bFlagCreate == true) { return ERROR_JPEG_DEVICE_ALREADY_CREATE; } int iRet = ERROR_NONE; t_iJpegFd = open(JPEG_DEC_NODE, O_RDWR, 0); if (t_iJpegFd < 0) { t_iJpegFd = -1; JPEG_ERROR_ALOG("[%s]: JPEG_DEC_NODE open failed", __func__); return ERROR_CANNOT_OPEN_JPEG_DEVICE; } if (t_iJpegFd <= 0) { t_iJpegFd = -1; JPEG_ERROR_ALOG("ERR(%s):JPEG device was closed\n", __func__); return ERROR_JPEG_DEVICE_ALREADY_CLOSED; } iRet = t_v4l2Querycap(t_iJpegFd); if (iRet < 0) { JPEG_ERROR_ALOG("[%s]: QUERYCAP failed", __func__); close(t_iJpegFd); return ERROR_CANNOT_OPEN_JPEG_DEVICE; } memset(&t_stJpegConfig, 0, sizeof(struct CONFIG)); memset(&t_stJpegInbuf, 0, sizeof(struct BUFFER)); memset(&t_stJpegOutbuf, 0, sizeof(struct BUFFER)); t_stJpegConfig.mode = MODE_DECODE; t_bFlagCreate = true; t_bFlagCreateInBuf = false; t_bFlagCreateOutBuf = false; t_bFlagExcute = false; t_iPlaneNum = 0; return ERROR_NONE; } int SecJpegDecoderHal::destroy(void) { if (t_bFlagCreate == false) { return ERROR_JPEG_DEVICE_ALREADY_DESTROY; } if (t_iJpegFd > 0) { struct BUF_INFO stBufInfo; int iRet = ERROR_NONE; if (t_bFlagExcute) { iRet = t_v4l2StreamOff(t_iJpegFd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE); } if (t_bFlagExcute) { stBufInfo.numOfPlanes = NUM_PLANES; stBufInfo.memory = V4L2_MEMORY_MMAP; stBufInfo.buf_type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; iRet = t_v4l2Reqbufs(t_iJpegFd, 0, &stBufInfo); stBufInfo.numOfPlanes = t_iPlaneNum; stBufInfo.buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; iRet = t_v4l2Reqbufs(t_iJpegFd, 0, &stBufInfo); } iRet = close(t_iJpegFd); if (iRet < 0) { JPEG_ERROR_ALOG("[%s:%d]: JPEG_DEC_NODE close failed", __func__, iRet); } } t_iJpegFd = -1; t_bFlagCreate = false; return ERROR_NONE; } int SecJpegDecoderHal::setSize(int iW, int iH) { if (t_bFlagCreate == false) { return ERROR_JPEG_DEVICE_NOT_CREATE_YET; } if (iW < 0 || MAX_JPG_WIDTH < iW) { return ERROR_INVALID_IMAGE_SIZE; } if (iH < 0 || MAX_JPG_HEIGHT < iH) { return ERROR_INVALID_IMAGE_SIZE; } t_stJpegConfig.width = iW; t_stJpegConfig.height = iH; return ERROR_NONE; } int SecJpegDecoderHal::setJpegConfig(void *pConfig) { if (t_bFlagCreate == false) { return ERROR_JPEG_DEVICE_NOT_CREATE_YET; } if (pConfig == NULL) { return ERROR_JPEG_CONFIG_POINTER_NULL; } memcpy(&t_stJpegConfig, pConfig, sizeof(struct CONFIG)); if (t_stJpegConfig.pix.dec_fmt.out_fmt == V4L2_PIX_FMT_NV12) { t_iPlaneNum = 2; } else { t_iPlaneNum = 1; } return ERROR_NONE; } void *SecJpegDecoderHal::getJpegConfig(void) { if (t_bFlagCreate == false) { return NULL; } return &t_stJpegConfig; } char *SecJpegDecoderHal::getInBuf(int *piInputSize) { if (t_bFlagCreate == false) { return NULL; } if (t_bFlagCreateInBuf == false) { *piInputSize = 0; return NULL; } *piInputSize = t_stJpegInbuf.size[0]; return (char *)(t_stJpegInbuf.addr[0]); } char **SecJpegDecoderHal::getOutBuf(int *piOutputSize) { if (t_bFlagCreate == false) { return NULL; } if (t_bFlagCreateOutBuf == false) { *piOutputSize = 0; return NULL; } for (int i=0;i