int mm_app_start_reprocess(mm_camera_test_obj_t *test_obj)
{
    int rc = MM_CAMERA_OK;
    mm_camera_channel_t *r_ch = NULL;

    mm_camera_queue_init(&test_obj->pp_frames,
                         mm_app_release_ppinput,
                         ( void * ) test_obj);

    r_ch = mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_REPROCESS);
    if (MM_CAMERA_OK != rc) {
        CDBG_ERROR("%s: No initialized reprocess channel d rc=%d\n",
                    __func__,
                    rc);
        return rc;
    }

    rc = mm_app_start_channel(test_obj, r_ch);
    if (MM_CAMERA_OK != rc) {
        CDBG_ERROR("%s:start reprocess failed rc=%d\n", __func__, rc);
        mm_app_del_channel(test_obj, r_ch);
        return rc;
    }

    return rc;
}
int mm_app_stop_capture_raw(mm_camera_test_obj_t *test_obj)
{
    int rc = MM_CAMERA_OK;
    mm_camera_channel_t *ch = NULL;
    int i;
    cam_stream_size_info_t abc ;
    memset (&abc , 0, sizeof (cam_stream_size_info_t));

    ch = mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_CAPTURE);

    rc = mm_app_stop_channel(test_obj, ch);
    if (MM_CAMERA_OK != rc) {
        LOGE("stop recording failed rc=%d\n",  rc);
    }

    for ( i = 0 ; i < ch->num_streams ; i++ ) {
        mm_app_del_stream(test_obj, ch, &ch->streams[i]);
    }
    rc = setmetainfoCommand(test_obj, &abc);
    if (rc != MM_CAMERA_OK) {
       LOGE(" meta info command failed\n");
    }
    mm_app_del_channel(test_obj, ch);

    return rc;
}
int mm_app_stop_preview(mm_camera_test_obj_t *test_obj)
{
    int rc = MM_CAMERA_OK;

    mm_camera_channel_t *channel =
        mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_PREVIEW);

    rc = mm_app_stop_and_del_channel(test_obj, channel);
    if (MM_CAMERA_OK != rc) {
        CDBG_ERROR("%s:Stop Preview failed rc=%d\n", __func__, rc);
    }

    return rc;
}
int mm_app_stop_capture(mm_camera_test_obj_t *test_obj)
{
    int rc = MM_CAMERA_OK;
    mm_camera_channel_t *ch = NULL;

    ch = mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_CAPTURE);

    rc = mm_app_stop_and_del_channel(test_obj, ch);
    if (MM_CAMERA_OK != rc) {
        LOGE("stop capture channel failed rc=%d\n",  rc);
    }

    return rc;
}
int mm_app_stop_preview_zsl(mm_camera_test_obj_t *test_obj)
{
    int rc = MM_CAMERA_OK;

    mm_camera_channel_t *channel =
        mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_ZSL);

    rc = mm_app_stop_and_del_channel(test_obj, channel);
    if (MM_CAMERA_OK != rc) {
        CDBG_ERROR("%s:Stop Preview failed rc=%d\n", __func__, rc);
    }

    if ( test_obj->enable_reproc ) {
        rc |= mm_app_stop_reprocess(test_obj);
    }

    return rc;
}
int mm_app_stop_capture_raw(mm_camera_test_obj_t *test_obj)
{
    int rc = MM_CAMERA_OK;
    mm_camera_channel_t *ch = NULL;
    int i;

    ch = mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_CAPTURE);

    rc = mm_app_stop_channel(test_obj, ch);
    if (MM_CAMERA_OK != rc) {
        CDBG_ERROR("%s:stop recording failed rc=%d\n", __func__, rc);
    }

    for ( i = 0 ; i < ch->num_streams ; i++ ) {
        mm_app_del_stream(test_obj, ch, &ch->streams[i]);
    }

    mm_app_del_channel(test_obj, ch);

    return rc;
}
int mm_app_stop_reprocess(mm_camera_test_obj_t *test_obj)
{
    int rc = MM_CAMERA_OK;
    mm_camera_channel_t *r_ch = NULL;

    r_ch = mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_REPROCESS);
    if (MM_CAMERA_OK != rc) {
        CDBG_ERROR("%s: No initialized reprocess channel d rc=%d\n",
                    __func__,
                    rc);
        return rc;
    }

    rc = mm_app_stop_and_del_channel(test_obj, r_ch);
    if (MM_CAMERA_OK != rc) {
        CDBG_ERROR("%s:Stop Preview failed rc=%d\n", __func__, rc);
    }

    mm_qcamera_queue_release(&test_obj->pp_frames);
    test_obj->reproc_stream = NULL;

    return rc;
}
int mm_app_do_reprocess(mm_camera_test_obj_t *test_obj,
                        mm_camera_buf_def_t *frame,
                        uint8_t meta_idx,
                        mm_camera_super_buf_t *super_buf,
                        mm_camera_stream_t *src_meta)
{
    int rc = MM_CAMERA_OK;
    mm_camera_channel_t *r_ch = NULL;
    mm_camera_super_buf_t *src_buf = NULL;

    if ( ( NULL == test_obj ) ||
         ( NULL == frame ) ||
         ( NULL == super_buf )) {
        CDBG_ERROR("%s: Invalid input rc=%d\n",
                    __func__,
                    rc);
        return rc;
    }

    if ( NULL == test_obj->reproc_stream ) {
        CDBG_ERROR("%s: No reprocess stream rc=%d\n",
                    __func__,
                    rc);
        return rc;
    }

    r_ch = mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_REPROCESS);
    if (MM_CAMERA_OK != rc) {
        CDBG_ERROR("%s: No reprocess channel rc=%d\n",
                    __func__,
                    rc);
        return rc;
    }

    src_buf = ( mm_camera_super_buf_t * ) malloc(sizeof(mm_camera_super_buf_t));
    if ( NULL == src_buf ) {
        CDBG_ERROR("%s: No resources for src frame rc=%d\n",
                    __func__,
                    rc);
        return -1;
    }
    memcpy(src_buf, super_buf, sizeof(mm_camera_super_buf_t));
    mm_qcamera_queue_enqueue(&test_obj->pp_frames, src_buf);

    cam_stream_parm_buffer_t param;
    memset(&param, 0, sizeof(cam_stream_parm_buffer_t));
    param.type = CAM_STREAM_PARAM_TYPE_DO_REPROCESS;
    param.reprocess.buf_index = frame->buf_idx;
    param.reprocess.frame_idx = frame->frame_idx;
    if (src_meta != NULL) {
        param.reprocess.meta_present = 1;
        param.reprocess.meta_stream_handle = src_meta->s_config.stream_info->stream_svr_id;
        param.reprocess.meta_buf_index = meta_idx;
    } else {
        CDBG_ERROR("%s: No metadata source stream rc=%d\n",
                   __func__,
                   rc);
    }

    test_obj->reproc_stream->s_config.stream_info->parm_buf = param;
    rc = test_obj->cam->ops->set_stream_parms(test_obj->cam->camera_handle,
                                              r_ch->ch_id,
                                              test_obj->reproc_stream->s_id,
                                              &test_obj->reproc_stream->s_config.stream_info->parm_buf);

    return rc;
}