From 97c47c4e1e14582218162e7cb8ed5185bd441357 Mon Sep 17 00:00:00 2001 From: Liong Sauw Ming Date: Fri, 21 Aug 2015 06:46:32 +0000 Subject: 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) git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@5166 74dad513-b988-da41-8d7b-12977e46ad98 --- pjmedia/include/pjmedia/types.h | 18 +++++++++++++----- pjmedia/src/pjmedia-videodev/android_dev.c | 19 ++++++++++++++++++- pjmedia/src/pjmedia-videodev/ios_dev.m | 4 ++++ 3 files changed, 35 insertions(+), 6 deletions(-) (limited to 'pjmedia') diff --git a/pjmedia/include/pjmedia/types.h b/pjmedia/include/pjmedia/types.h index 20e93d69..486f0ed8 100644 --- a/pjmedia/include/pjmedia/types.h +++ b/pjmedia/include/pjmedia/types.h @@ -202,26 +202,34 @@ typedef enum pjmedia_orient PJMEDIA_ORIENT_UNKNOWN, /** - * Natural orientation, e.g: sky upside on landscape view, head upside - * on human portrait. + * Natural orientation, i.e. the original orientation video will be + * displayed/captured without rotation. */ PJMEDIA_ORIENT_NATURAL, /** * Specifies that the video/picture needs to be rotated 90 degrees - * clockwise to be displayed in natural orientation. + * from its natural orientation in clockwise direction from the user's + * perspective. + * Note that for devices with back cameras (which faces away + * from the user), the video will actually need to be rotated + * 270 degrees clockwise instead. */ PJMEDIA_ORIENT_ROTATE_90DEG, /** * Specifies that the video/picture needs to be rotated 180 degrees - * clockwise to be displayed in natural orientation. + * from its natural orientation. */ PJMEDIA_ORIENT_ROTATE_180DEG, /** * Specifies that the video/picture needs to be rotated 270 degrees - * clockwise to be displayed in natural orientation. + * from its natural orientation in clockwise direction from the user's + * perspective. + * Note that for devices with back cameras (which faces away + * from the user), the video will actually need to be rotated + * 90 degrees clockwise instead. */ PJMEDIA_ORIENT_ROTATE_270DEG diff --git a/pjmedia/src/pjmedia-videodev/android_dev.c b/pjmedia/src/pjmedia-videodev/android_dev.c index dca0d338..1da72610 100644 --- a/pjmedia/src/pjmedia-videodev/android_dev.c +++ b/pjmedia/src/pjmedia-videodev/android_dev.c @@ -71,6 +71,7 @@ typedef struct and_dev_info { pjmedia_vid_dev_info info; /**< Base info */ unsigned dev_idx; /**< Original dev ID */ + pj_bool_t facing; /**< Front/back camera?*/ unsigned sup_size_cnt; /**< # of supp'd size */ pjmedia_rect_size *sup_size; /**< Supported size */ unsigned sup_fps_cnt; /**< # of supp'd FPS */ @@ -525,6 +526,7 @@ static pj_status_t and_factory_refresh(pjmedia_vid_dev_factory *ff) /* Set driver & name info */ pj_ansi_strncpy(vdi->driver, "Android", sizeof(vdi->driver)); + adi->facing = facing; if (facing == 0) { pj_ansi_strncpy(vdi->name, "Back camera", sizeof(vdi->name)); } else { @@ -953,6 +955,10 @@ static pj_status_t and_stream_set_cap(pjmedia_vid_dev_stream *s, status = PJMEDIA_EVID_SYSERR; } else { strm->param.cap_id = p->target_id; + + /* If successful, set the orientation as well */ + and_stream_set_cap(s, PJMEDIA_VID_DEV_CAP_ORIENTATION, + &strm->param.orient); } jni_detach_env(with_attach); break; @@ -961,6 +967,8 @@ static pj_status_t and_stream_set_cap(pjmedia_vid_dev_stream *s, case PJMEDIA_VID_DEV_CAP_ORIENTATION: { pjmedia_orient orient = *(pjmedia_orient *)pval; + pjmedia_orient eff_ori; + and_dev_info *adi; pj_assert(orient >= PJMEDIA_ORIENT_UNKNOWN && orient <= PJMEDIA_ORIENT_ROTATE_270DEG); @@ -984,7 +992,16 @@ static pj_status_t and_stream_set_cap(pjmedia_vid_dev_stream *s, return status; } - pjmedia_vid_dev_conv_set_rotation(&strm->conv, strm->param.orient); + eff_ori = strm->param.orient; + adi = &strm->factory->dev_info[strm->param.cap_id]; + /* Normalize the orientation for back-facing camera */ + if (!adi->facing) { + if (eff_ori == PJMEDIA_ORIENT_ROTATE_90DEG) + eff_ori = PJMEDIA_ORIENT_ROTATE_270DEG; + else if (eff_ori == PJMEDIA_ORIENT_ROTATE_270DEG) + eff_ori = PJMEDIA_ORIENT_ROTATE_90DEG; + } + pjmedia_vid_dev_conv_set_rotation(&strm->conv, eff_ori); PJ_LOG(4, (THIS_FILE, "Video capture orientation set to %d", strm->param.orient)); diff --git a/pjmedia/src/pjmedia-videodev/ios_dev.m b/pjmedia/src/pjmedia-videodev/ios_dev.m index 4ae06e70..c9b533e9 100644 --- a/pjmedia/src/pjmedia-videodev/ios_dev.m +++ b/pjmedia/src/pjmedia-videodev/ios_dev.m @@ -962,6 +962,10 @@ static pj_status_t ios_stream_set_cap(pjmedia_vid_dev_stream *s, strm->dev_input = new_dev_input; strm->param.cap_id = p->target_id; + /* Set the orientation as well */ + ios_stream_set_cap(s, PJMEDIA_VID_DEV_CAP_ORIENTATION, + &strm->param.orient); + return PJ_SUCCESS; } -- cgit v1.2.3