Merge remote-tracking branch 'gst-plugins-base/tizen_gst_1.19.2' into tizen_gst_1...
[platform/upstream/gstreamer.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   tbm_surface_info_s        surface_info;
60   GstVideoInfo              *info;
61
62   /* <protected> */
63   GMutex                    lock;
64   gboolean                  video_memory_map[GST_VIDEO_MAX_PLANES];
65   gint                      video_memory_map_count;
66
67   /* <private> */
68   GDestroyNotify            notify;
69   gpointer                  user_data;
70
71 };
72
73 struct _GstTizenAllocatorPrivate
74 {
75   GList *mem_cache;
76   GstAllocator *dmabuf_alloc;
77 };
78
79 /**
80  * GstTizenMemoryAllocator
81  *
82  * Base class for allocators with bo memory
83  */
84 struct _GstTizenAllocator
85 {
86   GstAllocator parent;
87   GstTizenAllocatorPrivate *priv;
88 };
89
90
91 struct _GstTizenAllocatorClass
92 {
93   GstAllocatorClass parent_class;
94 };
95
96 GST_ALLOCATORS_API
97 GstAllocator *  gst_tizen_allocator_new    (void);
98
99 GST_ALLOCATORS_API
100 GstMemory *     gst_tizen_allocator_alloc  (GstAllocator * allocator, GstVideoInfo * vinfo);
101
102 GST_ALLOCATORS_API
103 GstMemory *     gst_tizen_allocator_alloc_surface (GstAllocator * allocator, GstVideoInfo * vinfo,
104                                                    tbm_surface_h surface, gpointer user_data, GDestroyNotify notify);
105
106 GST_ALLOCATORS_API
107 gboolean        gst_is_tizen_memory        (GstMemory *mem);
108
109 GST_ALLOCATORS_API
110 gint            gst_tizen_memory_get_num_bos (GstMemory *mem);
111
112 GST_ALLOCATORS_API
113 void *          gst_tizen_memory_get_bos   (GstMemory *mem, gint index);
114
115 GST_ALLOCATORS_API
116 void *          gst_tizen_memory_get_surface (GstMemory *mem);
117
118 GST_ALLOCATORS_API
119 GstMemory *     gst_tizen_allocator_dmabuf_export (GstAllocator * allocator, GstMemory *tmem, int bo_idx);
120
121 GST_ALLOCATORS_API
122 GstTizenMemory *gst_tizen_allocator_dmabuf_import (GstAllocator * allocator, gint * fds, gint planes, gsize offsets[4], GstVideoInfo * vinfo);
123
124 GST_VIDEO_API
125 gboolean        gst_tizen_video_meta_map (GstVideoMeta * meta, guint plane, GstMapInfo * info,
126                     gpointer * data, gint * stride, GstMapFlags flags);
127
128 GST_VIDEO_API
129 gboolean        gst_tizen_video_meta_unmap (GstVideoMeta * meta, guint plane, GstMapInfo * info);
130
131 GST_ALLOCATORS_API
132 tbm_format      gst_video_format_to_tbm_format (GstVideoFormat format);
133
134 G_END_DECLS
135
136 #endif /* _GST_TIZEN_MEMORY_H_ */