📄 vout_intf.c
字号:
vlc_object_release( p_vout->p_parent_intf ); p_vout->p_parent_intf = NULL; } return VLC_SUCCESS; break; case VOUT_SNAPSHOT: p_vout->b_snapshot = VLC_TRUE; return VLC_SUCCESS; break; default: msg_Dbg( p_vout, "control query not supported" ); return VLC_EGENERIC; }}/***************************************************************************** * InitWindowSize: find the initial dimensions the video window should have. ***************************************************************************** * This function will check the "width", "height" and "zoom" config options and * will calculate the size that the video window should have. *****************************************************************************/static void InitWindowSize( vout_thread_t *p_vout, unsigned *pi_width, unsigned *pi_height ){ vlc_value_t val; int i_width, i_height; uint64_t ll_zoom;#define FP_FACTOR 1000 /* our fixed point factor */ var_Get( p_vout, "width", &val ); i_width = val.i_int; var_Get( p_vout, "height", &val ); i_height = val.i_int; var_Get( p_vout, "zoom", &val ); ll_zoom = (uint64_t)( FP_FACTOR * val.f_float ); if( i_width > 0 && i_height > 0) { *pi_width = (int)( i_width * ll_zoom / FP_FACTOR ); *pi_height = (int)( i_height * ll_zoom / FP_FACTOR ); goto initwsize_end; } else if( i_width > 0 ) { *pi_width = (int)( i_width * ll_zoom / FP_FACTOR ); *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom * p_vout->fmt_in.i_sar_den * i_width / p_vout->fmt_in.i_sar_num / FP_FACTOR / p_vout->fmt_in.i_visible_width ); goto initwsize_end; } else if( i_height > 0 ) { *pi_height = (int)( i_height * ll_zoom / FP_FACTOR ); *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom * p_vout->fmt_in.i_sar_num * i_height / p_vout->fmt_in.i_sar_den / FP_FACTOR / p_vout->fmt_in.i_visible_height ); goto initwsize_end; } if( p_vout->fmt_in.i_sar_num == 0 || p_vout->fmt_in.i_sar_den == 0 ) { msg_Warn( p_vout, "fucked up aspect" ); *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom / FP_FACTOR ); *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom /FP_FACTOR); } else if( p_vout->fmt_in.i_sar_num >= p_vout->fmt_in.i_sar_den ) { *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom * p_vout->fmt_in.i_sar_num / p_vout->fmt_in.i_sar_den / FP_FACTOR ); *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom / FP_FACTOR ); } else { *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom / FP_FACTOR ); *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom * p_vout->fmt_in.i_sar_den / p_vout->fmt_in.i_sar_num / FP_FACTOR ); }initwsize_end: msg_Dbg( p_vout, "window size: %dx%d", p_vout->i_window_width, p_vout->i_window_height );#undef FP_FACTOR}/***************************************************************************** * Object variables callbacks *****************************************************************************/static int ZoomCallback( vlc_object_t *p_this, char const *psz_cmd, vlc_value_t oldval, vlc_value_t newval, void *p_data ){ vout_thread_t *p_vout = (vout_thread_t *)p_this; InitWindowSize( p_vout, &p_vout->i_window_width, &p_vout->i_window_height ); vout_Control( p_vout, VOUT_SET_SIZE, p_vout->i_window_width, p_vout->i_window_height ); return VLC_SUCCESS;}static int CropCallback( vlc_object_t *p_this, char const *psz_cmd, vlc_value_t oldval, vlc_value_t newval, void *p_data ){ vout_thread_t *p_vout = (vout_thread_t *)p_this; int64_t i_aspect_num, i_aspect_den; unsigned int i_width, i_height; /* Restore defaults */ p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset; p_vout->fmt_in.i_visible_width = p_vout->fmt_render.i_visible_width; p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset; p_vout->fmt_in.i_visible_height = p_vout->fmt_render.i_visible_height; if( !strcmp( psz_cmd, "crop" ) ) { char *psz_end = NULL, *psz_parser = strchr( newval.psz_string, ':' ); if( psz_parser ) { /* We're using the 3:4 syntax */ i_aspect_num = strtol( newval.psz_string, &psz_end, 10 ); if( psz_end == newval.psz_string || !i_aspect_num ) goto crop_end; i_aspect_den = strtol( ++psz_parser, &psz_end, 10 ); if( psz_end == psz_parser || !i_aspect_den ) goto crop_end; i_width = p_vout->fmt_in.i_sar_den*p_vout->fmt_render.i_visible_height * i_aspect_num / i_aspect_den / p_vout->fmt_in.i_sar_num; i_height = p_vout->fmt_render.i_visible_width*p_vout->fmt_in.i_sar_num * i_aspect_den / i_aspect_num / p_vout->fmt_in.i_sar_den; if( i_width < p_vout->fmt_render.i_visible_width ) { p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset + (p_vout->fmt_render.i_visible_width - i_width) / 2; p_vout->fmt_in.i_visible_width = i_width; } else { p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset + (p_vout->fmt_render.i_visible_height - i_height) / 2; p_vout->fmt_in.i_visible_height = i_height; } } else { psz_parser = strchr( newval.psz_string, 'x' ); if( psz_parser ) { /* Maybe we're using the <width>x<height>+<left>+<top> syntax */ unsigned int i_crop_width, i_crop_height, i_crop_top, i_crop_left; i_crop_width = strtol( newval.psz_string, &psz_end, 10 ); if( psz_end != psz_parser ) goto crop_end; psz_parser = strchr( ++psz_end, '+' ); i_crop_height = strtol( psz_end, &psz_end, 10 ); if( psz_end != psz_parser ) goto crop_end; psz_parser = strchr( ++psz_end, '+' ); i_crop_left = strtol( psz_end, &psz_end, 10 ); if( psz_end != psz_parser ) goto crop_end; psz_end++; i_crop_top = strtol( psz_end, &psz_end, 10 ); if( *psz_end != '\0' ) goto crop_end; i_width = i_crop_width; p_vout->fmt_in.i_visible_width = i_width; i_height = i_crop_height; p_vout->fmt_in.i_visible_height = i_height; p_vout->fmt_in.i_x_offset = i_crop_left; p_vout->fmt_in.i_y_offset = i_crop_top; } else { /* Maybe we're using the <left>+<top>+<right>+<bottom> syntax */ unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right; psz_parser = strchr( newval.psz_string, '+' ); i_crop_left = strtol( newval.psz_string, &psz_end, 10 ); if( psz_end != psz_parser ) goto crop_end; psz_parser = strchr( ++psz_end, '+' ); i_crop_top = strtol( psz_end, &psz_end, 10 ); if( psz_end != psz_parser ) goto crop_end; psz_parser = strchr( ++psz_end, '+' ); i_crop_right = strtol( psz_end, &psz_end, 10 ); if( psz_end != psz_parser ) goto crop_end; psz_end++; i_crop_bottom = strtol( psz_end, &psz_end, 10 ); if( *psz_end != '\0' ) goto crop_end; i_width = p_vout->fmt_render.i_visible_width - i_crop_left - i_crop_right; p_vout->fmt_in.i_visible_width = i_width; i_height = p_vout->fmt_render.i_visible_height - i_crop_top - i_crop_bottom; p_vout->fmt_in.i_visible_height = i_height; p_vout->fmt_in.i_x_offset = i_crop_left; p_vout->fmt_in.i_y_offset = i_crop_top; } } } else if( !strcmp( psz_cmd, "crop-top" ) || !strcmp( psz_cmd, "crop-left" ) || !strcmp( psz_cmd, "crop-bottom" ) || !strcmp( psz_cmd, "crop-right" ) ) { unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right; i_crop_top = var_GetInteger( p_vout, "crop-top" ); i_crop_left = var_GetInteger( p_vout, "crop-left" ); i_crop_right = var_GetInteger( p_vout, "crop-right" ); i_crop_bottom = var_GetInteger( p_vout, "crop-bottom" ); i_width = p_vout->fmt_render.i_visible_width - i_crop_left - i_crop_right; p_vout->fmt_in.i_visible_width = i_width; i_height = p_vout->fmt_render.i_visible_height - i_crop_top - i_crop_bottom; p_vout->fmt_in.i_visible_height = i_height; p_vout->fmt_in.i_x_offset = i_crop_left; p_vout->fmt_in.i_y_offset = i_crop_top; } crop_end: InitWindowSize( p_vout, &p_vout->i_window_width, &p_vout->i_window_height ); p_vout->i_changes |= VOUT_CROP_CHANGE; msg_Dbg( p_vout, "cropping picture %ix%i to %i,%i,%ix%i", p_vout->fmt_in.i_width, p_vout->fmt_in.i_height, p_vout->fmt_in.i_x_offset, p_vout->fmt_in.i_y_offset, p_vout->fmt_in.i_visible_width, p_vout->fmt_in.i_visible_height ); return VLC_SUCCESS;}static int AspectCallback( vlc_object_t *p_this, char const *psz_cmd, vlc_value_t oldval, vlc_value_t newval, void *p_data ){ vout_thread_t *p_vout = (vout_thread_t *)p_this; unsigned int i_aspect_num, i_aspect_den, i_sar_num, i_sar_den; vlc_value_t val; char *psz_end, *psz_parser = strchr( newval.psz_string, ':' ); /* Restore defaults */ p_vout->fmt_in.i_sar_num = p_vout->fmt_render.i_sar_num; p_vout->fmt_in.i_sar_den = p_vout->fmt_render.i_sar_den; p_vout->fmt_in.i_aspect = p_vout->fmt_render.i_aspect; p_vout->render.i_aspect = p_vout->fmt_render.i_aspect; if( !psz_parser ) goto aspect_end; i_aspect_num = strtol( newval.psz_string, &psz_end, 10 ); if( psz_end == newval.psz_string || !i_aspect_num ) goto aspect_end; i_aspect_den = strtol( ++psz_parser, &psz_end, 10 ); if( psz_end == psz_parser || !i_aspect_den ) goto aspect_end; i_sar_num = i_aspect_num * p_vout->fmt_render.i_visible_height; i_sar_den = i_aspect_den * p_vout->fmt_render.i_visible_width; vlc_ureduce( &i_sar_num, &i_sar_den, i_sar_num, i_sar_den, 0 ); p_vout->fmt_in.i_sar_num = i_sar_num; p_vout->fmt_in.i_sar_den = i_sar_den; p_vout->fmt_in.i_aspect = i_aspect_num * VOUT_ASPECT_FACTOR / i_aspect_den; p_vout->render.i_aspect = p_vout->fmt_in.i_aspect; aspect_end: if( p_vout->i_par_num && p_vout->i_par_den ) { p_vout->fmt_in.i_sar_num *= p_vout->i_par_den; p_vout->fmt_in.i_sar_den *= p_vout->i_par_num; p_vout->fmt_in.i_aspect = p_vout->fmt_in.i_aspect * p_vout->i_par_den / p_vout->i_par_num; p_vout->render.i_aspect = p_vout->fmt_in.i_aspect; } p_vout->i_changes |= VOUT_ASPECT_CHANGE; vlc_ureduce( &i_aspect_num, &i_aspect_den, p_vout->fmt_in.i_aspect, VOUT_ASPECT_FACTOR, 0 ); msg_Dbg( p_vout, "new aspect-ratio %i:%i, sample aspect-ratio %i:%i", i_aspect_num, i_aspect_den, p_vout->fmt_in.i_sar_num, p_vout->fmt_in.i_sar_den ); var_Get( p_vout, "crop", &val ); return CropCallback( p_this, "crop", val, val, 0 ); return VLC_SUCCESS;}static int OnTopCallback( vlc_object_t *p_this, char const *psz_cmd, vlc_value_t oldval, vlc_value_t newval, void *p_data ){ vout_thread_t *p_vout = (vout_thread_t *)p_this; playlist_t *p_playlist; vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, newval.b_bool ); p_playlist = (playlist_t *)vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_PARENT ); if( p_playlist ) { /* Modify playlist as well because the vout might have to be restarted */ var_Create( p_playlist, "video-on-top", VLC_VAR_BOOL ); var_Set( p_playlist, "video-on-top", newval ); vlc_object_release( p_playlist ); } return VLC_SUCCESS;}static int FullscreenCallback( vlc_object_t *p_this, char const *psz_cmd, vlc_value_t oldval, vlc_value_t newval, void *p_data ){ vout_thread_t *p_vout = (vout_thread_t *)p_this; playlist_t *p_playlist; vlc_value_t val; p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE; p_playlist = (playlist_t *)vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_PARENT ); if( p_playlist ) { /* Modify playlist as well because the vout might have to be restarted */ var_Create( p_playlist, "fullscreen", VLC_VAR_BOOL ); var_Set( p_playlist, "fullscreen", newval ); vlc_object_release( p_playlist ); } /* Disable "always on top" in fullscreen mode */ var_Get( p_vout, "video-on-top", &val ); if( newval.b_bool && val.b_bool ) { val.b_bool = VLC_FALSE; vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, val.b_bool ); } else if( !newval.b_bool && val.b_bool ) { vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, val.b_bool ); } val.b_bool = VLC_TRUE; var_Set( p_vout, "intf-change", val ); return VLC_SUCCESS;}static int SnapshotCallback( vlc_object_t *p_this, char const *psz_cmd, vlc_value_t oldval, vlc_value_t newval, void *p_data ){ vout_thread_t *p_vout = (vout_thread_t *)p_this; vout_Control( p_vout, VOUT_SNAPSHOT ); return VLC_SUCCESS;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -