Merge branch 'upstream/1.16' into tizen_gst_1.16.2
[platform/upstream/gst-plugins-base.git] / gst-libs / gst / allocators / gsttizenmemory.h
1 /*
2  * GStreamer tizen memory
3  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
4  * Author: Sejun Park <sejun79.park@samsung.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 #ifndef __GST_TIZEN_MEMORY_H__
22 #define __GST_TIZEN_MEMORY_H__
23
24 #include <gst/gst.h>
25 #include <gst/allocators/allocators-prelude.h>
26 #include <gst/video/video.h>
27 #include <gst/video/gstvideometa.h>
28 //#include <gst/gstallocator.h>
29 #include <gst/gstmemory.h>
30 #include <tbm_bufmgr.h>
31 #include <tbm_surface.h>
32
33 G_BEGIN_DECLS
34
35 typedef struct _GstTizenAllocator GstTizenAllocator;
36 typedef struct _GstTizenAllocatorClass GstTizenAllocatorClass;
37 typedef struct _GstTizenAllocatorPrivate GstTizenAllocatorPrivate;
38
39 typedef struct _GstTizenMemory GstTizenMemory;
40 #define GST_TYPE_TIZEN_ALLOCATOR (gst_tizen_allocator_get_type())
41
42 GST_ALLOCATORS_API
43 GType gst_tizen_allocator_get_type(void);
44
45 #define GST_IS_TIZEN_ALLOCATOR(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_TIZEN_ALLOCATOR))
46 #define GST_IS_TIZEN_ALLOCATOR_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_TIZEN_ALLOCATOR))
47 #define GST_TIZEN_ALLOCATOR_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_TIZEN_ALLOCATOR, GstTizenAllocatorClass))
48 #define GST_TIZEN_ALLOCATOR(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_TIZEN_ALLOCATOR, GstTizenAllocator))
49 #define GST_TIZEN_ALLOCATOR_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_TIZEN_ALLOCATOR, GstTizenAllocatorClass))
50 #define GST_TIZEN_ALLOCATOR_CAST(obj)            ((GstTizenAllocator *)(obj))
51
52 #define GST_TIZEN_MEMORY_TYPE "TizenVideoMemory"
53
54 struct _GstTizenMemory
55 {
56   GstMemory                 mem;
57
58   tbm_surface_h             surface;
59   GstVideoInfo              *info;
60
61   /* <protected> */
62   GMutex                    lock;
63
64   /* <private> */
65   GDestroyNotify            notify;
66   gpointer                  user_data;
67
68 };
69
70 struct _GstTizenAllocatorPrivate
71 {
72   GList *mem_cache;
73   GstAllocator *dmabuf_alloc;
74 };
75
76 /**
77  * GstTizenMemoryAllocator
78  *
79  * Base class for allocators with bo memory
80  */
81 struct _GstTizenAllocator
82 {
83   GstAllocator parent;
84   GstTizenAllocatorPrivate *priv;
85 };
86
87
88 struct _GstTizenAllocatorClass
89 {
90   GstAllocatorClass parent_class;
91 };
92
93 GST_ALLOCATORS_API
94 GstAllocator *  gst_tizen_allocator_new    (void);
95
96 GST_ALLOCATORS_API
97 GstMemory *     gst_tizen_allocator_alloc  (GstAllocator * allocator, GstVideoInfo * vinfo);
98
99 GST_ALLOCATORS_API
100 GstMemory *     gst_tizen_allocator_alloc_surface (GstAllocator * allocator, GstVideoInfo * vinfo,
101                                                    tbm_surface_h surface, gpointer user_data, GDestroyNotify notify);
102
103 GST_ALLOCATORS_API
104 gboolean        gst_is_tizen_memory        (GstMemory *mem);
105
106 GST_ALLOCATORS_API
107 gint            gst_tizen_memory_get_num_bos (GstMemory *mem);
108
109 GST_ALLOCATORS_API
110 void *          gst_tizen_memory_get_bos   (GstMemory *mem, gint index);
111
112 GST_ALLOCATORS_API
113 void *          gst_tizen_memory_get_surface (GstMemory *mem);
114
115 GST_ALLOCATORS_API
116 GstMemory *     gst_tizen_allocator_dmabuf_export (GstAllocator * allocator, GstMemory *tmem, int bo_idx);
117
118 GST_ALLOCATORS_API
119 GstTizenMemory *gst_tizen_allocator_dmabuf_import (GstAllocator * allocator, gint * fds, gint planes, gsize offsets[4], GstVideoInfo * vinfo);
120
121 GST_ALLOCATORS_API
122 gboolean        gst_tizen_video_memory_map (GstVideoMeta * meta, guint plane, GstMapInfo * info,
123                     gpointer * data, gint * stride, GstMapFlags flags);
124
125 GST_ALLOCATORS_API
126 gboolean        gst_tizen_video_memory_unmap (GstVideoMeta * meta, guint plane, GstMapInfo * info);
127
128 GST_ALLOCATORS_API
129 tbm_format gst_video_format_to_tbm_format (GstVideoFormat format);
130
131 G_END_DECLS
132
133 #endif /* _GST_TIZEN_MEMORY_H_ */