summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLiong Sauw Ming <ming@teluu.com>2015-08-21 06:46:32 +0000
committerLiong Sauw Ming <ming@teluu.com>2015-08-21 06:46:32 +0000
commit97c47c4e1e14582218162e7cb8ed5185bd441357 (patch)
treefe0484a7af6ae60b4046dace0c395b64c923cc88
parent8c6f78c4426aae98c9d72b14afd010a3458a662d (diff)
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
-rw-r--r--pjmedia/include/pjmedia/types.h18
-rw-r--r--pjmedia/src/pjmedia-videodev/android_dev.c19
-rw-r--r--pjmedia/src/pjmedia-videodev/ios_dev.m4
-rw-r--r--pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaAppDelegate.m13
4 files changed, 45 insertions, 9 deletions
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;
}
diff --git a/pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaAppDelegate.m b/pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaAppDelegate.m
index 18d3557e..d85aba45 100644
--- a/pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaAppDelegate.m
+++ b/pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaAppDelegate.m
@@ -180,6 +180,7 @@ static void pjsuaOnAppConfigCb(pjsua_app_config *cfg)
static pj_thread_t *a_thread;
static UIDeviceOrientation prev_ori = 0;
UIDeviceOrientation dev_ori = [[UIDevice currentDevice] orientation];
+ int i;
if (dev_ori == prev_ori) return;
@@ -192,9 +193,15 @@ static void pjsuaOnAppConfigCb(pjsua_app_config *cfg)
pj_thread_register("ipjsua", a_thread_desc, &a_thread);
}
- pjsua_vid_dev_set_setting(PJMEDIA_VID_DEFAULT_CAPTURE_DEV,
- PJMEDIA_VID_DEV_CAP_ORIENTATION,
- &pj_ori[dev_ori-1], PJ_TRUE);
+ /* Here we set the orientation for all video devices.
+ * This may return failure for renderer devices or for
+ * capture devices which do not support orientation setting,
+ * we can simply ignore them.
+ */
+ for (i = pjsua_vid_dev_count()-1; i >= 0; i--) {
+ pjsua_vid_dev_set_setting(i, PJMEDIA_VID_DEV_CAP_ORIENTATION,
+ &pj_ori[dev_ori-1], PJ_TRUE);
+ }
}
#endif
}