1 /*
2  *  pv.h
3  *
4  *  Copyright (C) Thomas Oestreich - October 2002
5  *
6  *  based on "display.c
7  *     Copyright (C) Charles 'Buck' Krasic - April 2000
8  *     Copyright (C) Erik Walthinsen - April 2000
9  *  part of libdv, a free DV (IEC 61834/SMPTE 314M) codec.
10  *
11  *  This file is part of transcode, a video stream processing tool
12  *
13  *  transcode is free software; you can redistribute it and/or modify
14  *  it under the terms of the GNU General Public License as published by
15  *  the Free Software Foundation; either version 2, or (at your option)
16  *  any later version.
17  *
18  *  transcode is distributed in the hope that it will be useful,
19  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  *  GNU General Public License for more details.
22  *
23  *  You should have received a copy of the GNU General Public License
24  *  along with GNU Make; see the file COPYING.  If not, write to
25  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
26  *
27  */
28 
29 #ifndef PV_H
30 #define PV_H
31 
32 #include "transcode.h"
33 #include "libtc/libtc.h"
34 
35 #include <sys/types.h>
36 #include <sys/mman.h>
37 
38 #include <X11/Xlib.h>
39 #include <X11/Xutil.h>
40 #include <X11/keysym.h>
41 #include <X11/extensions/XShm.h>
42 #include <X11/extensions/Xvlib.h>
43 #include <X11/Xatom.h>
44 
45 #define DV_FOURCC_I420  0x30323449	/* 4:2:0 Planar mode: Y + U + V  (3 planes) */
46 #define DV_FOURCC_YV12  0x32315659	/* 4:2:0 Planar mode: Y + V + U  (3 planes) */
47 #define DV_FOURCC_YUY2  0x32595559	/* 4:2:2 Packed mode: Y0+U0+Y1+V0 (1 plane) */
48 #define DV_FOURCC_UYVY  0x59565955	/* 4:2:2 Packed mode: U0+Y0+V0+Y1 (1 plane) */
49 
50 #define DV_DISPLAY_OPT_METHOD   0
51 #define DV_DISPLAY_OPT_ASPECT	1
52 #define DV_DISPLAY_OPT_SIZE	2
53 #define DV_DISPLAY_OPT_CALLBACK 3
54 #define DV_DISPLAY_OPT_XV_PORT  4
55 #define DV_DISPLAY_NUM_OPTS     5
56 
57 typedef enum dv_dpy_lib_e {
58   e_dv_dpy_Xv,
59   e_dv_dpy_SDL,
60   e_dv_dpy_gtk,
61   e_dv_dpy_XShm,
62 } dv_dpy_lib_t;
63 
64 
65 typedef enum color_space_e {
66   e_dv_color_yuv,
67   e_dv_color_rgb,
68   e_dv_color_bgr0,
69 } dv_color_space_t;
70 
71 
72 typedef struct {
73   dv_color_space_t color_space;
74   int		    width, height;
75   char             *pixels[3];
76   int              pitches[3];
77   int              dontdraw;
78 
79   /* Begin Private */
80   dv_dpy_lib_t       lib;
81   uint32_t           len;
82   uint32_t           format;   /* fourcc code for YUV modes */
83 
84   /* -----------------------------------------------------------
85    * Xv specific members
86    */
87   Display          *dpy;
88   Screen           *scn;
89   Window            rwin, win;
90   int		    dwidth, dheight,
91 		    swidth, sheight,
92 		    lwidth, lheight,
93 		    lxoff, lyoff,
94 		    flags,
95 		    pic_format;
96   GC                gc;
97   Atom              wm_delete_window_atom;
98   XEvent            event;
99   XvPortID	    port;
100   XShmSegmentInfo   shminfo;
101   XvImage          *xv_image;
102 
103   int 			arg_display,
104 			arg_aspect_val,
105 			arg_size_val,
106 			arg_xv_port;
107   char			*arg_aspect_string;
108   char                  full_screen;
109 } xv_display_t;
110 
111 /* Book-keeping for mmap */
112 typedef struct dv_mmap_region_s {
113   void   *map_start;  /* Start of mapped region (page aligned) */
114   size_t  map_length; /* Size of mapped region */
115   uint8_t *data_start; /* Data we asked for */
116 } xv_mmap_region_t;
117 
118 typedef struct {
119 
120   xv_display_t    *display;
121   xv_mmap_region_t mmap_region;
122 
123   struct stat     statbuf;
124   struct timeval  tv[3];
125   int             arg_disable_audio;
126   int             arg_disable_video;
127   int             arg_num_frames;
128   int             arg_dump_frames;
129 } xv_player_t;
130 
131 #ifdef __cplusplus
132 extern "C" {
133 #endif
134 
135   extern xv_player_t *xv_player_new(void);
136   extern xv_display_t *xv_display_new(void);
137   extern int xv_display_init(xv_display_t *dpy,
138 			     int *argc, char ***argv,
139 			     int width, int height,
140 			     char *w_name, char *i_name, int yuv422);
141 
142   extern void xv_display_show(xv_display_t *dv_dpy);
143   extern void xv_display_event(xv_display_t *dv_dpy);
144   extern void xv_display_exit(xv_display_t *dv_dpy);
145   extern void xv_display_check_format(xv_display_t *dv_dpy, int pic_format);
146 
147   void preview_filter(void);
148   int preview_filter_buffer(int frames_needed);
149   void dec_preview_delay(void);
150   void inc_preview_delay(void);
151   void preview_cache_undo(void);
152   void preview_toggle_skip(void);
153   void preview_cache_draw(int d);
154   void preview_cache_submit(char *buf, int n, int flag);
155   int preview_cache_init(void);
156   int preview_grab_jpeg(void);
157 
158   char **char2bmp(char c);
159   void bmp2img(char *img, char **c, int width, int height,
160 	       int char_width, int char_height, int posx, int posy, int codec);
161   void str2img(char *img, char *c, int width,  int height,
162 	       int char_width, int char_height, int posx, int posy, int codec);
163 
164  extern int cache_long_skip;
165  extern int cache_short_skip;
166 
167  int DoSelection(XButtonEvent *ev, int *xanf, int *yanf, int *xend, int *yend);
168 
169 #ifdef __cplusplus
170 }
171 #endif
172 
173 #endif // PV_H
174 
175