omxvideoenc: Setup aspect ratio on RPi
authorMichal Lazo <michal.lazo@mdragon.org>
Sun, 31 Aug 2014 20:30:13 +0000 (20:30 +0000)
committerSebastian Dröge <sebastian@centricular.com>
Mon, 1 Sep 2014 09:18:58 +0000 (12:18 +0300)
Needs firmware from yesterday or newer to work with all possible
aspect ratios. Before that it only supported a fixed list.

https://bugzilla.gnome.org/show_bug.cgi?id=732533

omx/gstomxvideoenc.c

index de3f7a6..41ca346 100644 (file)
 #include "gstomxvideo.h"
 #include "gstomxvideoenc.h"
 
+#ifdef USE_OMX_TARGET_RPI
+#include <OMX_Broadcom.h>
+#include <OMX_Index.h>
+#endif
+
 GST_DEBUG_CATEGORY_STATIC (gst_omx_video_enc_debug_category);
 #define GST_CAT_DEFAULT gst_omx_video_enc_debug_category
 
@@ -1069,6 +1074,44 @@ gst_omx_video_enc_set_format (GstVideoEncoder * encoder,
           &port_def) != OMX_ErrorNone)
     return FALSE;
 
+#ifdef USE_OMX_TARGET_RPI
+  /* aspect ratio */
+  {
+    OMX_ERRORTYPE err;
+    OMX_CONFIG_POINTTYPE aspect_ratio_param;
+
+    GST_OMX_INIT_STRUCT (&aspect_ratio_param);
+    aspect_ratio_param.nPortIndex = self->enc_out_port->index;
+
+    err = gst_omx_component_get_parameter (self->enc,
+        OMX_IndexParamBrcmPixelAspectRatio, &aspect_ratio_param);
+
+    if (err == OMX_ErrorNone) {
+
+      aspect_ratio_param.nX = info->par_n;
+      aspect_ratio_param.nY = info->par_d;
+
+      err =
+          gst_omx_component_set_parameter (self->enc,
+          OMX_IndexParamBrcmPixelAspectRatio, &aspect_ratio_param);
+
+      if (err == OMX_ErrorUnsupportedIndex) {
+        GST_WARNING_OBJECT (self,
+            "Setting aspect ratio parameters not supported by the component");
+      } else if (err == OMX_ErrorUnsupportedSetting) {
+        GST_WARNING_OBJECT (self,
+            "Setting aspect ratio %u %u not supported by the component",
+            aspect_ratio_param.nX, aspect_ratio_param.nY);
+      } else if (err != OMX_ErrorNone) {
+        GST_ERROR_OBJECT (self,
+            "Failed to set aspect ratio: %s (0x%08x)",
+            gst_omx_error_to_string (err), err);
+        return FALSE;
+      }
+    }
+  }
+#endif // USE_OMX_TARGET_RPI
+
   if (klass->set_format) {
     if (!klass->set_format (self, self->enc_in_port, state)) {
       GST_ERROR_OBJECT (self, "Subclass failed to set the new format");