[vlc-commits] [Git][videolan/vlc][master] 6 commits: video_output: read the string aspect ratio as a vlc_rational_t
Steve Lhomme (@robUx4)
gitlab at videolan.org
Tue May 27 13:59:12 UTC 2025
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
5946854a by Steve Lhomme at 2025-05-27T13:31:01+00:00
video_output: read the string aspect ratio as a vlc_rational_t
- - - - -
e441d743 by Steve Lhomme at 2025-05-27T13:31:01+00:00
video_output: use a macro to check the aspect ratio is from the video source
- - - - -
324e303e by Steve Lhomme at 2025-05-27T13:31:01+00:00
vout_intf: check the default aspect ratio first
It's less heavy than calling sscanf() and is more likely to be the matching string.
- - - - -
9b973818 by Steve Lhomme at 2025-05-27T13:31:01+00:00
display: use a function to set the source aspect ratio
- - - - -
ff172d35 by Steve Lhomme at 2025-05-27T13:31:01+00:00
video_output: add special "fill" aspect ratio to fill the whole display
- - - - -
d2dcb5fa by Steve Lhomme at 2025-05-27T13:31:01+00:00
doc/libvlc: add fill mode aspect ratio in the cycling Aspect Ratio values
- - - - -
8 changed files:
- doc/libvlc/d3d11_player.cpp
- doc/libvlc/d3d9_player.c
- doc/libvlc/win_player.c
- include/vlc/libvlc_media_player.h
- src/video_output/display.c
- src/video_output/video_output.c
- src/video_output/vout_internal.h
- src/video_output/vout_intf.c
Changes:
=====================================
doc/libvlc/d3d11_player.cpp
=====================================
@@ -668,6 +668,8 @@ static LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARA
else if (strcmp(AspectRatio,"5:4")==0)
AspectRatio = "1:1";
else if (strcmp(AspectRatio,"1:1")==0)
+ AspectRatio = "fill";
+ else if (strcmp(AspectRatio,"fill")==0)
AspectRatio = NULL;
libvlc_video_set_aspect_ratio( ctx->p_mp, AspectRatio );
}
=====================================
doc/libvlc/d3d9_player.c
=====================================
@@ -343,6 +343,8 @@ static LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARA
else if (strcmp(AspectRatio,"5:4")==0)
AspectRatio = "1:1";
else if (strcmp(AspectRatio,"1:1")==0)
+ AspectRatio = "fill";
+ else if (strcmp(AspectRatio,"fill")==0)
AspectRatio = NULL;
libvlc_video_set_aspect_ratio( ctx->p_mp, AspectRatio );
}
=====================================
doc/libvlc/win_player.c
=====================================
@@ -82,6 +82,8 @@ static LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARA
else if (strcmp(AspectRatio,"5:4")==0)
AspectRatio = "1:1";
else if (strcmp(AspectRatio,"1:1")==0)
+ AspectRatio = "fill";
+ else if (strcmp(AspectRatio,"fill")==0)
AspectRatio = NULL;
libvlc_video_set_aspect_ratio( ctx->p_mediaplayer, AspectRatio );
}
=====================================
include/vlc/libvlc_media_player.h
=====================================
@@ -2054,7 +2054,7 @@ LIBVLC_API char *libvlc_video_get_aspect_ratio( libvlc_media_player_t *p_mi );
* Set new video aspect ratio.
*
* \param p_mi the media player
- * \param psz_aspect new video aspect-ratio or NULL to reset to source aspect ratio
+ * \param psz_aspect new video aspect-ratio, "fill" to fill the window or NULL to reset to source aspect ratio
* \note Invalid aspect ratios are ignored.
*/
LIBVLC_API void libvlc_video_set_aspect_ratio( libvlc_media_player_t *p_mi, const char *psz_aspect );
=====================================
src/video_output/display.c
=====================================
@@ -43,6 +43,8 @@
#include "display.h"
#include "vout_internal.h"
+static int UpdateSourceSAR(vout_display_t *, const video_format_t *);
+
static int vout_display_Control(vout_display_t *vd, int query)
{
return vd->ops->control(vd, query);
@@ -505,6 +507,8 @@ static int vout_UpdateSourceCrop(vout_display_t *vd)
osys->source.i_visible_height = bottom - top;
video_format_Print(VLC_OBJECT(vd), "CROPPED ", &osys->source);
+ err1 = UpdateSourceSAR(vd, vd->source);
+
bool place_changed = PlaceVideoInDisplay(osys);
err2 = vout_display_Control(vd, VOUT_DISPLAY_CHANGE_SOURCE_CROP);
@@ -573,10 +577,8 @@ void vout_UpdateDisplaySourceProperties(vout_display_t *vd, const video_format_t
vout_display_priv_t *osys = container_of(vd, vout_display_priv_t, display);
int err1 = VLC_SUCCESS, err2;
- if (osys->dar.den == VLC_DAR_FROM_SOURCE.den && osys->dar.num == VLC_DAR_FROM_SOURCE.num) {
- video_format_t fixed_src = *source;
- VoutFixFormatAR( &fixed_src );
- err2 = vout_SetSourceAspect(vd, fixed_src.i_sar_num, fixed_src.i_sar_den);
+ if (VLC_DAR_IS_FROM_SOURCE(osys->dar)) {
+ err2 = UpdateSourceSAR(vd, source);
if (err2 != VLC_SUCCESS)
err1 = err2;
}
@@ -606,6 +608,8 @@ void vout_display_SetSize(vout_display_t *vd, unsigned width, unsigned height)
osys->cfg.display.width = width;
osys->cfg.display.height = height;
+ err1 = UpdateSourceSAR(vd, vd->source);
+
bool place_changed = PlaceVideoInDisplay(osys);
err2 = vout_display_Control(vd, VOUT_DISPLAY_CHANGE_DISPLAY_SIZE);
@@ -664,27 +668,39 @@ void vout_SetDisplayZoom(vout_display_t *vd, unsigned num, unsigned den)
}
}
-void vout_SetDisplayAspect(vout_display_t *vd, unsigned dar_num, unsigned dar_den)
+static int UpdateSourceSAR(vout_display_t *vd, const video_format_t *source)
{
vout_display_priv_t *osys = container_of(vd, vout_display_priv_t, display);
- osys->dar = (vlc_rational_t){dar_num, dar_den};
-
- if (dar_num == VLC_DAR_FROM_SOURCE.num && dar_den == VLC_DAR_FROM_SOURCE.den)
- // use the source aspect ratio that we don't have yet
- // see vout_UpdateDisplaySourceProperties()
- return;
-
unsigned sar_num, sar_den;
- if (unlikely(dar_num == 0 || dar_den == 0)) {
+
+ if (VLC_DAR_IS_FROM_SOURCE(osys->dar)) {
+ video_format_t fixed_src = *source;
+ VoutFixFormatAR( &fixed_src );
+ sar_num = fixed_src.i_sar_num;
+ sar_den = fixed_src.i_sar_den;
+ } else if (VLC_DAR_IS_FILL_DISPLAY(osys->dar)) {
+ // trick vout_display_PlacePicture to fill the display
+ vlc_ureduce(&sar_num, &sar_den,
+ (uint64_t)osys->cfg.display.width * osys->source.i_visible_height,
+ (uint64_t)osys->cfg.display.height * osys->source.i_visible_width, 0);
+ } else if (unlikely(osys->dar.num == 0 || osys->dar.den == 0)) {
// bogus values should be filtered in GetAspectRatio()
vlc_assert_unreachable();
} else {
vlc_ureduce(&sar_num, &sar_den,
- (uint64_t)dar_num * osys->source.i_visible_height,
- (uint64_t)dar_den * osys->source.i_visible_width, 0);
+ (uint64_t)osys->dar.num * osys->source.i_visible_height,
+ (uint64_t)osys->dar.den * osys->source.i_visible_width, 0);
}
- int err1 = vout_SetSourceAspect(vd, sar_num, sar_den);
+ return vout_SetSourceAspect(vd, sar_num, sar_den);
+}
+
+void vout_SetDisplayAspect(vout_display_t *vd, unsigned dar_num, unsigned dar_den)
+{
+ vout_display_priv_t *osys = container_of(vd, vout_display_priv_t, display);
+ osys->dar = (vlc_rational_t){dar_num, dar_den};
+
+ int err1 = UpdateSourceSAR(vd, vd->source);
if (err1 != VLC_SUCCESS)
vout_display_Reset(vd);
}
=====================================
src/video_output/video_output.c
=====================================
@@ -2319,9 +2319,9 @@ static void vout_InitSource(vout_thread_sys_t *vout)
{
char *psz_ar = var_InheritString(&vout->obj, "aspect-ratio");
if (psz_ar) {
- unsigned num, den;
- if (GetAspectRatio(psz_ar, &num, &den))
- vout_SetAspectRatio(vout, num, den);
+ vlc_rational_t ar;
+ if (GetAspectRatio(psz_ar, &ar))
+ vout_SetAspectRatio(vout, ar.num, ar.den);
free(psz_ar);
}
=====================================
src/video_output/vout_internal.h
=====================================
@@ -32,6 +32,14 @@ typedef struct vlc_spu_highlight_t vlc_spu_highlight_t;
///< Use the aspect ratio from the source video format
#define VLC_DAR_FROM_SOURCE ((vlc_rational_t){0, 0})
+///< Use the whole display area to show the video
+#define VLC_DAR_FILL_DISPLAY ((vlc_rational_t){1, 0})
+
+#define VLC_DAR_IS_FROM_SOURCE(r) \
+ ((r).num == VLC_DAR_FROM_SOURCE.num && (r).den == VLC_DAR_FROM_SOURCE.den)
+
+#define VLC_DAR_IS_FILL_DISPLAY(r) \
+ ((r).num == VLC_DAR_FILL_DISPLAY.num && (r).den == VLC_DAR_FILL_DISPLAY.den)
/**
* Vout configuration
@@ -142,7 +150,7 @@ static inline bool vout_CropEqual(const struct vout_crop *a,
}
bool vout_ParseCrop(struct vout_crop *, const char *crop_str);
-bool GetAspectRatio(const char *ar_str, unsigned *num, unsigned *den);
+bool GetAspectRatio(const char *ar_str, vlc_rational_t *ar);
/* TODO to move them to vlc_vout.h */
void vout_ChangeFullscreen(vout_thread_t *, const char *id);
=====================================
src/video_output/vout_intf.c
=====================================
@@ -126,7 +126,7 @@ static const struct
static const struct
{
char psz_value[8];
- char psz_label[8];
+ char psz_label[12];
} p_aspect_ratio_values[] = {
{ "", N_("Default") },
{ "16:9", "16:9" },
@@ -137,6 +137,7 @@ static const struct
{ "235:100", "2.35:1" },
{ "239:100", "2.39:1" },
{ "5:4", "5:4" },
+ { "fill", N_("Fill Window") },
};
static const struct
@@ -610,16 +611,19 @@ static int CropBorderCallback(vlc_object_t *object, char const *cmd,
return VLC_SUCCESS;
}
-bool GetAspectRatio(const char *ar_str, unsigned *num, unsigned *den)
+bool GetAspectRatio(const char *ar_str, vlc_rational_t *ar)
{
- if (sscanf(ar_str, "%u:%u", num, den) == 2 &&
- (*num != 0) == (*den != 0))
+ if (*ar_str == '\0') {
+ *ar = VLC_DAR_FROM_SOURCE;
return true;
- else if (*ar_str == '\0') {
- *num = VLC_DAR_FROM_SOURCE.num;
- *den = VLC_DAR_FROM_SOURCE.den;
+ }
+ if (strcmp(ar_str,"fill")==0) {
+ *ar = VLC_DAR_FILL_DISPLAY;
return true;
}
+ if (sscanf(ar_str, "%u:%u", &ar->num, &ar->den) == 2 &&
+ (ar->num != 0) == (ar->den != 0))
+ return true;
return false;
}
@@ -628,10 +632,10 @@ static int AspectCallback( vlc_object_t *object, char const *cmd,
{
vout_thread_t *vout = (vout_thread_t *)object;
VLC_UNUSED(cmd); VLC_UNUSED(oldval); VLC_UNUSED(data);
- unsigned num, den;
+ vlc_rational_t ar;
- if (GetAspectRatio(newval.psz_string, &num, &den))
- vout_ChangeDisplayAspectRatio(vout, num, den);
+ if (GetAspectRatio(newval.psz_string, &ar))
+ vout_ChangeDisplayAspectRatio(vout, ar.num, ar.den);
return VLC_SUCCESS;
}
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/d0b1b4aa062ffdcd7644b765b541a9f07419c5bf...d2dcb5fa562b69787cd2410cd8e2670d268cbf25
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/d0b1b4aa062ffdcd7644b765b541a9f07419c5bf...d2dcb5fa562b69787cd2410cd8e2670d268cbf25
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list