마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

opencv와 sound pool 에러 도와주세요 ㅠㅠㅠ

0 추천
@Override
    public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
        SoundPool sound = new SoundPool(1, AudioManager.STREAM_ALARM, 0);// maxStreams, streamType, srcQuality
        int soundId_1 = sound.load(this, R.raw.to, 1);
        int soundId_2 = sound.load(this, R.raw.re, 1);
        int soundId_3 = sound.load(this, R.raw.me, 1);
        int soundId_4 = sound.load(this, R.raw.pa, 1);
        int soundId_5 = sound.load(this, R.raw.sol, 1);
        int soundId_6 = sound.load(this, R.raw.ra, 1);
        int soundId_7 = sound.load(this, R.raw.si, 1);
        int soundId_8 = sound.load(this, R.raw.high_do, 1);
        int result = 11;

        if (inputFrame.rgba() != null) {
            img_input = inputFrame.rgba();
            if (img_result != null) img_result.release();
                img_result = new Mat(inputFrame.rgba().rows(), inputFrame.rgba().cols(), CvType.CV_8UC1);
                result = convertNativeLib(img_input.getNativeObjAddr(), img_result.getNativeObjAddr());
                img_input.release();
                switch (result) {
                    case 1:
                        sound.play(soundId_1, 1.0F, 1.0F, 0, 0, 1.0F);
                        sound.stop(soundId_1);
                        break;
                    case 2:
                        sound.play(soundId_2, 1.0F, 1.0F, 0, 0, 1.0F);
                        sound.stop(soundId_2);
                        break;
                    case 3:
                        sound.play(soundId_3, 1.0F, 1.0F, 0, 0, 1.0F);
                        sound.stop(soundId_3);
                        break;
                    case 4:
                        sound.play(soundId_4, 1.0F, 1.0F, 0, 0, 1.0F);
                        sound.stop(soundId_4);
                        break;
                    case 5:
                        sound.play(soundId_5, 1.0F, 1.0F, 0, 0, 1.0F);
                        sound.stop(soundId_5);
                        break;
                    case 6:
                        sound.play(soundId_6, 1.0F, 1.0F, 0, 0, 1.0F);
                        sound.stop(soundId_6);
                        break;
                    case 7:
                        sound.play(soundId_7, 1.0F, 1.0F, 0, 0, 1.0F);
                        sound.stop(soundId_7);
                        break;
                    case 8:
                        sound.play(soundId_8, 1.0F, 1.0F, 0, 0, 1.0F);
                        sound.stop(soundId_8);
                        break;
           
                    default:
                        break;
                }
            }       
        return img_result;
    }
   
}

 

제가 안드로이드를 이용해 opencv를 하여 피아노 모양에 선을 추출해(허프라인이용) 소리를 내는 작업을 하고 있습니다 . ndk ,jni 를 이용해 c++로 opencv 소스를 활용하였고 소리 부분은 java 환경에 넘겨주어 soundpool로 각 계이름마다 소리를 내고 있습니다. 그런데 앱을 계속 켜 놓으면 화면이 바뀌지 않고 렉이 걸리면서 몇초 후에 어플이 종료 되는 경우가 발생합니다. 그 때 뜨는 에러가 (댓글에 썼습니다)

이렇습니다. 제생각에는 opencv를 사용하면서 메모리 부분에서 문제가 생기는 것같은데 어떻게 고쳐야 할지 모르겠습니다. 도와주세요 ㅠㅠ

 

yangyangji (170 포인트) 님이 2017년 2월 20일 질문
02-20 17:52:16.395 28863-4954/com.tistory.webnautes.dreaming_instrument A/art: art/runtime/indirect_reference_table.cc:76] Check failed: table_mem_map_.get() != nullptr ashmem_create_region failed for 'indirect ref table': Too many open files
02-20 17:52:16.395 28863-28876/com.tistory.webnautes.dreaming_instrument E/IMemory: binder=0xad20e480 transaction failed fd=-2147483647, size=0, err=-2147483646 (Unknown error 2147483646)
02-20 17:52:16.395 28863-28876/com.tistory.webnautes.dreaming_instrument E/IMemory: cannot dup fd=-2147483647, size=0, err=-2147483646 (Bad file number)
02-20 17:52:16.395 28863-28876/com.tistory.webnautes.dreaming_instrument E/IMemory: cannot map BpMemoryHeap (binder=0xad20e480), size=0, fd=-1 (Bad file number)

1개의 답변

0 추천
 
채택된 답변

코드가 잘 못 된 듯 합니다. 30fps 로 영상이 올라온다고 할 때 

이론상 1초에 onCameraFrame 가 30번 불리구, 불릴 때마다, sound.load가 8번 불리게 코드를 넣으셨는데, 사용 후 release 하지 않으셨으니, 1초마다 이론상  sound.load가 240개씩 누적될 듯 합니다.

그래서 돌다보면,  더 이상 로드 못 해서 오류가 나는 듯 합니다.

sound.load 가 호출 되는 시점을 onCameraFrame 가 아닌 앞단(ex camera open시 load하고, close시 release)에서 수행하게 해서 8번 이상 load 안되게 해 주셔야 할 듯 합니다.

익명사용자 님이 2017년 2월 20일 답변
2017년 2월 20일 수정
감사합니다!! ㅠㅠ 한번에 해결 되었네요 정말 감사합니다
...