camera/QCamera2/HAL/QCameraPostProc.cpp
/*===========================================================================
 * FUNCTION   : processJpegEvt
 *
 * DESCRIPTION: process jpeg event from mm-jpeg-interface.
 *
 * PARAMETERS :
 *   @evt     : payload of jpeg event, including information about jpeg encoding
 *              status, jpeg size and so on.
 *
 * RETURN     : int32_t type of status
 *              NO_ERROR  -- success
 *              none-zero failure code
 *
 * NOTE       : This event will also trigger DataProc thread to move to next job
 *              processing (i.e., send a new jpeg encoding job to mm-jpeg-interface
 *              if there is any pending job in jpeg input queue)
 *==========================================================================*/
FUNCTION   : processJpegEvt
DESCRIPTION: process jpeg event from mm-jpeg-interface.

PARAMETERS :
@evt     : payload of jpeg event, including information about jpeg encoding
status, jpeg size and so on.

RETURN     : int32_t type of status
NO_ERROR  -- success
none-zero failure code

NOTE       : This event will also trigger DataProc thread to move to next job
processing
FUNCTION : processJpegEvt DESCRIPTION : process jpeg event from mm - jpeg - interface . PARAMETERS : @evt : payload of jpeg event including information about jpeg encoding status jpeg size and so on . RETURN : int32_t type of status NO_ERROR -- success none - zero failure code NOTE : This event will also trigger DataProc thread to move to next job processing
int32_t QCameraPostProcessor::processJpegEvt(qcamera_jpeg_evt_payload_t *evt)
{
    if (m_bInited == FALSE) {
        ALOGE("%s: postproc not initialized yet", __func__);
        return UNKNOWN_ERROR;
    }
    int32_t rc = NO_ERROR;
    camera_memory_t *jpeg_mem = NULL;
    omx_jpeg_ouput_buf_t *jpeg_out = NULL;
    if (mUseSaveProc && m_parent->isLongshotEnabled()) {
        qcamera_jpeg_evt_payload_t *saveData = ( qcamera_jpeg_evt_payload_t * ) malloc(sizeof(qcamera_jpeg_evt_payload_t));
        if ( NULL == saveData ) {
            ALOGE("%s: Can not allocate save data message!", __func__);
            return NO_MEMORY;
        }
        *saveData = *evt;
        m_inputSaveQ.enqueue((void *) saveData);
        m_saveProcTh.sendCmd(CAMERA_CMD_TYPE_DO_NEXT_JOB, FALSE, FALSE);
    } else {
        m_ongoingJpegQ.flushNodes(matchJobId, (void*)&evt->jobId);
        if (m_inputPPQ.getCurrentSize() > 0) {
            m_dataProcTh.sendCmd(CAMERA_CMD_TYPE_DO_NEXT_JOB, FALSE, FALSE);
        }
        CDBG_HIGH("[KPI Perf] %s : jpeg job %d", __func__, evt->jobId);
        if ((false == m_parent->m_bIntEvtPending) &&
            (m_parent->mDataCb == NULL ||
            m_parent->msgTypeEnabledWithLock(CAMERA_MSG_COMPRESSED_IMAGE) == 0 )) {
            CDBG_HIGH("%s: No dataCB or CAMERA_MSG_COMPRESSED_IMAGE not enabled",
                  __func__);
            rc = NO_ERROR;
            goto end;
        }
        if(evt->status == JPEG_JOB_STATUS_ERROR) {
            ALOGE("%s: Error event handled from jpeg, status = %d",
                  __func__, evt->status);
            rc = FAILED_TRANSACTION;
            goto end;
        }
        if (!mJpegMemOpt) {
            m_parent->dumpJpegToFile(evt->out_data.buf_vaddr,
                                      evt->out_data.buf_filled_len,
                                      evt->jobId);
        }
        else {
            jpeg_out  = (omx_jpeg_ouput_buf_t*) evt->out_data.buf_vaddr;
            if (jpeg_out != NULL) {
                jpeg_mem = (camera_memory_t *)jpeg_out->mem_hdl;
                if (jpeg_mem != NULL) {
                    m_parent->dumpJpegToFile(jpeg_mem->data,
                                              evt->out_data.buf_filled_len,
                                              evt->jobId);
                    jpeg_mem = NULL;
                }
                jpeg_out = NULL;
            }
        }
        if(true == m_parent->m_bIntEvtPending) {
          pthread_mutex_lock(&m_parent->m_int_lock);
          pthread_cond_signal(&m_parent->m_int_cond);
          pthread_mutex_unlock(&m_parent->m_int_lock);
          m_dataProcTh.sendCmd(CAMERA_CMD_TYPE_DO_NEXT_JOB, FALSE, FALSE);
          return rc;
        }
        m_parent->setOutputImageCount(m_parent->getOutputImageCount() + 1);
        if ((m_parent->mParameters.isMTFRefocus())
                && (m_parent->getOutputImageCount() <
                m_parent->mParameters.MTFOutputCount())) {
            jpeg_out  = (omx_jpeg_ouput_buf_t*) evt->out_data.buf_vaddr;
            if (jpeg_out != NULL) {
                jpeg_mem = (camera_memory_t *)jpeg_out->mem_hdl;
            }
            if (NULL != jpeg_mem) {
                jpeg_mem->release(jpeg_mem);
                jpeg_mem = NULL;
            }
            goto end;
        }
        if (!mJpegMemOpt) {
            jpeg_mem = m_parent->mGetMemory(-1, evt->out_data.buf_filled_len,
                1, m_parent->mCallbackCookie);
            if (NULL == jpeg_mem) {
                rc = NO_MEMORY;
                ALOGE("%s : getMemory for jpeg, ret = NO_MEMORY", __func__);
                goto end;
            }
            memcpy(jpeg_mem->data, evt->out_data.buf_vaddr, evt->out_data.buf_filled_len);
        } else {
            jpeg_out  = (omx_jpeg_ouput_buf_t*) evt->out_data.buf_vaddr;
            if (jpeg_out != NULL) {
                jpeg_mem = (camera_memory_t *)jpeg_out->mem_hdl;
            }
        }
        CDBG_HIGH("%s : Calling upperlayer callback to store JPEG image", __func__);
        qcamera_release_data_t release_data;
        memset(&release_data, 0, sizeof(qcamera_release_data_t));
        release_data.data = jpeg_mem;
        CDBG_HIGH("[KPI Perf] %s: PROFILE_JPEG_CB ",__func__);
        rc = sendDataNotify(CAMERA_MSG_COMPRESSED_IMAGE,
                            jpeg_mem,
                            0,
                            NULL,
                            &release_data);
end:
        if (rc != NO_ERROR) {
            sendEvtNotify(CAMERA_MSG_ERROR,
                          UNKNOWN_ERROR,
                          0);
            if (NULL != jpeg_mem) {
                jpeg_mem->release(jpeg_mem);
                jpeg_mem = NULL;
            }
        }
        if ((m_parent->mParameters.isUbiRefocus() &&
                ((m_parent->getOutputImageCount() + 1) ==
                m_parent->mParameters.UfOutputCount()))) {
            m_parent->setOutputImageCount(m_parent->getOutputImageCount() + 1);
            jpeg_mem = m_DataMem;
            release_data.data = jpeg_mem;
            CDBG_HIGH("[KPI Perf] %s: send jpeg callback for depthmap ",__func__);
            rc = sendDataNotify(CAMERA_MSG_COMPRESSED_IMAGE,
                    jpeg_mem,
                    0,
                    NULL,
                    &release_data);
            if (rc != NO_ERROR) {
                sendEvtNotify(CAMERA_MSG_ERROR,
                        UNKNOWN_ERROR,
                        0);
                if (NULL != jpeg_mem) {
                    jpeg_mem->release(jpeg_mem);
                    jpeg_mem = NULL;
                }
            }
            m_DataMem = NULL;
        }
    }
    m_dataProcTh.sendCmd(CAMERA_CMD_TYPE_DO_NEXT_JOB, FALSE, FALSE);
    return rc;
}
int32_t QCameraPostProcessor :: processJpegEvt ( qcamera_jpeg_evt_payload_t * evt ) { if ( m_bInited == FALSE ) { ALOGE ( " " , __func__ ) ; return UNKNOWN_ERROR ; } int32_t rc = NO_ERROR ; camera_memory_t * jpeg_mem = NULL ; omx_jpeg_ouput_buf_t * jpeg_out = NULL ; if ( mUseSaveProc && m_parent -> isLongshotEnabled ( ) ) { qcamera_jpeg_evt_payload_t * saveData = ( qcamera_jpeg_evt_payload_t * ) malloc ( sizeof ( qcamera_jpeg_evt_payload_t ) ) ; if ( NULL == saveData ) { ALOGE ( " " , __func__ ) ; return NO_MEMORY ; } * saveData = * evt ; m_inputSaveQ . enqueue ( ( void * ) saveData ) ; m_saveProcTh . sendCmd ( CAMERA_CMD_TYPE_DO_NEXT_JOB , FALSE , FALSE ) ; } else { m_ongoingJpegQ . flushNodes ( matchJobId , ( void * ) & evt -> jobId ) ; if ( m_inputPPQ . getCurrentSize ( ) > 0 ) { m_dataProcTh . sendCmd ( CAMERA_CMD_TYPE_DO_NEXT_JOB , FALSE , FALSE ) ; } CDBG_HIGH ( " " , __func__ , evt -> jobId ) ; if ( ( false == m_parent -> m_bIntEvtPending ) && ( m_parent -> mDataCb == NULL || m_parent -> msgTypeEnabledWithLock ( CAMERA_MSG_COMPRESSED_IMAGE ) == 0 ) ) { CDBG_HIGH ( " " , __func__ ) ; rc = NO_ERROR ; goto end ; } if ( evt -> status == JPEG_JOB_STATUS_ERROR ) { ALOGE ( " " , __func__ , evt -> status ) ; rc = FAILED_TRANSACTION ; goto end ; } if ( ! mJpegMemOpt ) { m_parent -> dumpJpegToFile ( evt -> out_data . buf_vaddr , evt -> out_data . buf_filled_len , evt -> jobId ) ; } else { jpeg_out = ( omx_jpeg_ouput_buf_t * ) evt -> out_data . buf_vaddr ; if ( jpeg_out != NULL ) { jpeg_mem = ( camera_memory_t * ) jpeg_out -> mem_hdl ; if ( jpeg_mem != NULL ) { m_parent -> dumpJpegToFile ( jpeg_mem -> data , evt -> out_data . buf_filled_len , evt -> jobId ) ; jpeg_mem = NULL ; } jpeg_out = NULL ; } } if ( true == m_parent -> m_bIntEvtPending ) { pthread_mutex_lock ( & m_parent -> m_int_lock ) ; pthread_cond_signal ( & m_parent -> m_int_cond ) ; pthread_mutex_unlock ( & m_parent -> m_int_lock ) ; m_dataProcTh . sendCmd ( CAMERA_CMD_TYPE_DO_NEXT_JOB , FALSE , FALSE ) ; return rc ; } m_parent -> setOutputImageCount ( m_parent -> getOutputImageCount ( ) + 1 ) ; if ( ( m_parent -> mParameters . isMTFRefocus ( ) ) && ( m_parent -> getOutputImageCount ( ) < m_parent -> mParameters . MTFOutputCount ( ) ) ) { jpeg_out = ( omx_jpeg_ouput_buf_t * ) evt -> out_data . buf_vaddr ; if ( jpeg_out != NULL ) { jpeg_mem = ( camera_memory_t * ) jpeg_out -> mem_hdl ; } if ( NULL != jpeg_mem ) { jpeg_mem -> release ( jpeg_mem ) ; jpeg_mem = NULL ; } goto end ; } if ( ! mJpegMemOpt ) { jpeg_mem = m_parent -> mGetMemory ( -1 , evt -> out_data . buf_filled_len , 1 , m_parent -> mCallbackCookie ) ; if ( NULL == jpeg_mem ) { rc = NO_MEMORY ; ALOGE ( " " , __func__ ) ; goto end ; } memcpy ( jpeg_mem -> data , evt -> out_data . buf_vaddr , evt -> out_data . buf_filled_len ) ; } else { jpeg_out = ( omx_jpeg_ouput_buf_t * ) evt -> out_data . buf_vaddr ; if ( jpeg_out != NULL ) { jpeg_mem = ( camera_memory_t * ) jpeg_out -> mem_hdl ; } } CDBG_HIGH ( " " , __func__ ) ; qcamera_release_data_t release_data ; memset ( & release_data , 0 , sizeof ( qcamera_release_data_t ) ) ; release_data . data = jpeg_mem ; CDBG_HIGH ( " " , __func__ ) ; rc = sendDataNotify ( CAMERA_MSG_COMPRESSED_IMAGE , jpeg_mem , 0 , NULL , & release_data ) ; end : if ( rc != NO_ERROR ) { sendEvtNotify ( CAMERA_MSG_ERROR , UNKNOWN_ERROR , 0 ) ; if ( NULL != jpeg_mem ) { jpeg_mem -> release ( jpeg_mem ) ; jpeg_mem = NULL ; } } if ( ( m_parent -> mParameters . isUbiRefocus ( ) && ( ( m_parent -> getOutputImageCount ( ) + 1 ) == m_parent -> mParameters . UfOutputCount ( ) ) ) ) { m_parent -> setOutputImageCount ( m_parent -> getOutputImageCount ( ) + 1 ) ; jpeg_mem = m_DataMem ; release_data . data = jpeg_mem ; CDBG_HIGH ( " " , __func__ ) ; rc = sendDataNotify ( CAMERA_MSG_COMPRESSED_IMAGE , jpeg_mem , 0 , NULL , & release_data ) ; if ( rc != NO_ERROR ) { sendEvtNotify ( CAMERA_MSG_ERROR , UNKNOWN_ERROR , 0 ) ; if ( NULL != jpeg_mem ) { jpeg_mem -> release ( jpeg_mem ) ; jpeg_mem = NULL ; } } m_DataMem = NULL ; } } m_dataProcTh . sendCmd ( CAMERA_CMD_TYPE_DO_NEXT_JOB , FALSE , FALSE ) ; return rc ; }
FUNCTION   : processJpegEvt
 DESCRIPTION: process jpeg event from mm-jpeg-interface.
FUNCTION : processJpegEvt DESCRIPTION : process jpeg event from mm - jpeg - interface .
// Release jpeg job data //signal the eztune condition variable /* check if the all the captures are done */ // alloc jpeg memory to pass to upper layer // send error msg to upper layer /* check whether to send callback for depth map */ // send error msg to upper layer // wait up data proc thread to do next job, // if previous request is blocked due to ongoing jpeg job