Skip to content

Commit

Permalink
Merge pull request #45 from ua0lnj/master
Browse files Browse the repository at this point in the history
Added geomerty settings for drm video output, -g WidthxHeight[@Rate].…
  • Loading branch information
ua0lnj authored Dec 15, 2024
2 parents 82e51ab + 25cf875 commit 292d029
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 43 deletions.
6 changes: 5 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Command line arguments

-r
switch modeline to refresh rate of played file
x11:
xrandr is needed for this to work. If no xrandr is detected during compile time
this feature will be deactivated.

Expand All @@ -102,7 +103,10 @@ Command line arguments
windowed mode, not fullscreen

-g geometry
You can set X11 geometry with this parameter [W[xH]][+-x+-y][/WS] or x:y.
x11:
You can set X11 geometry with this parameter [W[xH]][+-x+-y][/WS] or x:y.
drm:
You can set drm mode with this parameter [WxH][@R].
Resolution of OSD get from settings of output plugin (softhd*). OSD is scaled to video size.

-e drm device
Expand Down
2 changes: 1 addition & 1 deletion mpv.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "menu_options.h"
#include "mpv_service.h"

static const char *VERSION = "1.7.4"
static const char *VERSION = "1.8.0"
#ifdef GIT_REV
"-GIT" GIT_REV
#endif
Expand Down
107 changes: 66 additions & 41 deletions player.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,8 @@ void cMpvPlayer::PlayerGetDRM()
drmModeRes *resources;
drmModeConnector *connector;
drmModeModeInfo mode;
drmModeEncoder *encoder;
drmModeCrtc *crtc;

fd = open(drm_dev, O_RDWR);
if (fd < 0) return;
Expand All @@ -526,13 +528,22 @@ void cMpvPlayer::PlayerGetDRM()
}
}
if(i < resources->count_connectors) {
mode = connector->modes[0];

encoder = drmModeGetEncoder(fd, connector->encoder_id);
crtc = drmModeGetCrtc(fd, encoder->crtc_id);

mode = crtc->mode;
windowWidth = mode.hdisplay;
windowHeight = mode.vdisplay;

drmModeFreeCrtc(crtc);
drmModeFreeEncoder(encoder);
drmModeFreeConnector(connector);

} else
esyslog("No active connector found\n");

esyslog("windowWidth %d windowHeight %d\n",windowWidth,windowHeight);
drmModeFreeResources(resources);
close(fd);
}
Expand Down Expand Up @@ -580,8 +591,9 @@ void cMpvPlayer::PlayerStart()
check_error(mpv_set_option_string(hMpv, "drm-device", drm_dev));
}
#endif
//no geometry with drm
if (!drm_ctx) {
//window geometry with x11, drm-mode with drm
if (!drm_ctx) //x11
{
if (strcmp(MpvPluginConfig->Geometry.c_str(),""))
{
check_error(mpv_set_option_string(hMpv, "geometry", MpvPluginConfig->Geometry.c_str()));
Expand All @@ -590,11 +602,20 @@ void cMpvPlayer::PlayerStart()
sprintf(geo, "%dx%d+%d+%d", windowWidth, windowHeight, windowX, windowY);
check_error(mpv_set_option_string(hMpv, "geometry", geo));
}
if (!MpvPluginConfig->Windowed)
{
check_error(mpv_set_option_string(hMpv, "fullscreen", "yes"));
}
}
if (!MpvPluginConfig->Windowed)
#ifdef USE_DRM
else //drm
{
check_error(mpv_set_option_string(hMpv, "fullscreen", "yes"));
if (strcmp(MpvPluginConfig->Geometry.c_str(),""))
{
check_error(mpv_set_option_string(hMpv, "drm-mode", MpvPluginConfig->Geometry.c_str()));
}
}
#endif
if (MpvPluginConfig->UseDeinterlace)
{
set_deinterlace(hMpv);
Expand Down Expand Up @@ -949,51 +970,55 @@ bool cMpvPlayer::IsPlaylist(string File)

void cMpvPlayer::ChangeFrameRate(int TargetRate)
{
#ifdef USE_XRANDR
if (!MpvPluginConfig->RefreshRate || drm_ctx)
if (!MpvPluginConfig->RefreshRate)
return;

Display *Dpl;
int RefreshRate;
XRRScreenConfiguration *CurrInfo;
int RefreshRate = 0;
#ifdef USE_XRANDR
if (!drm_ctx)
{
Display *Dpl;

if (TargetRate == 25)
TargetRate = 50; // fix DVD audio and since this is doubled it's ok
XRRScreenConfiguration *CurrInfo;

if (TargetRate == 23)
TargetRate = 24;
if (TargetRate == 25)
TargetRate = 50; // fix DVD audio and since this is doubled it's ok

Dpl = XOpenDisplay(MpvPluginConfig->X11Display.c_str());
if (TargetRate == 23)
TargetRate = 24;

if (Dpl)
{
short *Rates;
int NumberOfRates;
SizeID CurrentSizeId;
Rotation CurrentRotation;
int RateFound = 0;

CurrInfo = XRRGetScreenInfo(Dpl, DefaultRootWindow(Dpl));
RefreshRate = XRRConfigCurrentRate(CurrInfo);
CurrentSizeId =
XRRConfigCurrentConfiguration(CurrInfo, &CurrentRotation);
Rates = XRRConfigRates(CurrInfo, CurrentSizeId, &NumberOfRates);

while (NumberOfRates-- > 0)
{
if (TargetRate == *Rates++)
RateFound = 1;
}
Dpl = XOpenDisplay(MpvPluginConfig->X11Display.c_str());

if ((RefreshRate != TargetRate) && (RateFound == 1))
if (Dpl)
{
OriginalFps = RefreshRate;
XRRSetScreenConfigAndRate(Dpl, CurrInfo, DefaultRootWindow(Dpl),
CurrentSizeId, CurrentRotation, TargetRate, CurrentTime);
}
short *Rates;
int NumberOfRates;
SizeID CurrentSizeId;
Rotation CurrentRotation;
int RateFound = 0;

CurrInfo = XRRGetScreenInfo(Dpl, DefaultRootWindow(Dpl));
RefreshRate = XRRConfigCurrentRate(CurrInfo);
CurrentSizeId =
XRRConfigCurrentConfiguration(CurrInfo, &CurrentRotation);
Rates = XRRConfigRates(CurrInfo, CurrentSizeId, &NumberOfRates);

while (NumberOfRates-- > 0)
{
if (TargetRate == *Rates++)
RateFound = 1;
}

if ((RefreshRate != TargetRate) && (RateFound == 1))
{
OriginalFps = RefreshRate;
XRRSetScreenConfigAndRate(Dpl, CurrInfo, DefaultRootWindow(Dpl),
CurrentSizeId, CurrentRotation, TargetRate, CurrentTime);
}

XRRFreeScreenConfigInfo(CurrInfo);
XCloseDisplay(Dpl);
XRRFreeScreenConfigInfo(CurrInfo);
XCloseDisplay(Dpl);
}
}
#endif
}
Expand Down

0 comments on commit 292d029

Please sign in to comment.