Re: Android camera rotation

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

 



Hi Сергей,

Unfortunately this will make the behavior different with other
platforms. And FYI, we just changed the spec of pjmedia_orient in
ticket #1880 (https://trac.pjsip.org/repos/ticket/1880) -->
https://trac.pjsip.org/repos/browser/pjproject/trunk/pjmedia/include/pjmedia/types.h#L197

Regards,
Ming

On Mon, Apr 4, 2016 at 7:42 PM, Сергей Митрофанов <goretz.m@xxxxxxxxx> wrote:
> Yesterday I have published a patch, but today rechecked and it produces
> incorrect rotations for back camera.
> Here is the correct one patch.
> It works without any additional rotation offset calculations in app and with
> it pjsip rotations are mapped to android screen orientations directly.
>
> Was in test app:
>
> wm = (WindowManager)this.getSystemService(Context.WINDOW_SERVICE);
> display = wm.getDefaultDisplay();
> rotation = display.getRotation();
> Log.d("CallActivity", "Device orientation changed: " + rotation);
> switch (rotation) {
>     case Surface.ROTATION_0:   // Portrait
>         orient = pjmedia_orient.PJMEDIA_ORIENT_ROTATE_270DEG;
>         break;
>     case Surface.ROTATION_90:  // Landscape, home button on the right
>         orient = pjmedia_orient.PJMEDIA_ORIENT_NATURAL;
>         break;
>     case Surface.ROTATION_180:
>         orient = pjmedia_orient.PJMEDIA_ORIENT_ROTATE_90DEG;
>         break;
>     case Surface.ROTATION_270: // Landscape, home button on the left
>         orient = pjmedia_orient.PJMEDIA_ORIENT_ROTATE_180DEG;
>         break;
>     default:
>         orient = pjmedia_orient.PJMEDIA_ORIENT_UNKNOWN;
> }
>
> With this patch:
>
> wm = (WindowManager)this.getSystemService(Context.WINDOW_SERVICE);
> display = wm.getDefaultDisplay();
> rotation = display.getRotation();
> Log.d("CallActivity", "Device orientation changed: " + rotation);
> switch (rotation) {
>     case Surface.ROTATION_0:   // Portrait
>         orient = pjmedia_orient.PJMEDIA_ORIENT_NATURAL;
>         break;
>     case Surface.ROTATION_90:  // Landscape, home button on the right
>         orient = pjmedia_orient.PJMEDIA_ORIENT_ROTATE_90DEG;
>         break;
>     case Surface.ROTATION_180:
>         orient = pjmedia_orient.PJMEDIA_ORIENT_ROTATE_180DEG;
>         break;
>     case Surface.ROTATION_270: // Landscape, home button on the left
>         orient = pjmedia_orient.PJMEDIA_ORIENT_ROTATE_270DEG;
>         break;
>     default:
>         orient = pjmedia_orient.PJMEDIA_ORIENT_UNKNOWN;
> }
>
> And this works correct for both facing and back cameras without any
> additional work in application.
>
>
> вс, 3 апр. 2016 г. в 17:25, Сергей Митрофанов <goretz.m@xxxxxxxxx>:
>>
>> 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)
>>
>>
>
> _______________________________________________
> Visit our blog: http://blog.pjsip.org
>
> pjsip mailing list
> pjsip@xxxxxxxxxxxxxxx
> http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
>

_______________________________________________
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