예제 #1
0
static int32_t mm_camera_ch_util_release(mm_camera_obj_t * my_obj,
                                         mm_camera_channel_type_t ch_type,
                                         mm_camera_state_evt_type_t evt)
{
    mm_camera_stream_t *stream1, *stream2;

    if(!my_obj->ch[ch_type].acquired) return MM_CAMERA_OK;

    mm_camera_ch_util_get_stream_objs(my_obj,ch_type, &stream1, &stream2);
    if(stream1)
        mm_camera_stream_fsm_fn_vtbl(my_obj, stream1, evt, NULL);
    if(stream2)
        mm_camera_stream_fsm_fn_vtbl(my_obj, stream2, evt, NULL);
    pthread_mutex_destroy(&my_obj->ch[ch_type].mutex);
    memset(&my_obj->ch[ch_type],0,sizeof(my_obj->ch[ch_type]));
    return 0;
}
예제 #2
0
int mm_camera_poll_thread_launch(mm_camera_obj_t * my_obj, int ch_type)
{
    int rc = MM_CAMERA_OK;
    mm_camera_poll_thread_t *poll_cb = &my_obj->poll_threads[ch_type];
    if(mm_camera_poll_ch_busy(my_obj, ch_type) > 0) {
        CDBG_ERROR("%s: err, poll thread of channel %d already running. cam_id=%d\n",
             __func__, ch_type, my_obj->my_id);
        return -MM_CAMERA_E_INVALID_OPERATION;
    }
    poll_cb->data.ch_type = ch_type;
    rc = pipe(poll_cb->data.pfds);
    if(rc < 0) {
        CDBG_ERROR("%s: camera_id = %d, pipe open rc=%d\n", __func__, my_obj->my_id, rc);
        rc = - MM_CAMERA_E_GENERAL;
    }
    CDBG("%s: ch = %d, poll_type = %d, read fd = %d, write fd = %d",
        __func__, ch_type, poll_cb->data.poll_type,
        poll_cb->data.pfds[0], poll_cb->data.pfds[1]);
    poll_cb->data.my_obj = my_obj;
    poll_cb->data.used = 0;
    poll_cb->data.timeoutms = -1;  /* Infinite seconds */

    if(ch_type < MM_CAMERA_CH_MAX) {
        poll_cb->data.poll_type = MM_CAMERA_POLL_TYPE_CH;
        mm_camera_ch_util_get_stream_objs(my_obj, ch_type,
                                      &poll_cb->data.poll_streams[0],
                                      &poll_cb->data.poll_streams[1]);
    } else{
        poll_cb->data.poll_type = MM_CAMERA_POLL_TYPE_EVT;
    }

    ALOGE("%s: ch_type = %d, poll_type = %d, read fd = %d, write fd = %d",
         __func__, ch_type, poll_cb->data.poll_type,
         poll_cb->data.pfds[0], poll_cb->data.pfds[1]);
    /* launch the thread */
    rc = mm_camera_poll_start(my_obj, poll_cb);
    return rc;
}
예제 #3
0
/*for ZSL mode to send the image pair to client*/
void mm_camera_dispatch_buffered_frames(mm_camera_obj_t *my_obj,
                                        mm_camera_channel_type_t ch_type)
{
    int mcnt, i, rc = MM_CAMERA_E_GENERAL, scnt;
    int num_of_req_frame = 0;
    int j;
    mm_camera_ch_data_buf_t data;
    mm_camera_frame_t *mframe = NULL, *sframe = NULL;
    mm_camera_frame_t *qmframe = NULL, *qsframe = NULL;
    mm_camera_ch_t *ch = &my_obj->ch[ch_type];
    mm_camera_frame_queue_t *mq = NULL;
    mm_camera_frame_queue_t *sq = NULL;
    mm_camera_stream_t *stream1 = NULL;
    mm_camera_stream_t *stream2 = NULL;
ALOGE("%s: mzhu, E", __func__);
    mm_camera_ch_util_get_stream_objs(my_obj, ch_type, &stream1, &stream2);
    stream2 = &my_obj->ch[MM_CAMERA_CH_PREVIEW].preview.stream;
    if(stream1) {
      mq = &stream1->frame.readyq;
    }
    if(stream2) {
      sq = &stream2->frame.readyq;
    }
    pthread_mutex_lock(&ch->mutex);
    if (mq && sq && stream1 && stream2) {
        rc = mm_camera_channel_skip_frames(my_obj, mq, sq, stream1, stream2, &ch->buffering_frame);
        if(rc != MM_CAMERA_OK) {
            CDBG_ERROR("%s: Error getting right frame!", __func__);
            goto end;
        }
        num_of_req_frame = my_obj->snap_burst_num_by_user;
        ch->snapshot.pending_cnt = num_of_req_frame;
        for(i = 0; i < num_of_req_frame; i++) {
            mframe = mm_camera_stream_frame_deq(mq);
            sframe = mm_camera_stream_frame_deq(sq);
            if(mframe && sframe) {
                CDBG("%s: frame_id = 0x%x|0x%x, main idx = %d, thumbnail idx = %d", __func__,
                     mframe->frame.frame_id, sframe->frame.frame_id, mframe->idx, sframe->idx);
                if(mframe->frame.frame_id != sframe->frame.frame_id) {
                    CDBG_ERROR("%s: ZSL algorithm error, main and thumbnail "
                        "frame_ids not same. Need bug fix", __func__);
                }
                memset(&data, 0, sizeof(data));
                data.type = ch_type;
                data.snapshot.main.frame = &mframe->frame;
                data.snapshot.main.idx = mframe->idx;
                data.snapshot.thumbnail.frame = &sframe->frame;
                data.snapshot.thumbnail.idx = sframe->idx;
                ch->snapshot.pending_cnt--;
                mq->match_cnt--;
                sq->match_cnt--;
                for(j=0;j<MM_CAMERA_BUF_CB_MAX;j++) {
                    if( ch->buf_cb[j].cb!=NULL )
                        ch->buf_cb[j].cb(&data, ch->buf_cb[j].user_data);
                }
            } else {
               CDBG_ERROR("%s: mframe %p, sframe = %p", __func__, mframe, sframe);
                qmframe = mframe;
                qsframe = sframe;
                rc = -1;
                break;
            }
        }
        if(qmframe) {
            mm_camera_stream_frame_enq(mq, &stream1->frame.frame[qmframe->idx]);
            qmframe = NULL;
        }
        if(qsframe) {
            mm_camera_stream_frame_enq(sq, &stream2->frame.frame[qsframe->idx]);
            qsframe = NULL;
        }
    } else {
      CDBG_ERROR(" mq =%p sq =%p stream1 =%p stream2 =%p", mq, sq , stream1 , stream2);

    }
    CDBG("%s: burst number: %d, pending_count: %d", __func__,
        my_obj->snap_burst_num_by_user, ch->snapshot.pending_cnt);
end:
    pthread_mutex_unlock(&ch->mutex);
    /* If we are done sending callbacks for all the requested number of snapshots
       send data delivery done event*/
    if((rc == MM_CAMERA_OK) && (!ch->snapshot.pending_cnt)) {
        mm_camera_event_t data;
        data.event_type = MM_CAMERA_EVT_TYPE_CH;
        data.e.ch.evt = MM_CAMERA_CH_EVT_DATA_DELIVERY_DONE;
        data.e.ch.ch = ch_type;
        mm_camera_poll_send_ch_event(my_obj, &data);
    }
}