]> git.sesse.net Git - vlc/blob - plugins/idct/idctmmx.c
. fixed the bug-that-made-the-vlc-segfault-on-exit, which means that
[vlc] / plugins / idct / idctmmx.c
1 /*****************************************************************************
2  * idctmmx.c : MMX IDCT module
3  *****************************************************************************
4  * Copyright (C) 1999, 2000 VideoLAN
5  * $Id: idctmmx.c,v 1.2 2001/01/15 06:18:23 sam Exp $
6  *
7  * Authors: GaĆ«l Hendryckx <jimmy@via.ecp.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  * 
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 #define MODULE_NAME idctmmx
25
26 /*****************************************************************************
27  * Preamble
28  *****************************************************************************/
29 #include "defs.h"
30
31 #include <stdlib.h>
32
33 #include "config.h"
34 #include "common.h"
35 #include "threads.h"
36 #include "mtime.h"
37
38 #include "video.h"
39 #include "video_output.h"
40
41 #include "video_decoder.h"
42
43 #include "modules.h"
44 #include "modules_inner.h"
45
46 #include "idct.h"
47
48 /*****************************************************************************
49  * Local prototypes.
50  *****************************************************************************/
51 static void idct_getfunctions( function_list_t * p_function_list );
52
53 static int  idct_Probe      ( probedata_t *p_data );
54 static void vdec_InitIDCT   ( vdec_thread_t * p_vdec);
55        void vdec_SparseIDCT ( vdec_thread_t * p_vdec, dctelem_t * p_block,
56                               int i_sparse_pos);
57        void vdec_IDCT       ( vdec_thread_t * p_vdec, dctelem_t * p_block,
58                               int i_idontcare );
59
60
61 /*****************************************************************************
62  * Build configuration tree.
63  *****************************************************************************/
64 MODULE_CONFIG_START
65 ADD_WINDOW( "Configuration for MMX IDCT module" )
66     ADD_COMMENT( "Ha, ha -- nothing to configure yet" )
67 MODULE_CONFIG_END
68
69 /*****************************************************************************
70  * InitModule: get the module structure and configuration.
71  *****************************************************************************
72  * We have to fill psz_name, psz_longname and psz_version. These variables
73  * will be strdup()ed later by the main application because the module can
74  * be unloaded later to save memory, and we want to be able to access this
75  * data even after the module has been unloaded.
76  *****************************************************************************/
77 int InitModule( module_t * p_module )
78 {
79     p_module->psz_name = MODULE_STRING;
80     p_module->psz_longname = "MMX IDCT module";
81     p_module->psz_version = VERSION;
82
83     p_module->i_capabilities = MODULE_CAPABILITY_NULL
84                                 | MODULE_CAPABILITY_IDCT;
85
86     return( 0 );
87 }
88
89 /*****************************************************************************
90  * ActivateModule: set the module to an usable state.
91  *****************************************************************************
92  * This function fills the capability functions and the configuration
93  * structure. Once ActivateModule() has been called, the i_usage can
94  * be set to 0 and calls to NeedModule() be made to increment it. To unload
95  * the module, one has to wait until i_usage == 0 and call DeactivateModule().
96  *****************************************************************************/
97 int ActivateModule( module_t * p_module )
98 {
99     p_module->p_functions = malloc( sizeof( module_functions_t ) );
100     if( p_module->p_functions == NULL )
101     {
102         return( -1 );
103     }
104
105     idct_getfunctions( &p_module->p_functions->idct );
106
107     p_module->p_config = p_config;
108
109     return( 0 );
110 }
111
112 /*****************************************************************************
113  * DeactivateModule: make sure the module can be unloaded.
114  *****************************************************************************
115  * This function must only be called when i_usage == 0. If it successfully
116  * returns, i_usage can be set to -1 and the module unloaded. Be careful to
117  * lock usage_lock during the whole process.
118  *****************************************************************************/
119 int DeactivateModule( module_t * p_module )
120 {
121     free( p_module->p_functions );
122
123     return( 0 );
124 }
125
126 /* Following functions are local */
127
128 /*****************************************************************************
129  * Functions exported as capabilities. They are declared as static so that
130  * we don't pollute the namespace too much.
131  *****************************************************************************/
132 static void idct_getfunctions( function_list_t * p_function_list )
133 {
134     p_function_list->pf_probe = idct_Probe;
135     p_function_list->functions.idct.pf_init = vdec_InitIDCT;
136     p_function_list->functions.idct.pf_sparse_idct = vdec_SparseIDCT;
137     p_function_list->functions.idct.pf_idct = vdec_IDCT;
138 }
139
140 /*****************************************************************************
141  * idct_Probe: return a preference score
142  *****************************************************************************/
143 static int idct_Probe( probedata_t *p_data )
144 {
145     /* This plugin always works */
146     return( 100 );
147 }
148
149 /*****************************************************************************
150  * vdec_InitIDCT : initialize datas for vdec_SparceIDCT
151  *****************************************************************************/
152 static void vdec_InitIDCT (vdec_thread_t * p_vdec)
153 {
154     int i;
155
156     dctelem_t * p_pre = p_vdec->p_pre_idct;
157     memset( p_pre, 0, 64*64*sizeof(dctelem_t) );
158
159     for( i=0 ; i < 64 ; i++ )
160     {
161         p_pre[i*64+i] = 1 << SPARSE_SCALE_FACTOR;
162         vdec_IDCT( p_vdec, &p_pre[i*64], 0) ;
163     }
164     return;
165 }
166