Пример #1
0
static MozGfxMemory *
moz_gfx_memory_share (MozGfxMemory * mem, gssize offset, gsize size)
{
  MozGfxMemory *sub;
  GstMemory *parent;

  /* find the real parent */
  if ((parent = mem->memory.parent) == NULL)
    parent = (GstMemory *) mem;

  if (size == (gsize) -1)
    size = mem->memory.size - offset;

  /* the shared memory is always readonly */
  sub = g_slice_new (MozGfxMemory);

  gst_memory_init (GST_MEMORY_CAST (sub),
      (GstMemoryFlags) (GST_MINI_OBJECT_FLAGS (parent) | GST_MINI_OBJECT_FLAG_LOCK_READONLY),
      mem->memory.allocator, &mem->memory, mem->memory.maxsize, mem->memory.align,
      mem->memory.offset + offset, size);

  sub->image = mem->image;
  sub->data = mem->data;

  return sub;
}
static GstMemory* gst_allocator_fast_malloc_alloc(GstAllocator* allocator, gsize size, GstAllocationParams* params)
{
    ASSERT(G_TYPE_CHECK_INSTANCE_TYPE(allocator, gst_allocator_fast_malloc_get_type()));

    // alignment should be a (power-of-two - 1).
    gsize alignment = params->align | gst_memory_alignment;
    ASSERT(!((alignment + 1) & alignment));

    gsize headerSize = (sizeof(GstMemoryFastMalloc) + alignment) & ~alignment;
    gsize allocationSize = params->prefix + size + params->padding;

    GstMemoryFastMalloc* mem = static_cast<GstMemoryFastMalloc*>(fastAlignedMalloc(alignment + 1, headerSize + allocationSize));
    if (!mem)
        return nullptr;

    mem->data = reinterpret_cast<uint8_t*>(mem) + headerSize;

    if (params->prefix && (params->flags & GST_MEMORY_FLAG_ZERO_PREFIXED))
        std::memset(mem->data, 0, params->prefix);
    if (params->padding && (params->flags & GST_MEMORY_FLAG_ZERO_PADDED))
        std::memset(mem->data + params->prefix + size, 0, params->padding);

    gst_memory_init(GST_MEMORY_CAST(mem), params->flags, allocator, nullptr,
        allocationSize, alignment, params->prefix, size);

    return GST_MEMORY_CAST(mem);
}
Пример #3
0
static GstMemory *
gst_mir_image_mem_share (GstMemory * mem, gssize offset, gssize size)
{
  GstMemory *sub;
  GstMemory *parent;

  GST_WARNING ("%s", __PRETTY_FUNCTION__);

  if (offset != 0)
    return NULL;

  if (size != -1 && size != mem->size)
    return NULL;

  /* find the real parent */
  if ((parent = mem->parent) == NULL)
    parent = (GstMemory *) mem;

  if (size == -1)
    size = mem->size - offset;

  sub = (GstMemory *) g_slice_new (GstMirImageMemory);

  /* the shared memory is always readonly */
  gst_memory_init (GST_MEMORY_CAST (sub), GST_MINI_OBJECT_FLAGS (parent) |
      GST_MINI_OBJECT_FLAG_LOCK_READONLY, mem->allocator, parent,
      mem->maxsize, mem->align, mem->offset + offset, size);

  return sub;
}
Пример #4
0
GstMemory *
gst_mir_image_allocator_wrap (GstAllocator * allocator,
    MediaCodecDelegate delegate, gsize buffer_id, GstMemoryFlags flags,
    gsize size, gpointer user_data, GDestroyNotify user_data_destroy)
{
  GstMirImageMemory *mem;

  GST_WARNING ("%s", __PRETTY_FUNCTION__);
  GST_WARNING ("size: %d", size);
  GST_WARNING ("delegate: %p", delegate);

  if (!allocator) {
    allocator = gst_mir_image_allocator_obtain ();
  }
  mem = g_slice_new (GstMirImageMemory);
  // FIXME: calling gst_mir_image_allocator_obtain() is a hack to select my allocator, this really
  // should be selected automatically by the decoder. This selection is not working correctly yet.
  gst_memory_init (GST_MEMORY_CAST (mem), flags,
      gst_mir_image_allocator_obtain (), NULL, size, 0, 0, size);

  mem->codec_delegate = delegate;
  mem->buffer_index = buffer_id;
  mem->user_data = user_data;
  mem->user_data_destroy = user_data_destroy;

  return GST_MEMORY_CAST (mem);
}
Пример #5
0
static GstMemory *
gst_fd_mem_share (GstMemory * gmem, gssize offset, gssize size)
{
#ifdef HAVE_MMAP
  GstFdMemory *mem = (GstFdMemory *) gmem;
  GstFdMemory *sub;
  GstMemory *parent;

  GST_DEBUG ("%p: share %" G_GSSIZE_FORMAT " %" G_GSIZE_FORMAT, mem, offset,
      size);

  /* find the real parent */
  if ((parent = mem->mem.parent) == NULL)
    parent = (GstMemory *) mem;

  if (size == -1)
    size = gmem->maxsize - offset;

  sub = g_slice_new0 (GstFdMemory);
  /* the shared memory is always readonly */
  gst_memory_init (GST_MEMORY_CAST (sub), GST_MINI_OBJECT_FLAGS (parent) |
      GST_MINI_OBJECT_FLAG_LOCK_READONLY, mem->mem.allocator, parent,
      mem->mem.maxsize, mem->mem.align, mem->mem.offset + offset, size);

  sub->fd = mem->fd;
  g_mutex_init (&sub->lock);

  return GST_MEMORY_CAST (sub);
#else /* !HAVE_MMAP */
  return NULL;
#endif
}
Пример #6
0
GstMemory *
gst_egl_image_allocator_wrap (GstAllocator * allocator,
    GstEGLDisplay * display, EGLImageKHR image, GstEGLImageType type,
    GstMemoryFlags flags, gsize size, gpointer user_data,
    GDestroyNotify user_data_destroy)
{
  GstEGLImageMemory *mem;

  g_return_val_if_fail (display != NULL, NULL);
  g_return_val_if_fail (image != EGL_NO_IMAGE_KHR, NULL);
  g_return_val_if_fail (type != GST_EGL_IMAGE_MEMORY_TYPE_INVALID, NULL);

  if (!allocator) {
    allocator = gst_egl_image_allocator_obtain ();
  }

  mem = g_slice_new (GstEGLImageMemory);
  gst_memory_init (GST_MEMORY_CAST (mem), flags,
      allocator, NULL, size, 0, 0, size);

  mem->display = gst_egl_display_ref (display);
  mem->image = image;
  mem->type = type;

  mem->user_data = user_data;
  mem->user_data_destroy = user_data_destroy;

  return GST_MEMORY_CAST (mem);
}
Пример #7
0
/**
 * gst_fd_allocator_alloc:
 * @allocator: allocator to be used for this memory
 * @fd: file descriptor
 * @size: memory size
 * @flags: extra #GstFdMemoryFlags
 *
 * Return a %GstMemory that wraps a generic file descriptor.
 *
 * Returns: (transfer full): a GstMemory based on @allocator.
 * When the buffer will be released the allocator will close the @fd.
 * The memory is only mmapped on gst_buffer_mmap() request.
 *
 * Since: 1.6
 */
GstMemory *
gst_fd_allocator_alloc (GstAllocator * allocator, gint fd, gsize size,
    GstFdMemoryFlags flags)
{
#ifdef HAVE_MMAP
  GstFdMemory *mem;

  g_return_val_if_fail (GST_IS_FD_ALLOCATOR (allocator), NULL);

  mem = g_slice_new0 (GstFdMemory);
  gst_memory_init (GST_MEMORY_CAST (mem), 0, GST_ALLOCATOR_CAST (allocator),
      NULL, size, 0, 0, size);

  mem->flags = flags;
  mem->fd = fd;
  g_mutex_init (&mem->lock);

  GST_DEBUG ("%p: fd: %d size %" G_GSIZE_FORMAT, mem, mem->fd,
      mem->mem.maxsize);

  return (GstMemory *) mem;
#else /* !HAVE_MMAP */
  return NULL;
#endif
}
static GstMemory *
gst_egl_image_allocator_wrap (GstEGLImageAllocator * allocator,
    GstGLContextEGL * context, EGLImageKHR image, GstVideoGLTextureType type,
    GstMemoryFlags flags, gsize size, gpointer user_data,
    GstEGLImageDestroyNotify user_data_destroy)
{
  GstEGLImageMemory *mem = NULL;

  g_return_val_if_fail (context != NULL, NULL);
  g_return_val_if_fail (image != EGL_NO_IMAGE_KHR, NULL);

  if (!allocator) {
    allocator = gst_egl_image_allocator_obtain ();
  }

  mem = g_slice_new (GstEGLImageMemory);
  gst_memory_init (GST_MEMORY_CAST (mem), flags,
      GST_ALLOCATOR (allocator), NULL, size, 0, 0, size);

  gst_object_unref (allocator);

  mem->context = gst_object_ref (context);
  mem->image = image;
  mem->type = type;
  mem->orientation = GST_VIDEO_GL_TEXTURE_ORIENTATION_X_NORMAL_Y_NORMAL;

  mem->user_data = user_data;
  mem->user_data_destroy = user_data_destroy;

  return GST_MEMORY_CAST (mem);
}
GstMemory *
gst_msdk_system_memory_new (GstAllocator * base_allocator)
{
  GstMsdkSystemAllocator *allocator;
  GstVideoInfo *vip;
  GstMsdkSystemMemory *mem;

  g_return_val_if_fail (base_allocator, NULL);
  g_return_val_if_fail (GST_IS_MSDK_SYSTEM_ALLOCATOR (base_allocator), NULL);

  allocator = GST_MSDK_SYSTEM_ALLOCATOR_CAST (base_allocator);

  mem = g_slice_new0 (GstMsdkSystemMemory);
  if (!mem)
    return NULL;

  mem->surface = gst_msdk_system_allocator_create_surface (base_allocator);

  vip = &allocator->image_info;
  gst_memory_init (&mem->parent_instance, GST_MEMORY_FLAG_NO_SHARE,
      base_allocator, NULL, GST_VIDEO_INFO_SIZE (vip), 0, 0,
      GST_VIDEO_INFO_SIZE (vip));

  if (!ensure_data (mem))
    return NULL;

  return GST_MEMORY_CAST (mem);
}
Пример #10
0
bool gst_vlc_picture_plane_allocator_alloc(
        GstVlcPicturePlaneAllocator *p_allocator,
        GstBuffer *p_buffer )
{
    int i_plane;
    gsize i_max_size, i_align, i_offset, i_size;
    picture_t *p_pic;

    p_pic = &p_allocator->pic_info;

    for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
    {
        GstVlcPicturePlane *p_mem =
            (GstVlcPicturePlane*) g_slice_new0( GstVlcPicturePlane );

        i_size = p_pic->p[ i_plane ].i_pitch *
            p_pic->p[ i_plane ].i_lines;
        i_max_size = p_pic->p[ i_plane ].i_pitch *
            p_pic->p[ i_plane ].i_lines;
        i_align = 0;
        i_offset = 0;

        gst_memory_init( GST_MEMORY_CAST( p_mem ), GST_MEMORY_FLAG_NO_SHARE,
                GST_ALLOCATOR_CAST( p_allocator ), NULL, i_max_size,
                i_align, i_offset, i_size );
        gst_buffer_append_memory( p_buffer, (GstMemory*) p_mem );
    }

    return true;
}
static GstMemoryFastMalloc* gst_allocator_fast_malloc_mem_copy(GstMemoryFastMalloc* mem, gssize offset, gsize size)
{
    gsize alignment = mem->base.align | gst_memory_alignment;
    ASSERT(!((alignment + 1) & alignment));

    gsize headerSize = (sizeof(GstMemoryFastMalloc) + alignment) & ~alignment;

    gsize allocationSize = size;
    if (allocationSize == static_cast<gsize>(-1)) {
        allocationSize = 0;
        if (offset < 0 || (mem->base.size > static_cast<gsize>(offset)))
            allocationSize = mem->base.size - offset;
    }

    GstMemoryFastMalloc* copy = static_cast<GstMemoryFastMalloc*>(fastAlignedMalloc(alignment + 1, headerSize + allocationSize));
    if (!copy)
        return nullptr;

    gst_memory_init(GST_MEMORY_CAST(copy), static_cast<GstMemoryFlags>(0),
        mem->base.allocator, nullptr, allocationSize, alignment, 0, allocationSize);

    copy->data = reinterpret_cast<uint8_t*>(copy) + headerSize;
    std::memcpy(copy->data, mem->data + mem->base.offset + offset, allocationSize);

    return copy;
}
Пример #12
0
static MyMemory *
_my_mem_share (MyMemory * mem, gssize offset, gsize size)
{
  MyMemory *sub;
  GstMemory *parent;

  GST_DEBUG ("%p: share %" G_GSSIZE_FORMAT " %" G_GSIZE_FORMAT, mem, offset,
      size);

  /* find the real parent */
  if ((parent = mem->mem.parent) == NULL)
    parent = (GstMemory *) mem;

  if (size == -1)
    size = mem->mem.size - offset;

  sub = g_slice_new (MyMemory);
  /* the shared memory is always readonly */
  gst_memory_init (GST_MEMORY_CAST (sub), GST_MINI_OBJECT_FLAGS (parent) |
      GST_MINI_OBJECT_FLAG_LOCK_READONLY, mem->mem.allocator, parent,
      mem->mem.maxsize, mem->mem.align, mem->mem.offset + offset, size);

  /* install pointer */
  sub->data = _my_mem_map (mem, mem->mem.maxsize, GST_MAP_READ);

  return sub;
}
GstMemory *
gst_vaapi_video_memory_new (GstAllocator * base_allocator,
    GstVaapiVideoMeta * meta)
{
  GstVaapiVideoAllocator *const allocator =
      GST_VAAPI_VIDEO_ALLOCATOR_CAST (base_allocator);
  const GstVideoInfo *vip;
  GstVaapiVideoMemory *mem;

  g_return_val_if_fail (GST_VAAPI_IS_VIDEO_ALLOCATOR (allocator), NULL);

  mem = g_slice_new (GstVaapiVideoMemory);
  if (!mem)
    return NULL;

  vip = &allocator->image_info;
  gst_memory_init (&mem->parent_instance, GST_MEMORY_FLAG_NO_SHARE,
      gst_object_ref (allocator), NULL, GST_VIDEO_INFO_SIZE (vip), 0,
      0, GST_VIDEO_INFO_SIZE (vip));

  mem->proxy = NULL;
  mem->surface_info = &allocator->surface_info;
  mem->surface = NULL;
  mem->image_info = &allocator->image_info;
  mem->image = NULL;
  mem->meta = meta ? gst_vaapi_video_meta_ref (meta) : NULL;
  mem->map_type = 0;
  mem->map_count = 0;
  mem->use_direct_rendering = allocator->has_direct_rendering;

  GST_VAAPI_VIDEO_MEMORY_FLAG_SET (mem,
      GST_VAAPI_VIDEO_MEMORY_FLAG_SURFACE_IS_CURRENT);
  return GST_MEMORY_CAST (mem);
}
Пример #14
0
static GstMemory *
gst_omx_memory_allocator_alloc (GstAllocator * allocator, GstMemoryFlags flags,
    GstOMXBuffer * buf)
{
  GstOMXMemory *mem;
  gint align;

  /* FIXME: We don't allow sharing because we need to know
   * when the memory becomes unused and can only then put
   * it back to the pool. Which is done in the pool's release
   * function
   */
  flags |= GST_MEMORY_FLAG_NO_SHARE;

  /* GStreamer uses a bitmask for the alignment while
   * OMX uses the alignment itself. So we have to convert
   * here */
  align = buf->port->port_def.nBufferAlignment;
  if (align > 0)
    align -= 1;
  if (((align + 1) & align) != 0) {
    GST_WARNING ("Invalid alignment that is not a power of two: %u",
        (guint) buf->port->port_def.nBufferAlignment);
    align = 0;
  }

  mem = g_slice_new (GstOMXMemory);
  /* the shared memory is always readonly */
  gst_memory_init (GST_MEMORY_CAST (mem), flags, allocator, NULL,
      buf->omx_buf->nAllocLen, align, 0, buf->omx_buf->nAllocLen);

  mem->buf = buf;

  return GST_MEMORY_CAST (mem);
}
Пример #15
0
/**
 * gst_dmabuf_allocator_alloc:
 * @allocator: (allow-none): allocator to be used for this memory
 * @fd: dmabuf file descriptor
 * @size: memory size
 *
 * Return a %GstMemory that wraps a dmabuf file descriptor.
 *
 * Returns: (transfer full): a GstMemory based on @allocator.
 * When the buffer will be released dmabuf allocator will close the @fd.
 * The memory is only mmapped on gst_buffer_mmap() request.
 *
 * Since: 1.2
 */
GstMemory *
gst_dmabuf_allocator_alloc (GstAllocator * allocator, gint fd, gsize size)
{
    GstDmaBufMemory *mem;

    if (!allocator) {
        allocator = gst_dmabuf_allocator_obtain ();
    }

    if (!GST_IS_DMABUF_ALLOCATOR (allocator)) {
        GST_WARNING ("it isn't the correct allocator for dmabuf");
        return NULL;
    }

    GST_DEBUG ("alloc from allocator %p", allocator);

    mem = g_slice_new0 (GstDmaBufMemory);

    gst_memory_init (GST_MEMORY_CAST (mem), 0, allocator, NULL, size, 0, 0, size);

    mem->fd = fd;
    g_mutex_init (&mem->lock);

    GST_DEBUG ("%p: fd: %d size %" G_GSIZE_FORMAT, mem, mem->fd,
               mem->mem.maxsize);

    return (GstMemory *) mem;
}
Пример #16
0
static GstMemory *
gst_shmdata_sink_allocator_alloc_locked (GstShmdataSinkAllocator * self, gsize size,
    GstAllocationParams * params)
{
  GstMemory *memory = NULL;
  gsize maxsize = size + params->prefix + params->padding;
  gsize align = params->align;

  /* ensure configured alignment */
  align |= gst_memory_alignment;
  /* allocate more to compensate for alignment */
  maxsize += align;

  if (self->sink->size < size){
    if (0 == shmdata_shm_resize(self->sink->access, size))
      GST_ELEMENT_ERROR (self, RESOURCE, NO_SPACE_LEFT, 
                         ("Cannot resize shared memory area"), 
                         ("from %" G_GSIZE_FORMAT " to %" G_GSIZE_FORMAT,
			  self->sink->size, 
                          size)); 
    self->sink->size = size;
  }
  void *data = shmdata_get_mem(self->sink->access);
  if (data) {
    GstShmdataSinkMemory *mymem;
    gsize aoffset, padding;

    GST_LOG_OBJECT (self,
        "Allocated block with %" G_GSIZE_FORMAT " bytes at %p", size,
        data);

    mymem = g_slice_new0 (GstShmdataSinkMemory);
    memory = GST_MEMORY_CAST (mymem);
    mymem->data = data;
    mymem->sink = gst_object_ref (self->sink);

    /* do alignment */
    if ((aoffset = ((guintptr) mymem->data & align))) {
      aoffset = (align + 1) - aoffset;
      mymem->data += aoffset;
      maxsize -= aoffset;
    }

    if (params->prefix && (params->flags & GST_MEMORY_FLAG_ZERO_PREFIXED))
      memset (mymem->data, 0, params->prefix);

    padding = maxsize - (params->prefix + size);
    if (padding && (params->flags & GST_MEMORY_FLAG_ZERO_PADDED))
      memset (mymem->data + params->prefix + size, 0, padding);

    gst_memory_init (memory, params->flags, g_object_ref (self), NULL,
        maxsize, align, params->prefix, size);
  }

  return memory;
}
static GstMemory *
gst_droid_codec_gralloc_allocator_alloc (GstAllocator * allocator, gsize size,
    GstAllocationParams * params)
{
  GstMemory *gralloc;
  OMX_ERRORTYPE err;
  GstDroidCodecGrallocMemory *mem;
  struct ANativeWindowBuffer *native;
  GstDroidCodecGrallocAllocator *alloc = GST_GRALLOC_ALLOCATOR (allocator);
  OMX_BUFFERHEADERTYPE *omx_buf = NULL;

  if (size != alloc->port->def.nBufferSize) {
    GST_ERROR_OBJECT (alloc->port->comp->parent,
        "invalid size passed %i vs requested %li", size,
        alloc->port->def.nBufferSize);
    return NULL;
  }

  gralloc = gst_gralloc_allocator_alloc (alloc->gralloc,
      alloc->port->def.format.video.nFrameWidth,
      alloc->port->def.format.video.nFrameHeight,
      alloc->port->def.format.video.eColorFormat, alloc->port->usage);
  if (!gralloc) {
    GST_ERROR_OBJECT (alloc->port->comp->parent,
        "error allocating gralloc memory");
    return NULL;
  }

  mem = g_slice_new0 (GstDroidCodecGrallocMemory);
  native = gst_memory_get_native_buffer (gralloc);
  err =
      OMX_UseBuffer (alloc->port->comp->omx, &omx_buf,
      alloc->port->def.nPortIndex, mem, alloc->port->def.nBufferSize,
      (OMX_U8 *) native->handle);

  if (err != OMX_ErrorNone) {
    GST_ERROR_OBJECT (alloc->port->comp->parent,
        "Failed to use buffer for port %li: %s (0x%08x)",
        alloc->port->def.nPortIndex, gst_omx_error_to_string (err), err);
    gst_memory_unref (gralloc);
    g_slice_free (GstDroidCodecGrallocMemory, mem);
    return NULL;
  }

  mem->gralloc = gralloc;
  mem->omx_buf = omx_buf;

  gst_memory_init (GST_MEMORY_CAST (mem), GST_MEMORY_FLAG_NO_SHARE, allocator,
      NULL, omx_buf->nAllocLen, alloc->port->def.nBufferAlignment, 0,
      omx_buf->nAllocLen);

  GST_DEBUG_OBJECT (alloc->port->comp->parent,
      "Allocated buffer for port %li", alloc->port->def.nPortIndex);

  return GST_MEMORY_CAST (mem);
}
Пример #18
0
GstMemory *
gst_droid_media_buffer_allocator_alloc_from_data (GstAllocator * allocator,
    GstVideoInfo * info, DroidMediaData * data, DroidMediaBufferCallbacks * cb)
{
  GstDroidMediaBufferMemory *mem;
  DroidMediaBuffer *buffer;
  int format;
  GstDroidMediaBufferAllocator *alloc;

  if (!GST_IS_DROID_MEDIA_BUFFER_ALLOCATOR (allocator)) {
    GST_WARNING_OBJECT (allocator,
        "allocator is not the correct allocator for droidmediabuffer");
    return NULL;
  }

  alloc = (GstDroidMediaBufferAllocator *) allocator;

  if (info->finfo->format == GST_VIDEO_FORMAT_YV12) {
    format = alloc->c.HAL_PIXEL_FORMAT_YV12;
  } else if (info->finfo->format == GST_VIDEO_FORMAT_NV21) {
    format = alloc->c.HAL_PIXEL_FORMAT_YCrCb_420_SP;
  } else {
    GST_WARNING_OBJECT (allocator,
        "Unknown GStreamer format %s",
        gst_video_format_to_string (info->finfo->format));
    return NULL;
  }

  mem = g_slice_new0 (GstDroidMediaBufferMemory);

  buffer =
      droid_media_buffer_create_from_raw_data (info->width, info->height,
      GST_VIDEO_INFO_COMP_STRIDE (info, 0),
      GST_VIDEO_INFO_COMP_STRIDE (info, 1), format, data, cb);
  if (!buffer) {
    GST_ERROR_OBJECT (allocator, "failed to acquire media buffer");
    g_slice_free (GstDroidMediaBufferMemory, mem);
    return NULL;
  }

  mem->buffer = buffer;

  gst_memory_init (GST_MEMORY_CAST (mem),
      GST_MEMORY_FLAG_NO_SHARE | GST_MEMORY_FLAG_NOT_MAPPABLE, allocator, NULL,
      0, 0, 0, 0);

  GST_DEBUG_OBJECT (allocator, "alloc %p", mem);

  return GST_MEMORY_CAST (mem);
}
Пример #19
0
/* initialize the fields */
static inline void
_sysmem_init (GstMemorySystem * mem, GstMemoryFlags flags,
    GstMemory * parent, gsize slice_size,
    gpointer data, gsize maxsize, gsize align, gsize offset, gsize size,
    gpointer user_data, GDestroyNotify notify)
{
  gst_memory_init (GST_MEMORY_CAST (mem),
      flags, _sysmem_allocator, parent, maxsize, align, offset, size);

  mem->slice_size = slice_size;
  mem->data = data;
  mem->user_data = user_data;
  mem->notify = notify;
}
Пример #20
0
static GstMemory *
gst_shm_sink_allocator_alloc_locked (GstShmSinkAllocator * self, gsize size,
    GstAllocationParams * params)
{
  GstMemory *memory = NULL;
  ShmBlock *block = NULL;
  gsize maxsize = size + params->prefix + params->padding;
  gsize align = params->align;

  /* ensure configured alignment */
  align |= gst_memory_alignment;
  /* allocate more to compensate for alignment */
  maxsize += align;

  block = sp_writer_alloc_block (self->sink->pipe, maxsize);
  if (block) {
    GstShmSinkMemory *mymem;
    gsize aoffset, padding;

    GST_LOG_OBJECT (self,
        "Allocated block %p with %" G_GSIZE_FORMAT " bytes at %p", block, size,
        sp_writer_block_get_buf (block));

    mymem = g_slice_new0 (GstShmSinkMemory);
    memory = GST_MEMORY_CAST (mymem);
    mymem->data = sp_writer_block_get_buf (block);
    mymem->sink = gst_object_ref (self->sink);
    mymem->block = block;

    /* do alignment */
    if ((aoffset = ((guintptr) mymem->data & align))) {
      aoffset = (align + 1) - aoffset;
      mymem->data += aoffset;
      maxsize -= aoffset;
    }

    if (params->prefix && (params->flags & GST_MEMORY_FLAG_ZERO_PREFIXED))
      memset (mymem->data, 0, params->prefix);

    padding = maxsize - (params->prefix + size);
    if (padding && (params->flags & GST_MEMORY_FLAG_ZERO_PADDED))
      memset (mymem->data + params->prefix + size, 0, padding);

    gst_memory_init (memory, params->flags,
        GST_ALLOCATOR_CAST (g_object_ref (self)), NULL, maxsize, align,
        params->prefix, size);
  }

  return memory;
}
Пример #21
0
static GstMemory*
moz_gfx_memory_allocator_alloc(GstAllocator* aAllocator, gsize aSize,
    GstAllocationParams* aParams)
{
  MozGfxMemory* mem = g_slice_new (MozGfxMemory);
  gsize maxsize = aSize + aParams->prefix + aParams->padding;
  gst_memory_init(GST_MEMORY_CAST (mem),
                  (GstMemoryFlags)aParams->flags,
                  aAllocator, NULL, maxsize, aParams->align,
                  aParams->prefix, aSize);
  mem->image = NULL;
  moz_gfx_memory_reset(mem);

  return (GstMemory *) mem;
}
Пример #22
0
static GstMemory *
gst_wl_shm_allocator_alloc (GstAllocator * allocator, gsize size,
    GstAllocationParams * params)
{
  GstWlShmAllocator *self = GST_WL_SHM_ALLOCATOR (allocator);
  char filename[1024];
  static int init = 0;
  int fd;
  gpointer data;
  GstWlShmMemory *mem;

  /* TODO: make use of the allocation params, if necessary */

  /* allocate shm pool */
  snprintf (filename, 1024, "%s/%s-%d-%s", g_get_user_runtime_dir (),
      "wayland-shm", init++, "XXXXXX");

  fd = g_mkstemp (filename);
  if (fd < 0) {
    GST_ERROR_OBJECT (self, "opening temp file %s failed: %s", filename,
        strerror (errno));
    return NULL;
  }
  if (ftruncate (fd, size) < 0) {
    GST_ERROR_OBJECT (self, "ftruncate failed: %s", strerror (errno));
    close (fd);
    return NULL;
  }

  data = mmap (NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  if (data == MAP_FAILED) {
    GST_ERROR_OBJECT (self, "mmap failed: %s", strerror (errno));
    close (fd);
    return NULL;
  }

  unlink (filename);

  mem = g_slice_new0 (GstWlShmMemory);
  gst_memory_init ((GstMemory *) mem, GST_MEMORY_FLAG_NO_SHARE, allocator, NULL,
      size, 0, 0, size);
  mem->data = data;
  mem->fd = fd;

  return (GstMemory *) mem;
}
static void
_vdp_video_mem_init (GstVdpVideoMemory * mem, GstAllocator * allocator,
    GstMemory * parent, GstVdpDevice * device, GstVideoInfo * info)
{
  gst_memory_init (GST_MEMORY_CAST (mem), GST_MEMORY_FLAG_NO_SHARE,
      allocator, parent, GST_VIDEO_INFO_SIZE (info), 0, 0,
      GST_VIDEO_INFO_SIZE (info));

  mem->device = gst_object_ref (device);
  mem->info = info;
  mem->chroma_type = gst_video_info_to_vdp_chroma_type (info);
  mem->ycbcr_format =
      gst_video_format_to_vdp_ycbcr (GST_VIDEO_INFO_FORMAT (info));
  mem->refcount = 0;

  GST_DEBUG ("new VdpVideo memory");
}
Пример #24
0
static GstMemory *
_my_alloc (GstAllocator * allocator, gsize size, GstAllocationParams * params)
{
  MyMemory *mem;
  gsize maxsize = size + params->prefix + params->padding;

  GST_DEBUG ("alloc from allocator %p", allocator);

  mem = g_slice_new (MyMemory);

  gst_memory_init (GST_MEMORY_CAST (mem), params->flags, allocator, NULL,
      maxsize, params->align, params->prefix, size);

  mem->data = NULL;

  return (GstMemory *) mem;
}
Пример #25
0
static GstMemory *
gst_mmal_opaque_allocator_alloc (GstAllocator * allocator, gsize size,
    GstAllocationParams * params)
{
  GstMMALOpaqueMemory *mem = g_slice_new (GstMMALOpaqueMemory);

  gst_memory_init (GST_MEMORY_CAST (mem), GST_MEMORY_FLAG_NOT_MAPPABLE,
      allocator, NULL, size, 31, 0, size);

  /* We will have to fill this in later, once we have it.
     The client will do this by calling:
     gst_mmal_opaque_mem_set_mmal_header()
   */
  mem->mmal_buffer_header = NULL;

  return GST_MEMORY_CAST (mem);
}
static GstMemory *
gst_dwl_allocator_alloc (GstAllocator * allocator, gsize size,
    GstAllocationParams * params)
{
  GstDwlAllocator *dwl;
  GstDwlMemory *dwlmem;
  GstG1Memory *g1mem;
  GstMemory *mem;
  gsize maxsize;
  gint ret;

  dwl = GST_DWL_ALLOCATOR (allocator);
  dwlmem = g_slice_new (GstDwlMemory);
  mem = GST_MEMORY_CAST (dwlmem);

  /* Take into account prefix and padding */
  maxsize = size + params->prefix + params->padding;

  GST_LOG ("Allocating new slice %p of %d", mem, maxsize);

  ret = DWLMallocLinear (dwl->dwl, maxsize, &dwlmem->linearmem);
  if (DWL_FAILED (ret)) {
    GST_ERROR_OBJECT (dwl, "Unable to allocate buffer of size %d, reason: %d",
        size, ret);
    g_free (dwlmem);
    dwlmem = NULL;
    mem = NULL;
    goto exit;
  }

  /* Initialize GstMemory */
  gst_memory_init (mem, GST_MEMORY_FLAG_PHYSICALLY_CONTIGUOUS, _dwl_allocator,
      NULL, maxsize, 0, params->prefix, size);

  g1mem = (GstG1Memory *) dwlmem;
  g1mem->virtaddress = dwlmem->linearmem.virtualAddress;
  g1mem->physaddress = dwlmem->linearmem.busAddress;

exit:
  {
    return mem;
  }
}
static GstMemoryFastMalloc* gst_allocator_fast_malloc_mem_share(GstMemoryFastMalloc* mem, gssize offset, gsize size)
{
    GstMemory* parent = mem->base.parent;
    if (!parent)
        parent = GST_MEMORY_CAST(mem);

    if (size == static_cast<gsize>(-1))
        size = mem->base.size - offset;

    GstMemoryFastMalloc* sharedMem = static_cast<GstMemoryFastMalloc*>(fastMalloc(sizeof(GstMemoryFastMalloc)));
    gst_memory_init(GST_MEMORY_CAST(sharedMem),
        static_cast<GstMemoryFlags>(GST_MINI_OBJECT_FLAGS(parent) | GST_MINI_OBJECT_FLAG_LOCK_READONLY),
        mem->base.allocator, parent, mem->base.maxsize, mem->base.align,
        mem->base.offset + offset, size);

    sharedMem->data = mem->data;

    return sharedMem;
}
static void
_vk_mem_init (GstVulkanMemory * mem, GstAllocator * allocator,
    GstMemory * parent, GstVulkanDevice * device, guint32 memory_type_index,
    GstAllocationParams * params, gsize size,
    VkMemoryPropertyFlags mem_prop_flags, gpointer user_data,
    GDestroyNotify notify)
{
  gsize align = gst_memory_alignment, offset = 0, maxsize = size;
  GstMemoryFlags flags = 0;
  gchar *props_str;

  if (params) {
    flags = params->flags;
    align |= params->align;
    offset = params->prefix;
    maxsize += params->prefix + params->padding;
    if ((maxsize & align) != 0)
      maxsize += ~(maxsize & align) + 1;
  }

  gst_memory_init (GST_MEMORY_CAST (mem), flags, allocator, parent, maxsize,
      align, offset, size);

  mem->device = gst_object_ref (device);
  mem->alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
  mem->alloc_info.pNext = NULL;
  mem->alloc_info.allocationSize = (VkDeviceSize) mem->mem.maxsize;
  mem->alloc_info.memoryTypeIndex = memory_type_index;
  mem->properties = mem_prop_flags;
  mem->notify = notify;
  mem->user_data = user_data;
  mem->vk_offset = 0;

  g_mutex_init (&mem->lock);

  props_str = _memory_properties_to_string (mem_prop_flags);

  GST_CAT_DEBUG (GST_CAT_VULKAN_MEMORY, "new Vulkan memory:%p size:%"
      G_GSIZE_FORMAT " properties:%s", mem, maxsize, props_str);

  g_free (props_str);
}
static GstTestPhysMemory* gst_test_phys_mem_new_internal(GstTestPhysMemAllocator *phys_mem_alloc, GstMemory *parent, gsize maxsize, GstMemoryFlags flags, gsize align, gsize offset, gsize size)
{
	GstTestPhysMemory *phys_mem;
	phys_mem = g_slice_alloc(sizeof(GstTestPhysMemory));
	if (phys_mem == NULL)
	{
		GST_ERROR_OBJECT(phys_mem_alloc, "could not allocate memory for physmem structure");
		return NULL;
	}

	phys_mem->mapped_virt_addr = NULL;
	phys_mem->phys_addr = 0;
	phys_mem->mapping_refcount = 0;
	phys_mem->internal = NULL;

	//Initializes a newly allocated mem with the given parameters. 
	gst_memory_init(GST_MEMORY_CAST(phys_mem), flags, GST_ALLOCATOR_CAST(phys_mem_alloc), parent, maxsize, align, offset, size);

	return phys_mem;
}
Пример #30
0
static GstDroidMediaBufferMemory *
gst_droid_media_buffer_allocator_alloc_from_buffer (GstAllocator * allocator,
    DroidMediaBuffer * buffer, int format_index, gsize width, gsize height,
    gsize stride)
{
  GstDroidMediaBufferMemory *mem = g_slice_new0 (GstDroidMediaBufferMemory);
  GstFormat format;
  gsize padded_width = width;
  gsize padded_height = height;

  mem->buffer = buffer;
  mem->map_data = NULL;
  mem->map_flags = 0;
  mem->map_count = 0;

  if (format_index == GST_DROID_MEDIA_BUFFER_FORMAT_COUNT) {
    format = GST_VIDEO_FORMAT_ENCODED;
  } else {
    format = gst_droid_media_buffer_formats[format_index].gst_format;
    if (gst_droid_media_buffer_formats[format_index].bytes_per_pixel != 0) {
      padded_width =
          ALIGN_SIZE (stride,
          gst_droid_media_buffer_formats[format_index].h_align) /
          gst_droid_media_buffer_formats[format_index].bytes_per_pixel;
      padded_height =
          ALIGN_SIZE (height,
          gst_droid_media_buffer_formats[format_index].v_align);
    }
  }

  gst_video_info_set_format (&mem->video_info, format, padded_width,
      padded_height);
  mem->video_info.width = width;
  mem->video_info.height = height;

  gst_memory_init (GST_MEMORY_CAST (mem),
      GST_MEMORY_FLAG_NO_SHARE, allocator, NULL, mem->video_info.size, 0, 0,
      mem->video_info.size);

  return mem;
}