Index: /pjproject/trunk/pjmedia/include/pjmedia-videodev/videodev.h
===================================================================
--- /pjproject/trunk/pjmedia/include/pjmedia-videodev/videodev.h	(revision 3773)
+++ /pjproject/trunk/pjmedia/include/pjmedia-videodev/videodev.h	(revision 3774)
@@ -193,4 +193,16 @@
      */
     PJMEDIA_VID_DEV_CAP_INPUT_PREVIEW = 64,
+
+    /**
+     * Support for changing video orientation in renderer and querying
+     * video orientation info in capture. Changing video orientation in
+     * a renderer will potentially affect the size of render window,
+     * i.e: width and height swap. When a capture device supports this
+     * capability, it will generate event PJMEDIA_EVENT_ORIENT_CHANGED
+     * (see #pjmedia_event) everytime the capture orientation is changed.
+     *
+     * The value of this capability is pjmedia_orient.
+     */
+    PJMEDIA_VID_DEV_CAP_ORIENTATION = 128,
 
     /**
@@ -370,4 +382,11 @@
     pj_bool_t native_preview;
 
+    /**
+     * Video orientation. This setting is optional and is only used if
+     * PJMEDIA_VID_DEV_CAP_ORIENTATION capability is supported and is
+     * set in the flags.
+     */
+    pjmedia_orient orient;
+
 } pjmedia_vid_dev_param;
 
Index: /pjproject/trunk/pjmedia/include/pjmedia/event.h
===================================================================
--- /pjproject/trunk/pjmedia/include/pjmedia/event.h	(revision 3773)
+++ /pjproject/trunk/pjmedia/include/pjmedia/event.h	(revision 3774)
@@ -79,5 +79,10 @@
      * Video decoding error due to missing key frame event.
      */
-    PJMEDIA_EVENT_KEY_FRAME_MISSING = PJMEDIA_FOURCC('I', 'F', 'R', 'M')
+    PJMEDIA_EVENT_KEY_FRAME_MISSING = PJMEDIA_FOURCC('I', 'F', 'R', 'M'),
+
+    /**
+     * Video orientation has been changed event.
+     */
+    PJMEDIA_EVENT_ORIENT_CHANGED = PJMEDIA_FOURCC('O', 'R', 'N', 'T')
 
 } pjmedia_event_type;
Index: /pjproject/trunk/pjmedia/include/pjmedia/types.h
===================================================================
--- /pjproject/trunk/pjmedia/include/pjmedia/types.h	(revision 3773)
+++ /pjproject/trunk/pjmedia/include/pjmedia/types.h	(revision 3774)
@@ -191,4 +191,41 @@
     pjmedia_rect_size	size;	/**< The size.		*/
 } pjmedia_rect;
+
+/**
+ * Enumeration for video/picture orientation.
+ */
+typedef enum pjmedia_orient
+{
+    /**
+     * Unknown orientation.
+     */
+    PJMEDIA_ORIENT_UNKNOWN,
+
+    /**
+     * Natural orientation, e.g: sky upside on landscape view, head upside
+     * on human portrait.
+     */
+    PJMEDIA_ORIENT_NATURAL,
+
+    /**
+     * Specifies that the video/picture needs to be rotated 90 degrees
+     * clockwise to be displayed in natural orientation.
+     */
+    PJMEDIA_ORIENT_ROTATE_90DEG,
+
+    /**
+     * Specifies that the video/picture needs to be rotated 180 degrees
+     * clockwise to be displayed in natural orientation.
+     */
+    PJMEDIA_ORIENT_ROTATE_180DEG,
+
+    /**
+     * Specifies that the video/picture needs to be rotated 270 degrees
+     * clockwise to be displayed in natural orientation.
+     */
+    PJMEDIA_ORIENT_ROTATE_270DEG
+
+} pjmedia_orient;
+
 
 /**
Index: /pjproject/trunk/pjmedia/src/pjmedia-videodev/videodev.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia-videodev/videodev.c	(revision 3773)
+++ /pjproject/trunk/pjmedia/src/pjmedia-videodev/videodev.c	(revision 3774)
@@ -46,4 +46,5 @@
     DEFINE_CAP("hide",          "Renderer hide"),
     DEFINE_CAP("preview",       "Input preview"),
+    DEFINE_CAP("orientation",   "Video orientation")
 };
 
@@ -180,4 +181,7 @@
 	FIELD_INFO(native_preview);
 	break;
+    case PJMEDIA_VID_DEV_CAP_ORIENTATION:
+	FIELD_INFO(orient);
+	break;
     default:
 	return PJMEDIA_EVID_INVCAP;
Index: /pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h
===================================================================
--- /pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h	(revision 3773)
+++ /pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h	(revision 3774)
@@ -5719,4 +5719,19 @@
                                             const pjmedia_rect_size *size);
 
+/**
+ * Rotate the video window. This function will change the video orientation
+ * and also possibly the video window size (width and height get swapped).
+ * This operation is not valid for native windows (pjsua_vid_win_info.is_native
+ * =PJ_TRUE), on which native windowing API must be used instead.
+ *
+ * @param wid		The video window ID.
+ * @param angle		The rotation angle in degrees, must be multiple of 90.
+ *			Specify positive value for clockwise rotation or
+ *			negative value for counter-clockwise rotation.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjsua_vid_win_rotate(pjsua_vid_win_id wid,
+					  int angle);
 
 
Index: /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_vid.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_vid.c	(revision 3773)
+++ /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_vid.c	(revision 3774)
@@ -1358,4 +1358,64 @@
     status = pjmedia_vid_dev_stream_set_cap(s,
 			    PJMEDIA_VID_DEV_CAP_OUTPUT_RESIZE, size);
+
+    PJSUA_UNLOCK();
+
+    return status;
+}
+
+/*
+ * Set video orientation.
+ */
+PJ_DEF(pj_status_t) pjsua_vid_win_rotate( pjsua_vid_win_id wid,
+                                          int angle)
+{
+    pjsua_vid_win *w;
+    pjmedia_vid_dev_stream *s;
+    pjmedia_orient orient;
+    pj_status_t status;
+
+    PJ_ASSERT_RETURN(wid >= 0 && wid < PJSUA_MAX_VID_WINS, PJ_EINVAL);
+    PJ_ASSERT_RETURN((angle % 90) == 0, PJ_EINVAL);
+
+    /* Normalize angle, so it must be 0, 90, 180, or 270. */
+    angle %= 360;
+    if (angle < 0)
+	angle += 360;
+
+    /* Convert angle to pjmedia_orient */
+    switch(angle) {
+	case 0:
+	    /* No rotation */
+	    return PJ_SUCCESS;
+	case 90:
+	    orient = PJMEDIA_ORIENT_ROTATE_90DEG;
+	    break;
+	case 180:
+	    orient = PJMEDIA_ORIENT_ROTATE_180DEG;
+	    break;
+	case 270:
+	    orient = PJMEDIA_ORIENT_ROTATE_270DEG;
+	    break;
+	default:
+	    pj_assert(!"Angle must have been validated");
+	    return PJ_EBUG;
+    }
+
+    PJSUA_LOCK();
+    w = &pjsua_var.win[wid];
+    if (w->vp_rend == NULL) {
+	/* Native window */
+	PJSUA_UNLOCK();
+	return PJ_EINVAL;
+    }
+
+    s = pjmedia_vid_port_get_stream(w->vp_rend);
+    if (s == NULL) {
+	PJSUA_UNLOCK();
+	return PJ_EINVAL;
+    }
+
+    status = pjmedia_vid_dev_stream_set_cap(s,
+			    PJMEDIA_VID_DEV_CAP_ORIENTATION, &orient);
 
     PJSUA_UNLOCK();
