[Mesa-dev] [PATCHv2 3/3] omx: do not assume that everyone can do bitstream h264 and mpeg12

Emil Velikov emil.l.velikov at gmail.com
Sun Feb 16 04:40:03 PST 2014


 - Only report a component if there is a mpeg12/h264 decoder.
 - Advertise only the available formats.

v2:
 - Return the number of truely available components.
 - Set name/role specific only for supported formats.
 - Cleanup vid_dec_LoaderComponent error path.

Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---
 src/gallium/state_trackers/omx/entrypoint.c | 12 +++-
 src/gallium/state_trackers/omx/vid_dec.c    | 85 ++++++++++++++---------------
 2 files changed, 53 insertions(+), 44 deletions(-)

diff --git a/src/gallium/state_trackers/omx/entrypoint.c b/src/gallium/state_trackers/omx/entrypoint.c
index 9187f13..bff6507 100644
--- a/src/gallium/state_trackers/omx/entrypoint.c
+++ b/src/gallium/state_trackers/omx/entrypoint.c
@@ -53,7 +53,17 @@ int omx_component_library_Setup(stLoaderComponentType **stComponents)
    struct vl_screen *vscreen = omx_get_screen();
    struct pipe_screen *screen = vscreen ? vscreen->pscreen : NULL;
    OMX_ERRORTYPE r;
-   int num_components = 1;
+   int num_components = 0;
+
+   /* Provide a component only if the driver supports mpeg12/h264 decoding. */
+   if (screen->get_video_param(screen, PIPE_VIDEO_PROFILE_MPEG2_MAIN,
+                               PIPE_VIDEO_ENTRYPOINT_BITSTREAM,
+                               PIPE_VIDEO_CAP_SUPPORTED) ||
+       screen->get_video_param(screen, PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH,
+                               PIPE_VIDEO_ENTRYPOINT_BITSTREAM,
+                               PIPE_VIDEO_CAP_SUPPORTED)) {
+     num_components++;
+   }
 
    /* Provide a component only when the driver supports h264 encoding. */
    if (screen->get_video_param(screen, PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH,
diff --git a/src/gallium/state_trackers/omx/vid_dec.c b/src/gallium/state_trackers/omx/vid_dec.c
index e2a2891..d049228 100644
--- a/src/gallium/state_trackers/omx/vid_dec.c
+++ b/src/gallium/state_trackers/omx/vid_dec.c
@@ -81,67 +81,66 @@ static void vid_dec_name_avc(char str[OMX_MAX_STRINGNAME_SIZE])
 
 OMX_ERRORTYPE vid_dec_LoaderComponent(stLoaderComponentType *comp)
 {
+   const int has_h264 = screen->get_video_param(screen,
+                                                PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH,
+                                                PIPE_VIDEO_ENTRYPOINT_BITSTREAM,
+                                                PIPE_VIDEO_CAP_SUPPORTED);
+   const int has_mpeg12 = screen->get_video_param(screen,
+                                                  PIPE_VIDEO_PROFILE_MPEG2_MAIN,
+                                                  PIPE_VIDEO_ENTRYPOINT_BITSTREAM,
+                                                  PIPE_VIDEO_CAP_SUPPORTED);
+   int i;
+
    comp->componentVersion.s.nVersionMajor = 0;
    comp->componentVersion.s.nVersionMinor = 0;
    comp->componentVersion.s.nRevision = 0;
    comp->componentVersion.s.nStep = 1;
-   comp->name_specific_length = 2;
+
+   comp->name_specific_length = has_h264 + has_mpeg12;
 
    comp->name = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
-   if (comp->name == NULL)
-      goto error;
+   if (!comp->name)
+      goto error_arrays;
 
    comp->name_specific = CALLOC(comp->name_specific_length, sizeof(char *));
-   if (comp->name_specific == NULL)
-      goto error;
-
-   comp->name_specific[0] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
-   if (comp->name_specific[0] == NULL)
-      goto error;
-
-   comp->name_specific[1] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
-   if (comp->name_specific[1] == NULL)
-      goto error;
-
    comp->role_specific = CALLOC(comp->name_specific_length, sizeof(char *));
-   if (comp->role_specific == NULL)
-      goto error;
-
-   comp->role_specific[0] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
-   if (comp->role_specific[0] == NULL)
-      goto error;
-
-   comp->role_specific[1] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
-   if (comp->role_specific[1] == NULL)
-      goto error;
+   if (!comp->name_specific || !comp->role_specific)
+      goto error_arrays;
+
+   for (i = 0; i < comp->name_specific_length; ++i) {
+      comp->name_specific[i] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
+      comp->role_specific[i] = CALLOC(1, OMX_MAX_STRINGNAME_SIZE);
+      if (!comp->name_specific[i] || !comp->role_specific[i])
+         goto error_specific;
+   }
 
    vid_dec_name(comp->name);
-   vid_dec_name_mpeg2(comp->name_specific[0]);
-   vid_dec_name_avc(comp->name_specific[1]);
 
-   strcpy(comp->role_specific[0], OMX_VID_DEC_MPEG2_ROLE);
-   strcpy(comp->role_specific[1], OMX_VID_DEC_AVC_ROLE);
+   if (has_mpeg12) {
+      vid_dec_name_mpeg2(comp->name_specific[--i]);
+      strcpy(comp->role_specific[i], OMX_VID_DEC_MPEG2_ROLE);
+   }
+
+   if (has_h264) {
+      vid_dec_name_avc(comp->name_specific[--i]);
+      strcpy(comp->role_specific[i], OMX_VID_DEC_AVC_ROLE);
+   }
 
    comp->constructor = vid_dec_Constructor;
- 
+
    return OMX_ErrorNone;
 
-error:
+error_specific:
+   FREE(comp->name_specific[1]);
+   FREE(comp->name_specific[0]);
+   FREE(comp->role_specific[1]);
+   FREE(comp->role_specific[0]);
 
+error_arrays:
+   FREE(comp->role_specific);
+   FREE(comp->name_specific);
    FREE(comp->name);
 
-   if (comp->name_specific) {
-      FREE(comp->name_specific[0]);
-      FREE(comp->name_specific[1]);
-      FREE(comp->name_specific);
-   }
-
-   if (comp->role_specific) {
-      FREE(comp->role_specific[0]);
-      FREE(comp->role_specific[1]);
-      FREE(comp->role_specific);
-   }
-
    return OMX_ErrorInsufficientResources;
 }
 
@@ -162,7 +161,7 @@ static OMX_ERRORTYPE vid_dec_Constructor(OMX_COMPONENTTYPE *comp, OMX_STRING nam
 
    r = omx_base_filter_Constructor(comp, name);
    if (r)
-	return r;
+      return r;
 
    priv->profile = PIPE_VIDEO_PROFILE_UNKNOWN;
 
-- 
1.9.0



More information about the mesa-dev mailing list