summaryrefslogtreecommitdiff
path: root/omx/gstomxallocator.h
blob: 5c94584ec21b3f75740e24ab6d9ac40913424b6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
 * 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