Ignore:
Timestamp:
Jun 25, 2015 8:17:52 AM (9 years ago)
Author:
ming
Message:

Re #1861: Initial implementation of video orientation support

  • Utility to resize and rotate video frame
  • Support for iOS + sample
  • pjsua API to set video device's orientation
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaAppDelegate.m

    r5041 r5118  
    4040static char           **restartArgv; 
    4141static int              restartArgc; 
    42 static pj_thread_desc   a_thread_desc; 
    43 static pj_thread_t     *a_thread; 
    4442 
    4543static void displayMsg(const char *msg) 
     
    118116        } 
    119117     
     118        /* Setup device orientation change notification */ 
     119        [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
     120        [[NSNotificationCenter defaultCenter] addObserver:app 
     121            selector:@selector(orientationChanged:) 
     122            name:UIDeviceOrientationDidChangeNotification 
     123            object:[UIDevice currentDevice]]; 
     124         
    120125        status = pjsua_app_run(PJ_TRUE); 
    121126        if (status != PJ_SUCCESS) { 
     
    124129            displayMsg(errmsg); 
    125130        } 
     131         
     132        [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; 
    126133     
    127134        pjsua_app_destroy(); 
     
    158165} 
    159166 
     167- (void)orientationChanged:(NSNotification *)note 
     168{ 
     169#if PJSUA_HAS_VIDEO 
     170    const pjmedia_orient pj_ori[4] = 
     171    { 
     172        PJMEDIA_ORIENT_ROTATE_90DEG,  /* UIDeviceOrientationPortrait */ 
     173        PJMEDIA_ORIENT_ROTATE_270DEG, /* UIDeviceOrientationPortraitUpsideDown */ 
     174        PJMEDIA_ORIENT_ROTATE_180DEG, /* UIDeviceOrientationLandscapeLeft, 
     175                                         home button on the right side */ 
     176        PJMEDIA_ORIENT_NATURAL        /* UIDeviceOrientationLandscapeRight, 
     177                                         home button on the left side */ 
     178    }; 
     179    static pj_thread_desc a_thread_desc; 
     180    static pj_thread_t *a_thread; 
     181    static UIDeviceOrientation prev_ori = 0; 
     182    UIDeviceOrientation dev_ori = [[UIDevice currentDevice] orientation]; 
     183     
     184    if (dev_ori == prev_ori && !note) return; 
     185     
     186    NSLog(@"Device orientation changed: %d", (prev_ori = dev_ori)); 
     187     
     188    if (dev_ori >= UIDeviceOrientationPortrait && 
     189        dev_ori <= UIDeviceOrientationLandscapeRight) 
     190    { 
     191        if (!pj_thread_is_registered()) { 
     192            pj_thread_register("ipjsua", a_thread_desc, &a_thread); 
     193        } 
     194         
     195        pjsua_vid_dev_set_orient(PJMEDIA_VID_DEFAULT_CAPTURE_DEV, 
     196                                 pj_ori[dev_ori-1]); 
     197    } 
     198#endif 
     199} 
     200 
    160201- (void)keepAlive { 
     202    static pj_thread_desc a_thread_desc; 
     203    static pj_thread_t *a_thread; 
    161204    int i; 
    162205     
    163     if (!pj_thread_is_registered()) 
    164     { 
     206    if (!pj_thread_is_registered()) { 
    165207        pj_thread_register("ipjsua", a_thread_desc, &a_thread); 
    166208    } 
     
    230272    i = (wid == PJSUA_INVALID_ID) ? 0 : wid; 
    231273    last = (wid == PJSUA_INVALID_ID) ? PJSUA_MAX_VID_WINS : wid+1; 
     274 
     275    [app orientationChanged:NULL]; 
    232276     
    233277    for (;i < last; ++i) { 
Note: See TracChangeset for help on using the changeset viewer.