Changeset 5166 for pjproject


Ignore:
Timestamp:
Aug 21, 2015 6:46:32 AM (6 years ago)
Author:
ming
Message:

Fixed #1880: Incorrect orientation after switching video capture or when using back camera

Included in this fix:

  • Change the spec & doc of pjmedia_orient enumeration
  • Change iOS sample app to rotate all video devices upon orientation change event.
  • Set orientation as well when fast switching cameras (for iOS and Android)
Location:
pjproject/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/include/pjmedia/types.h

    r3774 r5166  
    203203 
    204204    /** 
    205      * Natural orientation, e.g: sky upside on landscape view, head upside 
    206      * on human portrait. 
     205     * Natural orientation, i.e. the original orientation video will be 
     206     * displayed/captured without rotation. 
    207207     */ 
    208208    PJMEDIA_ORIENT_NATURAL, 
     
    210210    /** 
    211211     * Specifies that the video/picture needs to be rotated 90 degrees 
    212      * clockwise to be displayed in natural orientation. 
     212     * from its natural orientation in clockwise direction from the user's 
     213     * perspective. 
     214     * Note that for devices with back cameras (which faces away 
     215     * from the user), the video will actually need to be rotated 
     216     * 270 degrees clockwise instead. 
    213217     */ 
    214218    PJMEDIA_ORIENT_ROTATE_90DEG, 
     
    216220    /** 
    217221     * Specifies that the video/picture needs to be rotated 180 degrees 
    218      * clockwise to be displayed in natural orientation. 
     222     * from its natural orientation. 
    219223     */ 
    220224    PJMEDIA_ORIENT_ROTATE_180DEG, 
     
    222226    /** 
    223227     * Specifies that the video/picture needs to be rotated 270 degrees 
    224      * clockwise to be displayed in natural orientation. 
     228     * from its natural orientation in clockwise direction from the user's 
     229     * perspective. 
     230     * Note that for devices with back cameras (which faces away 
     231     * from the user), the video will actually need to be rotated 
     232     * 90 degrees clockwise instead. 
    225233     */ 
    226234    PJMEDIA_ORIENT_ROTATE_270DEG 
  • pjproject/trunk/pjmedia/src/pjmedia-videodev/android_dev.c

    r5138 r5166  
    7272    pjmedia_vid_dev_info         info;          /**< Base info         */ 
    7373    unsigned                     dev_idx;       /**< Original dev ID   */ 
     74    pj_bool_t                    facing;        /**< Front/back camera?*/ 
    7475    unsigned                     sup_size_cnt;  /**< # of supp'd size  */ 
    7576    pjmedia_rect_size           *sup_size;      /**< Supported size    */ 
     
    526527        /* Set driver & name info */ 
    527528        pj_ansi_strncpy(vdi->driver, "Android", sizeof(vdi->driver)); 
     529        adi->facing = facing; 
    528530        if (facing == 0) { 
    529531            pj_ansi_strncpy(vdi->name, "Back camera", sizeof(vdi->name)); 
     
    954956            } else { 
    955957                strm->param.cap_id = p->target_id; 
     958                 
     959                /* If successful, set the orientation as well */ 
     960                and_stream_set_cap(s, PJMEDIA_VID_DEV_CAP_ORIENTATION, 
     961                                   &strm->param.orient); 
    956962            } 
    957963            jni_detach_env(with_attach); 
     
    962968        { 
    963969            pjmedia_orient orient = *(pjmedia_orient *)pval; 
     970            pjmedia_orient eff_ori; 
     971            and_dev_info *adi; 
    964972 
    965973            pj_assert(orient >= PJMEDIA_ORIENT_UNKNOWN && 
     
    985993            } 
    986994             
    987             pjmedia_vid_dev_conv_set_rotation(&strm->conv, strm->param.orient); 
     995            eff_ori = strm->param.orient; 
     996            adi = &strm->factory->dev_info[strm->param.cap_id]; 
     997            /* Normalize the orientation for back-facing camera */ 
     998            if (!adi->facing) { 
     999                if (eff_ori == PJMEDIA_ORIENT_ROTATE_90DEG) 
     1000                    eff_ori = PJMEDIA_ORIENT_ROTATE_270DEG; 
     1001                else if (eff_ori == PJMEDIA_ORIENT_ROTATE_270DEG) 
     1002                    eff_ori = PJMEDIA_ORIENT_ROTATE_90DEG; 
     1003            } 
     1004            pjmedia_vid_dev_conv_set_rotation(&strm->conv, eff_ori); 
    9881005             
    9891006            PJ_LOG(4, (THIS_FILE, "Video capture orientation set to %d", 
  • pjproject/trunk/pjmedia/src/pjmedia-videodev/ios_dev.m

    r5138 r5166  
    963963            strm->param.cap_id = p->target_id; 
    964964             
     965            /* Set the orientation as well */ 
     966            ios_stream_set_cap(s, PJMEDIA_VID_DEV_CAP_ORIENTATION, 
     967                               &strm->param.orient); 
     968             
    965969            return PJ_SUCCESS; 
    966970        } 
  • pjproject/trunk/pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaAppDelegate.m

    r5125 r5166  
    181181    static UIDeviceOrientation prev_ori = 0; 
    182182    UIDeviceOrientation dev_ori = [[UIDevice currentDevice] orientation]; 
     183    int i; 
    183184     
    184185    if (dev_ori == prev_ori) return; 
     
    193194        } 
    194195         
    195         pjsua_vid_dev_set_setting(PJMEDIA_VID_DEFAULT_CAPTURE_DEV, 
    196                                   PJMEDIA_VID_DEV_CAP_ORIENTATION, 
    197                                   &pj_ori[dev_ori-1], PJ_TRUE); 
     196        /* Here we set the orientation for all video devices. 
     197         * This may return failure for renderer devices or for 
     198         * capture devices which do not support orientation setting, 
     199         * we can simply ignore them. 
     200         */ 
     201        for (i = pjsua_vid_dev_count()-1; i >= 0; i--) { 
     202            pjsua_vid_dev_set_setting(i, PJMEDIA_VID_DEV_CAP_ORIENTATION, 
     203                                      &pj_ori[dev_ori-1], PJ_TRUE); 
     204        } 
    198205    } 
    199206#endif 
Note: See TracChangeset for help on using the changeset viewer.