Exemple #1
0
static gboolean
mir_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
{
  GstMirBufferPool *mpool = GST_MIR_BUFFER_POOL_CAST (pool);
  GstVideoInfo info;
  GstCaps *caps;

  GST_DEBUG_OBJECT (mpool, "%s", __PRETTY_FUNCTION__);

  if (!gst_buffer_pool_config_get_params (config, &caps, NULL, NULL, NULL))
    goto wrong_config;

  if (caps == NULL)
    goto no_caps;

  if (mpool->allocator)
    gst_object_unref (mpool->allocator);
  mpool->allocator = NULL;

  /* now parse the caps from the config */
  if (!gst_video_info_from_caps (&info, caps))
    goto wrong_caps;

  if (!gst_buffer_pool_config_get_allocator (config, &mpool->allocator,
          &mpool->params))
    return FALSE;
  if (mpool->allocator)
    gst_object_ref (mpool->allocator);

  GST_LOG_OBJECT (mpool, "%dx%d, caps %" GST_PTR_FORMAT, info.width,
      info.height, caps);

  /*Fixme: Enable metadata checking handling based on the config of pool */

  mpool->caps = gst_caps_ref (caps);
  mpool->info = info;
  mpool->width = info.width;
  mpool->height = info.height;

  GST_DEBUG_OBJECT (mpool, "Calling set_config() on the parent class");
  return GST_BUFFER_POOL_CLASS (parent_class)->set_config (pool, config);
  /* ERRORS */
wrong_config:
  {
    GST_WARNING_OBJECT (pool, "invalid config");
    return FALSE;
  }
no_caps:
  {
    GST_WARNING_OBJECT (pool, "no caps in config");
    return FALSE;
  }
wrong_caps:
  {
    GST_WARNING_OBJECT (pool,
        "failed getting geometry from caps %" GST_PTR_FORMAT, caps);
    return FALSE;
  }
}
Exemple #2
0
void
gst_mir_buffer_pool_set_codec_delegate (GstBufferPool * pool,
    MediaCodecDelegate * delegate)
{
  GstMirBufferPool *m_pool = GST_MIR_BUFFER_POOL_CAST (pool);

  GST_DEBUG_OBJECT (m_pool, "%s", __PRETTY_FUNCTION__);
  m_pool->codec_delegate = delegate;
}
Exemple #3
0
void
gst_mir_buffer_pool_set_surface_texture_client (GstBufferPool * pool,
    SurfaceTextureClientHybris sfc)
{
  GstMirBufferPool *m_pool = GST_MIR_BUFFER_POOL_CAST (pool);

  GST_DEBUG_OBJECT (m_pool, "%s", __PRETTY_FUNCTION__);
  m_pool->surface_texture_client = sfc;
}
Exemple #4
0
static void
gst_mir_buffer_pool_finalize (GObject * object)
{
  GstMirBufferPool *pool = GST_MIR_BUFFER_POOL_CAST (object);

  GST_DEBUG_OBJECT (pool, "%s", __PRETTY_FUNCTION__);
  gst_object_unref (pool->sink);

  G_OBJECT_CLASS (gst_mir_buffer_pool_parent_class)->finalize (object);
}
Exemple #5
0
static GstFlowReturn
mir_buffer_pool_alloc (GstBufferPool * pool, GstBuffer ** buffer,
    GstBufferPoolAcquireParams * params)
{
  GstMirBufferPool *m_pool = GST_MIR_BUFFER_POOL_CAST (pool);
  GstMirMeta *meta;

  GST_DEBUG_OBJECT (m_pool, "%s", __PRETTY_FUNCTION__);

  if (m_pool->allocator == NULL) {
    GST_ERROR_OBJECT (m_pool, "Can't create buffer, couldn't get allocator");
    return GST_FLOW_ERROR;
  }

  GST_WARNING_OBJECT (m_pool, "Height: %d, width: %d", m_pool->height,
      m_pool->width);

  *buffer =
      gst_mir_allocate_native_window_buffer (pool, m_pool->allocator, params,
      m_pool->info.finfo->format, m_pool->width, m_pool->height);

  meta = gst_buffer_add_mir_meta (*buffer, m_pool);
  if (meta == NULL) {
    gst_buffer_unref (*buffer);
    goto no_buffer;
  }

  return GST_FLOW_OK;

  /* ERROR */
no_buffer:
  {
    GST_WARNING_OBJECT (pool, "can't create buffer");
    return GST_FLOW_ERROR;
  }
}
static gboolean
gst_mir_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
{
    GstMirSink *sink = GST_MIR_SINK (bsink);
    GstBufferPool *newpool, *oldpool;
    GstMirBufferPool *m_pool;
    GstVideoInfo info;
    GstStructure *config;
    static GstAllocationParams params = {
        0, 0, 0, 15,
    };
    guint size;

    sink = GST_MIR_SINK (bsink);

    GST_DEBUG_OBJECT (sink, "set caps %" GST_PTR_FORMAT, caps);

    if (!gst_video_info_from_caps (&info, caps))
        goto invalid_format;

    sink->video_width = info.width;
    sink->video_height = info.height;
    size = info.size;

    GST_DEBUG_OBJECT (sink, "Creating new GstMirBufferPool");
    /* Create a new pool for the new configuration */
    newpool = gst_mir_buffer_pool_new (sink);

    if (!newpool) {
        GST_ERROR_OBJECT (sink, "Failed to create new pool");
        return FALSE;
    }

    GST_DEBUG_OBJECT (sink,
                      "Setting SurfaceTextureClientHybris instance in m_pool");
    /* Add the SurfaceTextureClientHybris instance to the pool for later use */
    gst_mir_buffer_pool_set_surface_texture_client (newpool,
            sink->surface_texture_client);
    GST_WARNING_OBJECT (sink, "SurfaceTextureClientHybris: %p",
                        sink->surface_texture_client);

    m_pool = GST_MIR_BUFFER_POOL_CAST (newpool);
    GST_WARNING_OBJECT (sink, "m_pool SurfaceTextureClientHybris: %p",
                        m_pool->surface_texture_client);
    m_pool->width = sink->video_width;
    m_pool->height = sink->video_height;

    config = gst_buffer_pool_get_config (newpool);
    gst_buffer_pool_config_set_params (config, caps, size, 2, 0);
    gst_buffer_pool_config_set_allocator (config, NULL, &params);
    if (!gst_buffer_pool_set_config (newpool, config))
        goto config_failed;

    GST_OBJECT_LOCK (sink);
    oldpool = sink->pool;
    sink->pool = newpool;
    GST_OBJECT_UNLOCK (sink);

    GST_DEBUG_OBJECT (sink, "Finishing up set_caps");

    if (oldpool)
        gst_object_unref (oldpool);

    return TRUE;

invalid_format:
    {
        GST_DEBUG_OBJECT (sink,
                          "Could not locate image format from caps %" GST_PTR_FORMAT, caps);
        return FALSE;
    }
config_failed:
    {
        GST_DEBUG_OBJECT (bsink, "failed setting config");
        return FALSE;
    }
}
Exemple #7
0
// FIXME: rename this function since it no longer makes sense
static GstBuffer *
gst_mir_allocate_native_window_buffer (GstBufferPool * pool,
    GstAllocator * allocator, GstBufferPoolAcquireParams * params,
    GstVideoFormat format, gint width, gint height)
{
  GstMirBufferPool *m_pool = GST_MIR_BUFFER_POOL_CAST (pool);
  GstBuffer *buffer;
  GstMemory *mem = { NULL };
  gsize size = 0;
  gint stride = 0;
  GstMemoryFlags flags = 0;

  GST_DEBUG_OBJECT (pool, "%s", __PRETTY_FUNCTION__);

  if (!gst_mir_image_memory_is_mappable ())
    flags |= GST_MEMORY_FLAG_NOT_MAPPABLE;

  flags |= GST_MEMORY_FLAG_NO_SHARE;

  switch (format) {
      gsize buffer_id = 0;

    case GST_VIDEO_FORMAT_RGB:
    case GST_VIDEO_FORMAT_BGR:
    case GST_VIDEO_FORMAT_RGB16:
    case GST_VIDEO_FORMAT_NV12:
    case GST_VIDEO_FORMAT_NV21:
    case GST_VIDEO_FORMAT_RGBA:
    case GST_VIDEO_FORMAT_BGRA:
    case GST_VIDEO_FORMAT_ARGB:
    case GST_VIDEO_FORMAT_ABGR:
    case GST_VIDEO_FORMAT_RGBx:
    case GST_VIDEO_FORMAT_BGRx:
    case GST_VIDEO_FORMAT_xRGB:
    case GST_VIDEO_FORMAT_xBGR:
    case GST_VIDEO_FORMAT_AYUV:
    case GST_VIDEO_FORMAT_YV12:
    case GST_VIDEO_FORMAT_I420:
    case GST_VIDEO_FORMAT_Y444:
    case GST_VIDEO_FORMAT_Y42B:
    case GST_VIDEO_FORMAT_Y41B:{

      GST_WARNING_OBJECT (m_pool,
          "Allocating new Mir image, height: %d, width: %d, size: %d", height,
          width, size);

      /* A fallback to make sure we have a size */
      if (size == 0)
        size = height * width;

      stride = size / height;
      size = stride * height;

      GST_WARNING_OBJECT (m_pool, "stride: %d, size: %d", stride, size);

      //if (m_pool->sink->surface_texture_client) {
      buffer_id = 0;

      GST_WARNING_OBJECT (m_pool, "Allocating new buffer memory of size: %d",
          size);
      mem =
          gst_mir_image_allocator_wrap (allocator, m_pool->codec_delegate,
          buffer_id, flags, size, NULL, NULL);
      if (mem == NULL)
        GST_WARNING_OBJECT (m_pool, "mem is NULL!");
      //}

      break;
    }
    default:
      GST_WARNING_OBJECT (m_pool,
          "Using the default buffer allocator, hit the default case");
      if (GST_BUFFER_POOL_CLASS (gst_mir_buffer_pool_parent_class)->alloc_buffer
          (pool, &buffer, params) != GST_FLOW_OK)
        return NULL;
      break;
  }

  buffer = gst_buffer_new ();
  if (!buffer) {
    GST_WARNING_OBJECT (m_pool, "Fallback memory allocation");
    if (GST_BUFFER_POOL_CLASS (gst_mir_buffer_pool_parent_class)->alloc_buffer
        (pool, &buffer, params) != GST_FLOW_OK)
      return NULL;
  }

  GST_DEBUG ("Appending memory to GstBuffer");
  gst_buffer_append_memory (buffer, mem);

  return buffer;
}