gst_plugins_base/sys/xvimage/xvimagesink.h
changeset 0 0e761a78d257
equal deleted inserted replaced
-1:000000000000 0:0e761a78d257
       
     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., 59 Temple Place - Suite 330,
       
    17  * Boston, MA 02111-1307, USA.
       
    18  */
       
    19 
       
    20 #ifndef __GST_XVIMAGESINK_H__
       
    21 #define __GST_XVIMAGESINK_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 <X11/extensions/Xv.h>
       
    39 #include <X11/extensions/Xvlib.h>
       
    40 
       
    41 #include <string.h>
       
    42 #include <math.h>
       
    43 #include <stdlib.h>
       
    44 
       
    45 G_BEGIN_DECLS
       
    46 
       
    47 #define GST_TYPE_XVIMAGESINK \
       
    48   (gst_xvimagesink_get_type())
       
    49 #define GST_XVIMAGESINK(obj) \
       
    50   (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_XVIMAGESINK, GstXvImageSink))
       
    51 #define GST_XVIMAGESINK_CLASS(klass) \
       
    52   (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_XVIMAGESINK, GstXvImageSinkClass))
       
    53 #define GST_IS_XVIMAGESINK(obj) \
       
    54   (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_XVIMAGESINK))
       
    55 #define GST_IS_XVIMAGESINK_CLASS(klass) \
       
    56   (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_XVIMAGESINK))
       
    57 
       
    58 typedef struct _GstXContext GstXContext;
       
    59 typedef struct _GstXWindow GstXWindow;
       
    60 typedef struct _GstXvImageFormat GstXvImageFormat;
       
    61 typedef struct _GstXvImageBuffer GstXvImageBuffer;
       
    62 typedef struct _GstXvImageBufferClass GstXvImageBufferClass;
       
    63 
       
    64 typedef struct _GstXvImageSink GstXvImageSink;
       
    65 typedef struct _GstXvImageSinkClass GstXvImageSinkClass;
       
    66 
       
    67 /**
       
    68  * GstXContext:
       
    69  * @disp: the X11 Display of this context
       
    70  * @screen: the default Screen of Display @disp
       
    71  * @screen_num: the Screen number of @screen
       
    72  * @visual: the default Visual of Screen @screen
       
    73  * @root: the root Window of Display @disp
       
    74  * @white: the value of a white pixel on Screen @screen
       
    75  * @black: the value of a black pixel on Screen @screen
       
    76  * @depth: the color depth of Display @disp
       
    77  * @bpp: the number of bits per pixel on Display @disp
       
    78  * @endianness: the endianness of image bytes on Display @disp
       
    79  * @width: the width in pixels of Display @disp
       
    80  * @height: the height in pixels of Display @disp
       
    81  * @widthmm: the width in millimeters of Display @disp
       
    82  * @heightmm: the height in millimeters of Display @disp
       
    83  * @par: the pixel aspect ratio calculated from @width, @widthmm and @height,
       
    84  * @heightmm ratio
       
    85  * @use_xshm: used to known wether of not XShm extension is usable or not even
       
    86  * if the Extension is present
       
    87  * @xv_port_id: the XVideo port ID
       
    88  * @im_format: used to store at least a valid format for XShm calls checks
       
    89  * @formats_list: list of supported image formats on @xv_port_id
       
    90  * @channels_list: list of #GstColorBalanceChannels
       
    91  * @caps: the #GstCaps that Display @disp can accept
       
    92  *
       
    93  * Structure used to store various informations collected/calculated for a
       
    94  * Display.
       
    95  */
       
    96 struct _GstXContext {
       
    97   Display *disp;
       
    98 
       
    99   Screen *screen;
       
   100   gint screen_num;
       
   101 
       
   102   Visual *visual;
       
   103 
       
   104   Window root;
       
   105 
       
   106   gulong white, black;
       
   107 
       
   108   gint depth;
       
   109   gint bpp;
       
   110   gint endianness;
       
   111 
       
   112   gint width, height;
       
   113   gint widthmm, heightmm;
       
   114   GValue *par;                  /* calculated pixel aspect ratio */
       
   115 
       
   116   gboolean use_xshm;
       
   117 
       
   118   XvPortID xv_port_id;
       
   119   guint nb_adaptors;
       
   120   gchar ** adaptors;
       
   121   gint im_format;
       
   122 
       
   123   GList *formats_list;
       
   124   GList *channels_list;
       
   125 
       
   126   GstCaps *caps;
       
   127 
       
   128   /* Optimisation storage for buffer_alloc return */
       
   129   GstCaps *last_caps;
       
   130   gint last_format;
       
   131 };
       
   132 
       
   133 /**
       
   134  * GstXWindow:
       
   135  * @win: the Window ID of this X11 window
       
   136  * @width: the width in pixels of Window @win
       
   137  * @height: the height in pixels of Window @win
       
   138  * @internal: used to remember if Window @win was created internally or passed
       
   139  * through the #GstXOverlay interface
       
   140  * @gc: the Graphical Context of Window @win
       
   141  *
       
   142  * Structure used to store informations about a Window.
       
   143  */
       
   144 struct _GstXWindow {
       
   145   Window win;
       
   146   gint width, height;
       
   147   gboolean internal;
       
   148   GC gc;
       
   149 };
       
   150 
       
   151 /**
       
   152  * GstXvImageFormat:
       
   153  * @format: the image format
       
   154  * @caps: generated #GstCaps for this image format
       
   155  *
       
   156  * Structure storing image format to #GstCaps association.
       
   157  */
       
   158 struct _GstXvImageFormat {
       
   159   gint format;
       
   160   GstCaps *caps;
       
   161 };
       
   162 
       
   163 /**
       
   164  * GstXImageBuffer:
       
   165  * @xvimagesink: a reference to our #GstXvImageSink
       
   166  * @xvimage: the XvImage of this buffer
       
   167  * @width: the width in pixels of XvImage @xvimage
       
   168  * @height: the height in pixels of XvImage @xvimage
       
   169  * @im_format: the image format of XvImage @xvimage
       
   170  * @size: the size in bytes of XvImage @xvimage
       
   171  *
       
   172  * Subclass of #GstBuffer containing additional information about an XvImage.
       
   173  */
       
   174 struct _GstXvImageBuffer {
       
   175   GstBuffer   buffer;
       
   176 
       
   177   /* Reference to the xvimagesink we belong to */
       
   178   GstXvImageSink *xvimagesink;
       
   179 
       
   180   XvImage *xvimage;
       
   181 
       
   182 #ifdef HAVE_XSHM
       
   183   XShmSegmentInfo SHMInfo;
       
   184 #endif /* HAVE_XSHM */
       
   185 
       
   186   gint width, height, im_format;
       
   187   size_t size;
       
   188 };
       
   189 
       
   190 /**
       
   191  * GstXvImageSink:
       
   192  * @display_name: the name of the Display we want to render to
       
   193  * @xcontext: our instance's #GstXContext
       
   194  * @xwindow: the #GstXWindow we are rendering to
       
   195  * @xvimage: internal #GstXvImage used to store incoming buffers and render when
       
   196  * not using the buffer_alloc optimization mechanism
       
   197  * @cur_image: a reference to the last #GstXvImage that was put to @xwindow. It
       
   198  * is used when Expose events are received to redraw the latest video frame
       
   199  * @event_thread: a thread listening for events on @xwindow and handling them
       
   200  * @running: used to inform @event_thread if it should run/shutdown
       
   201  * @fps_n: the framerate fraction numerator
       
   202  * @fps_d: the framerate fraction denominator
       
   203  * @x_lock: used to protect X calls as we are not using the XLib in threaded
       
   204  * mode
       
   205  * @flow_lock: used to protect data flow routines from external calls such as
       
   206  * events from @event_thread or methods from the #GstXOverlay interface
       
   207  * @par: used to override calculated pixel aspect ratio from @xcontext
       
   208  * @pool_lock: used to protect the buffer pool
       
   209  * @image_pool: a list of #GstXvImageBuffer that could be reused at next buffer
       
   210  * allocation call
       
   211  * @synchronous: used to store if XSynchronous should be used or not (for
       
   212  * debugging purpose only)
       
   213  * @keep_aspect: used to remember if reverse negotiation scaling should respect
       
   214  * aspect ratio
       
   215  * @handle_events: used to know if we should handle select XEvents or not
       
   216  * @brightness: used to store the user settings for color balance brightness
       
   217  * @contrast: used to store the user settings for color balance contrast
       
   218  * @hue: used to store the user settings for color balance hue
       
   219  * @saturation: used to store the user settings for color balance saturation
       
   220  * @cb_changed: used to store if the color balance settings where changed
       
   221  * @video_width: the width of incoming video frames in pixels
       
   222  * @video_height: the height of incoming video frames in pixels
       
   223  *
       
   224  * The #GstXvImageSink data structure.
       
   225  */
       
   226 struct _GstXvImageSink {
       
   227   /* Our element stuff */
       
   228   GstVideoSink videosink;
       
   229 
       
   230   char *display_name;
       
   231   guint adaptor_no;
       
   232 
       
   233   GstXContext *xcontext;
       
   234   GstXWindow *xwindow;
       
   235   GstXvImageBuffer *xvimage;
       
   236   GstXvImageBuffer *cur_image;
       
   237 
       
   238   GThread *event_thread;
       
   239   gboolean running;
       
   240 
       
   241   gint fps_n;
       
   242   gint fps_d;
       
   243 
       
   244   GMutex *x_lock;
       
   245   GMutex *flow_lock;
       
   246 
       
   247   /* object-set pixel aspect ratio */
       
   248   GValue *par;
       
   249 
       
   250   GMutex *pool_lock;
       
   251   GSList *image_pool;
       
   252 
       
   253   gboolean synchronous;
       
   254   gboolean double_buffer;
       
   255   gboolean keep_aspect;
       
   256   gboolean draw_border;
       
   257   gboolean handle_events;
       
   258   gboolean handle_expose;
       
   259 
       
   260   gint brightness;
       
   261   gint contrast;
       
   262   gint hue;
       
   263   gint saturation;
       
   264   gboolean cb_changed;
       
   265 
       
   266   guint video_width, video_height;     /* size of incoming video;
       
   267                                         * used as the size for XvImage */
       
   268 };
       
   269 
       
   270 struct _GstXvImageSinkClass {
       
   271   GstVideoSinkClass parent_class;
       
   272 };
       
   273 
       
   274 GType gst_xvimagesink_get_type(void);
       
   275 
       
   276 G_END_DECLS
       
   277 
       
   278 #endif /* __GST_XVIMAGESINK_H__ */