[vlc-devel] [PATCH] mmal: converter: use a single option to select the conversion MMAL component

Steve Lhomme robux4 at ycbcr.xyz
Fri Jan 24 15:37:22 CET 2020


There are 3 choices between Hardware Video Scaler (default, best), ISP and
resizer (slower but uses less memory).

Corresponds to the preexisting enum filter_resizer_t.
---
 modules/hw/mmal/converter.c | 74 +++++++++++++++++--------------------
 1 file changed, 33 insertions(+), 41 deletions(-)

diff --git a/modules/hw/mmal/converter.c b/modules/hw/mmal/converter.c
index 30c108c5aca..709fa8b01b8 100644
--- a/modules/hw/mmal/converter.c
+++ b/modules/hw/mmal/converter.c
@@ -41,13 +41,23 @@
 
 #include "subpic.h"
 
-#define MMAL_RESIZE_NAME "mmal-resize"
-#define MMAL_RESIZE_TEXT N_("Use mmal resizer rather than hvs.")
-#define MMAL_RESIZE_LONGTEXT N_("Use mmal resizer rather than isp. This uses less gpu memory than the ISP but is slower.")
+typedef enum filter_resizer_e {
+    FILTER_RESIZER_HVS,
+    FILTER_RESIZER_ISP,
+    FILTER_RESIZER_RESIZER,
+} filter_resizer_t;
 
-#define MMAL_ISP_NAME    "mmal-isp"
-#define MMAL_ISP_TEXT N_("Use mmal isp rather than hvs.")
-#define MMAL_ISP_LONGTEXT N_("Use mmal isp rather than Hardware Video Scaler. This may be faster but has no blend.")
+#define MMAL_CONVERTER_TYPE_NAME "mmal-hw-converter"
+#define MMAL_CONVERTER_TYPE_TEXT N_("Hardware used for MMAL conversions")
+#define MMAL_CONVERTER_TYPE_LONGTEXT N_("Hardware component used for MMAL conversions. Hardware Video Scaler"\
+        " (default) gives the best result and allows blending, Resizer is slower but uses less memory.")
+
+static const int pi_converter_modes[] = {
+    FILTER_RESIZER_HVS, FILTER_RESIZER_ISP, FILTER_RESIZER_RESIZER,
+};
+static const char * const  ppsz_converter_text[] = {
+    "Hardware Video Scaler", "ISP", "Resizer"
+};
 
 int OpenConverter(vlc_object_t *);
 void CloseConverter(vlc_object_t *);
@@ -60,8 +70,8 @@ vlc_module_begin()
     set_description(N_("MMAL resizing conversion filter"))
     add_shortcut("mmal_converter")
     set_capability( "video converter", 900 )
-    add_bool(MMAL_RESIZE_NAME, /* default */ false, MMAL_RESIZE_TEXT, MMAL_RESIZE_LONGTEXT, /* advanced option */ false)
-    add_bool(MMAL_ISP_NAME, /* default */ false, MMAL_ISP_TEXT, MMAL_ISP_LONGTEXT, /* advanced option */ false)
+    add_integer( MMAL_CONVERTER_TYPE_NAME, FILTER_RESIZER_HVS, MMAL_CONVERTER_TYPE_TEXT, MMAL_CONVERTER_TYPE_LONGTEXT, true )
+        change_integer_list( pi_converter_modes, ppsz_converter_text )
     set_callbacks(OpenConverter, CloseConverter)
 vlc_module_end()
 
@@ -143,12 +153,6 @@ static void pic_fifo_put(pic_fifo_t * const pf, picture_t * pic)
 
 #define SUBS_MAX 3
 
-typedef enum filter_resizer_e {
-    FILTER_RESIZER_RESIZER,
-    FILTER_RESIZER_ISP,
-    FILTER_RESIZER_HVS,
-} filter_resizer_t;
-
 typedef struct conv_frame_stash_s
 {
     mtime_t pts;
@@ -805,15 +809,12 @@ int OpenConverter(vlc_object_t * obj)
         return VLC_EGENERIC;
     const MMAL_FOURCC_T enc_out = vlc_to_mmal_video_fourcc(&p_filter->fmt_out.video);
     const MMAL_FOURCC_T enc_in = filter_enc_in(&p_filter->fmt_in.video);
-    bool use_resizer;
-    bool use_isp;
 
     // At least in principle we should deal with any mmal format as input
     if (enc_in == 0 || enc_out == 0)
         return VLC_EGENERIC;
 
-    use_resizer = var_InheritBool(p_filter, MMAL_RESIZE_NAME);
-    use_isp = var_InheritBool(p_filter, MMAL_ISP_NAME);
+    filter_resizer_t resizer_type = var_GetInteger(p_filter, MMAL_CONVERTER_TYPE_NAME);
 
 retry:
     // ** Make more generic by checking supported encs
@@ -821,29 +822,23 @@ retry:
     // Must use ISP - HVS can't do this, nor can resizer
     if (enc_in == MMAL_ENCODING_YUVUV64_10) {
         // If resizer selected then just give up
-        if (use_resizer)
+        if (resizer_type == FILTER_RESIZER_RESIZER)
             return VLC_EGENERIC;
         // otherwise downgrade HVS to ISP
-        use_isp = true;
+        resizer_type = FILTER_RESIZER_ISP;
     }
     // HVS can't do I420
-    if (enc_out == MMAL_ENCODING_I420) {
-        use_isp = true;
+    if (enc_out == MMAL_ENCODING_I420 && resizer_type == FILTER_RESIZER_HVS) {
+        resizer_type = FILTER_RESIZER_ISP;
     }
     // Only HVS can deal with SAND30
     if (enc_in == MMAL_ENCODING_YUV10_COL) {
-        if (use_isp || use_resizer)
+        if (resizer_type != FILTER_RESIZER_HVS)
             return VLC_EGENERIC;
     }
 
-
-    if (use_resizer) {
-        // use resizer overrides use_isp
-        use_isp = false;
-    }
-
     // Check we have a sliced version of the fourcc if we want the resizer
-    if (use_resizer && pic_to_slice_mmal_fourcc(enc_out) == 0) {
+    if (resizer_type == FILTER_RESIZER_RESIZER && pic_to_slice_mmal_fourcc(enc_out) == 0) {
         return VLC_EGENERIC;
     }
 
@@ -891,8 +886,7 @@ retry:
     }
 
     const char *component_name;
-    if (use_resizer) {
-        sys->resizer_type = FILTER_RESIZER_RESIZER;
+    if (resizer_type == FILTER_RESIZER_RESIZER) {
         sys->is_sliced = true;
         sys->out_port_cb_fn = slice_output_port_cb;
         component_name = MMAL_COMPONENT_DEFAULT_RESIZER;
@@ -900,21 +894,19 @@ retry:
     else {
         sys->is_sliced = false;  // Copy directly into filter picture
         sys->out_port_cb_fn = conv_output_port_cb;
-        if (use_isp) {
-            sys->resizer_type = FILTER_RESIZER_ISP;
+        if (resizer_type == FILTER_RESIZER_ISP)
             component_name = MMAL_COMPONENT_ISP_RESIZER;
-        } else {
-            sys->resizer_type = FILTER_RESIZER_HVS;
+        else
             component_name = MMAL_COMPONENT_HVS;
-        }
     }
+    sys->resizer_type = resizer_type;
 
     status = mmal_component_create(component_name, &sys->component);
     if (status != MMAL_SUCCESS) {
-        if (!use_isp && !use_resizer) {
+        if (resizer_type == FILTER_RESIZER_HVS) {
             msg_Warn(p_filter, "Failed to create HVS resizer - retrying with ISP");
             CloseConverter(obj);
-            use_isp = true;
+            resizer_type = FILTER_RESIZER_ISP;
             goto retry;
         }
         msg_Err(p_filter, "Failed to create MMAL component %s (status=%"PRIx32" %s)",
@@ -999,8 +991,8 @@ retry:
 fail:
     CloseConverter(obj);
 
-    if (!use_resizer && status == MMAL_ENOMEM) {
-        use_resizer = true;
+    if (resizer_type != FILTER_RESIZER_RESIZER && status == MMAL_ENOMEM) {
+        resizer_type = FILTER_RESIZER_RESIZER;
         msg_Warn(p_filter, "Lack of memory to use HVS/ISP: trying resizer");
         goto retry;
     }
-- 
2.17.1



More information about the vlc-devel mailing list