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., 51 Franklin St, Fifth Floor, 17 * Boston, MA 02110-1301, 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 _GstMetaXImage GstMetaXImage; 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 * @visual: the default Visual of Screen @screen 54 * @root: the root Window of Display @disp 55 * @white: the value of a white pixel on Screen @screen 56 * @black: the value of a black pixel on Screen @screen 57 * @depth: the color depth of Display @disp 58 * @bpp: the number of bits per pixel on Display @disp 59 * @endianness: the endianness of image bytes on Display @disp 60 * @width: the width in pixels of Display @disp 61 * @height: the height in pixels of Display @disp 62 * @widthmm: the width in millimeters of Display @disp 63 * @heightmm: the height in millimeters of Display @disp 64 * @par_n: the pixel aspect ratio numerator calculated from @width, @widthmm 65 * and @height, 66 * @par_d: the pixel aspect ratio denumerator calculated from @width, @widthmm 67 * and @height, 68 * @heightmm ratio 69 * @use_xshm: used to known wether of not XShm extension is usable or not even 70 * if the Extension is present 71 * @caps: the #GstCaps that Display @disp can accept 72 * 73 * Structure used to store various informations collected/calculated for a 74 * Display. 75 */ 76 struct _GstXContext { 77 Display *disp; 78 79 Screen *screen; 80 81 Visual *visual; 82 83 Window root; 84 85 gulong white, black; 86 87 gint depth; 88 gint bpp; 89 gint endianness; 90 91 gint width, height; 92 gint widthmm, heightmm; 93 94 /* these are the output masks 95 * for buffers from ximagesrc 96 * and are in big endian */ 97 guint32 r_mask_output, g_mask_output, b_mask_output; 98 99 guint par_n; /* calculated pixel aspect ratio numerator */ 100 guint par_d; /* calculated pixel aspect ratio denumerator */ 101 102 gboolean use_xshm; 103 104 GstCaps *caps; 105 }; 106 107 /** 108 * GstXWindow: 109 * @win: the Window ID of this X11 window 110 * @width: the width in pixels of Window @win 111 * @height: the height in pixels of Window @win 112 * @internal: used to remember if Window @win was created internally or passed 113 * through the #GstXOverlay interface 114 * @gc: the Graphical Context of Window @win 115 * 116 * Structure used to store informations about a Window. 117 */ 118 struct _GstXWindow { 119 Window win; 120 gint width, height; 121 gboolean internal; 122 GC gc; 123 }; 124 125 gboolean ximageutil_check_xshm_calls (GstXContext * xcontext); 126 127 GstXContext *ximageutil_xcontext_get (GstElement *parent, 128 const gchar *display_name); 129 void ximageutil_xcontext_clear (GstXContext *xcontext); 130 void ximageutil_calculate_pixel_aspect_ratio (GstXContext * xcontext); 131 132 /* custom ximagesrc buffer, copied from ximagesink */ 133 134 /* BufferReturnFunc is called when a buffer is finalised */ 135 typedef gboolean (*BufferReturnFunc) (GstElement *parent, GstBuffer *buf); 136 137 /** 138 * GstMetaXImage: 139 * @parent: a reference to the element we belong to 140 * @ximage: the XImage of this buffer 141 * @width: the width in pixels of XImage @ximage 142 * @height: the height in pixels of XImage @ximage 143 * @size: the size in bytes of XImage @ximage 144 * 145 * Extra data attached to buffers containing additional information about an XImage. 146 */ 147 struct _GstMetaXImage { 148 GstMeta meta; 149 150 /* Reference to the ximagesrc we belong to */ 151 GstElement *parent; 152 153 XImage *ximage; 154 155 #ifdef HAVE_XSHM 156 XShmSegmentInfo SHMInfo; 157 #endif /* HAVE_XSHM */ 158 159 gint width, height; 160 size_t size; 161 162 BufferReturnFunc return_func; 163 }; 164 165 GType gst_meta_ximage_api_get_type (void); 166 const GstMetaInfo * gst_meta_ximage_get_info (void); 167 #define GST_META_XIMAGE_GET(buf) ((GstMetaXImage *)gst_buffer_get_meta(buf,gst_meta_ximage_api_get_type())) 168 #define GST_META_XIMAGE_ADD(buf) ((GstMetaXImage *)gst_buffer_add_meta(buf,gst_meta_ximage_get_info(),NULL)) 169 170 GstBuffer *gst_ximageutil_ximage_new (GstXContext *xcontext, 171 GstElement *parent, int width, int height, BufferReturnFunc return_func); 172 173 void gst_ximageutil_ximage_destroy (GstXContext *xcontext, 174 GstBuffer * ximage); 175 176 /* Call to manually release a buffer */ 177 void gst_ximage_buffer_free (GstBuffer *ximage); 178 179 G_END_DECLS 180 181 #endif /* __GST_XIMAGEUTIL_H__ */ 182