From 27896c14e3d5edab41fca3f87c39221dd1a06668 Mon Sep 17 00:00:00 2001 From: Riza Sulistyo Date: Wed, 24 Apr 2013 04:55:00 +0000 Subject: Re #1655: pjsua app CLI for android git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4496 74dad513-b988-da41-8d7b-12977e46ad98 --- pjsip-apps/src/pjsua/android/.classpath | 8 + pjsip-apps/src/pjsua/android/.project | 101 +++++++++ pjsip-apps/src/pjsua/android/AndroidManifest.xml | 45 ++++ pjsip-apps/src/pjsua/android/jni/Android.mk | 61 ++++++ pjsip-apps/src/pjsua/android/jni/pjsua.i | 29 +++ .../src/pjsua/android/jni/pjsua_app_callback.cpp | 113 ++++++++++ .../src/pjsua/android/jni/pjsua_app_callback.h | 36 +++ pjsip-apps/src/pjsua/android/lint.xml | 3 + pjsip-apps/src/pjsua/android/proguard-project.txt | 20 ++ pjsip-apps/src/pjsua/android/project.properties | 14 ++ .../pjsua/android/res/drawable-hdpi/main_image.png | Bin 0 -> 8269 bytes .../pjsua/android/res/drawable-ldpi/main_image.png | Bin 0 -> 3863 bytes .../pjsua/android/res/drawable-mdpi/main_image.png | Bin 0 -> 5059 bytes .../android/res/drawable-xhdpi/main_image.png | Bin 0 -> 12058 bytes .../src/pjsua/android/res/layout/activity_main.xml | 34 +++ .../src/pjsua/android/res/values-v11/styles.xml | 5 + .../src/pjsua/android/res/values-v14/styles.xml | 5 + .../src/pjsua/android/res/values/strings.xml | 6 + pjsip-apps/src/pjsua/android/res/values/styles.xml | 5 + .../android/src/org/pjsip/pjsua/MainActivity.java | 242 +++++++++++++++++++++ 20 files changed, 727 insertions(+) create mode 100644 pjsip-apps/src/pjsua/android/.classpath create mode 100644 pjsip-apps/src/pjsua/android/.project create mode 100644 pjsip-apps/src/pjsua/android/AndroidManifest.xml create mode 100644 pjsip-apps/src/pjsua/android/jni/Android.mk create mode 100755 pjsip-apps/src/pjsua/android/jni/pjsua.i create mode 100644 pjsip-apps/src/pjsua/android/jni/pjsua_app_callback.cpp create mode 100644 pjsip-apps/src/pjsua/android/jni/pjsua_app_callback.h create mode 100644 pjsip-apps/src/pjsua/android/lint.xml create mode 100644 pjsip-apps/src/pjsua/android/proguard-project.txt create mode 100644 pjsip-apps/src/pjsua/android/project.properties create mode 100755 pjsip-apps/src/pjsua/android/res/drawable-hdpi/main_image.png create mode 100755 pjsip-apps/src/pjsua/android/res/drawable-ldpi/main_image.png create mode 100755 pjsip-apps/src/pjsua/android/res/drawable-mdpi/main_image.png create mode 100755 pjsip-apps/src/pjsua/android/res/drawable-xhdpi/main_image.png create mode 100644 pjsip-apps/src/pjsua/android/res/layout/activity_main.xml create mode 100644 pjsip-apps/src/pjsua/android/res/values-v11/styles.xml create mode 100644 pjsip-apps/src/pjsua/android/res/values-v14/styles.xml create mode 100644 pjsip-apps/src/pjsua/android/res/values/strings.xml create mode 100644 pjsip-apps/src/pjsua/android/res/values/styles.xml create mode 100644 pjsip-apps/src/pjsua/android/src/org/pjsip/pjsua/MainActivity.java (limited to 'pjsip-apps') diff --git a/pjsip-apps/src/pjsua/android/.classpath b/pjsip-apps/src/pjsua/android/.classpath new file mode 100644 index 00000000..3f9691c5 --- /dev/null +++ b/pjsip-apps/src/pjsua/android/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/pjsip-apps/src/pjsua/android/.project b/pjsip-apps/src/pjsua/android/.project new file mode 100644 index 00000000..ec83832d --- /dev/null +++ b/pjsip-apps/src/pjsua/android/.project @@ -0,0 +1,101 @@ + + + pjsua + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + ?name? + + + + org.eclipse.cdt.make.core.append_environment + true + + + org.eclipse.cdt.make.core.autoBuildTarget + all + + + org.eclipse.cdt.make.core.buildArguments + + + + org.eclipse.cdt.make.core.buildCommand + make + + + org.eclipse.cdt.make.core.cleanBuildTarget + clean + + + org.eclipse.cdt.make.core.contents + org.eclipse.cdt.make.core.activeConfigSettings + + + org.eclipse.cdt.make.core.enableAutoBuild + false + + + org.eclipse.cdt.make.core.enableCleanBuild + true + + + org.eclipse.cdt.make.core.enableFullBuild + true + + + org.eclipse.cdt.make.core.fullBuildTarget + all + + + org.eclipse.cdt.make.core.stopOnError + true + + + org.eclipse.cdt.make.core.useDefaultBuildCmd + true + + + + + com.android.ide.eclipse.adt.ResourceManagerBuilder + + + + + com.android.ide.eclipse.adt.PreCompilerBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + com.android.ide.eclipse.adt.ApkBuilder + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + com.android.ide.eclipse.adt.AndroidNature + org.eclipse.jdt.core.javanature + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/pjsip-apps/src/pjsua/android/AndroidManifest.xml b/pjsip-apps/src/pjsua/android/AndroidManifest.xml new file mode 100644 index 00000000..e5a0088a --- /dev/null +++ b/pjsip-apps/src/pjsua/android/AndroidManifest.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pjsip-apps/src/pjsua/android/jni/Android.mk b/pjsip-apps/src/pjsua/android/jni/Android.mk new file mode 100644 index 00000000..bcbdbbd6 --- /dev/null +++ b/pjsip-apps/src/pjsua/android/jni/Android.mk @@ -0,0 +1,61 @@ +# $id$ + +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + +# Get PJ build settings +include ../../../../build.mak +include $(PJDIR)/build/common.mak + +# Path to SWIG +MY_SWIG := swig + +#======================================================================== +# Choose console application to load +#======================================================================== + +# pjlib test +#MY_MODULE := $(PJDIR)/pjlib/build/output/pjlib-test-$(TARGET_NAME)/*.o + +# pjlib-util test +#MY_MODULE := $(PJDIR)/pjlib-util/build/output/pjlib-util-test-$(TARGET_NAME)/*.o + +# pjsip test +#MY_MODULE := $(PJDIR)/pjsip/build/output/pjsip-test-$(TARGET_NAME)/*.o + +# pjnath test +#MY_MODULE := $(PJDIR)/pjnath/build/output/pjnath-test-$(TARGET_NAME)/*.o + +# pjmedia test +# Note: jbuf test requires Jbtest.dat, this jbuf test must be disabled (for now). +#MY_MODULE := $(PJDIR)/pjmedia/build/output/pjmedia-test-$(TARGET_NAME)/*.o + +# pjsystest app (not supported yet) +# Todo: this test requires some input and output files (log & WAV). +#MY_MODULE := $(PJDIR)/pjsip-apps/build/output/pjsystest-$(TARGET_NAME)/*.o + +# pjsua app +# Note: must set USE_GUI to zero in config_site.h +MY_MODULE := $(PJDIR)/pjsip-apps/build/output/pjsua-$(TARGET_NAME)/*.o + +#======================================================================== + +# Constants +MY_JNI_WRAP := pjsua_wrap.cpp +MY_JNI_DIR := jni + +# Android build settings +LOCAL_MODULE := libpjsua +LOCAL_CFLAGS := -Werror $(APP_CFLAGS) -frtti +LOCAL_LDFLAGS := $(APP_LDFLAGS) +LOCAL_LDLIBS := $(MY_MODULE) $(APP_LDLIBS) +LOCAL_SRC_FILES := $(MY_JNI_WRAP) pjsua_app_callback.cpp + +# Invoke SWIG +$(MY_JNI_DIR)/$(MY_JNI_WRAP): + @echo "Invoking SWIG..." + $(MY_SWIG) -c++ -o $(MY_JNI_DIR)/$(MY_JNI_WRAP) -package org.pjsip.pjsua -outdir src/org/pjsip/pjsua -java $(MY_JNI_DIR)/pjsua.i + +.PHONY: $(MY_JNI_DIR)/$(MY_JNI_WRAP) + +include $(BUILD_SHARED_LIBRARY) diff --git a/pjsip-apps/src/pjsua/android/jni/pjsua.i b/pjsip-apps/src/pjsua/android/jni/pjsua.i new file mode 100755 index 00000000..99443160 --- /dev/null +++ b/pjsip-apps/src/pjsua/android/jni/pjsua.i @@ -0,0 +1,29 @@ +%module (directors="1") pjsua + +%{ +#include "pjsua_app_callback.h" +#include "../../pjsua_app.h" + +#ifdef __cplusplus +extern "C" { +#endif + int pjsuaStart(); + void pjsuaDestroy(); + int pjsuaRestart(); + void setCallbackObject(PjsuaAppCallback* callback); +#ifdef __cplusplus +} +#endif +%} + +int pjsuaStart(); +void pjsuaDestroy(); +int pjsuaRestart(); + +/* turn on director wrapping PjsuaAppCallback */ +%feature("director") PjsuaAppCallback; + +%include "pjsua_app_callback.h" + +void setCallbackObject(PjsuaAppCallback* callback); + diff --git a/pjsip-apps/src/pjsua/android/jni/pjsua_app_callback.cpp b/pjsip-apps/src/pjsua/android/jni/pjsua_app_callback.cpp new file mode 100644 index 00000000..6268b55e --- /dev/null +++ b/pjsip-apps/src/pjsua/android/jni/pjsua_app_callback.cpp @@ -0,0 +1,113 @@ +/* $Id: pjsua_app_callback.cpp $ */ +/* + * Copyright (C) 2012-2012 Teluu Inc. (http://www.teluu.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "pjsua_app_callback.h" +#include "../../pjsua_app.h" +#include "../../pjsua_app_config.h" + +#if defined(PJ_ANDROID) && PJ_ANDROID != 0 + +static PjsuaAppCallback* registeredCallbackObject = NULL; +static pjsua_app_cfg_t android_app_config; +static int restart_argc; +static char **restart_argv; + +extern const char *pjsua_app_def_argv[]; + +#define THIS_FILE "pjsua_app_callback.cpp" + +/** Callback wrapper **/ +void on_cli_started(pj_status_t status, const char *msg) +{ + char errmsg[PJ_ERR_MSG_SIZE]; + if (registeredCallbackObject) { + if ((status != PJ_SUCCESS) && (!msg || !*msg)) { + pj_strerror(status, errmsg, sizeof(errmsg)); + msg = errmsg; + } + registeredCallbackObject->onStarted(msg); + } +} + +void on_cli_stopped(pj_bool_t restart, int argc, char **argv) +{ + if (restart) { + restart_argc = argc; + restart_argv = argv; + } + + if (registeredCallbackObject) { + registeredCallbackObject->onStopped(restart); + } +} + +static int initMain(int argc, char **argv) +{ + pj_status_t status; + android_app_config.argc = argc; + android_app_config.argv = argv; + + status = pjsua_app_init(&android_app_config); + if (status == PJ_SUCCESS) { + status = pjsua_app_run(PJ_FALSE); + } else { + pjsua_app_destroy(); + } + + return status; +} + +int pjsuaStart() +{ + pj_status_t status; + + const char **argv = pjsua_app_def_argv; + int argc = pjsua_app_def_argc; + + pj_bzero(&android_app_config, sizeof(android_app_config)); + + android_app_config.on_started = &on_cli_started; + android_app_config.on_stopped = &on_cli_stopped; + + return initMain(argc, (char**)argv); +} + +void pjsuaDestroy() +{ + pjsua_app_destroy(); + + /** This is on purpose **/ + pjsua_app_destroy(); +} + +int pjsuaRestart() +{ + pj_status_t status; + + pjsuaDestroy(); + + return initMain(restart_argc, restart_argv); +} + +void setCallbackObject(PjsuaAppCallback* callback) +{ + registeredCallbackObject = callback; +} + +#endif diff --git a/pjsip-apps/src/pjsua/android/jni/pjsua_app_callback.h b/pjsip-apps/src/pjsua/android/jni/pjsua_app_callback.h new file mode 100644 index 00000000..561b5ce3 --- /dev/null +++ b/pjsip-apps/src/pjsua/android/jni/pjsua_app_callback.h @@ -0,0 +1,36 @@ +/* $Id: pjsua_app_callback.h $ */ +/* + * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef __PJSUA_APP_CALLBACK_H__ +#define __PJSUA_APP_CALLBACK_H__ + +class PjsuaAppCallback { +public: + virtual ~PjsuaAppCallback() {} + virtual void onStarted(const char *msg) {} + virtual void onStopped(int restart) {} +}; + +extern "C" { +int pjsuaStart(); +void pjsuaDestroy(); +int pjsuaRestart(); +void setCallbackObject(PjsuaAppCallback* callback); +} + +#endif /* __PJSUA_APP_CALLBACK_H__ */ diff --git a/pjsip-apps/src/pjsua/android/lint.xml b/pjsip-apps/src/pjsua/android/lint.xml new file mode 100644 index 00000000..ee0eead5 --- /dev/null +++ b/pjsip-apps/src/pjsua/android/lint.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/pjsip-apps/src/pjsua/android/proguard-project.txt b/pjsip-apps/src/pjsua/android/proguard-project.txt new file mode 100644 index 00000000..f2fe1559 --- /dev/null +++ b/pjsip-apps/src/pjsua/android/proguard-project.txt @@ -0,0 +1,20 @@ +# To enable ProGuard in your project, edit project.properties +# to define the proguard.config property as described in that file. +# +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in ${sdk.dir}/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the ProGuard +# include property in project.properties. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/pjsip-apps/src/pjsua/android/project.properties b/pjsip-apps/src/pjsua/android/project.properties new file mode 100644 index 00000000..9b84a6b4 --- /dev/null +++ b/pjsip-apps/src/pjsua/android/project.properties @@ -0,0 +1,14 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system edit +# "ant.properties", and override values to adapt the script to your +# project structure. +# +# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): +#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt + +# Project target. +target=android-16 diff --git a/pjsip-apps/src/pjsua/android/res/drawable-hdpi/main_image.png b/pjsip-apps/src/pjsua/android/res/drawable-hdpi/main_image.png new file mode 100755 index 00000000..a9c5328c Binary files /dev/null and b/pjsip-apps/src/pjsua/android/res/drawable-hdpi/main_image.png differ diff --git a/pjsip-apps/src/pjsua/android/res/drawable-ldpi/main_image.png b/pjsip-apps/src/pjsua/android/res/drawable-ldpi/main_image.png new file mode 100755 index 00000000..969971f8 Binary files /dev/null and b/pjsip-apps/src/pjsua/android/res/drawable-ldpi/main_image.png differ diff --git a/pjsip-apps/src/pjsua/android/res/drawable-mdpi/main_image.png b/pjsip-apps/src/pjsua/android/res/drawable-mdpi/main_image.png new file mode 100755 index 00000000..8312fcf2 Binary files /dev/null and b/pjsip-apps/src/pjsua/android/res/drawable-mdpi/main_image.png differ diff --git a/pjsip-apps/src/pjsua/android/res/drawable-xhdpi/main_image.png b/pjsip-apps/src/pjsua/android/res/drawable-xhdpi/main_image.png new file mode 100755 index 00000000..9978b0af Binary files /dev/null and b/pjsip-apps/src/pjsua/android/res/drawable-xhdpi/main_image.png differ diff --git a/pjsip-apps/src/pjsua/android/res/layout/activity_main.xml b/pjsip-apps/src/pjsua/android/res/layout/activity_main.xml new file mode 100644 index 00000000..da258b76 --- /dev/null +++ b/pjsip-apps/src/pjsua/android/res/layout/activity_main.xml @@ -0,0 +1,34 @@ + + + + + + + + + + \ No newline at end of file diff --git a/pjsip-apps/src/pjsua/android/res/values-v11/styles.xml b/pjsip-apps/src/pjsua/android/res/values-v11/styles.xml new file mode 100644 index 00000000..d408cbc3 --- /dev/null +++ b/pjsip-apps/src/pjsua/android/res/values-v11/styles.xml @@ -0,0 +1,5 @@ + + +