mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-20 23:36:38 +00:00
783e58fc48
One big restriction of the OMX buffer pool has always been that the GstMemory objects were flagged with NO_SHARE. This was because the buffer pool needed to be sure that when a buffer returned to the pool, it would be safe to release the OMX buffer back to OpenMAX. With this change, this is no longer a restriction. What this commit introduces is a new allocator that allows us to track the GstMemory objects independently. Now, when a buffer returns to the pool, it is not necessary for the memory to be released as well. We simply track the memory's ref count in the allocator and we return the OMX buffer back when the memory's ref count drops to 0. The reason for doing this is to allow implementing zero-copy transfers in situations where we may need to copy or map a certain region of the buffer. For instance, omxh264enc ! h264parse should be possible to be zero-copy by using an OMX buffer pool between them.
114 lines
3.1 KiB
C
114 lines
3.1 KiB
C
/*
|
|
* Copyright (C) 2019, Collabora Ltd.
|
|
* Author: George Kiagiadakis <george.kiagiadakis@collabora.com>
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation
|
|
* version 2.1 of the License.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*
|
|
*/
|
|
|
|
#ifndef __GST_OMX_ALLOCATOR_H__
|
|
#define __GST_OMX_ALLOCATOR_H__
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
#include "config.h"
|
|
#endif
|
|
|
|
#include <gst/gst.h>
|
|
|
|
#include "gstomx.h"
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
#define GST_OMX_MEMORY_QUARK gst_omx_memory_quark ()
|
|
|
|
#define GST_TYPE_OMX_ALLOCATOR (gst_omx_allocator_get_type())
|
|
#define GST_IS_OMX_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_OMX_ALLOCATOR))
|
|
#define GST_OMX_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_OMX_ALLOCATOR, GstOMXAllocator))
|
|
|
|
typedef struct _GstOMXMemory GstOMXMemory;
|
|
typedef struct _GstOMXAllocator GstOMXAllocator;
|
|
typedef struct _GstOMXAllocatorClass GstOMXAllocatorClass;
|
|
|
|
typedef enum {
|
|
GST_OMX_ALLOCATOR_FOREIGN_MEM_NONE,
|
|
GST_OMX_ALLOCATOR_FOREIGN_MEM_DMABUF,
|
|
GST_OMX_ALLOCATOR_FOREIGN_MEM_OTHER_POOL,
|
|
} GstOMXAllocatorForeignMemMode;
|
|
|
|
struct _GstOMXMemory
|
|
{
|
|
GstMemory mem;
|
|
GstOMXBuffer *buf;
|
|
|
|
/* TRUE if the memory is in use outside the allocator */
|
|
gboolean acquired;
|
|
|
|
/* memory allocated from the foreign_allocator
|
|
* or planted externally when using a foreign buffer pool */
|
|
GstMemory *foreign_mem;
|
|
/* the original dispose function of foreign_mem */
|
|
GstMiniObjectDisposeFunction foreign_dispose;
|
|
};
|
|
|
|
struct _GstOMXAllocator
|
|
{
|
|
GstAllocator parent;
|
|
|
|
GstOMXComponent *component;
|
|
GstOMXPort *port;
|
|
|
|
GstOMXAllocatorForeignMemMode foreign_mode;
|
|
GstAllocator *foreign_allocator;
|
|
|
|
/* array of GstOMXMemory */
|
|
GPtrArray *memories;
|
|
guint n_memories;
|
|
|
|
guint n_outstanding;
|
|
gboolean active;
|
|
|
|
GMutex lock;
|
|
GCond cond;
|
|
};
|
|
|
|
struct _GstOMXAllocatorClass
|
|
{
|
|
GstAllocatorClass parent_class;
|
|
};
|
|
|
|
GType gst_omx_allocator_get_type (void);
|
|
|
|
GQuark gst_omx_memory_quark (void);
|
|
|
|
GstOMXBuffer * gst_omx_memory_get_omx_buf (GstMemory * mem);
|
|
|
|
GstOMXAllocator * gst_omx_allocator_new (GstOMXComponent * component,
|
|
GstOMXPort * port);
|
|
|
|
gboolean gst_omx_allocator_configure (GstOMXAllocator * allocator, guint count,
|
|
GstOMXAllocatorForeignMemMode mode);
|
|
gboolean gst_omx_allocator_set_active (GstOMXAllocator * allocator,
|
|
gboolean active);
|
|
void gst_omx_allocator_wait_inactive (GstOMXAllocator * allocator);
|
|
|
|
GstFlowReturn gst_omx_allocator_acquire (GstOMXAllocator * allocator,
|
|
GstMemory ** memory, gint index, GstOMXBuffer * omx_buf);
|
|
|
|
GstMemory * gst_omx_allocator_allocate (GstOMXAllocator * allocator, gint index,
|
|
GstMemory * foreign_mem);
|
|
|
|
G_END_DECLS
|
|
|
|
#endif
|