xref: /OK3568_Linux_fs/external/gstreamer-rockchip/gst/rkximage/ximagesink.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 #ifndef __GST_X_IMAGE_SINK_H__
2 #define __GST_X_IMAGE_SINK_H__
3 
4 #include <gst/video/gstvideosink.h>
5 
6 #ifdef HAVE_XSHM
7 #include <sys/types.h>
8 #include <sys/ipc.h>
9 #include <sys/shm.h>
10 #endif /* HAVE_XSHM */
11 
12 #include <X11/Xlib.h>
13 #include <X11/Xutil.h>
14 
15 #include <string.h>
16 #include <math.h>
17 
18 /* Helper functions */
19 #include <gst/video/video.h>
20 
21 G_BEGIN_DECLS
22 #define GST_TYPE_X_IMAGE_SINK \
23   (gst_x_image_sink_get_type())
24 #define GST_X_IMAGE_SINK(obj) \
25   (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_X_IMAGE_SINK, GstRkXImageSink))
26 #define GST_X_IMAGE_SINK_CLASS(klass) \
27   (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_X_IMAGE_SINK, GstRkXImageSinkClass))
28 #define GST_IS_X_IMAGE_SINK(obj) \
29   (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_X_IMAGE_SINK))
30 #define GST_IS_X_IMAGE_SINK_CLASS(klass) \
31   (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_X_IMAGE_SINK))
32 
33 typedef struct _GstXContext GstXContext;
34 typedef struct _GstXWindow GstXWindow;
35 
36 typedef struct _GstRkXImageSink GstRkXImageSink;
37 typedef struct _GstRkXImageSinkClass GstRkXImageSinkClass;
38 
39 /*
40  * GstXContext:
41  * @disp: the X11 Display of this context
42  * @screen: the default Screen of Display @disp
43  * @screen_num: the Screen number of @screen
44  * @visual: the default Visual of Screen @screen
45  * @root: the root Window of Display @disp
46  * @white: the value of a white pixel on Screen @screen
47  * @black: the value of a black pixel on Screen @screen
48  * @depth: the color depth of Display @disp
49  * @bpp: the number of bits per pixel on Display @disp
50  * @endianness: the endianness of image bytes on Display @disp
51  * @width: the width in pixels of Display @disp
52  * @height: the height in pixels of Display @disp
53  * @widthmm: the width in millimeters of Display @disp
54  * @heightmm: the height in millimeters of Display @disp
55  *
56  * Structure used to store various informations collected/calculated for a
57  * Display.
58  */
59 struct _GstXContext
60 {
61   Display *disp;
62 
63   Screen *screen;
64   gint screen_num;
65 
66   Visual *visual;
67 
68   Window root;
69 
70   gulong white, black;
71 
72   gint depth;
73   gint bpp;
74 
75   gint width, height;
76   gint widthmm, heightmm;
77 };
78 
79 /*
80  * GstXWindow:
81  * @win: the Window ID of this X11 window
82  * @width: the width in pixels of Window @win
83  * @height: the height in pixels of Window @win
84  * @internal: used to remember if Window @win was created internally or passed
85  * through the #GstVideoOverlay interface
86  * @gc: the Graphical Context of Window @win
87  *
88  * Structure used to store informations about a Window.
89  */
90 struct _GstXWindow
91 {
92   Window win;
93   gint width, height;
94   gboolean internal;
95   GC gc;
96 };
97 
98 /**
99  * GstRkXImageSink:
100  * @display_name: the name of the Display we want to render to
101  * @xcontext: our instance's #GstXContext
102  * @xwindow: the #GstXWindow we are rendering to
103  * @ximage: internal #GstXImage used to store incoming buffers and render when
104  * not using the buffer_alloc optimization mechanism
105  * @cur_image: a reference to the last #GstXImage that was put to @xwindow. It
106  * is used when Expose events are received to redraw the latest video frame
107  * @event_thread: a thread listening for events on @xwindow and handling them
108  * @running: used to inform @event_thread if it should run/shutdown
109  * @fps_n: the framerate fraction numerator
110  * @fps_d: the framerate fraction denominator
111  * @x_lock: used to protect X calls as we are not using the XLib in threaded
112  * mode
113  * @flow_lock: used to protect data flow routines from external calls such as
114  * events from @event_thread or methods from the #GstVideoOverlay interface
115  * @par: used to override calculated pixel aspect ratio from @xcontext
116  * @pool_lock: used to protect the buffer pool
117  * @buffer_pool: a list of #GstXImageBuffer that could be reused at next buffer
118  * allocation call
119  * @synchronous: used to store if XSynchronous should be used or not (for
120  * debugging purpose only)
121  * @handle_events: used to know if we should handle select XEvents or not
122  *
123  * The #GstRkXImageSink data structure.
124  */
125 struct _GstRkXImageSink
126 {
127   /* Our element stuff */
128   GstVideoSink videosink;
129 
130   gint fd;
131   gint conn_id;
132   gint crtc_id;
133   gint plane_id;
134   guint pipe;
135 
136   guint16 hdisplay, vdisplay;
137   guint32 buffer_id;
138 
139   /* capabilities */
140   gboolean has_prime_import;
141   gboolean has_prime_export;
142   gboolean has_async_page_flip;
143 
144   char *display_name;
145 
146   GstXContext *xcontext;
147   GstXWindow *xwindow;
148   GstBuffer *cur_image;
149   GstVideoRectangle clip_rect;
150 
151   GThread *event_thread;
152   gboolean running;
153 
154   /* Framerate numerator and denominator */
155   gint fps_n;
156   gint fps_d;
157   gint par_n;
158   gint par_d;
159   gboolean keep_aspect;
160 
161   GMutex x_lock;
162   GMutex flow_lock;
163 
164   gboolean synchronous;
165   gboolean handle_events;
166   gboolean handle_expose;
167   gboolean draw_border;
168 
169   /* stream metadata */
170   gchar *media_title;
171 
172   GstVideoInfo vinfo;
173   GstCaps *allowed_caps;
174   GstBufferPool *pool;
175   GstAllocator *allocator;
176   GstBuffer *last_buffer;
177 
178   gchar *devname;
179   gchar *bus_id;
180 
181   guint32 mm_width, mm_height;
182 
183   GstPoll *poll;
184   GstPollFD pollfd;
185 
186   guint32 last_fb_id;
187   GstVideoRectangle save_rect;
188   gboolean paused;
189 };
190 
191 struct _GstRkXImageSinkClass
192 {
193   GstVideoSinkClass parent_class;
194 };
195 
196 GType gst_x_image_sink_get_type (void);
197 
198 G_END_DECLS
199 #endif /* __GST_X_IMAGE_SINK_H__ */
200