]> git.sesse.net Git - vlc/blob - plugins/dummy/vout_dummy.c
c0b77eda89ec33fe20787e0d53a6317af704da01
[vlc] / plugins / dummy / vout_dummy.c
1 /*****************************************************************************
2  * vout_dummy.c: Dummy video output display method for testing purposes
3  *****************************************************************************
4  * Copyright (C) 2000 VideoLAN
5  *
6  * Authors:
7  *
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.
12  * 
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.
17  *
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  *****************************************************************************/
22
23 /*****************************************************************************
24  * Preamble
25  *****************************************************************************/
26 #include "defs.h"
27
28 #include <errno.h>                                                 /* ENOMEM */
29 #include <stdlib.h>                                                /* free() */
30 #include <string.h>                                            /* strerror() */
31
32 #include "config.h"
33 #include "common.h"
34 #include "threads.h"
35 #include "mtime.h"
36 #include "plugins.h"
37
38 #include "video.h"
39 #include "video_output.h"
40
41 #include "intf_msg.h"
42
43 #define WIDTH 128
44 #define HEIGHT 64
45 #define BITS_PER_PLANE 16
46 #define BYTES_PER_PIXEL 2
47
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
55 {
56     /* Dummy video memory */
57     byte_t *                    p_video;                      /* base adress */
58     size_t                      i_page_size;                    /* page size */
59
60 } vout_sys_t;
61
62 /*****************************************************************************
63  * Local prototypes
64  *****************************************************************************/
65 static int     DummyOpenDisplay   ( vout_thread_t *p_vout );
66 static void    DummyCloseDisplay  ( vout_thread_t *p_vout );
67
68 /*****************************************************************************
69  * vout_SysCreate: allocates dummy video thread output method
70  *****************************************************************************
71  * This function allocates and initializes a dummy vout method.
72  *****************************************************************************/
73 int vout_SysCreate( vout_thread_t *p_vout, char *psz_display,
74                     int i_root_window, void *p_data )
75 {
76     /* Allocate structure */
77     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
78     if( p_vout->p_sys == NULL )
79     {
80         intf_ErrMsg("error: %s\n", strerror(ENOMEM) );
81         return( 1 );
82     }
83
84     /* Open and initialize device */
85     if( DummyOpenDisplay( p_vout ) )
86     {
87         intf_ErrMsg("vout error: can't open display\n");
88         free( p_vout->p_sys );
89         return( 1 );
90     }
91
92     return( 0 );
93 }
94
95 /*****************************************************************************
96  * vout_SysInit: initialize dummy video thread output method
97  *****************************************************************************/
98 int vout_SysInit( vout_thread_t *p_vout )
99 {
100     return( 0 );
101 }
102
103 /*****************************************************************************
104  * vout_SysEnd: terminate dummy video thread output method
105  *****************************************************************************/
106 void vout_SysEnd( vout_thread_t *p_vout )
107 {
108     ;
109 }
110
111 /*****************************************************************************
112  * vout_SysDestroy: destroy dummy video thread output method
113  *****************************************************************************
114  * Terminate an output method created by DummyCreateOutputMethod
115  *****************************************************************************/
116 void vout_SysDestroy( vout_thread_t *p_vout )
117 {
118     DummyCloseDisplay( p_vout );
119     free( p_vout->p_sys );
120 }
121
122 /*****************************************************************************
123  * vout_SysManage: 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_SysManage( vout_thread_t *p_vout )
129 {
130     return( 0 );
131 }
132
133 /*****************************************************************************
134  * vout_SysDisplay: 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_SysDisplay( vout_thread_t *p_vout )
140 {
141     ;
142 }
143
144 /* following functions are local */
145
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
152  * own risk !
153  *****************************************************************************/
154
155 static int DummyOpenDisplay( vout_thread_t *p_vout )
156 {
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;
162
163     p_vout->p_sys->i_page_size = WIDTH * HEIGHT * BYTES_PER_PIXEL;
164
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 )
168     {
169         intf_ErrMsg("vout error: can't map video memory (%s)\n", strerror(errno) );
170         return( 1 );
171     }
172
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 );
176     return( 0 );
177 }
178
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 )
186 {
187     free( p_vout->p_sys->p_video );
188 }
189