1 | /* GStreamer dmabuf allocator |
2 | * Copyright (C) 2013 Linaro SA |
3 | * Author: Benjamin Gaignard <benjamin.gaignard@linaro.org> for Linaro. |
4 | * |
5 | * This library is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU Library General Public |
7 | * License as published by the Free Software Foundation; either |
8 | * version 2 of the License, or (at your option) any later version. |
9 | * |
10 | * This library is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * Library General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU Library General Public |
16 | * License along with this library; if not, write to the |
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | * Boston, MA 02111-1307, USA. |
19 | */ |
20 | |
21 | #ifndef __GST_DMABUF_H__ |
22 | #define __GST_DMABUF_H__ |
23 | |
24 | #include <gst/gst.h> |
25 | #include <gst/allocators/gstfdmemory.h> |
26 | |
27 | G_BEGIN_DECLS |
28 | |
29 | /** |
30 | * GST_CAPS_FEATURE_MEMORY_DMABUF: |
31 | * |
32 | * Constant that defines the caps feature name for DMA buffer sharing. |
33 | * |
34 | * It has to be used for non-mappable dma-buf only, i.e. when the underlying |
35 | * memory is not mappable to user space. Or when the mapped memory contains |
36 | * non meaningful data. It can be the case for protected content or when the |
37 | * user wants explicitly avoid any software post processing. |
38 | * |
39 | * In these cases all elements between the exported and the importer has to work |
40 | * in passthrough mode. This is done by adding this caps feature. |
41 | * |
42 | * When the memory is mappable for read and write requests then it is assumes |
43 | * to be a fast path and so this caps feature should not be used. Though |
44 | * according to the dma-buf protocol, while it is mapped it prevents the |
45 | * exporter to migrate the buffer. |
46 | * |
47 | * This caps feature should not serve at all the purpose of selecting the |
48 | * @GST_ALLOCATOR_DMABUF allocator during caps negotiation. |
49 | * When the exporter is the upstream element from the importer point of view, |
50 | * the exporter should try to map the dma buffer at runtime (preferably during |
51 | * decide_allocation phase). When it succeeds for #GST_MAP_READWRITE this caps |
52 | * feature should not be used. This allows scalers, color converts and any image |
53 | * processing filters to work directly on the dma buffer. |
54 | * In this case the importer element should check all incoming memory using |
55 | * gst_is_dmabuf_memory(). |
56 | * |
57 | * Since: 1.12 |
58 | */ |
59 | #define GST_CAPS_FEATURE_MEMORY_DMABUF "memory:DMABuf" |
60 | |
61 | #define GST_ALLOCATOR_DMABUF "dmabuf" |
62 | |
63 | #define GST_TYPE_DMABUF_ALLOCATOR (gst_dmabuf_allocator_get_type()) |
64 | #define GST_IS_DMABUF_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_DMABUF_ALLOCATOR)) |
65 | #define GST_IS_DMABUF_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_DMABUF_ALLOCATOR)) |
66 | #define GST_DMABUF_ALLOCATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_DMABUF_ALLOCATOR, GstDmaBufAllocatorClass)) |
67 | #define GST_DMABUF_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_DMABUF_ALLOCATOR, GstDmaBufAllocator)) |
68 | #define GST_DMABUF_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_DMABUF_ALLOCATOR, GstDmaBufAllocatorClass)) |
69 | #define GST_DMABUF_ALLOCATOR_CAST(obj) ((GstDmaBufAllocator *)(obj)) |
70 | |
71 | typedef struct _GstDmaBufAllocator GstDmaBufAllocator; |
72 | typedef struct _GstDmaBufAllocatorClass GstDmaBufAllocatorClass; |
73 | |
74 | /** |
75 | * GstDmaBufAllocator: |
76 | * |
77 | * Base class for allocators with dmabuf-backed memory |
78 | * |
79 | * Since: 1.12 |
80 | */ |
81 | struct _GstDmaBufAllocator |
82 | { |
83 | GstFdAllocator parent; |
84 | |
85 | /*< private >*/ |
86 | gpointer _gst_reserved[GST_PADDING]; |
87 | }; |
88 | |
89 | struct _GstDmaBufAllocatorClass |
90 | { |
91 | GstFdAllocatorClass parent_class; |
92 | |
93 | /*< private >*/ |
94 | gpointer _gst_reserved[GST_PADDING]; |
95 | }; |
96 | |
97 | |
98 | GST_ALLOCATORS_API |
99 | GType gst_dmabuf_allocator_get_type (void); |
100 | |
101 | GST_ALLOCATORS_API |
102 | GstAllocator * gst_dmabuf_allocator_new (void); |
103 | |
104 | GST_ALLOCATORS_API |
105 | GstMemory * gst_dmabuf_allocator_alloc (GstAllocator * allocator, gint fd, gsize size); |
106 | |
107 | GST_ALLOCATORS_API |
108 | GstMemory * gst_dmabuf_allocator_alloc_with_flags (GstAllocator * allocator, gint fd, gsize size, GstFdMemoryFlags flags); |
109 | |
110 | GST_ALLOCATORS_API |
111 | gint gst_dmabuf_memory_get_fd (GstMemory * mem); |
112 | |
113 | GST_ALLOCATORS_API |
114 | gboolean gst_is_dmabuf_memory (GstMemory * mem); |
115 | |
116 | |
117 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstDmaBufAllocator, gst_object_unref) |
118 | |
119 | G_END_DECLS |
120 | #endif /* __GST_DMABUF_H__ */ |
121 | |