Changeset 5014
- Timestamp:
- Mar 22, 2015 8:53:03 AM (10 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia-videodev/android_opengl.c
r5007 r5014 137 137 }; 138 138 139 static void get_jvm(JNIEnv **jni_env)140 {141 (*pj_jni_jvm)->GetEnv(pj_jni_jvm, (void **)jni_env, JNI_VERSION_1_4);142 }143 144 void* android_opengl_get_surface(jobject surface)145 {146 JNIEnv *env = 0;147 get_jvm(&env);148 return ((env && surface)? ANativeWindow_fromSurface(env, surface): NULL);149 }150 151 139 int pjmedia_vid_dev_opengl_imp_get_cap(void) 152 140 { -
pjproject/trunk/pjsip-apps/src/pjsua/android/jni/pjsua.i
r4496 r5014 4 4 #include "pjsua_app_callback.h" 5 5 #include "../../pjsua_app.h" 6 #include <android/native_window_jni.h> 6 7 7 8 #ifdef __cplusplus … … 17 18 %} 18 19 19 int pjsuaStart(); 20 void pjsuaDestroy(); 21 int pjsuaRestart(); 22 23 /* turn on director wrapping PjsuaAppCallback */ 20 /* Turn on director wrapping PjsuaAppCallback */ 24 21 %feature("director") PjsuaAppCallback; 25 22 23 /* Convert Surface object to ANativeWindow for setIncomingVideoRenderer() */ 24 %typemap(in) jobject surface { 25 $1 = (jobject)ANativeWindow_fromSurface(jenv, $input); 26 } 27 26 28 %include "pjsua_app_callback.h" 27 28 void setCallbackObject(PjsuaAppCallback* callback);29 -
pjproject/trunk/pjsip-apps/src/pjsua/android/jni/pjsua_app_callback.cpp
r5005 r5014 30 30 static int restart_argc; 31 31 static char **restart_argv; 32 static pjsua_callback pjsua_cb_orig; 33 static jobject callVideoSurface; 32 34 33 35 extern const char *pjsua_app_def_argv[]; … … 42 44 } 43 45 46 static void on_call_media_state(pjsua_call_id call_id) 47 { 48 pjsua_call_info call_info; 49 unsigned mi; 50 pj_bool_t has_error = PJ_FALSE; 51 52 pjsua_call_get_info(call_id, &call_info); 53 54 for (mi=0; mi<call_info.media_cnt; ++mi) { 55 pjsua_call_media_info *med_info = &call_info.media[mi]; 56 if (med_info->type == PJMEDIA_TYPE_VIDEO && 57 med_info->status == PJSUA_CALL_MEDIA_ACTIVE && 58 med_info->stream.vid.win_in != PJSUA_INVALID_ID) 59 { 60 pjmedia_vid_dev_hwnd vhwnd; 61 62 /* Setup renderer surface */ 63 pj_bzero(&vhwnd, sizeof(vhwnd)); 64 vhwnd.type = PJMEDIA_VID_DEV_HWND_TYPE_ANDROID; 65 vhwnd.info.window = callVideoSurface; 66 pjsua_vid_win_set_win(med_info->stream.vid.win_in, &vhwnd); 67 break; 68 } 69 } 70 71 /* Forward to original callback */ 72 if (pjsua_cb_orig.on_call_media_state) 73 (*pjsua_cb_orig.on_call_media_state)(call_id); 74 } 44 75 45 76 /** Callback wrapper **/ 46 77 static void on_cli_config(pjsua_app_config *cfg) 47 78 { 79 pjsua_cb_orig = cfg->cfg.cb; 48 80 cfg->log_cfg.cb = &log_writer; 81 82 /* Override pjsua callback, e.g: to install renderer view */ 83 cfg->cfg.cb.on_call_media_state = &on_call_media_state; 49 84 } 50 85 … … 127 162 } 128 163 164 165 void setIncomingVideoRenderer(jobject surface) 166 { 167 callVideoSurface = surface; 168 } 169 129 170 #endif -
pjproject/trunk/pjsip-apps/src/pjsua/android/jni/pjsua_app_callback.h
r4496 r5014 20 20 #define __PJSUA_APP_CALLBACK_H__ 21 21 22 #include <jni.h> 23 22 24 class PjsuaAppCallback { 23 25 public: … … 32 34 int pjsuaRestart(); 33 35 void setCallbackObject(PjsuaAppCallback* callback); 36 void setIncomingVideoRenderer(jobject surface); 34 37 } 35 38 -
pjproject/trunk/pjsip-apps/src/pjsua/android/res/layout/activity_main.xml
r4496 r5014 4 4 android:layout_height="fill_parent" 5 5 android:orientation="vertical" > 6 7 <TextView 8 android:id="@+id/textStatus" 9 android:layout_width="wrap_content" 10 android:layout_height="wrap_content" 11 android:layout_alignParentBottom="true" 12 android:layout_alignParentTop="false" 13 android:layout_centerHorizontal="true" 14 android:textIsSelectable="false" /> 15 16 <SurfaceView 17 android:id="@+id/surfaceViewIncomingCall" 18 android:layout_width="wrap_content" 19 android:layout_height="match_parent" 20 android:layout_above="@+id/imageApp" 21 android:layout_alignParentLeft="true" 22 android:layout_alignParentRight="true" 23 android:layout_alignParentTop="true" 24 android:layout_marginBottom="50dp" /> 25 26 <TextView 27 android:id="@+id/textApp" 28 android:layout_width="wrap_content" 29 android:layout_height="wrap_content" 30 android:layout_above="@+id/textStatus" 31 android:layout_centerHorizontal="true" 32 android:layout_marginBottom="126dp" 33 android:text="@string/app_name" 34 android:textSize="40sp" 35 android:typeface="serif" /> 6 36 7 37 <ImageView … … 14 44 android:src="@drawable/main_image" /> 15 45 16 <TextView17 android:id="@+id/textApp"18 android:layout_width="wrap_content"19 android:layout_height="wrap_content"20 android:layout_centerHorizontal="true"21 android:layout_centerVertical="true"22 android:text="@string/app_name"23 android:textSize="40sp"24 android:typeface="serif" />25 26 <TextView27 android:id="@+id/textStatus"28 android:layout_width="wrap_content"29 android:layout_height="wrap_content"30 android:layout_alignParentBottom="true"31 android:layout_centerHorizontal="true"32 android:textIsSelectable="false"/>33 34 46 </RelativeLayout> -
pjproject/trunk/pjsip-apps/src/pjsua/android/src/org/pjsip/pjsua/MainActivity.java
r4496 r5014 26 26 import android.os.Bundle; 27 27 import android.util.Log; 28 import android.view.SurfaceHolder; 29 import android.view.SurfaceView; 28 30 import android.os.Handler; 29 31 import android.os.Message; … … 31 33 32 34 class CONST { 33 34 35 36 37 38 39 40 41 42 43 }; 35 public static final String LIB_FILENAME = "pjsua"; 36 public static final String TAG = "pjsua"; 37 public static final Boolean AUTOKILL_ON_FINISH = true; 38 public enum MSG_TYPE { 39 STR_DEBUG, 40 STR_INFO, 41 STR_ERROR, 42 CLI_STOP, 43 CLI_RESTART, 44 QUIT 45 }; 44 46 } 45 47 46 48 class LOG { 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 49 public static void DEBUG(Handler h, String str) { 50 Message msg = Message.obtain(h, CONST.MSG_TYPE.STR_DEBUG.ordinal(), 51 str); 52 msg.sendToTarget(); 53 } 54 public static void INFO(Handler h, String str) { 55 Message msg = Message.obtain(h, CONST.MSG_TYPE.STR_INFO.ordinal(), 56 str); 57 msg.sendToTarget(); 58 } 59 public static void ERROR(Handler h, String str) { 60 Message msg = Message.obtain(h, CONST.MSG_TYPE.STR_ERROR.ordinal(), 61 str); 62 msg.sendToTarget(); 63 } 62 64 } 63 65 64 public class MainActivity extends Activity { 65 private MyHandler ui_handler = new MyHandler(this); 66 private static MyCallback callback; 67 68 private static class MyHandler extends Handler { 69 private final WeakReference<MainActivity> mTarget; 70 71 public MyHandler(MainActivity target) { 72 mTarget = new WeakReference<MainActivity>(target); 66 public class MainActivity extends Activity implements SurfaceHolder.Callback { 67 private MyHandler ui_handler = new MyHandler(this); 68 private static MyCallback callback; 69 70 private static class MyHandler extends Handler { 71 private final WeakReference<MainActivity> mTarget; 72 73 public MyHandler(MainActivity target) { 74 mTarget = new WeakReference<MainActivity>(target); 75 } 76 77 @Override 78 public void handleMessage(Message m) { 79 MainActivity target = mTarget.get(); 80 if (target == null) 81 return; 82 83 if (m.what == CONST.MSG_TYPE.STR_DEBUG.ordinal()) { 84 Log.d(CONST.TAG, (String)m.obj); 85 } else if (m.what == CONST.MSG_TYPE.STR_INFO.ordinal()) { 86 target.updateStatus((String)m.obj); 87 Log.i(CONST.TAG, (String)m.obj); 88 } else if (m.what == CONST.MSG_TYPE.STR_ERROR.ordinal()) { 89 target.updateStatus((String)m.obj); 90 Log.e(CONST.TAG, (String)m.obj); 91 } else if (m.what == CONST.MSG_TYPE.CLI_STOP.ordinal()) { 92 pjsua.pjsuaDestroy(); 93 LOG.INFO(this, "Telnet Unavailable"); 94 } else if (m.what == CONST.MSG_TYPE.CLI_RESTART.ordinal()) { 95 int status = pjsua.pjsuaRestart(); 96 if (status != 0) { 97 LOG.INFO(this, "Failed restarting telnet"); 73 98 } 74 75 @Override 76 public void handleMessage(Message m) { 77 MainActivity target = mTarget.get(); 78 if (target == null) 79 return; 80 81 if (m.what == CONST.MSG_TYPE.STR_DEBUG.ordinal()) { 82 Log.d(CONST.TAG, (String)m.obj); 83 } else if (m.what == CONST.MSG_TYPE.STR_INFO.ordinal()) { 84 target.updateStatus((String)m.obj); 85 Log.i(CONST.TAG, (String)m.obj); 86 } else if (m.what == CONST.MSG_TYPE.STR_ERROR.ordinal()) { 87 target.updateStatus((String)m.obj); 88 Log.e(CONST.TAG, (String)m.obj); 89 } else if (m.what == CONST.MSG_TYPE.CLI_STOP.ordinal()) { 90 pjsua.pjsuaDestroy(); 91 LOG.INFO(this, "Telnet Unavailable"); 92 } else if (m.what == CONST.MSG_TYPE.CLI_RESTART.ordinal()) { 93 int status = pjsua.pjsuaRestart(); 94 if (status != 0) { 95 LOG.INFO(this, "Failed restarting telnet"); 96 } 97 } else if (m.what == CONST.MSG_TYPE.QUIT.ordinal()) { 98 target.finish(); 99 System.gc(); 100 android.os.Process.killProcess(android.os.Process.myPid()); 101 } 102 } 103 } 104 105 /** Callback object **/ 106 private static class MyCallback extends PjsuaAppCallback { 107 private WeakReference<Handler> ui_handler; 108 109 public MyCallback(Handler in_ui_handler) { 110 set_ui_handler(in_ui_handler); 111 } 112 113 public void set_ui_handler(Handler in_ui_handler) { 114 ui_handler = new WeakReference<Handler>(in_ui_handler); 115 } 116 117 @Override 118 public void onStarted(String msg) { 119 Handler ui = ui_handler.get(); 120 LOG.INFO(ui, msg); 121 } 122 123 @Override 124 public void onStopped(int restart) { 125 Handler ui = ui_handler.get(); 126 /** Use timer to stopped/restart **/ 127 if (restart != 0) { 128 LOG.INFO(ui, "Telnet Restarting"); 129 Message msg = Message.obtain(ui, 130 CONST.MSG_TYPE.CLI_RESTART.ordinal()); 131 ui.sendMessageDelayed(msg, 100); 132 } else { 133 LOG.INFO(ui, "Telnet Stopping"); 134 Message msg = Message.obtain(ui, 135 CONST.MSG_TYPE.CLI_STOP.ordinal()); 136 ui.sendMessageDelayed(msg, 100); 137 } 138 } 139 } 140 141 private void updateStatus(String output) { 142 TextView tStatus = (TextView) findViewById(R.id.textStatus); 143 tStatus.setText(output); 144 } 99 } else if (m.what == CONST.MSG_TYPE.QUIT.ordinal()) { 100 target.finish(); 101 System.gc(); 102 android.os.Process.killProcess(android.os.Process.myPid()); 103 } 104 } 105 } 106 107 /** Callback object **/ 108 private static class MyCallback extends PjsuaAppCallback { 109 private WeakReference<Handler> ui_handler; 110 111 public MyCallback(Handler in_ui_handler) { 112 set_ui_handler(in_ui_handler); 113 } 114 115 public void set_ui_handler(Handler in_ui_handler) { 116 ui_handler = new WeakReference<Handler>(in_ui_handler); 117 } 118 119 @Override 120 public void onStarted(String msg) { 121 Handler ui = ui_handler.get(); 122 LOG.INFO(ui, msg); 123 } 124 125 @Override 126 public void onStopped(int restart) { 127 Handler ui = ui_handler.get(); 128 /** Use timer to stopped/restart **/ 129 if (restart != 0) { 130 LOG.INFO(ui, "Telnet Restarting"); 131 Message msg = Message.obtain(ui, 132 CONST.MSG_TYPE.CLI_RESTART.ordinal()); 133 ui.sendMessageDelayed(msg, 100); 134 } else { 135 LOG.INFO(ui, "Telnet Stopping"); 136 Message msg = Message.obtain(ui, 137 CONST.MSG_TYPE.CLI_STOP.ordinal()); 138 ui.sendMessageDelayed(msg, 100); 139 } 140 } 141 } 142 143 private void updateStatus(String output) { 144 TextView tStatus = (TextView) findViewById(R.id.textStatus); 145 tStatus.setText(output); 146 } 147 148 @Override 149 protected void onCreate(Bundle savedInstanceState) { 150 LOG.DEBUG(ui_handler, "=== Activity::onCreate() ==="); 151 super.onCreate(savedInstanceState); 152 153 init_view(); 154 155 init_lib(); 156 } 157 158 @Override 159 protected void onStart() { 160 LOG.DEBUG(ui_handler, "=== Activity::onStart() ==="); 161 super.onStart(); 162 } 163 164 @Override 165 protected void onRestart() { 166 LOG.DEBUG(ui_handler, "=== Activity::onRestart() ==="); 167 super.onRestart(); 168 } 169 170 @Override 171 protected void onResume() { 172 LOG.DEBUG(ui_handler, "=== Activity::onResume() ==="); 173 super.onResume(); 174 } 175 176 @Override 177 protected void onPause() { 178 LOG.DEBUG(ui_handler, "=== Activity::onPause() ==="); 179 super.onPause(); 180 } 181 182 @Override 183 protected void onStop() { 184 LOG.DEBUG(ui_handler, "=== Activity::onStop() ==="); 185 super.onStop(); 186 } 187 188 @Override 189 protected void onDestroy() { 190 LOG.DEBUG(ui_handler, "=== Activity::onDestroy() ==="); 191 super.onDestroy(); 192 } 193 194 @Override 195 protected void onSaveInstanceState(Bundle outState) { 196 super.onSaveInstanceState(outState); 197 } 198 199 @Override 200 protected void onRestoreInstanceState(Bundle savedInstanceState) { 201 super.onRestoreInstanceState(savedInstanceState); 202 } 203 204 private void init_view() { 205 setContentView(R.layout.activity_main); 206 } 207 208 private int init_lib() { 209 LOG.INFO(ui_handler, "Loading module..."); 210 211 // Try loading video dependency libs 212 try { 213 System.loadLibrary("openh264"); 214 System.loadLibrary("yuv"); 215 } catch (UnsatisfiedLinkError e) { 216 LOG.ERROR(ui_handler, "UnsatisfiedLinkError: " + e.getMessage()); 217 LOG.ERROR(ui_handler, "This could be safely ignored if you "+ 218 "don't need video."); 219 } 220 221 // Load pjsua 222 try { 223 System.loadLibrary(CONST.LIB_FILENAME); 224 } catch (UnsatisfiedLinkError e) { 225 LOG.ERROR(ui_handler, "UnsatisfiedLinkError: " + e.getMessage()); 226 return -1; 227 } 228 229 // Wait for GDB to init, for native debugging only 230 if (false && (getApplicationInfo().flags & 231 ApplicationInfo.FLAG_DEBUGGABLE) != 0) 232 { 233 try { 234 Thread.sleep(5000); 235 } catch (InterruptedException e) { 236 LOG.ERROR(ui_handler, "InterruptedException: " + 237 e.getMessage()); 238 } 239 } 240 241 // Set callback object 242 if (callback == null) 243 callback = new MyCallback(ui_handler); 244 245 pjsua.setCallbackObject(callback); 246 247 SurfaceView surfaceView = (SurfaceView) 248 findViewById(R.id.surfaceViewIncomingCall); 249 surfaceView.getHolder().addCallback(this); 250 251 LOG.INFO(ui_handler, "Starting module.."); 252 253 int rc = pjsua.pjsuaStart(); 254 255 if (rc != 0) { 256 LOG.INFO(ui_handler, "Failed starting telnet"); 257 } 258 259 return 0; 260 } 145 261 146 @Override 147 protected void onCreate(Bundle savedInstanceState) { 148 LOG.DEBUG(ui_handler, "=== Activity::onCreate() ==="); 149 super.onCreate(savedInstanceState); 150 151 init_view(); 152 153 init_lib(); 154 } 155 156 @Override 157 protected void onStart() { 158 LOG.DEBUG(ui_handler, "=== Activity::onStart() ==="); 159 super.onStart(); 262 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) 263 { 264 pjsua.setIncomingVideoRenderer(holder.getSurface()); 265 } 266 267 public void surfaceCreated(SurfaceHolder holder) 268 { 269 pjsua.setIncomingVideoRenderer(holder.getSurface()); 270 } 271 272 public void surfaceDestroyed(SurfaceHolder holder) 273 { 274 pjsua.setIncomingVideoRenderer(null); 160 275 } 161 276 162 @Override163 protected void onRestart() {164 LOG.DEBUG(ui_handler, "=== Activity::onRestart() ===");165 super.onRestart();166 }167 168 @Override169 protected void onResume() {170 LOG.DEBUG(ui_handler, "=== Activity::onResume() ===");171 super.onResume();172 }173 174 @Override175 protected void onPause() {176 LOG.DEBUG(ui_handler, "=== Activity::onPause() ===");177 super.onPause();178 }179 180 @Override181 protected void onStop() {182 LOG.DEBUG(ui_handler, "=== Activity::onStop() ===");183 super.onStop();184 }185 186 @Override187 protected void onDestroy() {188 LOG.DEBUG(ui_handler, "=== Activity::onDestroy() ===");189 super.onDestroy();190 }191 192 @Override193 protected void onSaveInstanceState(Bundle outState) {194 super.onSaveInstanceState(outState);195 }196 197 @Override198 protected void onRestoreInstanceState(Bundle savedInstanceState) {199 super.onRestoreInstanceState(savedInstanceState);200 }201 202 private void init_view() {203 setContentView(R.layout.activity_main);204 }205 206 private int init_lib() {207 LOG.INFO(ui_handler, "Loading module...");208 try {209 System.loadLibrary(CONST.LIB_FILENAME);210 } catch (UnsatisfiedLinkError e) {211 LOG.ERROR(ui_handler, "UnsatisfiedLinkError: " + e.getMessage());212 return -1;213 }214 215 // Wait for GDB to init216 if ((getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0)217 {218 try {219 Thread.sleep(5000);220 } catch (InterruptedException e) {221 LOG.ERROR(ui_handler, "InterruptedException: " +222 e.getMessage());223 }224 }225 226 // Set callback object227 if (callback == null)228 callback = new MyCallback(ui_handler);229 230 pjsua.setCallbackObject(callback);231 232 LOG.INFO(ui_handler, "Starting module..");233 234 int rc = pjsua.pjsuaStart();235 236 if (rc != 0) {237 LOG.INFO(ui_handler, "Failed starting telnet");238 }239 240 return 0;241 }242 277 } -
pjproject/trunk/pjsip-apps/src/swig/java/android/src/org/pjsip/pjsua2/app/CallActivity.java
r4997 r5014 80 80 vidWH.getHandle().setWindow(null); 81 81 else 82 vidWH.getHandle().setWindow(pjsua2.android_opengl_get_surface(holder.getSurface()));82 vidWH.getHandle().setWindow(holder.getSurface()); 83 83 try { 84 84 MainActivity.currentCall.vidWin.setWindow(vidWH); -
pjproject/trunk/pjsip-apps/src/swig/java/android/src/org/pjsip/pjsua2/app/MyApp.java
r4997 r5014 21 21 import java.io.File; 22 22 import java.util.ArrayList; 23 23 24 import org.pjsip.pjsua2.*; 24 25 … … 244 245 class MyApp { 245 246 static { 247 try{ 248 System.loadLibrary("openh264"); 249 System.loadLibrary("yuv"); 250 } catch (UnsatisfiedLinkError e) { 251 System.out.println("UnsatisfiedLinkError: " + e.getMessage()); 252 System.out.println("This could be safely ignored if you " + 253 "don't need video."); 254 } 246 255 System.loadLibrary("pjsua2"); 247 256 System.out.println("Library loaded"); -
pjproject/trunk/pjsip-apps/src/swig/pjsua2.i
r4996 r5014 102 102 %template(CodecInfoVector) std::vector<pj::CodecInfo*>; 103 103 104 %include "pjsua2/media.hpp" 105 // Create an interface for android_opengl_get_surface() 104 /* pj::WindowHandle::setWindow() receives Surface object */ 106 105 #if defined(SWIGJAVA) && defined(__ANDROID__) 107 %inline %{ 108 extern "C" { 109 void* android_opengl_get_surface(jobject surface); 106 %{#include <android/native_window_jni.h>%} 107 %ignore pj::WindowHandle::display; 108 %ignore pj::WindowHandle::window; 109 %typemap(in) jobject surface { 110 $1 = (jobject)ANativeWindow_fromSurface(jenv, $input); 110 111 } 111 %} 112 %extend pj::WindowHandle { 113 void setWindow(jobject surface) { $self->window = surface; } 114 } 112 115 #endif 113 116 117 %include "pjsua2/media.hpp" 114 118 %include "pjsua2/presence.hpp" 115 119 %include "pjsua2/account.hpp"
Note: See TracChangeset
for help on using the changeset viewer.