| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
#include <cxcore.h> |
|---|
| 28 |
#include <cv.h> |
|---|
| 29 |
#include <highgui.h> |
|---|
| 30 |
|
|---|
| 31 |
#ifdef HAVE_CONFIG_H |
|---|
| 32 |
# include "config.h" |
|---|
| 33 |
#endif |
|---|
| 34 |
|
|---|
| 35 |
#include <vlc_common.h> |
|---|
| 36 |
#include <vlc_plugin.h> |
|---|
| 37 |
#include <vlc_vout.h> |
|---|
| 38 |
|
|---|
| 39 |
#include <math.h> |
|---|
| 40 |
#include <time.h> |
|---|
| 41 |
|
|---|
| 42 |
#include "vlc_filter.h" |
|---|
| 43 |
#include "filter_common.h" |
|---|
| 44 |
#include <vlc_charset.h> |
|---|
| 45 |
#include "vlc_image.h" |
|---|
| 46 |
#include "vlc_input.h" |
|---|
| 47 |
#include "vlc_playlist.h" |
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
static int Create ( vlc_object_t * ); |
|---|
| 54 |
static void Destroy ( vlc_object_t * ); |
|---|
| 55 |
|
|---|
| 56 |
static int Init ( vout_thread_t * ); |
|---|
| 57 |
static void End ( vout_thread_t * ); |
|---|
| 58 |
static void Render ( vout_thread_t *, picture_t * ); |
|---|
| 59 |
|
|---|
| 60 |
static int SendEvents( vlc_object_t *, char const *, |
|---|
| 61 |
vlc_value_t, vlc_value_t, void * ); |
|---|
| 62 |
static void ReleaseImages( vout_thread_t *p_vout ); |
|---|
| 63 |
static void VlcPictureToIplImage( vout_thread_t *p_vout, picture_t *p_in ); |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
static const char *const chroma_list[] = { "input", "I420", "RGB32"}; |
|---|
| 70 |
static const char *const chroma_list_text[] = { N_("Use input chroma unaltered"), |
|---|
| 71 |
N_("I420 - first plane is greyscale"), N_("RGB32")}; |
|---|
| 72 |
|
|---|
| 73 |
static const char *const output_list[] = { "none", "input", "processed"}; |
|---|
| 74 |
static const char *const output_list_text[] = { N_("Don't display any video"), |
|---|
| 75 |
N_("Display the input video"), N_("Display the processed video")}; |
|---|
| 76 |
|
|---|
| 77 |
static const char *const verbosity_list[] = { "error", "warning", "debug"}; |
|---|
| 78 |
static const char *const verbosity_list_text[] = { N_("Show only errors"), |
|---|
| 79 |
N_("Show errors and warnings"), N_("Show everything including debug messages")}; |
|---|
| 80 |
|
|---|
| 81 |
vlc_module_begin(); |
|---|
| 82 |
set_description( N_("OpenCV video filter wrapper") ); |
|---|
| 83 |
set_shortname( N_("OpenCV" )); |
|---|
| 84 |
set_category( CAT_VIDEO ); |
|---|
| 85 |
set_subcategory( SUBCAT_VIDEO_VFILTER ); |
|---|
| 86 |
set_capability( "video filter", 0 ); |
|---|
| 87 |
add_shortcut( "opencv_wrapper" ); |
|---|
| 88 |
set_callbacks( Create, Destroy ); |
|---|
| 89 |
add_float_with_range( "opencv-scale", 1.0, 0.1, 2.0, NULL, |
|---|
| 90 |
N_("Scale factor (0.1-2.0)"), |
|---|
| 91 |
N_("Ammount by which to scale the picture before sending it to the internal OpenCV filter"), |
|---|
| 92 |
false ); |
|---|
| 93 |
add_string( "opencv-chroma", "input", NULL, |
|---|
| 94 |
N_("OpenCV filter chroma"), |
|---|
| 95 |
N_("Chroma to convert picture to before sending it to the internal OpenCV filter"), false); |
|---|
| 96 |
change_string_list( chroma_list, chroma_list_text, 0); |
|---|
| 97 |
add_string( "opencv-output", "input", NULL, |
|---|
| 98 |
N_("Wrapper filter output"), |
|---|
| 99 |
N_("Determines what (if any) video is displayed by the wrapper filter"), false); |
|---|
| 100 |
change_string_list( output_list, output_list_text, 0); |
|---|
| 101 |
add_string( "opencv-verbosity", "error", NULL, |
|---|
| 102 |
N_("Wrapper filter verbosity"), |
|---|
| 103 |
N_("Determines wrapper filter verbosity level"), false); |
|---|
| 104 |
change_string_list( verbosity_list, verbosity_list_text, 0); |
|---|
| 105 |
add_string( "opencv-filter-name", "none", NULL, |
|---|
| 106 |
N_("OpenCV internal filter name"), |
|---|
| 107 |
N_("Name of internal OpenCV plugin filter to use"), false); |
|---|
| 108 |
vlc_module_end(); |
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
enum wrapper_output_t |
|---|
| 115 |
{ |
|---|
| 116 |
NONE, |
|---|
| 117 |
VINPUT, |
|---|
| 118 |
PROCESSED |
|---|
| 119 |
}; |
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
enum internal_chroma_t |
|---|
| 125 |
{ |
|---|
| 126 |
CINPUT, |
|---|
| 127 |
GREY, |
|---|
| 128 |
RGB |
|---|
| 129 |
}; |
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
enum verbosity_t |
|---|
| 135 |
{ |
|---|
| 136 |
VERB_ERROR, |
|---|
| 137 |
VERB_WARN, |
|---|
| 138 |
VERB_DEBUG |
|---|
| 139 |
}; |
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
struct vout_sys_t |
|---|
| 148 |
{ |
|---|
| 149 |
vout_thread_t *p_vout; |
|---|
| 150 |
|
|---|
| 151 |
image_handler_t *p_image; |
|---|
| 152 |
|
|---|
| 153 |
int i_cv_image_size; |
|---|
| 154 |
|
|---|
| 155 |
picture_t *p_proc_image; |
|---|
| 156 |
picture_t *p_to_be_freed; |
|---|
| 157 |
|
|---|
| 158 |
float f_scale; |
|---|
| 159 |
|
|---|
| 160 |
int i_wrapper_output; |
|---|
| 161 |
int i_internal_chroma; |
|---|
| 162 |
int i_verbosity; |
|---|
| 163 |
|
|---|
| 164 |
IplImage *p_cv_image[VOUT_MAX_PLANES]; |
|---|
| 165 |
|
|---|
| 166 |
filter_t *p_opencv; |
|---|
| 167 |
char* psz_inner_name; |
|---|
| 168 |
|
|---|
| 169 |
picture_t hacked_pic; |
|---|
| 170 |
}; |
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 |
|
|---|
| 175 |
static int Control( vout_thread_t *p_vout, int i_query, va_list args ) |
|---|
| 176 |
{ |
|---|
| 177 |
return vout_vaControl( p_vout->p_sys->p_vout, i_query, args ); |
|---|
| 178 |
} |
|---|
| 179 |
|
|---|
| 180 |
|
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
static int Create( vlc_object_t *p_this ) |
|---|
| 186 |
{ |
|---|
| 187 |
vout_thread_t *p_vout = (vout_thread_t *)p_this; |
|---|
| 188 |
char *psz_chroma, *psz_output, *psz_verbosity; |
|---|
| 189 |
int i = 0; |
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 |
p_vout->p_sys = malloc( sizeof( vout_sys_t ) ); |
|---|
| 193 |
if( p_vout->p_sys == NULL ) |
|---|
| 194 |
return VLC_ENOMEM; |
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 |
p_vout->p_sys->p_image = image_HandlerCreate( p_vout ); |
|---|
| 198 |
for (i = 0; i < VOUT_MAX_PLANES; i++) |
|---|
| 199 |
p_vout->p_sys->p_cv_image[i] = NULL; |
|---|
| 200 |
p_vout->p_sys->p_proc_image = NULL; |
|---|
| 201 |
p_vout->p_sys->p_to_be_freed = NULL; |
|---|
| 202 |
p_vout->p_sys->i_cv_image_size = 0; |
|---|
| 203 |
|
|---|
| 204 |
p_vout->pf_init = Init; |
|---|
| 205 |
p_vout->pf_end = End; |
|---|
| 206 |
p_vout->pf_manage = NULL; |
|---|
| 207 |
p_vout->pf_render = Render; |
|---|
| 208 |
p_vout->pf_display = NULL; |
|---|
| 209 |
p_vout->pf_control = Control; |
|---|
| 210 |
|
|---|
| 211 |
|
|---|
| 212 |
if( !(psz_chroma = config_GetPsz( p_vout, "opencv-chroma" )) ) |
|---|
| 213 |
{ |
|---|
| 214 |
msg_Err( p_vout, "configuration variable %s empty, using 'grey'", |
|---|
| 215 |
"opencv-chroma" ); |
|---|
| 216 |
p_vout->p_sys->i_internal_chroma = GREY; |
|---|
| 217 |
} |
|---|
| 218 |
else |
|---|
| 219 |
{ |
|---|
| 220 |
if( !strcmp( psz_chroma, "input" ) ) |
|---|
| 221 |
p_vout->p_sys->i_internal_chroma = CINPUT; |
|---|
| 222 |
else if( !strcmp( psz_chroma, "I420" ) ) |
|---|
| 223 |
p_vout->p_sys->i_internal_chroma = GREY; |
|---|
| 224 |
else if( !strcmp( psz_chroma, "RGB32" ) ) |
|---|
| 225 |
p_vout->p_sys->i_internal_chroma = RGB; |
|---|
| 226 |
else |
|---|
| 227 |
{ |
|---|
| 228 |
msg_Err( p_vout, "no valid opencv-chroma provided, using 'grey'" ); |
|---|
| 229 |
p_vout->p_sys->i_internal_chroma = GREY; |
|---|
| 230 |
} |
|---|
| 231 |
} |
|---|
| 232 |
free( psz_chroma); |
|---|
| 233 |
|
|---|
| 234 |
if( !(psz_output = config_GetPsz( p_vout, "opencv-output" )) ) |
|---|
| 235 |
{ |
|---|
| 236 |
msg_Err( p_vout, "configuration variable %s empty, using 'input'", |
|---|
| 237 |
"opencv-output" ); |
|---|
| 238 |
p_vout->p_sys->i_wrapper_output = VINPUT; |
|---|
| 239 |
} |
|---|
| 240 |
else |
|---|
| 241 |
{ |
|---|
| 242 |
if( !strcmp( psz_output, "none" ) ) |
|---|
| 243 |
p_vout->p_sys->i_wrapper_output = NONE; |
|---|
| 244 |
else if( !strcmp( psz_output, "input" ) ) |
|---|
| 245 |
p_vout->p_sys->i_wrapper_output = VINPUT; |
|---|
| 246 |
else if( !strcmp( psz_output, "processed" ) ) |
|---|
| 247 |
p_vout->p_sys->i_wrapper_output = PROCESSED; |
|---|
| 248 |
else |
|---|
| 249 |
{ |
|---|
| 250 |
msg_Err( p_vout, "no valid opencv-output provided, using 'input'" ); |
|---|
| 251 |
p_vout->p_sys->i_wrapper_output = VINPUT; |
|---|
| 252 |
} |
|---|
| 253 |
} |
|---|
| 254 |
free( psz_output); |
|---|
| 255 |
|
|---|
| 256 |
if( !(psz_verbosity = config_GetPsz( p_vout, "opencv-verbosity" )) ) |
|---|
| 257 |
{ |
|---|
| 258 |
msg_Err( p_vout, "configuration variable %s empty, using 'input'", |
|---|
| 259 |
"opencv-verbosity" ); |
|---|
| 260 |
p_vout->p_sys->i_verbosity = VERB_ERROR; |
|---|
| 261 |
} |
|---|
| 262 |
else |
|---|
| 263 |
{ |
|---|
| 264 |
if( !strcmp( psz_verbosity, "error" ) ) |
|---|
| 265 |
p_vout->p_sys->i_verbosity = VERB_ERROR; |
|---|
| 266 |
else if( !strcmp( psz_verbosity, "warning" ) ) |
|---|
| 267 |
p_vout->p_sys->i_verbosity = VERB_WARN; |
|---|
| 268 |
else if( !strcmp( psz_verbosity, "debug" ) ) |
|---|
| 269 |
p_vout->p_sys->i_verbosity = VERB_DEBUG; |
|---|
| 270 |
else |
|---|
| 271 |
{ |
|---|
| 272 |
msg_Err( p_vout, "no valid opencv-verbosity provided, using 'error'" ); |
|---|
| 273 |
p_vout->p_sys->i_verbosity = VERB_ERROR; |
|---|
| 274 |
} |
|---|
| 275 |
} |
|---|
| 276 |
free( psz_verbosity); |
|---|
| 277 |
|
|---|
| 278 |
p_vout->p_sys->psz_inner_name = config_GetPsz( p_vout, "opencv-filter-name" ); |
|---|
| 279 |
|
|---|
| 280 |
p_vout->p_sys->f_scale = |
|---|
| 281 |
config_GetFloat( p_vout, "opencv-scale" ); |
|---|
| 282 |
|
|---|
| 283 |
if (p_vout->p_sys->i_verbosity > VERB_WARN) |
|---|
| 284 |
msg_Info(p_vout, "Configuration: opencv-scale: %f, opencv-chroma: %d, " |
|---|
| 285 |
"opencv-output: %d, opencv-verbosity %d, opencv-filter %s", |
|---|
| 286 |
p_vout->p_sys->f_scale, |
|---|
| 287 |
p_vout->p_sys->i_internal_chroma, |
|---|
| 288 |
p_vout->p_sys->i_wrapper_output, |
|---|
| 289 |
p_vout->p_sys->i_verbosity, |
|---|
| 290 |
p_vout->p_sys->psz_inner_name); |
|---|
| 291 |
|
|---|
| 292 |
return VLC_SUCCESS; |
|---|
| 293 |
} |
|---|
| 294 |
|
|---|
| 295 |
|
|---|
| 296 |
|
|---|
| 297 |
|
|---|
| 298 |
static int Init( vout_thread_t *p_vout ) |
|---|
| 299 |
{ |
|---|
| 300 |
int i_index; |
|---|
| 301 |
picture_t *p_pic; |
|---|
| 302 |
video_format_t fmt; |
|---|
| 303 |
vout_sys_t *p_sys = p_vout->p_sys; |
|---|
| 304 |
I_OUTPUTPICTURES = 0; |
|---|
| 305 |
|
|---|
| 306 |
|
|---|
| 307 |
memset( &fmt, 0, sizeof(video_format_t) ); |
|---|
| 308 |
p_vout->output.i_chroma = p_vout->render.i_chroma; |
|---|
| 309 |
p_vout->output.i_width = p_vout->render.i_width; |
|---|
| 310 |
p_vout->output.i_height = p_vout->render.i_height; |
|---|
| 311 |
p_vout->output.i_aspect = p_vout->render.i_aspect; |
|---|
| 312 |
p_vout->fmt_out = p_vout->fmt_in; |
|---|
| 313 |
|
|---|
| 314 |
fmt = p_vout->fmt_out; |
|---|
| 315 |
if (p_sys->i_wrapper_output == PROCESSED) |
|---|
| 316 |
{ |
|---|
| 317 |
fmt.i_width = fmt.i_width * p_sys->f_scale; |
|---|
| 318 |
fmt.i_height = fmt.i_height * p_sys->f_scale; |
|---|
| 319 |
fmt.i_visible_width = fmt.i_visible_width * p_sys->f_scale; |
|---|
| 320 |
fmt.i_visible_height = fmt.i_visible_height * p_sys->f_scale; |
|---|
| 321 |
fmt.i_x_offset = fmt.i_x_offset * p_sys->f_scale; |
|---|
| 322 |
fmt.i_y_offset = fmt.i_y_offset * p_sys->f_scale; |
|---|
| 323 |
|
|---|
| 324 |
if (p_sys->i_internal_chroma == GREY) |
|---|
| 325 |
fmt.i_chroma = VLC_FOURCC('I','4','2','0'); |
|---|
| 326 |
else if (p_sys->i_internal_chroma == RGB) |
|---|
| 327 |
fmt.i_chroma = VLC_FOURCC('R','V','3','2'); |
|---|
| 328 |
} |
|---|
| 329 |
|
|---|
| 330 |
|
|---|
| 331 |
|
|---|
| 332 |
p_sys->p_opencv = vlc_object_create( p_vout, sizeof(filter_t) ); |
|---|
| 333 |
vlc_object_attach( p_sys->p_opencv, p_vout ); |
|---|
| 334 |
|
|---|
| 335 |
if (p_vout->p_sys->psz_inner_name) |
|---|
| 336 |
p_sys->p_opencv->p_module = |
|---|
| 337 |
module_Need( p_sys->p_opencv, p_sys->psz_inner_name, 0, 0 ); |
|---|
| 338 |
|
|---|
| 339 |
if( !p_sys->p_opencv->p_module ) |
|---|
| 340 |
{ |
|---|
| 341 |
msg_Err( p_vout, "can't open internal opencv filter: %s", p_vout->p_sys->psz_inner_name ); |
|---|
| 342 |
p_vout->p_sys->psz_inner_name = NULL; |
|---|
| 343 |
vlc_object_detach( p_sys->p_opencv ); |
|---|
| 344 |
vlc_object_release( p_sys->p_opencv ); |
|---|
| 345 |
p_sys->p_opencv = NULL; |
|---|
| 346 |
} |
|---|
| 347 |
|
|---|
| 348 |
|
|---|
| 349 |
if (p_sys->i_verbosity > VERB_WARN) |
|---|
| 350 |
msg_Dbg( p_vout, "spawning the real video output" ); |
|---|
| 351 |
|
|---|
| 352 |
p_vout->p_sys->p_vout = vout_Create( p_vout, &fmt ); |
|---|
| 353 |
|
|---|
| 354 |
|
|---|
| 355 |
if( p_vout->p_sys->p_vout == NULL ) |
|---|
| 356 |
{ |
|---|
| 357 |
msg_Err( p_vout, "can't open vout, aborting" ); |
|---|
| 358 |
return VLC_EGENERIC; |
|---|
| 359 |
} |
|---|
| 360 |
|
|---|
| 361 |
ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES ); |
|---|
| 362 |
|
|---|
| 363 |
ADD_CALLBACKS( p_vout->p_sys->p_vout, SendEvents ); |
|---|
| 364 |
|
|---|
| 365 |
ADD_PARENT_CALLBACKS( SendEventsToChild ); |
|---|
| 366 |
|
|---|
| 367 |
return VLC_SUCCESS; |
|---|
| 368 |
} |
|---|
| 369 |
|
|---|
| 370 |
|
|---|
| 371 |
|
|---|
| 372 |
|
|---|
| 373 |
static void End( vout_thread_t *p_vout ) |
|---|
| 374 |
{ |
|---|
| 375 |
int i_index; |
|---|
| 376 |
|
|---|
| 377 |
DEL_PARENT_CALLBACKS( SendEventsToChild ); |
|---|
| 378 |
|
|---|
| 379 |
DEL_CALLBACKS( p_vout->p_sys->p_vout, SendEvents ); |
|---|
| 380 |
|
|---|
| 381 |
|
|---|
| 382 |
for( i_index = I_OUTPUTPICTURES ; i_index ; ) |
|---|
| 383 |
{ |
|---|
| 384 |
i_index--; |
|---|
| 385 |
free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig ); |
|---|
| 386 |
} |
|---|
| 387 |
|
|---|
| 388 |
if ( p_vout->p_sys->p_opencv ) |
|---|
| 389 |
{ |
|---|
| 390 |
|
|---|
| 391 |
if( p_vout->p_sys->p_opencv->p_module ) |
|---|
| 392 |
module_Unneed( p_vout->p_sys->p_opencv, p_vout->p_sys->p_opencv->p_module ); |
|---|
| 393 |
vlc_object_detach( p_vout->p_sys->p_opencv ); |
|---|
| 394 |
vlc_object_release( p_vout->p_sys->p_opencv ); |
|---|
| 395 |
p_vout->p_sys->p_opencv = NULL; |
|---|
| 396 |
} |
|---|
| 397 |
|
|---|
| 398 |
vout_CloseAndRelease( p_vout->p_sys->p_vout ); |
|---|
| 399 |
} |
|---|
| 400 |
|
|---|
| 401 |
|
|---|
| 402 |
|
|---|
| 403 |
|
|---|
| 404 |
|
|---|
| 405 |
|
|---|
| 406 |
static void Destroy( vlc_object_t *p_this ) |
|---|
| 407 |
{ |
|---|
| 408 |
vout_thread_t *p_vout = (vout_thread_t *)p_this; |
|---|
| 409 |
|
|---|
| 410 |
ReleaseImages(p_vout); |
|---|
| 411 |
|
|---|
| 412 |
if( p_vout->p_sys->p_image ) |
|---|
| 413 |
image_HandlerDelete( p_vout->p_sys->p_image ); |
|---|
| 414 |
|
|---|
| 415 |
free( p_vout->p_sys ); |
|---|
| 416 |
} |
|---|
| 417 |
|
|---|
| 418 |
|
|---|
| 419 |
|
|---|
| 420 |
|
|---|
| 421 |
static void ReleaseImages(vout_thread_t *p_vout) |
|---|
| 422 |
{ |
|---|
| 423 |
int i = 0; |
|---|
| 424 |
if (p_vout->p_sys->p_cv_image) |
|---|
| 425 |
{ |
|---|
| 426 |
for (i = 0; i < VOUT_MAX_PLANES; i++) |
|---|
| 427 |
{ |
|---|
| 428 |
if (p_vout->p_sys->p_cv_image[i]) |
|---|
| 429 |
cvReleaseImageHeader(&(p_vout->p_sys->p_cv_image[i])); |
|---|
| 430 |
p_vout->p_sys->p_cv_image[i] = NULL; |
|---|
| 431 |
} |
|---|
| 432 |
} |
|---|
| 433 |
p_vout->p_sys->i_cv_image_size = 0; |
|---|
| 434 |
|
|---|
| 435 |
|
|---|
| 436 |
if (p_vout->p_sys->p_to_be_freed) |
|---|
| 437 |
{ |
|---|
| 438 |
picture_Release( p_vout->p_sys->p_to_be_freed ); |
|---|
| 439 |
p_vout->p_sys->p_to_be_freed = NULL; |
|---|
| 440 |
} |
|---|
| 441 |
if (p_vout->p_sys->i_verbosity > VERB_WARN) |
|---|
| 442 |
msg_Dbg( p_vout, "images released" ); |
|---|
| 443 |
} |
|---|
| 444 |
|
|---|
| 445 |
|
|---|
| 446 |
|
|---|
| 447 |
|
|---|
| 448 |
|
|---|
| 449 |
|
|---|
| 450 |
|
|---|
| 451 |
static void VlcPictureToIplImage( vout_thread_t *p_vout, picture_t *p_in ) |
|---|
| 452 |
{ |
|---|
| 453 |
int planes = p_in->i_planes; |
|---|
| 454 |
|
|---|
| 455 |
CvSize sz = cvSize(abs(p_in->format.i_width), abs(p_in->format.i_height)); |
|---|
| 456 |
video_format_t fmt_out; |
|---|
| 457 |
clock_t start, finish; |
|---|
| 458 |
double duration; |
|---|
| 459 |
int i = 0; |
|---|
| 460 |
vout_sys_t* p_sys = p_vout->p_sys; |
|---|
| 461 |
|
|---|
| 462 |
memset( &fmt_out, 0, sizeof(video_format_t) ); |
|---|
| 463 |
|
|---|
| 464 |
start = clock(); |
|---|
| 465 |
|
|---|
| 466 |
|
|---|
| 467 |
if ((p_sys->f_scale != 1) || (p_sys->i_internal_chroma != CINPUT)) |
|---|
| 468 |
{ |
|---|
| 469 |
fmt_out = p_in->format; |
|---|
| 470 |
|
|---|
| 471 |
|
|---|
| 472 |
fmt_out.i_width = p_in->format.i_width * p_sys->f_scale; |
|---|
| 473 |
fmt_out.i_height = p_in->format.i_height * p_sys->f_scale; |
|---|
| 474 |
|
|---|
| 475 |
if (p_sys->i_internal_chroma == RGB) |
|---|
| 476 |
{ |
|---|
| 477 |
|
|---|
| 478 |
|
|---|
| 479 |
|
|---|
| 480 |
fmt_out.i_chroma = VLC_FOURCC('R','V','3','2'); |
|---|
| 481 |
} |
|---|
| 482 |
else if (p_sys->i_internal_chroma == GREY) |
|---|
| 483 |
{ |
|---|
| 484 |
|
|---|
| 485 |
|
|---|
| 486 |
fmt_out.i_chroma = VLC_FOURCC('I','4','2','0'); |
|---|
| 487 |
} |
|---|
| 488 |
|
|---|
| 489 |
|
|---|
| 490 |
p_sys->p_proc_image = image_Convert( p_sys->p_image, p_in, |
|---|
| 491 |
&(p_in->format), &fmt_out ); |
|---|
| 492 |
|
|---|
| 493 |
if (!p_sys->p_proc_image) |
|---|
| 494 |
{ |
|---|
| 495 |
msg_Err(p_vout, "can't convert (unsupported formats?), aborting..."); |
|---|
| 496 |
return; |
|---|
| 497 |
} |
|---|
| 498 |
|
|---|
| 499 |
p_sys->p_to_be_freed = p_sys->p_proc_image; |
|---|
| 500 |
|
|---|
| 501 |
} |
|---|
| 502 |
else |
|---|
| 503 |
{ |
|---|
| 504 |
|
|---|
| 505 |
p_sys->p_proc_image = p_in; |
|---|
| 506 |
} |
|---|
| 507 |
|
|---|
| 508 |
|
|---|
| 509 |
|
|---|
| 510 |
|
|---|
| 511 |
planes = p_sys->p_proc_image->i_planes; |
|---|
| 512 |
p_sys->i_cv_image_size = planes; |
|---|
| 513 |
for ( i = 0; i < planes; i++ ) |
|---|
| 514 |
{ |
|---|
| 515 |
sz = cvSize(abs(p_sys->p_proc_image->p[i].i_visible_pitch / |
|---|
| 516 |
p_sys->p_proc_image->p[i].i_pixel_pitch), |
|---|
| 517 |
abs(p_sys->p_proc_image->p[i].i_visible_lines)); |
|---|
| 518 |
|
|---|
| 519 |
p_sys->p_cv_image[i] = cvCreateImageHeader(sz, IPL_DEPTH_8U, |
|---|
| 520 |
p_sys->p_proc_image->p[i].i_pixel_pitch); |
|---|
| 521 |
|
|---|
| 522 |
cvSetData( p_sys->p_cv_image[i], |
|---|
| 523 |
(char*)(p_sys->p_proc_image->p[i].p_pixels), p_sys->p_proc_image->p[i].i_pitch ); |
|---|
| 524 |
} |
|---|
| 525 |
|
|---|
| 526 |
|
|---|
| 527 |
|
|---|
| 528 |
p_sys->hacked_pic.p_data_orig = p_sys->p_cv_image; |
|---|
| 529 |
p_sys->hacked_pic.i_planes = planes; |
|---|
| 530 |
p_sys->hacked_pic.format.i_chroma = fmt_out.i_chroma; |
|---|
| 531 |
|
|---|
| 532 |
|
|---|
| 533 |
finish = clock(); |
|---|
| 534 |
duration = (double)(finish - start) / CLOCKS_PER_SEC; |
|---|
| 535 |
if (p_sys->i_verbosity > VERB_WARN) |
|---|
| 536 |
msg_Dbg( p_vout, "VlcPictureToIplImageRgb took %2.4f seconds\n", duration ); |
|---|
| 537 |
} |
|---|
| 538 |
|
|---|
| 539 |
|
|---|
| 540 |
|
|---|
| 541 |
|
|---|
| 542 |
|
|---|
| 543 |
|
|---|
| 544 |
|
|---|
| 545 |
static void Render( vout_thread_t *p_vout, picture_t *p_pic ) |
|---|
| 546 |
{ |
|---|
| 547 |
picture_t *p_outpic = NULL; |
|---|
| 548 |
clock_t start, finish; |
|---|
| 549 |
double duration; |
|---|
| 550 |
|
|---|
| 551 |
while( ( p_outpic = vout_CreatePicture( p_vout->p_sys->p_vout, 0, 0, 0 ) ) |
|---|
| 552 |
== NULL ) |
|---|
| 553 |
{ |
|---|
| 554 |
if( !vlc_object_alive (p_vout) || p_vout->b_error ) |
|---|
| 555 |
{ return; } |
|---|
| 556 |
msleep( VOUT_OUTMEM_SLEEP ); |
|---|
| 557 |
} |
|---|
| 558 |
|
|---|
| 559 |
vout_LinkPicture( p_vout->p_sys->p_vout, p_outpic ); |
|---|
| 560 |
|
|---|
| 561 |
start = clock(); |
|---|
| 562 |
|
|---|
| 563 |
if (p_vout->p_sys->i_wrapper_output == VINPUT) |
|---|
| 564 |
{ |
|---|
| 565 |
|
|---|
| 566 |
|
|---|
| 567 |
|
|---|
| 568 |
vout_CopyPicture( p_vout, p_outpic, p_pic ); |
|---|
| 569 |
VlcPictureToIplImage( p_vout, p_pic); |
|---|
| 570 |
|
|---|
| 571 |
if ((p_vout->p_sys->p_opencv) && (p_vout->p_sys->p_opencv->p_module)) |
|---|
| 572 |
p_vout->p_sys->p_opencv->pf_video_filter( p_vout->p_sys->p_opencv, &(p_vout->p_sys->hacked_pic)); |
|---|
| 573 |
} |
|---|
| 574 |
else |
|---|
| 575 |
{ |
|---|
| 576 |
VlcPictureToIplImage( p_vout, p_pic); |
|---|
| 577 |
|
|---|
| 578 |
if ((p_vout->p_sys->p_opencv) && (p_vout->p_sys->p_opencv->p_module)) |
|---|
| 579 |
p_vout->p_sys->p_opencv->pf_video_filter( p_vout->p_sys->p_opencv, &(p_vout->p_sys->hacked_pic)); |
|---|
| 580 |
|
|---|
| 581 |
if ((p_vout->p_sys->p_proc_image) && (p_vout->p_sys->p_proc_image->p_data)) |
|---|
| 582 |
vout_CopyPicture( p_vout, p_outpic, p_vout->p_sys->p_proc_image ); |
|---|
| 583 |
} |
|---|
| 584 |
|
|---|
| 585 |
|
|---|
| 586 |
finish = clock(); |
|---|
| 587 |
duration = (double)(finish - start) / CLOCKS_PER_SEC; |
|---|
| 588 |
if (p_vout->p_sys->i_verbosity > VERB_WARN) |
|---|
| 589 |
msg_Dbg( p_vout, "Render took %2.4f seconds\n", duration ); |
|---|
| 590 |
|
|---|
| 591 |
ReleaseImages(p_vout); |
|---|
| 592 |
vout_DatePicture( p_vout->p_sys->p_vout, p_outpic, p_pic->date ); |
|---|
| 593 |
|
|---|
| 594 |
vout_UnlinkPicture( p_vout->p_sys->p_vout, p_outpic ); |
|---|
| 595 |
vout_DisplayPicture( p_vout->p_sys->p_vout, p_outpic ); |
|---|
| 596 |
} |
|---|
| 597 |
|
|---|
| 598 |
|
|---|
| 599 |
|
|---|
| 600 |
|
|---|
| 601 |
static int SendEvents( vlc_object_t *p_this, char const *psz_var, |
|---|
| 602 |
vlc_value_t oldval, vlc_value_t newval, void *p_data ) |
|---|
| 603 |
{ |
|---|
| 604 |
var_Set( (vlc_object_t *)p_data, psz_var, newval ); |
|---|
| 605 |
|
|---|
| 606 |
return VLC_SUCCESS; |
|---|
| 607 |
} |
|---|
| 608 |
|
|---|
| 609 |
|
|---|
| 610 |
|
|---|
| 611 |
|
|---|
| 612 |
static int SendEventsToChild( vlc_object_t *p_this, char const *psz_var, |
|---|
| 613 |
vlc_value_t oldval, vlc_value_t newval, void *p_data ) |
|---|
| 614 |
{ |
|---|
| 615 |
vout_thread_t *p_vout = (vout_thread_t *)p_this; |
|---|
| 616 |
var_Set( p_vout->p_sys->p_vout, psz_var, newval ); |
|---|
| 617 |
return VLC_SUCCESS; |
|---|
| 618 |
} |
|---|