import load-applet 0.46-1
[cpumem-applet] / gst / ximageutil.h
1 /* GStreamer
2  * Copyright (C) <2005> Luca Ognibene <luogni@tin.it>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #ifndef __GST_XIMAGEUTIL_H__
21 #define __GST_XIMAGEUTIL_H__
22
23 #include <gst/gst.h>
24
25 #ifdef HAVE_XSHM
26 #include <sys/types.h>
27 #include <sys/ipc.h>
28 #include <sys/shm.h>
29 #endif /* HAVE_XSHM */
30
31 #include <X11/Xlib.h>
32 #include <X11/Xutil.h>
33
34 #ifdef HAVE_XSHM
35 #include <X11/extensions/XShm.h>
36 #endif /* HAVE_XSHM */
37
38 #include <string.h>
39 #include <math.h>
40
41 G_BEGIN_DECLS
42
43 typedef struct _GstXContext GstXContext;
44 typedef struct _GstXWindow GstXWindow;
45 typedef struct _GstXImage GstXImage;
46 typedef struct _GstXImageSrcBuffer GstXImageSrcBuffer;
47
48 /* Global X Context stuff */
49 /**
50  * GstXContext:
51  * @disp: the X11 Display of this context
52  * @screen: the default Screen of Display @disp
53  * @screen_num: the Screen number of @screen
54  * @visual: the default Visual of Screen @screen
55  * @root: the root Window of Display @disp
56  * @white: the value of a white pixel on Screen @screen
57  * @black: the value of a black pixel on Screen @screen
58  * @depth: the color depth of Display @disp
59  * @bpp: the number of bits per pixel on Display @disp
60  * @endianness: the endianness of image bytes on Display @disp
61  * @width: the width in pixels of Display @disp
62  * @height: the height in pixels of Display @disp
63  * @widthmm: the width in millimeters of Display @disp
64  * @heightmm: the height in millimeters of Display @disp
65  * @par: the pixel aspect ratio calculated from @width, @widthmm and @height,
66  * @heightmm ratio
67  * @use_xshm: used to known wether of not XShm extension is usable or not even
68  * if the Extension is present
69  * @caps: the #GstCaps that Display @disp can accept
70  *
71  * Structure used to store various informations collected/calculated for a
72  * Display.
73  */
74 struct _GstXContext {
75   Display *disp;
76
77   Screen *screen;
78   gint screen_num;
79
80   Visual *visual;
81
82   Window root;
83
84   gulong white, black;
85
86   gint depth;
87   gint bpp;
88   gint endianness;
89
90   gint width, height;
91   gint widthmm, heightmm;
92
93   /* these are the output masks 
94    * for buffers from ximagesrc
95    * and are in big endian */
96   guint32 r_mask_output, g_mask_output, b_mask_output;
97   
98   GValue *par;                  /* calculated pixel aspect ratio */
99
100   gboolean use_xshm;
101
102   GstCaps *caps;
103 };
104
105 /**
106  * GstXWindow:
107  * @win: the Window ID of this X11 window
108  * @width: the width in pixels of Window @win
109  * @height: the height in pixels of Window @win
110  * @internal: used to remember if Window @win was created internally or passed
111  * through the #GstXOverlay interface
112  * @gc: the Graphical Context of Window @win
113  *
114  * Structure used to store informations about a Window.
115  */
116 struct _GstXWindow {
117   Window win;
118   gint width, height;
119   gboolean internal;
120   GC gc;
121 };
122
123 gboolean ximageutil_check_xshm_calls (GstXContext * xcontext);
124
125 GstXContext *ximageutil_xcontext_get (GstElement *parent, 
126     const gchar *display_name);
127 void ximageutil_xcontext_clear (GstXContext *xcontext);
128 void ximageutil_calculate_pixel_aspect_ratio (GstXContext * xcontext);
129
130 /* custom ximagesrc buffer, copied from ximagesink */
131
132 /* BufferReturnFunc is called when a buffer is finalised */
133 typedef void (*BufferReturnFunc) (GstElement *parent, GstXImageSrcBuffer *buf);
134
135 /**
136  * GstXImageSrcBuffer:
137  * @parent: a reference to the element we belong to
138  * @ximage: the XImage of this buffer
139  * @width: the width in pixels of XImage @ximage
140  * @height: the height in pixels of XImage @ximage
141  * @size: the size in bytes of XImage @ximage
142  *
143  * Subclass of #GstBuffer containing additional information about an XImage.
144  */
145 struct _GstXImageSrcBuffer {
146   GstBuffer buffer;
147
148   /* Reference to the ximagesrc we belong to */
149   GstElement *parent;
150
151   XImage *ximage;
152
153 #ifdef HAVE_XSHM
154   XShmSegmentInfo SHMInfo;
155 #endif /* HAVE_XSHM */
156
157   gint width, height;
158   size_t size;
159   
160   BufferReturnFunc return_func;
161 };
162
163
164 GstXImageSrcBuffer *gst_ximageutil_ximage_new (GstXContext *xcontext,
165   GstElement *parent, int width, int height, BufferReturnFunc return_func);
166
167 void gst_ximageutil_ximage_destroy (GstXContext *xcontext, 
168   GstXImageSrcBuffer * ximage);
169   
170 /* Call to manually release a buffer */
171 void gst_ximage_buffer_free (GstXImageSrcBuffer *ximage);
172
173 #define GST_TYPE_XIMAGESRC_BUFFER            (gst_ximagesrc_buffer_get_type())
174 #define GST_IS_XIMAGESRC_BUFFER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_XIMAGESRC_BUFFER))
175 #define GST_IS_XIMAGESRC_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_XIMAGESRC_BUFFER))
176 #define GST_XIMAGESRC_BUFFER(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_XIMAGESRC_BUFFER, GstXImageSrcBuffer))
177 #define GST_XIMAGESRC_BUFFER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_XIMAGESRC_BUFFER, GstXImageSrcBufferClass))
178 #define GST_XIMAGESRC_BUFFER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_XIMAGESRC_BUFFER, GstXImageSrcBufferClass))
179
180 G_END_DECLS 
181
182 #endif /* __GST_XIMAGEUTIL_H__ */