]> git.sesse.net Git - vlc/blob - modules/video_chroma/chain.c
let gcc choose how to reference memory addresses in i420_rgx mmx asm
[vlc] / modules / video_chroma / chain.c
1 /*****************************************************************************
2  * chain.c : chain multiple chroma modules as a last resort solution
3  *****************************************************************************
4  * Copyright (C) 2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Antoine Cellerier <dionoea at videolan dot org>
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <vlc/vlc.h>
33 #include <vlc_vout.h>
34
35 /*****************************************************************************
36  * Local and extern prototypes.
37  *****************************************************************************/
38 static int  Activate ( vlc_object_t * );
39 static void Destroy  ( vlc_object_t * );
40 static void Chain    ( vout_thread_t *, picture_t *, picture_t * );
41
42 /*****************************************************************************
43  * Module descriptor
44  *****************************************************************************/
45 vlc_module_begin();
46     set_description( _("Chroma conversions using a chain of chroma conversion modules") );
47     set_capability( "chroma", 1 );
48     set_callbacks( Activate, Destroy );
49 vlc_module_end();
50
51 #define MAX_CHROMAS 2
52
53 struct chroma_sys_t
54 {
55     vlc_fourcc_t i_chroma;
56
57     vout_chroma_t chroma1;
58     vout_chroma_t chroma2;
59
60     picture_t *p_tmp;
61 };
62
63 static const vlc_fourcc_t pi_allowed_chromas[] = {
64     VLC_FOURCC('I','4','2','0'),
65     VLC_FOURCC('I','4','2','2'),
66     0
67 };
68
69 /*****************************************************************************
70  * Activate: allocate a chroma function
71  *****************************************************************************
72  * This function allocates and initializes a chroma function
73  *****************************************************************************/
74 static int Activate( vlc_object_t *p_this )
75 {
76     static int hack = 1;
77     vout_thread_t *p_vout = (vout_thread_t *)p_this;
78
79     hack++;
80     if( hack > MAX_CHROMAS )
81     {
82         hack--;
83         msg_Err( p_this, "Preventing chain chroma reccursion (already %d long)",
84                  hack );
85         return VLC_EGENERIC;
86     }
87
88     chroma_sys_t *p_sys = (chroma_sys_t *)malloc( sizeof( chroma_sys_t ) );
89     if( !p_sys )
90     {
91         hack--;
92         return VLC_ENOMEM;
93     }
94     memset( p_sys, 0, sizeof( chroma_sys_t ) );
95
96     int i;
97     vlc_fourcc_t i_output_chroma = p_vout->output.i_chroma;
98     vlc_fourcc_t i_render_chroma = p_vout->render.i_chroma;
99
100     for( i = 0; pi_allowed_chromas[i]; i++ )
101     {
102         msg_Warn( p_vout, "Trying %4s as a chroma chain",
103                   (const char *)&pi_allowed_chromas[i] );
104         p_vout->output.i_chroma = pi_allowed_chromas[i];
105         p_vout->chroma.p_module = module_Need( p_vout, "chroma", NULL, 0 );
106         p_vout->output.i_chroma = i_output_chroma;
107
108         if( !p_vout->chroma.p_module )
109             continue;
110
111         p_sys->chroma1 = p_vout->chroma;
112         memset( &p_vout->chroma, 0, sizeof( vout_chroma_t ) );
113
114         p_vout->render.i_chroma = pi_allowed_chromas[i];
115         p_vout->chroma.p_module = module_Need( p_vout, "chroma", NULL, 0 );
116         p_vout->render.i_chroma = i_render_chroma;
117
118         if( !p_vout->chroma.p_module )
119         {
120             p_vout->chroma = p_sys->chroma1;
121             module_Unneed( p_vout, p_vout->chroma.p_module );
122             continue;
123         }
124
125         p_sys->chroma2 = p_vout->chroma;
126         memset( &p_vout->chroma, 0, sizeof( vout_chroma_t ) );
127
128         p_sys->i_chroma = pi_allowed_chromas[i];
129         p_vout->chroma.pf_convert = Chain;
130         p_vout->chroma.p_sys = p_sys;
131         hack--;
132         printf("Init: p_sys->p_tmp= %p\n", p_sys->p_tmp );
133         return VLC_SUCCESS;
134     }
135
136     free( p_sys );
137     hack--;
138     return VLC_EGENERIC;
139 }
140
141 static void Destroy( vlc_object_t *p_this )
142 {
143     vout_thread_t *p_vout = (vout_thread_t *)p_this;
144     vout_chroma_t chroma = p_vout->chroma;
145
146
147     p_vout->chroma = chroma.p_sys->chroma1;
148     module_Unneed( p_vout, p_vout->chroma.p_module );
149     p_vout->chroma = chroma.p_sys->chroma2;
150     module_Unneed( p_vout, p_vout->chroma.p_module );
151     p_vout->chroma = chroma;
152
153     if( chroma.p_sys->p_tmp )
154     {
155         free( chroma.p_sys->p_tmp->p_data_orig );
156         free( chroma.p_sys->p_tmp );
157     }
158     free( chroma.p_sys );
159     chroma.p_sys = NULL;
160 }
161
162 /*****************************************************************************
163  * Chain
164  *****************************************************************************/
165 static void Chain( vout_thread_t *p_vout, picture_t *p_source,
166                    picture_t *p_dest )
167 {
168     chroma_sys_t *p_sys = p_vout->chroma.p_sys;
169
170     if( !p_sys->p_tmp )
171     {
172         picture_t *p_tmp = malloc( sizeof( picture_t ) );
173         vout_AllocatePicture( VLC_OBJECT( p_vout ), p_tmp,
174                               p_sys->i_chroma,
175                               p_source->p_heap->i_width,
176                               p_source->p_heap->i_height,
177                               p_source->p_heap->i_aspect );
178         if( !p_tmp )
179             return;
180         p_sys->p_tmp = p_tmp;
181         p_tmp->pf_release = NULL;
182         p_tmp->i_status = RESERVED_PICTURE;
183         p_tmp->p_sys = NULL;
184     }
185
186     vout_chroma_t chroma = p_vout->chroma;
187     p_vout->chroma = p_sys->chroma1;
188     p_sys->chroma1.pf_convert( p_vout, p_source, p_sys->p_tmp );
189     p_vout->chroma = p_sys->chroma2;
190     p_sys->chroma2.pf_convert( p_vout, p_sys->p_tmp, p_dest );
191     p_vout->chroma = chroma;
192 }