Android camera rotation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi!

I have found that pjsip does not respect initial camera rotation in android devices.
Sure the android_dev.c itself extracts the rotation value from android camera devices,
but for now this value is actually not used, resulting wrong capture video orientation.
I made a simple patch (a little bit raw code style) that resolves this bug.
It takes the camera rotation value in the game and make PJSUA2 easier to use - developer need no more think about camera initial rotation and tweak the rotation value before giving it to PJSUA2 itself.

Here is the diff patch for the changes:

From 1ea38ce9103f6fadd9812f635c83442994fd37ea Mon Sep 17 00:00:00 2001

From: Sergey Mitrofanov <GOretZ.M@xxxxxxxxx>

Date: Sun, 3 Apr 2016 17:21:48 +0300

Subject: [PATCH] Fixing to respect initial camera rotation in android devices.


---

 pjmedia/src/pjmedia-videodev/android_dev.c | 36 ++++++++++++++++++++++++++++++

 1 file changed, 36 insertions(+)


diff --git a/pjmedia/src/pjmedia-videodev/android_dev.c b/pjmedia/src/pjmedia-videodev/android_dev.c

index 1da7261..fd6e61d 100644

--- a/pjmedia/src/pjmedia-videodev/android_dev.c

+++ b/pjmedia/src/pjmedia-videodev/android_dev.c

@@ -72,6 +72,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 rotation; /**< initial camera rotation*/

     unsigned sup_size_cnt; /**< # of supp'd size  */

     pjmedia_rect_size *sup_size; /**< Supported size    */

     unsigned sup_fps_cnt; /**< # of supp'd FPS   */

@@ -532,6 +533,8 @@ static pj_status_t and_factory_refresh(pjmedia_vid_dev_factory *ff)

  } else {

      pj_ansi_strncpy(vdi->name, "Front camera", sizeof(vdi->name));

  }

+ adi->rotation = (*jni_env)->GetIntField(jni_env, jdev_info,

+ jobjs.cam_info.f_orient);

 

  /* Get supported sizes */

  jtmp = (*jni_env)->GetObjectField(jni_env, jdev_info,

@@ -1001,6 +1004,39 @@ static pj_status_t and_stream_set_cap(pjmedia_vid_dev_stream *s,

  else if (eff_ori == PJMEDIA_ORIENT_ROTATE_270DEG)

      eff_ori = PJMEDIA_ORIENT_ROTATE_90DEG;

      }

+     /* Normalize the orientation for rotated camera */

+     switch(adi->rotation){

+ case 90:

+ if (eff_ori == PJMEDIA_ORIENT_ROTATE_90DEG)

+     eff_ori = PJMEDIA_ORIENT_ROTATE_180DEG;

+ else if (eff_ori == PJMEDIA_ORIENT_ROTATE_180DEG)

+     eff_ori = PJMEDIA_ORIENT_ROTATE_270DEG;

+ else if (eff_ori == PJMEDIA_ORIENT_ROTATE_270DEG)

+     eff_ori = PJMEDIA_ORIENT_NATURAL;

+ else if (eff_ori == PJMEDIA_ORIENT_NATURAL)

+     eff_ori = PJMEDIA_ORIENT_ROTATE_90DEG;

+ break;

+ case 180:

+ if (eff_ori == PJMEDIA_ORIENT_ROTATE_90DEG)

+     eff_ori = PJMEDIA_ORIENT_ROTATE_270DEG;

+ else if (eff_ori == PJMEDIA_ORIENT_ROTATE_180DEG)

+     eff_ori = PJMEDIA_ORIENT_NATURAL;

+ else if (eff_ori == PJMEDIA_ORIENT_ROTATE_270DEG)

+     eff_ori = PJMEDIA_ORIENT_ROTATE_90DEG;

+ else if (eff_ori == PJMEDIA_ORIENT_NATURAL)

+     eff_ori = PJMEDIA_ORIENT_ROTATE_180DEG;

+ break;

+ case 270:

+ if (eff_ori == PJMEDIA_ORIENT_ROTATE_90DEG)

+     eff_ori = PJMEDIA_ORIENT_NATURAL;

+ else if (eff_ori == PJMEDIA_ORIENT_ROTATE_180DEG)

+     eff_ori = PJMEDIA_ORIENT_ROTATE_90DEG;

+ else if (eff_ori == PJMEDIA_ORIENT_ROTATE_270DEG)

+     eff_ori = PJMEDIA_ORIENT_ROTATE_180DEG;

+ else if (eff_ori == PJMEDIA_ORIENT_NATURAL)

+     eff_ori = PJMEDIA_ORIENT_ROTATE_270DEG;

+ break;

+     }

      pjmedia_vid_dev_conv_set_rotation(&strm->conv, eff_ori);

     

      PJ_LOG(4, (THIS_FILE, "Video capture orientation set to %d",

-- 

2.6.4 (Apple Git-63)


Attachment: 0001-Fixing-to-respect-initial-camera-rotation-in-android.patch
Description: Binary data

_______________________________________________
Visit our blog: http://blog.pjsip.org

pjsip mailing list
pjsip@xxxxxxxxxxxxxxx
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org

[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux