]> git.sesse.net Git - vlc/blob - modules/video_filter/swscale_maemo.c
macosx: fixed menubar appearance in fullscreen mode by partially reverting [46c93c9cc...
[vlc] / modules / video_filter / swscale_maemo.c
1 /*****************************************************************************
2  * swscale_maemo.c: scaling and chroma conversion using libswscale_nokia770
3  *****************************************************************************
4  * Copyright (C) 1999-2008 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Antoine Lejeune <phytos@videolan.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 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <vlc_common.h>
32 #include <vlc_plugin.h>
33 #include <vlc_vout.h>
34 #include <vlc_filter.h>
35
36 #include "libswscale_nokia770/arm_jit_swscale.h"
37 #include "libswscale_nokia770/arm_colorconv.h"
38
39 /****************************************************************************
40  * Local prototypes
41  ****************************************************************************/
42 static int  OpenScaler( vlc_object_t * );
43 static void CloseScaler( vlc_object_t * );
44
45 static picture_t *Filter( filter_t *, picture_t * );
46 static int Init( filter_t * );
47
48 /*****************************************************************************
49  * Module descriptor
50  *****************************************************************************/
51 vlc_module_begin();
52     set_description( N_("Video scaling filter") );
53     set_capability( "video filter2", 1000 );
54     set_category( CAT_VIDEO );
55     set_subcategory( SUBCAT_VIDEO_VFILTER );
56     set_callbacks( OpenScaler, CloseScaler );
57 vlc_module_end();
58
59 /*****************************************************************************
60  * filter_sys_t : filter descriptor
61  *****************************************************************************/
62 struct filter_sys_t
63 {
64     struct SwsContextArmJit *ctx;
65
66     es_format_t fmt_in;
67     es_format_t fmt_out;
68 };
69
70 /*****************************************************************************
71  * OpenScaler: probe the filter and return score
72  *****************************************************************************/
73 static int OpenScaler( vlc_object_t *p_this )
74 {
75     filter_t *p_filter = (filter_t*)p_this;
76     filter_sys_t *p_sys;
77
78     /* Allocate the memory needed to store the decoder's structure */
79     if( ( p_filter->p_sys = p_sys =
80           (filter_sys_t *)malloc(sizeof(filter_sys_t)) ) == NULL )
81     {
82         return VLC_ENOMEM;
83     }
84
85     /* Misc init */
86     p_sys->ctx = NULL;
87     p_filter->pf_video_filter = Filter;
88     es_format_Init( &p_sys->fmt_in, 0, 0 );
89     es_format_Init( &p_sys->fmt_out, 0, 0 );
90
91     if( Init( p_filter ) )
92     {
93         free( p_sys );
94         return VLC_EGENERIC;
95     }
96
97     msg_Dbg( p_filter, "%ix%i chroma: %4.4s -> %ix%i chroma: %4.4s",
98              p_filter->fmt_in.video.i_width, p_filter->fmt_in.video.i_height,
99              (char *)&p_filter->fmt_in.video.i_chroma,
100              p_filter->fmt_out.video.i_width, p_filter->fmt_out.video.i_height,
101              (char *)&p_filter->fmt_out.video.i_chroma );
102
103     return VLC_SUCCESS;
104 }
105
106 /*****************************************************************************
107  * CloseFilter: clean up the filter
108  *****************************************************************************/
109 static void CloseScaler( vlc_object_t *p_this )
110 {
111     filter_t *p_filter = (filter_t*)p_this;
112     filter_sys_t *p_sys = p_filter->p_sys;
113
114     if( p_sys->ctx )
115         sws_arm_jit_free( p_sys->ctx );
116     free( p_sys );
117 }
118
119 /*****************************************************************************
120  * Helpers
121  *****************************************************************************/
122
123 static bool IsFmtSimilar( const video_format_t *p_fmt1, const video_format_t *p_fmt2 )
124 {
125     return p_fmt1->i_chroma == p_fmt2->i_chroma &&
126            p_fmt1->i_width  == p_fmt2->i_width &&
127            p_fmt1->i_height == p_fmt2->i_height;
128 }
129
130 static int Init( filter_t *p_filter )
131 {
132     filter_sys_t *p_sys = p_filter->p_sys;
133
134     if( IsFmtSimilar( &p_filter->fmt_in.video, &p_sys->fmt_in ) &&
135         IsFmtSimilar( &p_filter->fmt_out.video, &p_sys->fmt_out ) &&
136         p_sys->ctx )
137     {
138         return VLC_SUCCESS;
139     }
140
141     if( ( p_filter->fmt_in.video.i_chroma != VLC_FOURCC('I','4','2','0') &&
142           p_filter->fmt_in.video.i_chroma != VLC_FOURCC('I','Y','U','V') &&
143           p_filter->fmt_in.video.i_chroma != VLC_FOURCC('Y','V','1','2') ) ||
144           p_filter->fmt_out.video.i_chroma != VLC_FOURCC('Y','4','2','0') )
145     {
146         msg_Err( p_filter, "format not supported" );
147         return VLC_EGENERIC;
148     }
149
150     if( p_sys->ctx )
151         sws_arm_jit_free( p_sys->ctx );
152
153     p_sys->ctx =
154         sws_arm_jit_create_omapfb_yuv420_scaler_armv6(
155             p_filter->fmt_in.video.i_width,
156             p_filter->fmt_in.video.i_height,
157             p_filter->fmt_out.video.i_width,
158             p_filter->fmt_out.video.i_height, 2 );
159
160     if( !p_sys->ctx )
161     {
162         msg_Err( p_filter, "could not init SwScaler" );
163         return VLC_EGENERIC;
164     }
165
166     p_sys->fmt_in = p_filter->fmt_in;
167     p_sys->fmt_out = p_filter->fmt_out;
168
169     return VLC_SUCCESS;
170 }
171
172 /****************************************************************************
173  * Filter: the whole thing
174  ****************************************************************************
175  * This function is called just after the thread is launched.
176  ****************************************************************************/
177 static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
178 {
179     filter_sys_t *p_sys = p_filter->p_sys;
180     uint8_t *src[3]; int src_stride[3];
181     uint8_t *dst[3]; int dst_stride[3];
182     picture_t *p_pic_dst;
183     int i_plane;
184     int i_nb_planes = p_pic->i_planes;
185
186     /* Check if format properties changed */
187     if( Init( p_filter ) != VLC_SUCCESS )
188         return NULL;
189
190     /* Request output picture */
191     p_pic_dst = p_filter->pf_vout_buffer_new( p_filter );
192     if( !p_pic_dst )
193     {
194         msg_Warn( p_filter, "can't get output picture" );
195         return NULL;
196     }
197
198     for( i_plane = 0; i_plane < __MIN(3, p_pic->i_planes); i_plane++ )
199     {
200         src[i_plane] = p_pic->p[i_plane].p_pixels;
201         src_stride[i_plane] = p_pic->p[i_plane].i_pitch;
202     }
203     for( i_plane = 0; i_plane < __MIN(3, i_nb_planes); i_plane++ )
204     {
205         dst[i_plane] = p_pic_dst->p[i_plane].p_pixels;
206         dst_stride[i_plane] = p_pic_dst->p[i_plane].i_pitch;
207     }
208
209     sws_arm_jit_scale( p_sys->ctx, src, src_stride, 0,
210                        p_filter->fmt_in.video.i_height, dst, dst_stride);
211
212     picture_CopyProperties( p_pic_dst, p_pic );
213     picture_Release( p_pic );
214
215     return p_pic_dst;
216 }