Ignore:
Timestamp:
Jul 30, 2015 6:23:35 AM (9 years ago)
Author:
ming
Message:

Fixed #1861: Add support for video capture orientation on Android

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip-apps/src/swig/java/android/src/org/pjsip/pjsua2/app/CallActivity.java

    r5102 r5138  
    2222import android.os.Handler; 
    2323import android.os.Message; 
     24import android.view.Display; 
     25import android.view.Surface; 
    2426import android.view.SurfaceHolder; 
    2527import android.view.SurfaceView; 
    2628import android.view.View; 
     29import android.view.WindowManager; 
    2730import android.widget.Button; 
    2831import android.widget.TextView; 
    2932import android.app.Activity; 
     33import android.content.Context; 
     34import android.content.res.Configuration; 
    3035 
    3136import org.pjsip.pjsua2.*; 
     
    132137 
    133138    @Override 
     139    public void onConfigurationChanged(Configuration newConfig) { 
     140        super.onConfigurationChanged(newConfig); 
     141         
     142        WindowManager wm; 
     143        Display display; 
     144        int rotation; 
     145        pjmedia_orient orient; 
     146 
     147        wm = (WindowManager)this.getSystemService(Context.WINDOW_SERVICE); 
     148        display = wm.getDefaultDisplay(); 
     149        rotation = display.getRotation(); 
     150        System.out.println("Device orientation changed: " + rotation); 
     151         
     152        switch (rotation) { 
     153        case Surface.ROTATION_0:   // Portrait 
     154            orient = pjmedia_orient.PJMEDIA_ORIENT_ROTATE_270DEG; 
     155            break; 
     156        case Surface.ROTATION_90:  // Landscape, home button on the right 
     157            orient = pjmedia_orient.PJMEDIA_ORIENT_NATURAL; 
     158            break; 
     159        case Surface.ROTATION_180: 
     160            orient = pjmedia_orient.PJMEDIA_ORIENT_ROTATE_90DEG; 
     161            break; 
     162        case Surface.ROTATION_270: // Landscape, home button on the left 
     163            orient = pjmedia_orient.PJMEDIA_ORIENT_ROTATE_180DEG; 
     164            break; 
     165        default: 
     166            orient = pjmedia_orient.PJMEDIA_ORIENT_UNKNOWN; 
     167        } 
     168 
     169        if (MyApp.ep != null && MainActivity.account != null) { 
     170            try { 
     171                AccountConfig cfg = MainActivity.account.cfg; 
     172                int cap_dev = cfg.getVideoConfig().getDefaultCaptureDevice(); 
     173                MyApp.ep.vidDevManager().setCaptureOrient(cap_dev, orient, 
     174                                                          true); 
     175            } catch (Exception e) { 
     176                System.out.println(e); 
     177            } 
     178        } 
     179    }     
     180 
     181    @Override 
    134182    protected void onDestroy() 
    135183    { 
     
    256304 
    257305            if (MainActivity.currentCall.vidWin != null) { 
     306                /* Set capture orientation according to current 
     307                 * device orientation. 
     308                 */ 
     309                onConfigurationChanged(getResources().getConfiguration()); 
    258310                /* If there's incoming video, display it. */ 
    259311                setupVideoSurface(); 
Note: See TracChangeset for help on using the changeset viewer.