解決三星ARM11開發板圖片採集程序源碼出現的Bug

三星公司提供的圖片採集程序源碼是這個:

/***************** Capture Thread *****************/
void capture_thread(void)
{
    int start, ret;
    int key;

    start = 1;
    ret = ioctl(cam_c_fp, VIDIOC_STREAMON, &start);
    if (ret < 0) {
        printf("V4L2 : ioctl on VIDIOC_STREAMON failed\n");
        exit(1);
    }

    printf("\nc : Capture\n");
    printf("x : Exit\n");
    printf("Select ==> ");  

    while (1) { 
        fflush(stdin);
        key = getchar();

        if(key == 'c') {
            cap_flag = TRUE;    
        }
        else if(key == 'x'){
            finished = 1;
            pthread_exit(0);
        }

        if (cap_flag == TRUE) {
            capture();
            cap_flag = FALSE;
        }
    }

    start = 0;
    ret = ioctl(cam_c_fp, VIDIOC_STREAMOFF, &start);
    if (ret < 0) {
        printf("V4L2 : ioctl on VIDIOC_STREAMOFF failed\n");
        exit(1);
    }

    pthread_exit(0);
}

有同學會發現當連續輸入”c“採集圖片的時候會出現錯誤,而且每次都是第五次的時候出錯”PP instance allocation is fail: No more instance“。這是爲什麼呢?
原來在三星提供的內核當中(經過查看內核發現這個問題)給出的攝像頭採集圖片的緩衝爲4張圖片,這裏給出的方案爲:
應爲程序中出現了

ioctl(pp_fd, S3C_PP_ALLOC_KMEM, &alloc_info)

但是在 close之前沒有釋放這段內存,在close前增加

ioctl(pp_fd, S3C_PP_FREE_KMEM, &alloc_info) 

在SsbSipJPEGEncodeExe()中因爲有open post processor所以在close之前close pp

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章