Changeset 4997 for pjproject


Ignore:
Timestamp:
Mar 18, 2015 12:02:51 PM (9 years ago)
Author:
ming
Message:

Re #1823 (pjsua2 video api): sample usage of Video Window API in pjsua2 app for android

Location:
pjproject/trunk/pjsip-apps/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip-apps/src/pjsua/android/.classpath

    r4496 r4997  
    22<classpath> 
    33        <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> 
    4         <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/> 
     4        <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/> 
    55        <classpathentry kind="src" path="src"/> 
    66        <classpathentry kind="src" path="gen"/> 
     7        <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/> 
    78        <classpathentry kind="output" path="bin/classes"/> 
    89</classpath> 
  • pjproject/trunk/pjsip-apps/src/swig/java/android/AndroidManifest.xml

    r4928 r4997  
    1010 
    1111    <uses-permission android:name="android.permission.INTERNET" /> 
     12    <uses-permission android:name="android.permission.CAMERA" /> 
    1213    <uses-permission android:name="android.permission.RECORD_AUDIO" /> 
    1314    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> 
  • pjproject/trunk/pjsip-apps/src/swig/java/android/res/layout/activity_call.xml

    r4704 r4997  
    3939        android:text="Reject" /> 
    4040 
     41    <SurfaceView 
     42        android:id="@+id/surfaceIncomingVideo" 
     43        android:layout_width="match_parent" 
     44        android:layout_height="match_parent" /> 
     45 
    4146</LinearLayout> 
  • pjproject/trunk/pjsip-apps/src/swig/java/android/src/org/pjsip/pjsua2/app/CallActivity.java

    r4840 r4997  
    2222import android.os.Handler; 
    2323import android.os.Message; 
     24import android.view.SurfaceHolder; 
     25import android.view.SurfaceView; 
    2426import android.view.View; 
    2527import android.widget.Button; 
     
    2931import org.pjsip.pjsua2.*; 
    3032 
    31 public class CallActivity extends Activity implements Handler.Callback { 
     33public class CallActivity extends Activity 
     34        implements Handler.Callback, SurfaceHolder.Callback 
     35{ 
    3236         
    3337        public static Handler handler_; 
     
    4044                super.onCreate(savedInstanceState); 
    4145                setContentView(R.layout.activity_call); 
     46                 
     47                SurfaceView surfaceView = (SurfaceView)findViewById(R.id.surfaceIncomingVideo); 
     48                if (MainActivity.currentCall == null || 
     49                        MainActivity.currentCall.vidWin == null) 
     50                { 
     51                        surfaceView.setVisibility(View.GONE); 
     52                } 
     53                surfaceView.getHolder().addCallback(this); 
    4254                 
    4355                handler_ = handler; 
     
    5971        handler_ = null; 
    6072    } 
    61          
     73 
     74    private void updateVideoWindow(SurfaceHolder holder) { 
     75                if (MainActivity.currentCall != null && 
     76                        MainActivity.currentCall.vidWin != null) 
     77                { 
     78                        VideoWindowHandle vidWH = new VideoWindowHandle(); 
     79                        if (holder == null) 
     80                                vidWH.getHandle().setWindow(null); 
     81                        else 
     82                                vidWH.getHandle().setWindow(pjsua2.android_opengl_get_surface(holder.getSurface())); 
     83                        try { 
     84                                MainActivity.currentCall.vidWin.setWindow(vidWH); 
     85                        } catch (Exception e) {} 
     86                } 
     87    } 
     88     
     89        public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { 
     90                updateVideoWindow(holder); 
     91    } 
     92 
     93    public void surfaceCreated(SurfaceHolder holder) { 
     94    } 
     95 
     96    public void surfaceDestroyed(SurfaceHolder holder) { 
     97        updateVideoWindow(null); 
     98    } 
     99     
    62100        public void acceptCall(View view) { 
    63101                CallOpParam prm = new CallOpParam(); 
     
    87125        } 
    88126         
     127        private void setupVideoSurface() { 
     128 
     129                SurfaceView surfaceView = (SurfaceView)findViewById(R.id.surfaceIncomingVideo); 
     130                surfaceView.setVisibility(View.VISIBLE); 
     131                updateVideoWindow(surfaceView.getHolder()); 
     132                 
     133        } 
     134         
    89135        @Override 
    90136        public boolean handleMessage(Message m) { 
     
    95141                        updateCallState(lastCallInfo); 
    96142                         
     143                } else if (m.what == MainActivity.MSG_TYPE.CALL_MEDIA_STATE) { 
     144                         
     145                        if (MainActivity.currentCall.vidWin != null) { 
     146                                /* If there's incoming video, display it. */ 
     147                                setupVideoSurface(); 
     148                        } 
     149 
    97150                } else { 
    98151                         
  • pjproject/trunk/pjsip-apps/src/swig/java/android/src/org/pjsip/pjsua2/app/MainActivity.java

    r4870 r4997  
    6262                public final static int REG_STATE = 3; 
    6363                public final static int BUDDY_STATE = 4; 
     64                public final static int CALL_MEDIA_STATE = 5; 
    6465        } 
    6566 
     
    171172                        if (CallActivity.handler_ != null) { 
    172173                                Message m2 = Message.obtain(CallActivity.handler_, MSG_TYPE.CALL_STATE, ci); 
     174                                m2.sendToTarget(); 
     175                        } 
     176                         
     177                } else if (m.what == MSG_TYPE.CALL_MEDIA_STATE) { 
     178                         
     179                        /* Forward the message to CallActivity */ 
     180                        if (CallActivity.handler_ != null) { 
     181                                Message m2 = Message.obtain(CallActivity.handler_, MSG_TYPE.CALL_MEDIA_STATE, null); 
    173182                                m2.sendToTarget(); 
    174183                        } 
     
    333342                 
    334343                MyCall call = new MyCall(account, -1); 
    335                 CallOpParam prm = new CallOpParam(); 
    336                 CallSetting opt = prm.getOpt(); 
    337                 opt.setAudioCount(1); 
    338                 opt.setVideoCount(0); 
     344                CallOpParam prm = new CallOpParam(true); 
    339345 
    340346                try { 
     
    503509        } 
    504510         
     511        public void notifyCallMediaState(MyCall call) { 
     512                Message m = Message.obtain(handler, MSG_TYPE.CALL_MEDIA_STATE, null); 
     513                m.sendToTarget(); 
     514        } 
     515         
    505516        public void notifyBuddyState(MyBuddy buddy) { 
    506517                Message m = Message.obtain(handler, MSG_TYPE.BUDDY_STATE, buddy); 
  • pjproject/trunk/pjsip-apps/src/swig/java/android/src/org/pjsip/pjsua2/app/MyApp.java

    r4870 r4997  
    2929        abstract void notifyIncomingCall(MyCall call); 
    3030        abstract void notifyCallState(MyCall call); 
     31        abstract void notifyCallMediaState(MyCall call); 
    3132        abstract void notifyBuddyState(MyBuddy buddy); 
    3233} 
     
    4243 
    4344class MyCall extends Call { 
     45        public VideoWindow vidWin; 
     46         
    4447        MyCall(MyAccount acc, int call_id) { 
    4548                super(acc, call_id); 
     49                vidWin = null; 
    4650        } 
    4751 
     
    8791                                        continue; 
    8892                                } 
    89                         } 
    90                 } 
     93                        } else if (cmi.getType() == pjmedia_type.PJMEDIA_TYPE_VIDEO && 
     94                                       cmi.getStatus() == pjsua_call_media_status.PJSUA_CALL_MEDIA_ACTIVE && 
     95                                       cmi.getVideoIncomingWindowId() != pjsua2.INVALID_ID) 
     96                        { 
     97                                vidWin = cmi.getVideoWindow(); 
     98                        } 
     99                } 
     100                 
     101                MyApp.observer.notifyCallMediaState(this); 
    91102        } 
    92103} 
  • pjproject/trunk/pjsip-apps/src/swig/java/sample.java

    r4767 r4997  
    4545         
    4646        @Override 
     47        public void notifyCallMediaState(MyCall call) { 
     48        } 
     49 
    4750        public void notifyCallState(MyCall call) { 
    4851                if (currentCall == null || call.getId() != currentCall.getId()) 
Note: See TracChangeset for help on using the changeset viewer.