1 /*****************************************************************************
2 * swscale_maemo.c: scaling and chroma conversion using libswscale_nokia770
3 *****************************************************************************
4 * Copyright (C) 1999-2008 the VideoLAN team
7 * Authors: Antoine Lejeune <phytos@videolan.org>
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.
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.
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 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
31 #include <vlc_common.h>
32 #include <vlc_plugin.h>
34 #include <vlc_filter.h>
36 #include "libswscale_nokia770/arm_jit_swscale.h"
37 #include "libswscale_nokia770/arm_colorconv.h"
39 /****************************************************************************
41 ****************************************************************************/
42 static int OpenScaler( vlc_object_t * );
43 static void CloseScaler( vlc_object_t * );
45 static picture_t *Filter( filter_t *, picture_t * );
46 static int Init( filter_t * );
48 /*****************************************************************************
50 *****************************************************************************/
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 );
59 /*****************************************************************************
60 * filter_sys_t : filter descriptor
61 *****************************************************************************/
64 struct SwsContextArmJit *ctx;
70 /*****************************************************************************
71 * OpenScaler: probe the filter and return score
72 *****************************************************************************/
73 static int OpenScaler( vlc_object_t *p_this )
75 filter_t *p_filter = (filter_t*)p_this;
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 )
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 );
91 if( Init( p_filter ) )
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 );
106 /*****************************************************************************
107 * CloseFilter: clean up the filter
108 *****************************************************************************/
109 static void CloseScaler( vlc_object_t *p_this )
111 filter_t *p_filter = (filter_t*)p_this;
112 filter_sys_t *p_sys = p_filter->p_sys;
115 sws_arm_jit_free( p_sys->ctx );
119 /*****************************************************************************
121 *****************************************************************************/
123 static bool IsFmtSimilar( const video_format_t *p_fmt1, const video_format_t *p_fmt2 )
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;
130 static int Init( filter_t *p_filter )
132 filter_sys_t *p_sys = p_filter->p_sys;
134 if( IsFmtSimilar( &p_filter->fmt_in.video, &p_sys->fmt_in ) &&
135 IsFmtSimilar( &p_filter->fmt_out.video, &p_sys->fmt_out ) &&
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') )
146 msg_Err( p_filter, "format not supported" );
151 sws_arm_jit_free( 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 );
162 msg_Err( p_filter, "could not init SwScaler" );
166 p_sys->fmt_in = p_filter->fmt_in;
167 p_sys->fmt_out = p_filter->fmt_out;
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 )
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;
184 int i_nb_planes = p_pic->i_planes;
186 /* Check if format properties changed */
187 if( Init( p_filter ) != VLC_SUCCESS )
190 /* Request output picture */
191 p_pic_dst = p_filter->pf_vout_buffer_new( p_filter );
194 msg_Warn( p_filter, "can't get output picture" );
198 for( i_plane = 0; i_plane < __MIN(3, p_pic->i_planes); i_plane++ )
200 src[i_plane] = p_pic->p[i_plane].p_pixels;
201 src_stride[i_plane] = p_pic->p[i_plane].i_pitch;
203 for( i_plane = 0; i_plane < __MIN(3, i_nb_planes); i_plane++ )
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;
209 sws_arm_jit_scale( p_sys->ctx, src, src_stride, 0,
210 p_filter->fmt_in.video.i_height, dst, dst_stride);
212 picture_CopyProperties( p_pic_dst, p_pic );
213 picture_Release( p_pic );