]> git.sesse.net Git - vlc/blob - plugins/motion/motion.c
* Totally rewrote the video decoder (inspired by walken's mpeg2dec), implying :
[vlc] / plugins / motion / motion.c
1 /*****************************************************************************
2  * motion.c : C motion compensation module for vlc
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  * $Id: motion.c,v 1.9 2001/08/22 17:21:45 massiot Exp $
6  *
7  * Authors: Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
8  *          Michel Lespinasse <walken@zoy.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 #define MODULE_NAME motion
26 #include "modules_inner.h"
27
28 /*****************************************************************************
29  * Preamble
30  *****************************************************************************/
31 #include "defs.h"
32
33 #include <stdlib.h>                                      /* malloc(), free() */
34
35 #include "config.h"
36 #include "common.h"                                     /* boolean_t, byte_t */
37 #include "threads.h"
38 #include "mtime.h"
39 #include "tests.h"
40
41 #include "modules.h"
42 #include "modules_export.h"
43
44 /*****************************************************************************
45  * Local and extern prototypes.
46  *****************************************************************************/
47 static void motion_getfunctions( function_list_t * p_function_list );
48
49 /*****************************************************************************
50  * Build configuration tree.
51  *****************************************************************************/
52 MODULE_CONFIG_START
53 ADD_WINDOW( "Configuration for motion compensation module" )
54     ADD_COMMENT( "Ha, ha -- nothing to configure yet" )
55 MODULE_CONFIG_STOP
56
57 MODULE_INIT_START
58     p_module->i_capabilities = MODULE_CAPABILITY_NULL
59                                 | MODULE_CAPABILITY_MOTION;
60     p_module->psz_longname = "motion compensation module";
61 MODULE_INIT_STOP
62
63 MODULE_ACTIVATE_START
64     motion_getfunctions( &p_module->p_functions->motion );
65 MODULE_ACTIVATE_STOP
66
67 MODULE_DEACTIVATE_START
68 MODULE_DEACTIVATE_STOP
69
70 /*****************************************************************************
71  * motion_Probe: tests probe the CPU and return a score
72  *****************************************************************************/
73 static int motion_Probe( probedata_t *p_data )
74 {
75     if( TestMethod( MOTION_METHOD_VAR, "motion" )
76          || TestMethod( MOTION_METHOD_VAR, "c" ) )
77     {
78         return( 999 );
79     }
80
81     /* This module always works */
82     return( 50 );
83 }
84
85 /*****************************************************************************
86  * Simple motion compensation in C
87  *****************************************************************************/
88
89 #define avg2(a,b) ((a+b+1)>>1)
90 #define avg4(a,b,c,d) ((a+b+c+d+2)>>2)
91
92 #define predict_(i) (ref[i])
93 #define predict_x(i) (avg2 (ref[i], ref[i+1]))
94 #define predict_y(i) (avg2 (ref[i], (ref+stride)[i]))
95 #define predict_xy(i) (avg4 (ref[i], ref[i+1], (ref+stride)[i], (ref+stride)[i+1]))
96
97 #define put(predictor,i) dest[i] = predictor (i)
98 #define avg(predictor,i) dest[i] = avg2 (predictor (i), dest[i])
99
100 // mc function template
101
102 #define MC_FUNC(op,xy)                                                                                \
103 static void MC_##op##_##xy##16_c (yuv_data_t * dest, yuv_data_t * ref,      \
104                                  int stride, int height)                    \
105 {                                                                           \
106     do {                                                                    \
107         op (predict_##xy, 0);                                               \
108         op (predict_##xy, 1);                                               \
109         op (predict_##xy, 2);                                               \
110         op (predict_##xy, 3);                                               \
111         op (predict_##xy, 4);                                               \
112         op (predict_##xy, 5);                                               \
113         op (predict_##xy, 6);                                               \
114         op (predict_##xy, 7);                                               \
115         op (predict_##xy, 8);                                               \
116         op (predict_##xy, 9);                                               \
117         op (predict_##xy, 10);                                              \
118         op (predict_##xy, 11);                                              \
119         op (predict_##xy, 12);                                              \
120         op (predict_##xy, 13);                                              \
121         op (predict_##xy, 14);                                              \
122         op (predict_##xy, 15);                                              \
123         ref += stride;                                                      \
124         dest += stride;                                                     \
125     } while (--height);                                                     \
126 }                                                                           \
127 static void MC_##op##_##xy##8_c (yuv_data_t * dest, yuv_data_t * ref,       \
128                                 int stride, int height)                     \
129 {                                                                           \
130     do {                                                                    \
131         op (predict_##xy, 0);                                               \
132         op (predict_##xy, 1);                                               \
133         op (predict_##xy, 2);                                               \
134         op (predict_##xy, 3);                                               \
135         op (predict_##xy, 4);                                               \
136         op (predict_##xy, 5);                                               \
137         op (predict_##xy, 6);                                               \
138         op (predict_##xy, 7);                                               \
139         ref += stride;                                                      \
140         dest += stride;                                                     \
141     } while (--height);                                                     \
142 }
143
144 // definitions of the actual mc functions
145
146 MC_FUNC (put,)
147 MC_FUNC (avg,)
148 MC_FUNC (put,x)
149 MC_FUNC (avg,x)
150 MC_FUNC (put,y)
151 MC_FUNC (avg,y)
152 MC_FUNC (put,xy)
153 MC_FUNC (avg,xy)
154
155 /*****************************************************************************
156  * Functions exported as capabilities. They are declared as static so that
157  * we don't pollute the namespace too much.
158  *****************************************************************************/
159 static void motion_getfunctions( function_list_t * p_function_list )
160 {
161     static void (* ppppf_motion[2][2][4])( yuv_data_t *, yuv_data_t *,
162                                            int, int ) =
163     {
164         {
165             /* Copying functions */
166             {
167                 /* Width == 16 */
168                 MC_put_16_c, MC_put_x16_c, MC_put_y16_c, MC_put_xy16_c
169             },
170             {
171                 /* Width == 8 */
172                 MC_put_8_c,  MC_put_x8_c,  MC_put_y8_c, MC_put_xy8_c
173             }
174         },
175         {
176             /* Averaging functions */
177             {
178                 /* Width == 16 */
179                 MC_avg_16_c, MC_avg_x16_c, MC_avg_y16_c, MC_avg_xy16_c
180             },
181             {
182                 /* Width == 8 */
183                 MC_avg_8_c,  MC_avg_x8_c,  MC_avg_y8_c,  MC_avg_xy8_c
184             }
185         }
186     };
187
188     p_function_list->pf_probe = motion_Probe;
189
190 #define list p_function_list->functions.motion
191     memcpy( list.ppppf_motion, ppppf_motion, sizeof( void * ) * 16 );
192 #undef list
193
194     return;
195 }