]> git.sesse.net Git - vlc/blob - plugins/dummy/vout_dummy.c
d76e015edfc4d274eab9c9342c79e07fe40054ef
[vlc] / plugins / dummy / vout_dummy.c
1 /*****************************************************************************
2  * vout_dummy.c: Dummy video output display method for testing purposes
3  *****************************************************************************
4  * Copyright (C) 2000, 2001 VideoLAN
5  *
6  * Authors: Samuel Hocevar <sam@zoy.org>
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 "tests.h"
37 #include "modules.h"
38
39 #include "video.h"
40 #include "video_output.h"
41
42 #include "intf_msg.h"
43
44 #define DUMMY_WIDTH 16
45 #define DUMMY_HEIGHT 16
46 #define DUMMY_BITS_PER_PLANE 16
47 #define DUMMY_BYTES_PER_PIXEL 2
48
49 /*****************************************************************************
50  * vout_sys_t: dummy video output method descriptor
51  *****************************************************************************
52  * This structure is part of the video output thread descriptor.
53  * It describes the dummy specific properties of an output thread.
54  *****************************************************************************/
55 typedef struct vout_sys_s
56 {
57     /* Dummy video memory */
58     byte_t *                    p_video;                      /* base adress */
59     size_t                      i_page_size;                    /* page size */
60
61 } vout_sys_t;
62
63 /*****************************************************************************
64  * Local prototypes
65  *****************************************************************************/
66 static int  vout_Probe     ( probedata_t *p_data );
67 static int  vout_Create    ( struct vout_thread_s * );
68 static int  vout_Init      ( struct vout_thread_s * );
69 static void vout_End       ( struct vout_thread_s * );
70 static void vout_Destroy   ( struct vout_thread_s * );
71 static int  vout_Manage    ( struct vout_thread_s * );
72 static void vout_Display   ( struct vout_thread_s * );
73
74 /*****************************************************************************
75  * Functions exported as capabilities. They are declared as static so that
76  * we don't pollute the namespace too much.
77  *****************************************************************************/
78 void vout_getfunctions( function_list_t * p_function_list )
79 {
80     p_function_list->pf_probe = vout_Probe;
81     p_function_list->functions.vout.pf_create     = vout_Create;
82     p_function_list->functions.vout.pf_init       = vout_Init;
83     p_function_list->functions.vout.pf_end        = vout_End;
84     p_function_list->functions.vout.pf_destroy    = vout_Destroy;
85     p_function_list->functions.vout.pf_manage     = vout_Manage;
86     p_function_list->functions.vout.pf_display    = vout_Display;
87     p_function_list->functions.vout.pf_setpalette = NULL;
88 }
89
90 /*****************************************************************************
91  * intf_Probe: return a score
92  *****************************************************************************/
93 static int vout_Probe( probedata_t *p_data )
94 {
95     if( TestMethod( VOUT_METHOD_VAR, "dummy" ) )
96     {
97         return( 999 );
98     }
99
100     return( 1 );
101 }
102
103 /*****************************************************************************
104  * vout_Create: allocates dummy video thread output method
105  *****************************************************************************
106  * This function allocates and initializes a dummy vout method.
107  *****************************************************************************/
108 static int vout_Create( vout_thread_t *p_vout )
109 {
110     /* Allocate structure */
111     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
112     if( p_vout->p_sys == NULL )
113     {
114         intf_ErrMsg("error: %s", strerror(ENOMEM) );
115         return( 1 );
116     }
117
118     p_vout->i_width            = DUMMY_WIDTH;
119     p_vout->i_height           = DUMMY_HEIGHT;
120     p_vout->i_screen_depth     = DUMMY_BITS_PER_PLANE;
121     p_vout->i_bytes_per_pixel  = DUMMY_BYTES_PER_PIXEL;
122     p_vout->i_bytes_per_line   = DUMMY_WIDTH * DUMMY_BYTES_PER_PIXEL;
123
124     p_vout->p_sys->i_page_size = DUMMY_WIDTH * DUMMY_HEIGHT
125                                   * DUMMY_BYTES_PER_PIXEL;
126
127     /* Map two framebuffers a the very beginning of the fb */
128     p_vout->p_sys->p_video = malloc( 2 * p_vout->p_sys->i_page_size );
129     if( p_vout->p_sys->p_video == NULL )
130     {
131         intf_ErrMsg( "vout error: can't map video memory (%s)",
132                      strerror(errno) );
133         free( p_vout->p_sys );
134         return( 1 );
135     }
136
137     /* Set and initialize buffers */
138     vout_SetBuffers( p_vout, p_vout->p_sys->p_video,
139                      p_vout->p_sys->p_video + p_vout->p_sys->i_page_size );
140
141     return( 0 );
142 }
143
144 /*****************************************************************************
145  * vout_Init: initialize dummy video thread output method
146  *****************************************************************************/
147 static int vout_Init( vout_thread_t *p_vout )
148 {
149     return( 0 );
150 }
151
152 /*****************************************************************************
153  * vout_End: terminate dummy video thread output method
154  *****************************************************************************/
155 static void vout_End( vout_thread_t *p_vout )
156 {
157     ;
158 }
159
160 /*****************************************************************************
161  * vout_Destroy: destroy dummy video thread output method
162  *****************************************************************************
163  * Terminate an output method created by DummyCreateOutputMethod
164  *****************************************************************************/
165 static void vout_Destroy( vout_thread_t *p_vout )
166 {
167     free( p_vout->p_sys->p_video );
168     free( p_vout->p_sys );
169 }
170
171 /*****************************************************************************
172  * vout_Manage: handle dummy events
173  *****************************************************************************
174  * This function should be called regularly by video output thread. It manages
175  * console events. It returns a non null value on error.
176  *****************************************************************************/
177 static int vout_Manage( vout_thread_t *p_vout )
178 {
179     return( 0 );
180 }
181
182 /*****************************************************************************
183  * vout_Display: displays previously rendered output
184  *****************************************************************************
185  * This function send the currently rendered image to dummy image, waits until
186  * it is displayed and switch the two rendering buffers, preparing next frame.
187  *****************************************************************************/
188 static void vout_Display( vout_thread_t *p_vout )
189 {
190     ;
191 }
192