1 /*****************************************************************************
2 * blendbench.c : blending benchmark plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2007 the VideoLAN team
7 * Author: Søren Bøg <avacore@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 *****************************************************************************/
33 #include <stdlib.h> /* malloc(), free() */
41 #include "vlc_filter.h"
42 #include "vlc_image.h"
44 /*****************************************************************************
46 *****************************************************************************/
47 static int Create( vlc_object_t * );
48 static void Destroy( vlc_object_t * );
50 static picture_t *Filter( filter_t *, picture_t * );
52 /*****************************************************************************
54 *****************************************************************************/
56 #define LOOPS_TEXT N_("Number of time to blend")
57 #define LOOPS_LONGTEXT N_("The number of time the blend will be performed")
59 #define ALPHA_TEXT N_("Alpha of the blended image")
60 #define ALPHA_LONGTEXT N_("Alpha with which the blend image is blended")
62 #define BASE_IMAGE_TEXT N_("Image to be blended onto")
63 #define BASE_IMAGE_LONGTEXT N_("The image which will be used to blend onto")
65 #define BASE_CHROMA_TEXT N_("Chroma for the base image")
66 #define BASE_CHROMA_LONGTEXT N_("Chroma which the base image will be loaded in")
68 #define BLEND_IMAGE_TEXT N_("Image which will be blended.")
69 #define BLEND_IMAGE_LONGTEXT N_("The image blended onto the base image")
71 #define BLEND_CHROMA_TEXT N_("Chroma for the blend image")
72 #define BLEND_CHROMA_LONGTEXT N_("Chroma which the blend image will be loaded" \
75 #define CFG_PREFIX "blendbench-"
78 set_description( _("Blending benchmark filter") );
79 set_shortname( _("blendbench" ));
80 set_category( CAT_VIDEO );
81 set_subcategory( SUBCAT_VIDEO_VFILTER );
82 set_capability( "video filter2", 0 );
84 set_section( N_("Benchmarking"), NULL );
85 add_integer( CFG_PREFIX "loops", 1000, NULL, LOOPS_TEXT,
86 LOOPS_LONGTEXT, VLC_FALSE );
87 add_integer_with_range( CFG_PREFIX "alpha", 128, 0, 255, NULL, ALPHA_TEXT,
88 ALPHA_LONGTEXT, VLC_FALSE );
90 set_section( N_("Base image"), NULL );
91 add_file( CFG_PREFIX "base-image", NULL, NULL, BASE_IMAGE_TEXT,
92 BASE_IMAGE_LONGTEXT, VLC_FALSE );
93 add_string( CFG_PREFIX "base-chroma", "I420", NULL, BASE_CHROMA_TEXT,
94 BASE_CHROMA_LONGTEXT, VLC_FALSE );
96 set_section( N_("Blend image"), NULL );
97 add_file( CFG_PREFIX "blend-image", NULL, NULL, BLEND_IMAGE_TEXT,
98 BLEND_IMAGE_LONGTEXT, VLC_FALSE );
99 add_string( CFG_PREFIX "blend-chroma", "YUVA", NULL, BLEND_CHROMA_TEXT,
100 BLEND_CHROMA_LONGTEXT, VLC_FALSE );
102 set_callbacks( Create, Destroy );
105 static const char *ppsz_filter_options[] = {
106 "loops", "alpha", "base-image", "base-chroma", "blend-image",
110 /*****************************************************************************
111 * filter_sys_t: filter method descriptor
112 *****************************************************************************/
116 int i_loops, i_alpha;
118 picture_t *p_base_image;
119 picture_t *p_blend_image;
121 vlc_fourcc_t i_base_chroma;
122 vlc_fourcc_t i_blend_chroma;
125 static int LoadImage( vlc_object_t *p_this, picture_t **pp_pic,
126 vlc_fourcc_t i_chroma, char *psz_file, const char *psz_name )
128 image_handler_t *p_image;
129 video_format_t fmt_in, fmt_out;
131 memset( &fmt_in, 0, sizeof(video_format_t) );
132 memset( &fmt_out, 0, sizeof(video_format_t) );
134 fmt_out.i_chroma = i_chroma;
135 p_image = image_HandlerCreate( p_this );
136 *pp_pic = image_ReadUrl( p_image, psz_file, &fmt_in, &fmt_out );
137 image_HandlerDelete( p_image );
139 if( *pp_pic == NULL ) {
140 msg_Err( p_this, "Unable to load %s image", psz_name );
144 msg_Dbg( p_this, "%s image has dim %d x %d (Y plane)", psz_name,
145 (*pp_pic)->p[Y_PLANE].i_visible_pitch,
146 (*pp_pic)->p[Y_PLANE].i_visible_lines );
149 /*****************************************************************************
150 * Create: allocates video thread output method
151 *****************************************************************************/
152 static int Create( vlc_object_t *p_this )
154 filter_t *p_filter = (filter_t *)p_this;
158 /* Allocate structure */
159 p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
160 if( p_filter->p_sys == NULL )
162 msg_Err( p_filter, "out of memory" );
165 p_sys = p_filter->p_sys;
166 p_sys->b_done = VLC_FALSE;
168 p_filter->pf_video_filter = Filter;
170 /* needed to get options passed in transcode using the
171 * adjust{name=value} syntax */
172 config_ChainParse( p_filter, CFG_PREFIX, ppsz_filter_options,
175 p_sys->i_loops = var_CreateGetIntegerCommand( p_filter,
176 CFG_PREFIX "loops" );
177 p_sys->i_alpha = var_CreateGetIntegerCommand( p_filter,
178 CFG_PREFIX "alpha" );
180 psz_temp = var_CreateGetStringCommand( p_filter, CFG_PREFIX "base-chroma" );
181 p_sys->i_base_chroma = VLC_FOURCC( psz_temp[0], psz_temp[1],
182 psz_temp[2], psz_temp[3] );
183 LoadImage( p_this, &p_sys->p_base_image, p_sys->i_base_chroma,
184 var_CreateGetStringCommand( p_filter, CFG_PREFIX "base-image" ),
187 psz_temp = var_CreateGetStringCommand( p_filter,
188 CFG_PREFIX "blend-chroma" );
189 p_sys->i_blend_chroma = VLC_FOURCC( psz_temp[0], psz_temp[1],
190 psz_temp[2], psz_temp[3] );
191 LoadImage( p_this, &p_sys->p_blend_image, p_sys->i_blend_chroma,
192 var_CreateGetStringCommand( p_filter, CFG_PREFIX "blend-image" ),
198 /*****************************************************************************
199 * Destroy: destroy video thread output method
200 *****************************************************************************/
201 static void Destroy( vlc_object_t *p_this )
203 filter_t *p_filter = (filter_t *)p_this;
204 filter_sys_t *p_sys = p_filter->p_sys;
206 p_sys->p_base_image->pf_release( p_sys->p_base_image );
207 p_sys->p_blend_image->pf_release( p_sys->p_blend_image );
210 /*****************************************************************************
211 * Render: displays previously rendered output
212 *****************************************************************************/
213 static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
215 filter_sys_t *p_sys = p_filter->p_sys;
224 p_blend = vlc_object_create( p_filter, VLC_OBJECT_FILTER );
225 vlc_object_attach( p_blend, p_filter );
226 p_blend->fmt_out.video = p_sys->p_base_image->format;
227 p_blend->fmt_in.video = p_sys->p_blend_image->format;
228 p_blend->p_module = module_Need( p_blend, "video blending", 0, 0 );
230 mtime_t time = mdate();
231 for( int i_iter = 0; i_iter < p_sys->i_loops; ++i_iter )
233 p_blend->pf_video_blend( p_blend, p_sys->p_base_image,
234 p_sys->p_base_image, p_sys->p_blend_image, 0,
237 time = mdate() - time;
239 msg_Info( p_filter, "Blended %d images in %f sec.", p_sys->i_loops,
241 msg_Info( p_filter, "Speed is: %f images/second, %f pixels/second",
242 (float) p_sys->i_loops / time * 1000000,
243 (float) p_sys->i_loops / time * 1000000 *
244 p_sys->p_blend_image->p[Y_PLANE].i_visible_pitch *
245 p_sys->p_blend_image->p[Y_PLANE].i_visible_lines );
247 module_Unneed( p_blend, p_blend->p_module );
249 vlc_object_detach( p_blend );
250 vlc_object_release( p_blend );
252 p_sys->b_done = VLC_TRUE;