1 /* GStreamer 2 * Copyright (C) <2005> Julien Moutte <julien@moutte.net> 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_X_IMAGE_SINK_H__ 21 #define __GST_X_IMAGE_SINK_H__ 22 23 #include <gst/video/gstvideosink.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 /* Helper functions */ 42 #include <gst/video/video.h> 43 44 G_BEGIN_DECLS 45 #define GST_TYPE_X_IMAGE_SINK \ 46 (gst_x_image_sink_get_type()) 47 #define GST_X_IMAGE_SINK(obj) \ 48 (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_X_IMAGE_SINK, GstXImageSink)) 49 #define GST_X_IMAGE_SINK_CLASS(klass) \ 50 (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_X_IMAGE_SINK, GstXImageSinkClass)) 51 #define GST_IS_X_IMAGE_SINK(obj) \ 52 (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_X_IMAGE_SINK)) 53 #define GST_IS_X_IMAGE_SINK_CLASS(klass) \ 54 (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_X_IMAGE_SINK)) 55 56 typedef struct _GstXContext GstXContext; 57 typedef struct _GstXWindow GstXWindow; 58 59 typedef struct _GstXImageSink GstXImageSink; 60 typedef struct _GstXImageSinkClass GstXImageSinkClass; 61 62 #include "ximagepool.h" 63 64 /* 65 * GstXContext: 66 * @disp: the X11 Display of this context 67 * @screen: the default Screen of Display @disp 68 * @screen_num: the Screen number of @screen 69 * @visual: the default Visual of Screen @screen 70 * @root: the root Window of Display @disp 71 * @white: the value of a white pixel on Screen @screen 72 * @black: the value of a black pixel on Screen @screen 73 * @depth: the color depth of Display @disp 74 * @bpp: the number of bits per pixel on Display @disp 75 * @endianness: the endianness of image bytes on Display @disp 76 * @width: the width in pixels of Display @disp 77 * @height: the height in pixels of Display @disp 78 * @widthmm: the width in millimeters of Display @disp 79 * @heightmm: the height in millimeters of Display @disp 80 * @par: the pixel aspect ratio calculated from @width, @widthmm and @height, 81 * @heightmm ratio 82 * @use_xshm: used to known whether of not XShm extension is usable or not even 83 * if the Extension is present 84 * @use_xkb: used to known wether of not Xkb extension is usable or not even 85 * if the Extension is present 86 * @caps: the #GstCaps that Display @disp can accept 87 * 88 * Structure used to store various information collected/calculated for a 89 * Display. 90 */ 91 struct _GstXContext 92 { 93 Display *disp; 94 95 Screen *screen; 96 gint screen_num; 97 98 Visual *visual; 99 100 Window root; 101 102 gulong white, black; 103 104 gint depth; 105 gint bpp; 106 107 gint width, height; 108 gint widthmm, heightmm; 109 GValue *par; /* calculated pixel aspect ratio */ 110 111 gboolean use_xshm; 112 gboolean use_xkb; 113 114 GstCaps *caps; 115 GstCaps *last_caps; 116 }; 117 118 /* 119 * GstXWindow: 120 * @win: the Window ID of this X11 window 121 * @width: the width in pixels of Window @win 122 * @height: the height in pixels of Window @win 123 * @internal: used to remember if Window @win was created internally or passed 124 * through the #GstVideoOverlay interface 125 * @gc: the Graphical Context of Window @win 126 * 127 * Structure used to store information about a Window. 128 */ 129 struct _GstXWindow 130 { 131 Window win; 132 gint width, height; 133 gboolean internal; 134 GC gc; 135 }; 136 137 /** 138 * GstXImageSink: 139 * @display_name: the name of the Display we want to render to 140 * @xcontext: our instance's #GstXContext 141 * @xwindow: the #GstXWindow we are rendering to 142 * @ximage: internal #GstXImage used to store incoming buffers and render when 143 * not using the buffer_alloc optimization mechanism 144 * @cur_image: a reference to the last #GstXImage that was put to @xwindow. It 145 * is used when Expose events are received to redraw the latest video frame 146 * @event_thread: a thread listening for events on @xwindow and handling them 147 * @running: used to inform @event_thread if it should run/shutdown 148 * @fps_n: the framerate fraction numerator 149 * @fps_d: the framerate fraction denominator 150 * @x_lock: used to protect X calls as we are not using the XLib in threaded 151 * mode 152 * @flow_lock: used to protect data flow routines from external calls such as 153 * events from @event_thread or methods from the #GstVideoOverlay interface 154 * @par: used to override calculated pixel aspect ratio from @xcontext 155 * @pool_lock: used to protect the buffer pool 156 * @buffer_pool: a list of #GstXImageBuffer that could be reused at next buffer 157 * allocation call 158 * @synchronous: used to store if XSynchronous should be used or not (for 159 * debugging purpose only) 160 * @keep_aspect: used to remember if reverse negotiation scaling should respect 161 * aspect ratio 162 * @handle_events: used to know if we should handle select XEvents or not 163 * 164 * The #GstXImageSink data structure. 165 */ 166 struct _GstXImageSink 167 { 168 /* Our element stuff */ 169 GstVideoSink videosink; 170 171 char *display_name; 172 173 GstXContext *xcontext; 174 GstXWindow *xwindow; 175 GstBuffer *cur_image; 176 177 GThread *event_thread; 178 gboolean running; 179 180 GstVideoInfo info; 181 182 /* Framerate numerator and denominator */ 183 gint fps_n; 184 gint fps_d; 185 186 GMutex x_lock; 187 GMutex flow_lock; 188 189 /* object-set pixel aspect ratio */ 190 GValue *par; 191 192 /* the buffer pool */ 193 GstBufferPool *pool; 194 195 gboolean synchronous; 196 gboolean keep_aspect; 197 gboolean handle_events; 198 gboolean handle_expose; 199 gboolean draw_border; 200 201 /* stream metadata */ 202 gchar *media_title; 203 }; 204 205 struct _GstXImageSinkClass 206 { 207 GstVideoSinkClass parent_class; 208 }; 209 210 GType gst_x_image_sink_get_type (void); 211 GST_ELEMENT_REGISTER_DECLARE (ximagesink); 212 213 G_END_DECLS 214 #endif /* __GST_X_IMAGE_SINK_H__ */ 215