• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * GStreamer
3  * Copyright (C) 2012 Collabora Ltd.
4  *   @author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
5  * Copyright (C) 2014 Julien Isorce <julien.isorce@gmail.com>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef _GST_EGL_IMAGE_H_
24 #define _GST_EGL_IMAGE_H_
25 
26 #include <gst/gl/gstgl_fwd.h>
27 #include <gst/gl/gstglformat.h>
28 
29 G_BEGIN_DECLS
30 
31 GST_GL_API GType gst_egl_image_get_type (void);
32 
33 #define GST_TYPE_EGL_IMAGE                         (gst_egl_image_get_type())
34 #define GST_IS_EGL_IMAGE(obj)                      (GST_IS_MINI_OBJECT_TYPE(obj, GST_TYPE_EGL_IMAGE))
35 #define GST_EGL_IMAGE_CAST(obj)                    ((GstEGLImage *)(obj))
36 #define GST_EGL_IMAGE(obj)                         (GST_EGL_IMAGE_CAST(obj))
37 
38 typedef struct _GstEGLImage GstEGLImage;
39 
40 /**
41  * GstEGLImageDestroyNotify:
42  * @image: a #GstEGLImage
43  * @data: user data passed to gst_egl_image_new_wrapped()
44  *
45  * Function to be called when the GstEGLImage is destroyed. It should free
46  * the associated `EGLImage` if necessary
47  */
48 typedef void (*GstEGLImageDestroyNotify) (GstEGLImage * image,
49     gpointer data);
50 
51 /**
52  * GstEGLImage:
53  *
54  * Opaque #GstEGLImage struct.
55  */
56 struct _GstEGLImage
57 {
58   /*< private >*/
59   GstMiniObject parent;
60 
61   GstGLContext *context;
62   gpointer image;
63   GstGLFormat format;
64 
65   gpointer destroy_data;
66   GstEGLImageDestroyNotify destroy_notify;
67 
68   gpointer _padding[GST_PADDING];
69 };
70 
71 GST_GL_API
72 GstEGLImage *             gst_egl_image_new_wrapped             (GstGLContext * context,
73                                                                  gpointer image,
74                                                                  GstGLFormat format,
75                                                                  gpointer user_data,
76                                                                  GstEGLImageDestroyNotify user_data_destroy);
77 GST_GL_API
78 gpointer                gst_egl_image_get_image                 (GstEGLImage * image);
79 
80 GST_GL_API
81 GstEGLImage *           gst_egl_image_from_texture              (GstGLContext * context,
82                                                                  GstGLMemory * gl_mem,
83                                                                  guintptr * attribs);
84 #if GST_GL_HAVE_DMABUF
85 GST_GL_API
86 GstEGLImage *           gst_egl_image_from_dmabuf               (GstGLContext * context,
87                                                                  gint dmabuf,
88                                                                  const GstVideoInfo * in_info,
89                                                                  gint plane,
90                                                                  gsize offset);
91 GST_GL_API
92 GstEGLImage *           gst_egl_image_from_dmabuf_direct        (GstGLContext * context,
93                                                                  gint *fd,
94                                                                  const gsize *offset,
95                                                                  const GstVideoInfo * in_info);
96 GST_GL_API
97 GstEGLImage *           gst_egl_image_from_dmabuf_direct_target (GstGLContext * context,
98                                                                  gint *fd,
99                                                                  const gsize *offset,
100                                                                  const GstVideoInfo * in_info,
101                                                                  GstGLTextureTarget target);
102 
103 GST_GL_API
104 gboolean                gst_egl_image_export_dmabuf             (GstEGLImage *image, int *fd, gint *stride, gsize *offset);
105 #endif
106 
107 /**
108  * gst_egl_image_ref:
109  * @image: a #GstEGLImage.
110  *
111  * Increases the refcount of the given image by one.
112  *
113  * Returns: (transfer full): @image
114  */
115 static inline GstEGLImage *
gst_egl_image_ref(GstEGLImage * image)116 gst_egl_image_ref (GstEGLImage * image)
117 {
118   return (GstEGLImage *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (image));
119 }
120 
121 /**
122  * gst_egl_image_unref:
123  * @image: (transfer full): a #GstEGLImage.
124  *
125  * Decreases the refcount of the image. If the refcount reaches 0, the image
126  * with the associated metadata and memory will be freed.
127  */
128 static inline void
gst_egl_image_unref(GstEGLImage * image)129 gst_egl_image_unref (GstEGLImage * image)
130 {
131   gst_mini_object_unref (GST_MINI_OBJECT_CAST (image));
132 }
133 
134 G_END_DECLS
135 
136 #endif /* _GST_EGL_IMAGE_H_ */
137