Skip to content

Commit

Permalink
ofxAndroidGrabber: when changing camera ID close device if it was open
Browse files Browse the repository at this point in the history
  • Loading branch information
arturoc committed Aug 1, 2018
1 parent 31ca506 commit 347f437
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion addons/ofxAndroid/src/ofxAndroidVideoGrabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,12 @@ int ofxAndroidVideoGrabber::getFacingOfCamera(int device)const{
}

void ofxAndroidVideoGrabber::setDeviceID(int _deviceID){
bool wasInited = data->bGrabberInited;
int w = this->getWidth();
int h = this->getHeight();
if(data->bGrabberInited){
close();
}

JNIEnv *env = ofGetJNIEnv();
if(!env) return;
Expand All @@ -445,6 +451,10 @@ void ofxAndroidVideoGrabber::setDeviceID(int _deviceID){
ofLogError("ofxAndroidVideoGrabber") << "setDeviceID(): couldn't get OFAndroidVideoGrabber setDeviceID method";
return;
}

if(wasInited){
setup(w, h);
}
}

bool ofxAndroidVideoGrabber::setAutoFocus(bool autofocus){
Expand Down Expand Up @@ -746,11 +756,12 @@ Java_cc_openframeworks_OFAndroidVideoGrabber_newFrame(JNIEnv* env, jobject thi
pixels.setFromPixels(currentFrame, width, height, OF_PIXELS_NV21);
}

env->ReleaseByteArrayElements(array, (jbyte*)currentFrame, 0);

if (needsResize) {
pixels.resize(data->width, data->height, OF_INTERPOLATE_NEAREST_NEIGHBOR);
}

env->ReleaseByteArrayElements(array, (jbyte*)currentFrame, 0);

data->bNewBackFrame=true;
}
Expand Down

0 comments on commit 347f437

Please sign in to comment.