[vlc-commits] mediacodec: update fmt_out if codec support rotation

Thomas Guillem git at videolan.org
Mon Dec 19 17:24:43 CET 2016


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Mon Dec 19 16:47:29 2016 +0100| [30937af9684b5f6e54316a1f235c628322018af3] | committer: Thomas Guillem

mediacodec: update fmt_out if codec support rotation

If MediaCodec can handle the rotation, we don't need to ask the vout to
rotate the video again.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=30937af9684b5f6e54316a1f235c628322018af3
---

 modules/codec/omxil/mediacodec.c     | 44 ++++++++++++++++++++++++------------
 modules/codec/omxil/mediacodec.h     |  1 +
 modules/codec/omxil/mediacodec_jni.c | 21 +++++++----------
 modules/codec/omxil/mediacodec_ndk.c |  1 +
 4 files changed, 39 insertions(+), 28 deletions(-)

diff --git a/modules/codec/omxil/mediacodec.c b/modules/codec/omxil/mediacodec.c
index bb21d08..d662028 100644
--- a/modules/codec/omxil/mediacodec.c
+++ b/modules/codec/omxil/mediacodec.c
@@ -118,6 +118,7 @@ struct decoder_sys_t
         struct
         {
             void *p_surface, *p_jsurface;
+            unsigned i_angle;
             unsigned int i_stride, i_slice_height;
             int i_pixel_format;
             uint8_t i_nal_length_size;
@@ -491,6 +492,33 @@ static int UpdateOpaqueVout(decoder_t *p_dec)
     decoder_sys_t *p_sys = p_dec->p_sys;
     picture_t *p_dummy_hwpic;
 
+    if (p_sys->api->b_support_rotation)
+    {
+        switch (p_dec->fmt_in.video.orientation)
+        {
+            case ORIENT_ROTATED_90:
+                p_sys->video.i_angle = 90;
+                break;
+            case ORIENT_ROTATED_180:
+                p_sys->video.i_angle = 180;
+                break;
+            case ORIENT_ROTATED_270:
+                p_sys->video.i_angle = 270;
+                break;
+            default:
+                p_sys->video.i_angle = 0;
+                break;
+        }
+
+        /* If MediaCodec can handle the rotation, reset the orientation to
+         * Normal in order to ask the vout not to rotate. */
+        if (p_sys->video.i_angle != 0)
+            video_format_ApplyRotation(&p_dec->fmt_out.video,
+                                       &p_dec->fmt_in.video);
+    }
+    else
+        p_sys->video.i_angle = 0;
+
     /* Direct rendering: Request a valid OPAQUE Vout in order to get
      * the surface attached to it */
     if (decoder_UpdateVideoFormat(p_dec) != 0
@@ -535,21 +563,7 @@ static int StartMediaCodec(decoder_t *p_dec)
         }
         args.video.i_width = p_dec->fmt_out.video.i_width;
         args.video.i_height = p_dec->fmt_out.video.i_height;
-
-        switch (p_dec->fmt_in.video.orientation)
-        {
-            case ORIENT_ROTATED_90:
-                args.video.i_angle = 90;
-                break;
-            case ORIENT_ROTATED_180:
-                args.video.i_angle = 180;
-                break;
-            case ORIENT_ROTATED_270:
-                args.video.i_angle = 270;
-                break;
-            default:
-                args.video.i_angle = 0;
-        }
+        args.video.i_angle = p_sys->video.i_angle;
 
         /* Configure again if h264 profile changed */
         if (p_dec->fmt_in.i_codec == VLC_CODEC_H264
diff --git a/modules/codec/omxil/mediacodec.h b/modules/codec/omxil/mediacodec.h
index b07faf1..2948123 100644
--- a/modules/codec/omxil/mediacodec.h
+++ b/modules/codec/omxil/mediacodec.h
@@ -115,6 +115,7 @@ struct mc_api
     int  i_quirks;
     char *psz_name;
     bool b_support_interlaced;
+    bool b_support_rotation;
 
     bool b_started;
     bool b_direct_rendering;
diff --git a/modules/codec/omxil/mediacodec_jni.c b/modules/codec/omxil/mediacodec_jni.c
index 2264a5c..40e7097 100644
--- a/modules/codec/omxil/mediacodec_jni.c
+++ b/modules/codec/omxil/mediacodec_jni.c
@@ -530,6 +530,7 @@ static int Start(mc_api *api, union mc_api_args *p_args)
 
     if (api->i_cat == VIDEO_ES)
     {
+        assert(p_args->video.i_angle == 0 || api->b_support_rotation);
         jformat = (*env)->CallStaticObjectMethod(env,
                                                  jfields.media_format_class,
                                                  jfields.create_video_format,
@@ -539,16 +540,7 @@ static int Start(mc_api *api, union mc_api_args *p_args)
         jsurface = p_args->video.p_jsurface;
         b_direct_rendering = !!jsurface;
 
-        /* There is no way to rotate the video using direct rendering (and
-         * using a SurfaceView) before  API 21 (Lollipop). Therefore, we
-         * deactivate direct rendering if video doesn't have a normal rotation
-         * and if get_input_buffer method is not present (This method exists
-         * since API 21). */
-        if (b_direct_rendering && p_args->video.i_angle != 0
-         && !jfields.get_input_buffer)
-            b_direct_rendering = false;
-
-        if (b_direct_rendering && p_args->video.i_angle != 0)
+        if (p_args->video.i_angle != 0)
             SET_INTEGER(jformat, "rotation-degrees", p_args->video.i_angle);
 
         /* feature-tunneled-playback available since API 21 */
@@ -991,8 +983,11 @@ int MediaCodecJni_Init(mc_api *api)
     api->release_out = ReleaseOutput;
     api->set_output_surface = SetOutputSurface;
 
-    /* Allow interlaced picture only after API 21 */
-    api->b_support_interlaced = jfields.get_input_buffer
-                                && jfields.get_output_buffer;
+    /* Allow interlaced picture and rotation only after API 21 */
+    if (jfields.get_input_buffer && jfields.get_output_buffer)
+    {
+        api->b_support_interlaced = true;
+        api->b_support_rotation = true;
+    }
     return 0;
 }
diff --git a/modules/codec/omxil/mediacodec_ndk.c b/modules/codec/omxil/mediacodec_ndk.c
index da8343f..e331c20 100644
--- a/modules/codec/omxil/mediacodec_ndk.c
+++ b/modules/codec/omxil/mediacodec_ndk.c
@@ -618,5 +618,6 @@ int MediaCodecNdk_Init(mc_api *api)
     api->set_output_surface = SetOutputSurface;
 
     api->b_support_interlaced = true;
+    api->b_support_rotation = true;
     return 0;
 }



More information about the vlc-commits mailing list