1 /*****************************************************************************
2 * vout_dummy.c: Dummy video output display method for testing purposes
3 *****************************************************************************
4 * Copyright (C) 2000 VideoLAN
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
21 *****************************************************************************/
23 /*****************************************************************************
25 *****************************************************************************/
28 #include <errno.h> /* ENOMEM */
29 #include <stdlib.h> /* free() */
30 #include <string.h> /* strerror() */
39 #include "video_output.h"
45 #define BITS_PER_PLANE 16
46 #define BYTES_PER_PIXEL 2
48 /*****************************************************************************
49 * vout_sys_t: dummy video output method descriptor
50 *****************************************************************************
51 * This structure is part of the video output thread descriptor.
52 * It describes the dummy specific properties of an output thread.
53 *****************************************************************************/
54 typedef struct vout_sys_s
56 /* Dummy video memory */
57 byte_t * p_video; /* base adress */
58 size_t i_page_size; /* page size */
62 /*****************************************************************************
64 *****************************************************************************/
65 static int DummyOpenDisplay ( vout_thread_t *p_vout );
66 static void DummyCloseDisplay ( vout_thread_t *p_vout );
68 /*****************************************************************************
69 * vout_DummyCreate: allocates dummy video thread output method
70 *****************************************************************************
71 * This function allocates and initializes a dummy vout method.
72 *****************************************************************************/
73 int vout_DummyCreate( vout_thread_t *p_vout, char *psz_display,
74 int i_root_window, void *p_data )
76 /* Allocate structure */
77 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
78 if( p_vout->p_sys == NULL )
80 intf_ErrMsg("error: %s\n", strerror(ENOMEM) );
84 /* Open and initialize device */
85 if( DummyOpenDisplay( p_vout ) )
87 intf_ErrMsg("vout error: can't open display\n");
88 free( p_vout->p_sys );
95 /*****************************************************************************
96 * vout_DummyInit: initialize dummy video thread output method
97 *****************************************************************************/
98 int vout_DummyInit( vout_thread_t *p_vout )
103 /*****************************************************************************
104 * vout_DummyEnd: terminate dummy video thread output method
105 *****************************************************************************/
106 void vout_DummyEnd( vout_thread_t *p_vout )
111 /*****************************************************************************
112 * vout_DummyDestroy: destroy dummy video thread output method
113 *****************************************************************************
114 * Terminate an output method created by DummyCreateOutputMethod
115 *****************************************************************************/
116 void vout_DummyDestroy( vout_thread_t *p_vout )
118 DummyCloseDisplay( p_vout );
119 free( p_vout->p_sys );
122 /*****************************************************************************
123 * vout_DummyManage: handle dummy events
124 *****************************************************************************
125 * This function should be called regularly by video output thread. It manages
126 * console events. It returns a non null value on error.
127 *****************************************************************************/
128 int vout_DummyManage( vout_thread_t *p_vout )
133 /*****************************************************************************
134 * vout_DummyDisplay: displays previously rendered output
135 *****************************************************************************
136 * This function send the currently rendered image to dummy image, waits until
137 * it is displayed and switch the two rendering buffers, preparing next frame.
138 *****************************************************************************/
139 void vout_DummyDisplay( vout_thread_t *p_vout )
144 /* following functions are local */
146 /*****************************************************************************
147 * DummyOpenDisplay: open and initialize dummy device
148 *****************************************************************************
149 * XXX?? The framebuffer mode is only provided as a fast and efficient way to
150 * display video, providing the card is configured and the mode ok. It is
151 * not portable, and is not supposed to work with many cards. Use at your
153 *****************************************************************************/
155 static int DummyOpenDisplay( vout_thread_t *p_vout )
157 p_vout->i_width = WIDTH;
158 p_vout->i_height = HEIGHT;
159 p_vout->i_screen_depth = BITS_PER_PLANE;
160 p_vout->i_bytes_per_pixel = BYTES_PER_PIXEL;
161 p_vout->i_bytes_per_line = WIDTH * BYTES_PER_PIXEL;
163 p_vout->p_sys->i_page_size = WIDTH * HEIGHT * BYTES_PER_PIXEL;
165 /* Map two framebuffers a the very beginning of the fb */
166 p_vout->p_sys->p_video = malloc( p_vout->p_sys->i_page_size * 2 );
167 if( (int)p_vout->p_sys->p_video == -1 )
169 intf_ErrMsg("vout error: can't map video memory (%s)\n", strerror(errno) );
173 /* Set and initialize buffers */
174 vout_SetBuffers( p_vout, p_vout->p_sys->p_video,
175 p_vout->p_sys->p_video + p_vout->p_sys->i_page_size );
179 /*****************************************************************************
180 * DummyCloseDisplay: close and reset dummy device
181 *****************************************************************************
182 * Returns all resources allocated by DummyOpenDisplay and restore the original
183 * state of the device.
184 *****************************************************************************/
185 static void DummyCloseDisplay( vout_thread_t *p_vout )
187 free( p_vout->p_sys->p_video );