camera/QCamera2/HAL/QCameraPostProc.cpp
/*===========================================================================
 * FUNCTION   : start
 *
 * DESCRIPTION: start postprocessor. Data process thread and data notify thread
 *              will be launched.
 *
 * PARAMETERS :
 *   @pSrcChannel : source channel obj ptr that possibly needs reprocess
 *
 * RETURN     : int32_t type of status
 *              NO_ERROR  -- success
 *              none-zero failure code
 *
 * NOTE       : if any reprocess is needed, a reprocess channel/stream
 *              will be started.
 *==========================================================================*/
FUNCTION   : start
DESCRIPTION: start postprocessor. Data process thread and data notify thread
will be launched.

PARAMETERS :
@pSrcChannel : source channel obj ptr that possibly needs reprocess

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

NOTE       : if any reprocess is needed, a reprocess channel/stream
will be started.
FUNCTION : start DESCRIPTION : start postprocessor . Data process thread and data notify thread will be launched . PARAMETERS : @pSrcChannel : source channel obj ptr that possibly needs reprocess RETURN : int32_t type of status NO_ERROR -- success none - zero failure code NOTE : if any reprocess is needed a reprocess channel / stream will be started .
int32_t QCameraPostProcessor::start(QCameraChannel *pSrcChannel)
{
    char prop[PROPERTY_VALUE_MAX];
    int32_t rc = NO_ERROR;
    if (m_bInited == FALSE) {
        ALOGE("%s: postproc not initialized yet", __func__);
        return UNKNOWN_ERROR;
    }
    if (m_parent->needReprocess()) {
        if (m_pReprocChannel != NULL) {
            delete m_pReprocChannel;
            m_pReprocChannel = NULL;
        }
        m_pReprocChannel = m_parent->addReprocChannel(pSrcChannel);
        if (m_pReprocChannel == NULL) {
            ALOGE("%s: cannot add reprocess channel", __func__);
            return UNKNOWN_ERROR;
        }
        QCameraStream *pStream = NULL;
        for (uint8_t i = 0; i < m_pReprocChannel->getNumOfStreams(); i++) {
            pStream = m_pReprocChannel->getStreamByIndex(i);
            if (pStream->isTypeOf(CAM_STREAM_TYPE_OFFLINE_PROC)) {
                m_reprocStream = pStream;
                break;
            }
        }
        rc = m_pReprocChannel->start();
        if (rc != 0) {
            ALOGE("%s: cannot start reprocess channel", __func__);
            delete m_pReprocChannel;
            m_pReprocChannel = NULL;
            return rc;
        }
    }
    if (m_pReprocChannel && m_parent->needDualReprocess()) {
        if (m_pDualReprocChannel != NULL) {
            delete m_pDualReprocChannel;
            m_pDualReprocChannel = NULL;
        }
        m_pDualReprocChannel = m_parent->addDualReprocChannel(m_pReprocChannel);
        if (m_pDualReprocChannel == NULL) {
            ALOGE("%s: cannot add second reprocess channel", __func__);
            return UNKNOWN_ERROR;
        }
        rc = m_pDualReprocChannel->start();
        if (rc != 0) {
            ALOGE("%s: cannot start second reprocess channel", __func__);
            delete m_pDualReprocChannel;
            m_pDualReprocChannel = NULL;
            return rc;
        }
    }
    property_get("persist.camera.longshot.save", prop, "0");
    mUseSaveProc = atoi(prop) > 0 ? true : false;
    m_dataProcTh.sendCmd(CAMERA_CMD_TYPE_START_DATA_PROC, TRUE, FALSE);
    m_parent->m_cbNotifier.startSnapshots();
    mMultipleStages = false;
    if ( !m_parent->mParameters.getRecordingHintValue() &&
            !m_parent->isLongshotEnabled() &&
            !m_parent->isZSLMode()) {
        QCameraChannel *pChannel = NULL;
        pChannel = m_parent->needReprocess() ? m_pReprocChannel : pSrcChannel;
        QCameraStream *pSnapshotStream = NULL;
        QCameraStream *pThumbStream = NULL;
        for (uint32_t i = 0; i < pChannel->getNumOfStreams(); ++i) {
            QCameraStream *pStream = pChannel->getStreamByIndex(i);
            if ( NULL == pStream ) {
                break;
            }
            if (pStream->isTypeOf(CAM_STREAM_TYPE_SNAPSHOT) ||
                    pStream->isOrignalTypeOf(CAM_STREAM_TYPE_SNAPSHOT)) {
                pSnapshotStream = pStream;
            }
            if (pStream->isTypeOf(CAM_STREAM_TYPE_POSTVIEW) ||
                    pStream->isOrignalTypeOf(CAM_STREAM_TYPE_POSTVIEW)) {
                pThumbStream = pStream;
            }
        }
        if ((NULL == pThumbStream) && (pChannel == m_pReprocChannel)) {
            for (uint32_t i = 0; i < pSrcChannel->getNumOfStreams(); ++i) {
                QCameraStream *pStream = pSrcChannel->getStreamByIndex(i);
                if ( NULL == pStream ) {
                    break;
                }
                if (pStream->isTypeOf(CAM_STREAM_TYPE_POSTVIEW) ||
                        pStream->isOrignalTypeOf(CAM_STREAM_TYPE_POSTVIEW)) {
                    pThumbStream = pStream;
                }
            }
        }
        if ( NULL != pSnapshotStream ) {
            mm_jpeg_encode_params_t encodeParam;
            memset(&encodeParam, 0, sizeof(mm_jpeg_encode_params_t));
            rc = getJpegEncodingConfig(encodeParam, pSnapshotStream, pThumbStream);
            if (rc != NO_ERROR) {
                ALOGE("%s: error getting encoding config", __func__);
                return rc;
            }
            CDBG_HIGH("[KPI Perf] %s : call jpeg create_session", __func__);
            rc = mJpegHandle.create_session(mJpegClientHandle,
                    &encodeParam,
                    &mJpegSessionId);
            if (rc != NO_ERROR) {
                ALOGE("%s: error creating a new jpeg encoding session", __func__);
                return rc;
            }
            mNewJpegSessionNeeded = false;
        }
    }
    return rc;
}
int32_t QCameraPostProcessor :: start ( QCameraChannel * pSrcChannel ) { char prop [ PROPERTY_VALUE_MAX ] ; int32_t rc = NO_ERROR ; if ( m_bInited == FALSE ) { ALOGE ( " " , __func__ ) ; return UNKNOWN_ERROR ; } if ( m_parent -> needReprocess ( ) ) { if ( m_pReprocChannel != NULL ) { delete m_pReprocChannel ; m_pReprocChannel = NULL ; } m_pReprocChannel = m_parent -> addReprocChannel ( pSrcChannel ) ; if ( m_pReprocChannel == NULL ) { ALOGE ( " " , __func__ ) ; return UNKNOWN_ERROR ; } QCameraStream * pStream = NULL ; for ( uint8_t i = 0 ; i < m_pReprocChannel -> getNumOfStreams ( ) ; i ++ ) { pStream = m_pReprocChannel -> getStreamByIndex ( i ) ; if ( pStream -> isTypeOf ( CAM_STREAM_TYPE_OFFLINE_PROC ) ) { m_reprocStream = pStream ; break ; } } rc = m_pReprocChannel -> start ( ) ; if ( rc != 0 ) { ALOGE ( " " , __func__ ) ; delete m_pReprocChannel ; m_pReprocChannel = NULL ; return rc ; } } if ( m_pReprocChannel && m_parent -> needDualReprocess ( ) ) { if ( m_pDualReprocChannel != NULL ) { delete m_pDualReprocChannel ; m_pDualReprocChannel = NULL ; } m_pDualReprocChannel = m_parent -> addDualReprocChannel ( m_pReprocChannel ) ; if ( m_pDualReprocChannel == NULL ) { ALOGE ( " " , __func__ ) ; return UNKNOWN_ERROR ; } rc = m_pDualReprocChannel -> start ( ) ; if ( rc != 0 ) { ALOGE ( " " , __func__ ) ; delete m_pDualReprocChannel ; m_pDualReprocChannel = NULL ; return rc ; } } property_get ( " " , prop , " " ) ; mUseSaveProc = atoi ( prop ) > 0 ? true : false ; m_dataProcTh . sendCmd ( CAMERA_CMD_TYPE_START_DATA_PROC , TRUE , FALSE ) ; m_parent -> m_cbNotifier . startSnapshots ( ) ; mMultipleStages = false ; if ( ! m_parent -> mParameters . getRecordingHintValue ( ) && ! m_parent -> isLongshotEnabled ( ) && ! m_parent -> isZSLMode ( ) ) { QCameraChannel * pChannel = NULL ; pChannel = m_parent -> needReprocess ( ) ? m_pReprocChannel : pSrcChannel ; QCameraStream * pSnapshotStream = NULL ; QCameraStream * pThumbStream = NULL ; for ( uint32_t i = 0 ; i < pChannel -> getNumOfStreams ( ) ; ++ i ) { QCameraStream * pStream = pChannel -> getStreamByIndex ( i ) ; if ( NULL == pStream ) { break ; } if ( pStream -> isTypeOf ( CAM_STREAM_TYPE_SNAPSHOT ) || pStream -> isOrignalTypeOf ( CAM_STREAM_TYPE_SNAPSHOT ) ) { pSnapshotStream = pStream ; } if ( pStream -> isTypeOf ( CAM_STREAM_TYPE_POSTVIEW ) || pStream -> isOrignalTypeOf ( CAM_STREAM_TYPE_POSTVIEW ) ) { pThumbStream = pStream ; } } if ( ( NULL == pThumbStream ) && ( pChannel == m_pReprocChannel ) ) { for ( uint32_t i = 0 ; i < pSrcChannel -> getNumOfStreams ( ) ; ++ i ) { QCameraStream * pStream = pSrcChannel -> getStreamByIndex ( i ) ; if ( NULL == pStream ) { break ; } if ( pStream -> isTypeOf ( CAM_STREAM_TYPE_POSTVIEW ) || pStream -> isOrignalTypeOf ( CAM_STREAM_TYPE_POSTVIEW ) ) { pThumbStream = pStream ; } } } if ( NULL != pSnapshotStream ) { mm_jpeg_encode_params_t encodeParam ; memset ( & encodeParam , 0 , sizeof ( mm_jpeg_encode_params_t ) ) ; rc = getJpegEncodingConfig ( encodeParam , pSnapshotStream , pThumbStream ) ; if ( rc != NO_ERROR ) { ALOGE ( " " , __func__ ) ; return rc ; } CDBG_HIGH ( " " , __func__ ) ; rc = mJpegHandle . create_session ( mJpegClientHandle , & encodeParam , & mJpegSessionId ) ; if ( rc != NO_ERROR ) { ALOGE ( " " , __func__ ) ; return rc ; } mNewJpegSessionNeeded = false ; } } return rc ; }
FUNCTION   : start
 DESCRIPTION: start postprocessor.
FUNCTION : start DESCRIPTION : start postprocessor .
// if reprocess is needed, start reprocess channel // if reprocess is needed, start reprocess channel // Create Jpeg session // If thumbnail is not part of the reprocess channel, then // try to get it from the source channel