Skip to content

Commit

Permalink
Merge branch 'master' of github.com:openframeworks/openFrameworks
Browse files Browse the repository at this point in the history
  • Loading branch information
theo authored and theo committed Aug 5, 2011
2 parents e19c791 + 5602560 commit 4dc631d
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 66 deletions.
48 changes: 30 additions & 18 deletions addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFAndroid.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,24 +232,35 @@ static public boolean menuItemChecked(int id, boolean checked){
}

static public void setMenuItemChecked(String idStr, boolean checked){
try {
Class<?> menu_ids = Class.forName(packageName+".R$id");
Field field = menu_ids.getField(idStr);
//ofActivity.getMenuInflater().
} catch (Exception e) {
Log.w("OF","Trying to get menu items ", e);
}
final String id = idStr;
ofActivity.runOnUiThread(new Runnable(){
public void run() {
try {
Class<?> menu_ids = Class.forName(packageName+".R$id");
Field field = menu_ids.getField(id);
//ofActivity.getMenuInflater().
} catch (Exception e) {
Log.w("OF","Trying to get menu items ", e);
}
}
});
}

static public void setViewItemChecked(String idStr, boolean checked){
try {
Class<?> menu_ids = Class.forName(packageName+".R$id");
Field field = menu_ids.getField(idStr);
CompoundButton checkbox = (CompoundButton) ofActivity.findViewById(field.getInt(null));
checkbox.setChecked(checked);
} catch (Exception e) {
Log.w("OF","Trying to get menu items ", e);
}
final String id = idStr;
final boolean fchecked = checked;
ofActivity.runOnUiThread(new Runnable(){
public void run() {
try {
Class<?> menu_ids = Class.forName(packageName+".R$id");
Field field = menu_ids.getField(id);
CompoundButton checkbox = (CompoundButton) ofActivity.findViewById(field.getInt(null));
checkbox.setChecked(fchecked);
} catch (Exception e) {
Log.w("OF","Trying to get menu items ", e);
}
}
});
}

static public String getStringRes(String idStr){
Expand Down Expand Up @@ -675,24 +686,25 @@ public void onSurfaceCreated(GL10 gl, EGLConfig config) {
}

public void onSurfaceChanged(GL10 gl, int w, int h) {
OFAndroid.resize(w, h);
if(!setup){
Log.i("OF","initializing app");
OFAndroid.init();
OFAndroid.setup(w,h);
initialized = true;
setup = false;
setup = true;
android.os.Process.setThreadPriority(8);

/*if(ETC1Util.isETC1Supported()) Log.i("OF","ETC supported");
else Log.i("OF","ETC not supported");*/
}
OFAndroid.resize(w, h);
this.w = w;
this.h = h;
}

public void onDrawFrame(GL10 gl) {
OFAndroid.render();
if(setup)
OFAndroid.render();
}

static boolean initialized;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ public void stop(){

@Override
protected void pause() {
if(broadcastReceiver != null){
try{
activity.unregisterReceiver(broadcastReceiver);
}catch(Exception e){

}finally{
broadcastReceiver = null;
}
}
stop();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.content.Context;
import android.graphics.ImageFormat;
import android.hardware.Camera;
import android.hardware.Camera.Size;
import android.util.Log;
import android.view.OrientationEventListener;

Expand All @@ -30,23 +31,51 @@ public static OFAndroidVideoGrabber getInstance(int id){
void initGrabber(int w, int h, int _targetFps){
camera = Camera.open();
Camera.Parameters config = camera.getParameters();

Log.i("OF","Grabber supported sizes");
for(Size s : config.getSupportedPreviewSizes()){
Log.i("OF",s.width + " " + s.height);
}

Log.i("OF","Grabber supported formats");
for(Integer i : config.getSupportedPreviewFormats()){
Log.i("OF",i.toString());
}

Log.i("OF","Grabber supported fps");
for(Integer i : config.getSupportedPreviewFrameRates()){
Log.i("OF",i.toString());
}

Log.i("OF", "Grabber default format: " + config.getPreviewFormat());
Log.i("OF", "Grabber default preview size: " + config.getPreviewSize().width + "," + config.getPreviewSize().height);
config.setPreviewSize(w, h);
config.setPreviewFormat(ImageFormat.NV21);
config.setPreviewFrameRate(targetFps);
try{
camera.setParameters(config);
}catch(Exception e){
Log.e("OF","couldn init camera", e);
}

config = camera.getParameters();
width = config.getPreviewSize().width;
height = config.getPreviewSize().height;
if(width!=w || height!=h) Log.w("OF","camera size different than asked for, resizing (this can slow the app)");


if(_targetFps!=-1){
config = camera.getParameters();
config.setPreviewFrameRate(_targetFps);
try{
camera.setParameters(config);
}catch(Exception e){
Log.e("OF","couldn init camera", e);
}
}

targetFps = _targetFps;
Log.i("OF","camera settings: " + width + "x" + height);
if(width!=w || height!=h) Log.w("OF","camera size different than asked for, resizing (this can slow the app)");

buffer = new byte[width*height*2];

orientationListener = new OrientationListener(OFAndroid.getContext());
Expand Down Expand Up @@ -76,27 +105,14 @@ public void stop(){

@Override
public void pause(){
if(initialized){
Log.i("OF","pausing camera preview");
camera.stopPreview();
orientationListener.disable();
}
stop();

}

@Override
public void resume(){
if(initialized){
switch(state){
case Paused:
Log.i("OF","camera paused, resuming");
camera.startPreview();
break;
case Stopped:
Log.i("OF","camera stopped, reinitializing");
initGrabber(width,height,targetFps);
break;
}
initGrabber(width,height,targetFps);
orientationListener.enable();
}
}
Expand Down Expand Up @@ -155,19 +171,23 @@ public OrientationListener(Context context) {
@Override
public void onOrientationChanged(int orientation) {
if (orientation == ORIENTATION_UNKNOWN) return;
Camera.Parameters config = camera.getParameters();
/*Camera.CameraInfo info =
new Camera.CameraInfo();*/
//Camera.getCameraInfo(camera, info);
orientation = (orientation + 45) / 90 * 90;
int rotation = orientation % 360;
//if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
//rotation = (info.orientation - orientation + 360) % 360;
/*} else { // back-facing camera
rotation = (info.orientation + orientation) % 360;
}*/
config.setRotation(rotation);
camera.setParameters(config);
try{
Camera.Parameters config = camera.getParameters();
/*Camera.CameraInfo info =
new Camera.CameraInfo();*/
//Camera.getCameraInfo(camera, info);
orientation = (orientation + 45) / 90 * 90;
int rotation = orientation % 360;
//if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
//rotation = (info.orientation - orientation + 360) % 360;
/*} else { // back-facing camera
rotation = (info.orientation + orientation) % 360;
}*/
config.setRotation(rotation);
camera.setParameters(config);
}catch(Exception e){

}
}

}
Expand Down
2 changes: 1 addition & 1 deletion addons/ofxAndroid/src/ofAppAndroidWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ jboolean
Java_cc_openframeworks_OFAndroid_onMenuItemChecked( JNIEnv* env, jobject thiz, jstring menu_id, jboolean checked){
jboolean iscopy;
const char *menu_id_str = env->GetStringUTFChars(menu_id, &iscopy);
if(androidApp) return androidApp->menuItemChecked(menu_id_str,checked);
if(androidApp && menu_id_str) return androidApp->menuItemChecked(menu_id_str,checked);
else return false;
}

Expand Down
8 changes: 4 additions & 4 deletions addons/ofxAndroid/src/ofxAndroidUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void ofxAndroidPauseApp(){
ofLog(OF_LOG_ERROR,"cannot find OFAndroid pauseApp method");
return;
}
ofGetJNIEnv()->CallStaticObjectMethod(javaClass,pauseApp);
ofGetJNIEnv()->CallStaticVoidMethod(javaClass,pauseApp);
}

void ofxAndroidAlertBox(string msg){
Expand Down Expand Up @@ -171,7 +171,7 @@ void ofxAndroidToast(string msg){
return;
}
jstring jMsg = ofGetJNIEnv()->NewStringUTF(msg.c_str());
ofGetJNIEnv()->CallStaticObjectMethod(javaClass,toast,jMsg);
ofGetJNIEnv()->CallStaticVoidMethod(javaClass,toast,jMsg);
}

void ofxAndroidLockScreenSleep(){
Expand All @@ -187,7 +187,7 @@ void ofxAndroidLockScreenSleep(){
ofLog(OF_LOG_ERROR,"cannot find OFAndroid lockScreenSleep method");
return;
}
ofGetJNIEnv()->CallStaticObjectMethod(javaClass,lockScreenSleep);
ofGetJNIEnv()->CallStaticVoidMethod(javaClass,lockScreenSleep);
}

void ofxAndroidUnlockScreenSleep(){
Expand All @@ -203,5 +203,5 @@ void ofxAndroidUnlockScreenSleep(){
ofLog(OF_LOG_ERROR,"cannot find OFAndroid unlockScreenSleep method");
return;
}
ofGetJNIEnv()->CallStaticObjectMethod(javaClass,unlockScreenSleep);
ofGetJNIEnv()->CallStaticVoidMethod(javaClass,unlockScreenSleep);
}
2 changes: 1 addition & 1 deletion addons/ofxAndroid/src/ofxAndroidVideoGrabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ static void releaseJavaObject(){

ofxAndroidVideoGrabber::ofxAndroidVideoGrabber(){

attemptFramerate = 30;
attemptFramerate = -1;
newPixels = false;
InitConvertTable();
bGrabberInited = false;
Expand Down
3 changes: 2 additions & 1 deletion libs/openFrameworks/sound/ofSoundPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ void ofSoundUpdate(){
#endif
}

#ifndef TARGET_ANDROID
//--------------------
void ofSoundShutdown(){
#ifdef OF_SOUND_PLAYER_FMOD
ofFmodSoundPlayer::closeFmod();
#endif
}

#endif

//--------------------
float * ofSoundGetSpectrum(int nBands){
Expand Down
4 changes: 4 additions & 0 deletions libs/openFrameworks/sound/ofSoundPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ void ofSoundShutdown();
#define OF_SOUND_PLAYER_TYPE ofxOpenALSoundPlayer
#endif

#ifdef TARGET_ANDROID
inline void ofSoundShutdown(){}
#endif

//---------------------------------------------
class ofSoundPlayer : public ofBaseSoundPlayer {

Expand Down
2 changes: 1 addition & 1 deletion libs/openFrameworksCompiled/project/android/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ ifeq ($(findstring Release,$(MAKECMDGOALS)),Release)
endif

ifeq ($(findstring Release_arm7,$(MAKECMDGOALS)),Release_arm7)
TARGET_CFLAGS += -march=armv7-a -mfloat-abi=softfp -mthumb
TARGET_CFLAGS += -march=armv7-a -mfloat-abi=softfp
TARGET = ../../lib/$(LIBSPATH)/libopenFrameworks_arm7.a
endif

Expand Down
5 changes: 3 additions & 2 deletions scripts/linux/debian/install_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ else
fi

WHO=`sudo who am i`;ID=`echo ${WHO%% *}`
GROUP_ID=`id --group -n ${ID}`
cd ../../../libs/openFrameworksCompiled/project/$LIBSPATH
make Debug
if [ $? != 0 ]; then
echo "there has been a problem compiling Debug OF library"
echo "please report this problem in the forums"
exit
fi
chown -R $ID:$ID obj ../../lib/${LIBSPATH}/*
chown -R $ID:$GROUP_ID obj ../../lib/${LIBSPATH}/*
make Release
if [ $? != 0 ]; then
echo "there has been a problem compiling Release OF library"
echo "please report this problem in the forums"
fi
chown -R $ID:$ID obj ../../lib/${LIBSPATH}/*
chown -R $ID:$GROUP_ID obj ../../lib/${LIBSPATH}/*

# libpoco-dev
5 changes: 3 additions & 2 deletions scripts/linux/fedora/install_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@ else
fi

WHO=`sudo who am i`;ID=`echo ${WHO%% *}`
GROUP_ID=`id --group -n ${ID}`
cd ../../../libs/openFrameworksCompiled/project/$LIBSPATH
make Debug
if [ $? != 0 ]; then
echo "there has been a problem compiling Debug OF library"
echo "please report this problem in the forums"
exit
fi
chown -R $ID:$ID obj ../../lib/${LIBSPATH}/*
chown -R $ID:$GROUP_ID obj ../../lib/${LIBSPATH}/*
make Release
if [ $? != 0 ]; then
echo "there has been a problem compiling Release OF library"
echo "please report this problem in the forums"
fi
chown -R $ID:$ID obj ../../lib/${LIBSPATH}/*
chown -R $ID:$GROUP_ID obj ../../lib/${LIBSPATH}/*

6 changes: 3 additions & 3 deletions scripts/linux/template/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ ifeq ($(ARCH),android)
LDFLAGS = --sysroot=$(SYSROOT) -nostdlib -L"$(NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/libs/armeabi"
SYSTEMLIBS += -lstdc++ -lsupc++ -lgcc -lz -lGLESv1_CM -llog -ldl -lm -lc
else
LDFLAGS = -Wl,-rpath=./libs
SYSTEMLIBS += $(shell pkg-config jack glew gstreamer-0.10 gstreamer-video-0.10 gstreamer-base-0.10 gstreamer-app-0.10 libudev --libs)
SYSTEMLIBS += -lglut -lGL -lasound -lopenal -lsndfile -lvorbis -lFLAC -logg -lfreeimage
LDFLAGS = -Wl,-rpath=./libs
SYSTEMLIBS += $(shell pkg-config jack glew gstreamer-0.10 gstreamer-video-0.10 gstreamer-base-0.10 gstreamer-app-0.10 libudev cairo --libs)
SYSTEMLIBS += -lglut -lGL -lasound -lopenal -lsndfile -lvorbis -lFLAC -logg -lfreeimage -lGLU
endif


Expand Down
5 changes: 3 additions & 2 deletions scripts/linux/ubuntu/install_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ else
fi

WHO=`sudo who am i`;ID=`echo ${WHO%% *}`
GROUP_ID=`id --group -n ${ID}`
cd ../../../libs/openFrameworksCompiled/project/$LIBSPATH
make Debug
if [ $? != 0 ]; then
echo "there has been a problem compiling Debug OF library"
echo "please report this problem in the forums"
exit
fi
chown -R $ID:$ID obj ../../lib/${LIBSPATH}/*
chown -R $ID:$GROUP_ID obj ../../lib/${LIBSPATH}/*
make Release
if [ $? != 0 ]; then
echo "there has been a problem compiling Release OF library"
echo "please report this problem in the forums"
fi
chown -R $ID:$ID obj ../../lib/${LIBSPATH}/*
chown -R $ID:$GROUP_ID obj ../../lib/${LIBSPATH}/*
# libpoco-dev

0 comments on commit 4dc631d

Please sign in to comment.