📄 mosaic.c
字号:
&fmt_in, &fmt_out ); if( !p_converted ) { msg_Warn( p_filter, "image resizing and chroma conversion failed" ); continue; } } else { p_converted = p_es->p_picture; picture_Yield( p_converted ); fmt_in.i_width = fmt_out.i_width = p_converted->format.i_width; fmt_in.i_height = fmt_out.i_height = p_converted->format.i_height; fmt_in.i_chroma = fmt_out.i_chroma = p_converted->format.i_chroma; fmt_out.i_visible_width = fmt_out.i_width; fmt_out.i_visible_height = fmt_out.i_height; } p_region = p_spu->pf_make_region( VLC_OBJECT(p_filter), &fmt_out, p_converted ); if( !p_region ) { msg_Err( p_filter, "cannot allocate SPU region" ); p_filter->pf_sub_buffer_del( p_filter, p_spu ); vlc_mutex_unlock( &p_sys->lock ); vlc_mutex_unlock( p_sys->p_lock ); return p_spu; } /* HACK ALERT: let's fix the pointers to avoid picture duplication. * This is necessary because p_region->picture is not a pointer * as it ought to be. */ if( !p_sys->b_keep ) { free( p_converted ); } else { /* Keep a pointer to the original picture (and its refcount...). */ p_region->picture.p_sys = (picture_sys_t *)p_converted; p_region->picture.pf_release = MosaicReleasePicture; } if( p_es->i_x >= 0 && p_es->i_y >= 0 ) { p_region->i_x = p_es->i_x; p_region->i_y = p_es->i_y; } else if( p_sys->i_position == position_offsets ) { p_region->i_x = p_sys->pi_x_offsets[i_real_index]; p_region->i_y = p_sys->pi_y_offsets[i_real_index]; } else { if( fmt_out.i_width > col_inner_width || p_sys->b_ar || p_sys->b_keep ) { /* we don't have to center the video since it takes the whole rectangle area or it's larger than the rectangle */ p_region->i_x = p_sys->i_xoffset + i_col * ( p_sys->i_width / p_sys->i_cols ) + ( i_col * p_sys->i_borderw ) / p_sys->i_cols; } else { /* center the video in the dedicated rectangle */ p_region->i_x = p_sys->i_xoffset + i_col * ( p_sys->i_width / p_sys->i_cols ) + ( i_col * p_sys->i_borderw ) / p_sys->i_cols + ( col_inner_width - fmt_out.i_width ) / 2; } if( fmt_out.i_height > row_inner_height || p_sys->b_ar || p_sys->b_keep ) { /* we don't have to center the video since it takes the whole rectangle area or it's taller than the rectangle */ p_region->i_y = p_sys->i_yoffset + i_row * ( p_sys->i_height / p_sys->i_rows ) + ( i_row * p_sys->i_borderh ) / p_sys->i_rows; } else { /* center the video in the dedicated rectangle */ p_region->i_y = p_sys->i_yoffset + i_row * ( p_sys->i_height / p_sys->i_rows ) + ( i_row * p_sys->i_borderh ) / p_sys->i_rows + ( row_inner_height - fmt_out.i_height ) / 2; } } p_region->i_align = p_sys->i_align; p_region->i_alpha = p_es->i_alpha; if( p_region_prev == NULL ) { p_spu->p_region = p_region; } else { p_region_prev->p_next = p_region; } p_region_prev = p_region; } vlc_mutex_unlock( p_sys->p_lock ); vlc_mutex_unlock( &p_sys->lock ); return p_spu;}/****************************************************************************** Callback to update params on the fly*****************************************************************************/static int MosaicCallback( vlc_object_t *p_this, char const *psz_var, vlc_value_t oldval, vlc_value_t newval, void *p_data ){ VLC_UNUSED(oldval); filter_sys_t *p_sys = (filter_sys_t *) p_data;#define VAR_IS( a ) !strcmp( psz_var, CFG_PREFIX a ) if( VAR_IS( "alpha" ) ) { vlc_mutex_lock( &p_sys->lock ); msg_Dbg( p_this, "changing alpha from %d/255 to %d/255", p_sys->i_alpha, newval.i_int); p_sys->i_alpha = __MIN( __MAX( newval.i_int, 0 ), 255 ); vlc_mutex_unlock( &p_sys->lock ); } else if( VAR_IS( "height" ) ) { vlc_mutex_lock( &p_sys->lock ); msg_Dbg( p_this, "changing height from %dpx to %dpx", p_sys->i_height, newval.i_int ); p_sys->i_height = __MAX( newval.i_int, 0 ); vlc_mutex_unlock( &p_sys->lock ); } else if( VAR_IS( "width" ) ) { vlc_mutex_lock( &p_sys->lock ); msg_Dbg( p_this, "changing width from %dpx to %dpx", p_sys->i_width, newval.i_int ); p_sys->i_width = __MAX( newval.i_int, 0 ); vlc_mutex_unlock( &p_sys->lock ); } else if( VAR_IS( "xoffset" ) ) { vlc_mutex_lock( &p_sys->lock ); msg_Dbg( p_this, "changing x offset from %dpx to %dpx", p_sys->i_xoffset, newval.i_int ); p_sys->i_xoffset = __MAX( newval.i_int, 0 ); vlc_mutex_unlock( &p_sys->lock ); } else if( VAR_IS( "yoffset" ) ) { vlc_mutex_lock( &p_sys->lock ); msg_Dbg( p_this, "changing y offset from %dpx to %dpx", p_sys->i_yoffset, newval.i_int ); p_sys->i_yoffset = __MAX( newval.i_int, 0 ); vlc_mutex_unlock( &p_sys->lock ); } else if( VAR_IS( "align" ) ) { int i_old = 0, i_new = 0; vlc_mutex_lock( &p_sys->lock ); newval.i_int = __MIN( __MAX( newval.i_int, 0 ), 10 ); if( newval.i_int == 3 || newval.i_int == 7 ) newval.i_int = 5; while( pi_align_values[i_old] != p_sys->i_align ) i_old++; while( pi_align_values[i_new] != newval.i_int ) i_new++; msg_Dbg( p_this, "changing alignment from %d (%s) to %d (%s)", p_sys->i_align, ppsz_align_descriptions[i_old], newval.i_int, ppsz_align_descriptions[i_new] ); p_sys->i_align = newval.i_int; vlc_mutex_unlock( &p_sys->lock ); } else if( VAR_IS( "borderw" ) ) { vlc_mutex_lock( &p_sys->lock ); msg_Dbg( p_this, "changing border width from %dpx to %dpx", p_sys->i_borderw, newval.i_int ); p_sys->i_borderw = __MAX( newval.i_int, 0 ); vlc_mutex_unlock( &p_sys->lock ); } else if( VAR_IS( "borderh" ) ) { vlc_mutex_lock( &p_sys->lock ); msg_Dbg( p_this, "changing border height from %dpx to %dpx", p_sys->i_borderh, newval.i_int ); p_sys->i_borderh = __MAX( newval.i_int, 0 ); vlc_mutex_unlock( &p_sys->lock ); } else if( VAR_IS( "position" ) ) { if( newval.i_int > 2 || newval.i_int < 0 ) { msg_Err( p_this, "Position is either 0 (%s), 1 (%s) or 2 (%s)", ppsz_pos_descriptions[0], ppsz_pos_descriptions[1], ppsz_pos_descriptions[2] ); } else { vlc_mutex_lock( &p_sys->lock ); msg_Dbg( p_this, "changing position method from %d (%s) to %d (%s)", p_sys->i_position, ppsz_pos_descriptions[p_sys->i_position], newval.i_int, ppsz_pos_descriptions[newval.i_int]); p_sys->i_position = newval.i_int; vlc_mutex_unlock( &p_sys->lock ); } } else if( VAR_IS( "rows" ) ) { vlc_mutex_lock( &p_sys->lock ); msg_Dbg( p_this, "changing number of rows from %d to %d", p_sys->i_rows, newval.i_int ); p_sys->i_rows = __MAX( newval.i_int, 1 ); vlc_mutex_unlock( &p_sys->lock ); } else if( VAR_IS( "cols" ) ) { vlc_mutex_lock( &p_sys->lock ); msg_Dbg( p_this, "changing number of columns from %d to %d", p_sys->i_cols, newval.i_int ); p_sys->i_cols = __MAX( newval.i_int, 1 ); vlc_mutex_unlock( &p_sys->lock ); } else if( VAR_IS( "order" ) ) { char *psz_order; int i_index; vlc_mutex_lock( &p_sys->lock ); msg_Dbg( p_this, "Changing mosaic order to %s", newval.psz_string ); psz_order = newval.psz_string; while( p_sys->i_order_length-- ) { free( p_sys->ppsz_order[p_sys->i_order_length] ); } free( p_sys->ppsz_order ); p_sys->ppsz_order = NULL; if( *psz_order ) { char *psz_end = NULL; i_index = 0; do { psz_end = strchr( psz_order, ',' ); i_index++; p_sys->ppsz_order = realloc( p_sys->ppsz_order, i_index * sizeof(char *) ); p_sys->ppsz_order[i_index - 1] = strndup( psz_order, psz_end - psz_order ); psz_order = psz_end+1; } while( psz_end ); p_sys->i_order_length = i_index; } vlc_mutex_unlock( &p_sys->lock ); } else if( VAR_IS( "offsets" ) ) { vlc_mutex_lock( &p_sys->lock ); msg_Info( p_this, "Changing mosaic-offsets to %s", newval.psz_string ); if( p_sys->i_offsets_length != 0 ) { p_sys->i_offsets_length = 0; free( p_sys->pi_x_offsets ); free( p_sys->pi_y_offsets ); p_sys->pi_x_offsets = NULL; p_sys->pi_y_offsets = NULL; } mosaic_ParseSetOffsets( p_this, p_sys, newval.psz_string ); vlc_mutex_unlock( &p_sys->lock ); } else if( VAR_IS( "keep-aspect-ratio" ) ) { vlc_mutex_lock( &p_sys->lock ); if( newval.i_int ) { msg_Dbg( p_this, "keeping aspect ratio" ); p_sys->b_ar = 1; } else { msg_Dbg( p_this, "won't keep aspect ratio" ); p_sys->b_ar = 0; } vlc_mutex_unlock( &p_sys->lock ); } else if( VAR_IS( "keep-picture" ) ) { vlc_mutex_lock( &p_sys->lock ); p_sys->b_keep = newval.b_bool; if ( !p_sys->b_keep && !p_sys->p_image ) { p_sys->p_image = image_HandlerCreate( p_this ); } vlc_mutex_unlock( &p_sys->lock ); } return VLC_SUCCESS;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -