]> git.sesse.net Git - vlc/blob - modules/video_chroma/chain.c
Chroma modules now exactly implement the "video filter2" capability.
[vlc] / modules / video_chroma / chain.c
1 /*****************************************************************************
2  * chain.c : chain multiple chroma modules as a last resort solution
3  *****************************************************************************
4  * Copyright (C) 2007-2008 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_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_filter.h>
35 #include <vlc_vout.h>
36
37 /*****************************************************************************
38  * Local and extern prototypes.
39  *****************************************************************************/
40 static int  Activate ( vlc_object_t * );
41 static void Destroy  ( vlc_object_t * );
42 static void Chain    ( filter_t *, picture_t *, picture_t * );
43
44 /*****************************************************************************
45  * Module descriptor
46  *****************************************************************************/
47 vlc_module_begin();
48     set_description( N_("Chroma conversions using a chain of chroma conversion modules") );
49     set_capability( "video filter2", 1 );
50     set_callbacks( Activate, Destroy );
51 vlc_module_end();
52
53 #define MAX_CHROMAS 2
54
55 struct filter_sys_t
56 {
57     vlc_fourcc_t i_chroma;
58
59     filter_t    *p_chroma1;
60     filter_t    *p_chroma2;
61
62     picture_t   *p_tmp;
63 };
64
65 static const vlc_fourcc_t pi_allowed_chromas[] = {
66     VLC_FOURCC('I','4','2','0'),
67     VLC_FOURCC('I','4','2','2'),
68     VLC_FOURCC('R','V','3','2'),
69     VLC_FOURCC('R','V','2','4'),
70     0
71 };
72
73 /*****************************************************************************
74  * Activate: allocate a chroma function
75  *****************************************************************************
76  * This function allocates and initializes a chroma function
77  *****************************************************************************/
78 static int Activate( vlc_object_t *p_this )
79 {
80 #if 0
81     static int hack = 1;
82     filter_t *p_filter = (filter_t *)p_this;
83
84     hack++;
85     if( hack > MAX_CHROMAS )
86     {
87         hack--;
88         msg_Err( p_this, "Preventing chain chroma reccursion (already %d long)",
89                  hack );
90         return VLC_EGENERIC;
91     }
92
93     filter_sys_t *p_sys = (filter_sys_t *)malloc( sizeof( filter_sys_t ) );
94     if( !p_sys )
95     {
96         hack--;
97         return VLC_ENOMEM;
98     }
99     memset( p_sys, 0, sizeof( filter_sys_t ) );
100
101     int i;
102     vlc_fourcc_t i_output_chroma = p_filter->fmt_in.video.i_chroma;
103     vlc_fourcc_t i_render_chroma = p_filter->fmt_out.video.i_chroma;
104
105     for( i = 0; pi_allowed_chromas[i]; i++ )
106     {
107         msg_Warn( p_filter, "Trying %4s as a chroma chain",
108                   (const char *)&pi_allowed_chromas[i] );
109         p_filter->output.i_chroma = pi_allowed_chromas[i];
110         p_filter->p_chroma1.p_module = module_Need( p_vout, "chroma", NULL, 0 );
111         p_filter->output.i_chroma = i_output_chroma;
112
113         if( !p_vout->chroma.p_module )
114             continue;
115
116         p_sys->chroma1 = p_vout->chroma;
117         memset( &p_vout->chroma, 0, sizeof( vout_chroma_t ) );
118
119         p_vout->render.i_chroma = pi_allowed_chromas[i];
120         p_vout->chroma.p_module = module_Need( p_vout, "chroma", NULL, 0 );
121         p_vout->render.i_chroma = i_render_chroma;
122
123         if( !p_vout->chroma.p_module )
124         {
125             p_vout->chroma = p_sys->chroma1;
126             module_Unneed( p_vout, p_vout->chroma.p_module );
127             continue;
128         }
129
130         p_sys->chroma2 = p_vout->chroma;
131         memset( &p_vout->chroma, 0, sizeof( vout_chroma_t ) );
132
133         p_sys->i_chroma = pi_allowed_chromas[i];
134         p_vout->chroma.pf_convert = Chain;
135         p_vout->chroma.p_sys = p_sys;
136         hack--;
137         printf("Init: p_sys->p_tmp= %p\n", p_sys->p_tmp );
138         return VLC_SUCCESS;
139     }
140
141     free( p_sys );
142     hack--;
143 #endif
144     return VLC_EGENERIC;
145 }
146
147 static void Destroy( vlc_object_t *p_this )
148 {
149 #if 0
150     filter_t *p_filter = (filter_t *)p_this;
151     vout_chroma_t chroma = p_vout->chroma;
152
153     p_vout->chroma = chroma.p_sys->chroma1;
154     module_Unneed( p_vout, p_vout->chroma.p_module );
155     p_vout->chroma = chroma.p_sys->chroma2;
156     module_Unneed( p_vout, p_vout->chroma.p_module );
157     p_vout->chroma = chroma;
158
159     if( chroma.p_sys->p_tmp )
160     {
161         free( chroma.p_sys->p_tmp->p_data_orig );
162         free( chroma.p_sys->p_tmp );
163     }
164     free( chroma.p_sys );
165     chroma.p_sys = NULL;
166 #endif
167 }
168
169 /*****************************************************************************
170  * Chain
171  *****************************************************************************/
172 static void Chain( filter_t *p_filter, picture_t *p_source,
173                    picture_t *p_dest )
174 {
175 #if 0
176     chroma_sys_t *p_sys = p_vout->chroma.p_sys;
177
178     if( !p_sys->p_tmp )
179     {
180         picture_t *p_tmp = malloc( sizeof( picture_t ) );
181         vout_AllocatePicture( VLC_OBJECT( p_vout ), p_tmp,
182                               p_sys->i_chroma,
183                               p_source->p_heap->i_width,
184                               p_source->p_heap->i_height,
185                               p_source->p_heap->i_aspect );
186         if( !p_tmp )
187             return;
188         p_sys->p_tmp = p_tmp;
189         p_tmp->pf_release = NULL;
190         p_tmp->i_status = RESERVED_PICTURE;
191         p_tmp->p_sys = NULL;
192     }
193
194     vout_chroma_t chroma = p_vout->chroma;
195     p_vout->chroma = p_sys->chroma1;
196     p_sys->chroma1.pf_convert( p_vout, p_source, p_sys->p_tmp );
197     p_vout->chroma = p_sys->chroma2;
198     p_sys->chroma2.pf_convert( p_vout, p_sys->p_tmp, p_dest );
199     p_vout->chroma = chroma;
200 #endif
201 }