Index: pjproject/trunk/pjmedia/include/pjmedia/types.h
===================================================================
--- pjproject/trunk/pjmedia/include/pjmedia/types.h	(revision 5165)
+++ pjproject/trunk/pjmedia/include/pjmedia/types.h	(revision 5166)
@@ -203,6 +203,6 @@
 
     /**
-     * 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,
@@ -210,5 +210,9 @@
     /**
      * 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,
@@ -216,5 +220,5 @@
     /**
      * 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,
@@ -222,5 +226,9 @@
     /**
      * 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
Index: pjproject/trunk/pjmedia/src/pjmedia-videodev/android_dev.c
===================================================================
--- pjproject/trunk/pjmedia/src/pjmedia-videodev/android_dev.c	(revision 5165)
+++ pjproject/trunk/pjmedia/src/pjmedia-videodev/android_dev.c	(revision 5166)
@@ -72,4 +72,5 @@
     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    */
@@ -526,4 +527,5 @@
 	/* 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));
@@ -954,4 +956,8 @@
 	    } 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);
@@ -962,4 +968,6 @@
         {
             pjmedia_orient orient = *(pjmedia_orient *)pval;
+            pjmedia_orient eff_ori;
+            and_dev_info *adi;
 
 	    pj_assert(orient >= PJMEDIA_ORIENT_UNKNOWN &&
@@ -985,5 +993,14 @@
 	    }
 	    
-	    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",
Index: pjproject/trunk/pjmedia/src/pjmedia-videodev/ios_dev.m
===================================================================
--- pjproject/trunk/pjmedia/src/pjmedia-videodev/ios_dev.m	(revision 5165)
+++ pjproject/trunk/pjmedia/src/pjmedia-videodev/ios_dev.m	(revision 5166)
@@ -963,4 +963,8 @@
             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;
         }
Index: pjproject/trunk/pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaAppDelegate.m
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaAppDelegate.m	(revision 5165)
+++ pjproject/trunk/pjsip-apps/src/pjsua/ios/ipjsua/ipjsuaAppDelegate.m	(revision 5166)
@@ -181,4 +181,5 @@
     static UIDeviceOrientation prev_ori = 0;
     UIDeviceOrientation dev_ori = [[UIDevice currentDevice] orientation];
+    int i;
     
     if (dev_ori == prev_ori) return;
@@ -193,7 +194,13 @@
         }
         
-        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
