[vlc-commits] codec/mediacodec: rework interlaced support detection

Thomas Guillem git at videolan.org
Wed Jan 4 09:29:03 CET 2017


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Fri Dec 30 11:14:20 2016 +0100| [d9f218f80c1092559d16843d8da52c4504d5e774] | committer: Thomas Guillem

codec/mediacodec: rework interlaced support detection

Small reminder: before Android 21 and depending on the vendor, MediaCodec can
crash or be in an inconsistent state when decoding interlaced videos.

This rework will allow to white list some decoders depending on the codec name
(used only before Android 21).

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

 modules/codec/omxil/mediacodec.c     | 9 ++++++++-
 modules/codec/omxil/mediacodec.h     | 4 ++--
 modules/codec/omxil/mediacodec_jni.c | 9 +++++----
 modules/codec/omxil/mediacodec_ndk.c | 3 ++-
 modules/codec/omxil/omxil_utils.h    | 3 ++-
 5 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/modules/codec/omxil/mediacodec.c b/modules/codec/omxil/mediacodec.c
index 170c5fc..ef7c14e 100644
--- a/modules/codec/omxil/mediacodec.c
+++ b/modules/codec/omxil/mediacodec.c
@@ -1602,8 +1602,15 @@ static int Video_OnNewBlock(decoder_t *p_dec, block_t **pp_block)
     block_t *p_block = *pp_block;
 
     if (p_block->i_flags & BLOCK_FLAG_INTERLACED_MASK
-        && !p_sys->api.b_support_interlaced)
+     && !(p_sys->api.i_quirks & MC_API_VIDEO_QUIRKS_SUPPORT_INTERLACED))
+    {
+        /* Before Android 21 and depending on the vendor, MediaCodec can crash
+         * or be in an inconsistent state when decoding interlaced videos. See
+         * OMXCodec_GetQuirks() for a white list of decoders that supported
+         * interlaced videos before Android 21. */
+        msg_Warn(p_dec, "codec doesn't support interlaced videos");
         return -1;
+    }
 
     timestamp_FifoPut(p_sys->video.timestamp_fifo,
                       p_block->i_pts ? VLC_TS_INVALID : p_block->i_dts);
diff --git a/modules/codec/omxil/mediacodec.h b/modules/codec/omxil/mediacodec.h
index 2948123..211bbf6 100644
--- a/modules/codec/omxil/mediacodec.h
+++ b/modules/codec/omxil/mediacodec.h
@@ -42,7 +42,8 @@ int MediaCodecNdk_Init(mc_api*);
 #define MC_API_NO_QUIRKS 0
 #define MC_API_QUIRKS_NEED_CSD 0x1
 #define MC_API_VIDEO_QUIRKS_IGNORE_PADDING 0x2
-#define MC_API_AUDIO_QUIRKS_NEED_CHANNELS 0x4
+#define MC_API_VIDEO_QUIRKS_SUPPORT_INTERLACED 0x4
+#define MC_API_AUDIO_QUIRKS_NEED_CHANNELS 0x8
 
 struct mc_api_out
 {
@@ -114,7 +115,6 @@ struct mc_api
     /* Set after configure */
     int  i_quirks;
     char *psz_name;
-    bool b_support_interlaced;
     bool b_support_rotation;
 
     bool b_started;
diff --git a/modules/codec/omxil/mediacodec_jni.c b/modules/codec/omxil/mediacodec_jni.c
index 40e7097..3f20957 100644
--- a/modules/codec/omxil/mediacodec_jni.c
+++ b/modules/codec/omxil/mediacodec_jni.c
@@ -952,6 +952,10 @@ static int Configure(mc_api *api, size_t i_h264_profile)
         return MC_API_ERROR;
     api->i_quirks = OMXCodec_GetQuirks(api->i_cat, api->i_codec, api->psz_name,
                                        strlen(api->psz_name));
+
+    /* Allow interlaced picture after API 21 */
+    if (jfields.get_input_buffer && jfields.get_output_buffer)
+        api->i_quirks |= MC_API_VIDEO_QUIRKS_SUPPORT_INTERLACED;
     return 0;
 }
 
@@ -983,11 +987,8 @@ int MediaCodecJni_Init(mc_api *api)
     api->release_out = ReleaseOutput;
     api->set_output_surface = SetOutputSurface;
 
-    /* Allow interlaced picture and rotation only after API 21 */
+    /* Allow 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 e331c20..50f0392 100644
--- a/modules/codec/omxil/mediacodec_ndk.c
+++ b/modules/codec/omxil/mediacodec_ndk.c
@@ -590,6 +590,8 @@ static int Configure(mc_api * api, size_t i_h264_profile)
         return MC_API_ERROR;
     api->i_quirks = OMXCodec_GetQuirks(api->i_cat, api->i_codec, api->psz_name,
                                        strlen(api->psz_name));
+    /* Allow interlaced picture after API 21 */
+    api->i_quirks |= MC_API_VIDEO_QUIRKS_SUPPORT_INTERLACED;
     return 0;
 }
 
@@ -617,7 +619,6 @@ int MediaCodecNdk_Init(mc_api *api)
     api->release_out = ReleaseOutput;
     api->set_output_surface = SetOutputSurface;
 
-    api->b_support_interlaced = true;
     api->b_support_rotation = true;
     return 0;
 }
diff --git a/modules/codec/omxil/omxil_utils.h b/modules/codec/omxil/omxil_utils.h
index eefc4c1..aebf7c3 100644
--- a/modules/codec/omxil/omxil_utils.h
+++ b/modules/codec/omxil/omxil_utils.h
@@ -228,7 +228,8 @@ enum {
     OMXCODEC_NO_QUIRKS = 0,
     OMXCODEC_QUIRKS_NEED_CSD = 0x1,
     OMXCODEC_VIDEO_QUIRKS_IGNORE_PADDING = 0x2,
-    OMXCODEC_AUDIO_QUIRKS_NEED_CHANNELS = 0x4,
+    OMXCODEC_VIDEO_QUIRKS_SUPPORT_INTERLACED = 0x4,
+    OMXCODEC_AUDIO_QUIRKS_NEED_CHANNELS = 0x8,
 };
 int OMXCodec_GetQuirks( int i_cat, vlc_fourcc_t i_codec,
                         const char *p_name, unsigned int i_name_len );



More information about the vlc-commits mailing list