Skip to content

Commit

Permalink
Merge pull request #18 from ua0lnj/master
Browse files Browse the repository at this point in the history
OSD scales now. Version 1.2.0.
  • Loading branch information
ua0lnj authored Apr 14, 2021
2 parents 649fa5d + af711ac commit 2302de3
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 7 deletions.
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.1.1"
static const char *VERSION = "1.2.0"
#ifdef GIT_REV
"-GIT" GIT_REV
#endif
Expand Down
47 changes: 41 additions & 6 deletions osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ cMpvOsd::cMpvOsd(int Left, int Top, uint Level, cMpvPlayer *player)
{
Player = player;

int OsdAreaWidth = OsdWidth() + cOsd::Left();
int OsdAreaHeight = OsdHeight() + cOsd::Top();
// int OsdAreaWidth = OsdWidth() + cOsd::Left();
// int OsdAreaHeight = OsdHeight() + cOsd::Top();
int OsdAreaWidth = Player->WindowWidth();
int OsdAreaHeight = Player->WindowHeight();

fdOsd = open ("/tmp/vdr_mpv_osd", O_CREAT | O_RDWR, S_IWUSR | S_IRUSR);
if (fdOsd < 0)
{
Expand Down Expand Up @@ -87,20 +90,52 @@ void cMpvOsd::WriteToMpv(int sw, int sh, int x, int y, int w, int h, const uint8
int sy;
int pos;
char cmd[64];
double scalew, scaleh;

int osdWidth = 0;
int osdHeight = 0;
double Aspect;

cDevice::PrimaryDevice()->GetOsdSize(osdWidth, osdHeight, Aspect);

scalew = (double) Player->WindowWidth() / osdWidth;
scaleh = (double) Player->WindowHeight() / osdHeight;

for (sy = 0; sy < h; ++sy) {
for (sx = 0; sx < w; ++sx) {
pos=0;
pos = pos + ((sy+y)*sw*4);
pos = pos + ((sx+x)*4);
if (pos > (OsdWidth() + cOsd::Left())*(OsdHeight() + cOsd::Top())*4) break; //memory overflow prevention
pos = pos + 4 * Player->WindowWidth() * (int)(scaleh *(sy + y));
pos = pos + 4 * (int)(scalew *(sx + x));

if ((pos + 3) > (Player->WindowWidth() * Player->WindowHeight() * 4)) break; //memory overflow prevention
pOsd[pos + 0] = argb[(w * sy + sx) * 4 + 0];
pOsd[pos + 1] = argb[(w * sy + sx) * 4 + 1];
pOsd[pos + 2] = argb[(w * sy + sx) * 4 + 2];
pOsd[pos + 3] = argb[(w * sy + sx) * 4 + 3];

//upscale
if (scalew > 1.0) {
if ((pos + 7) > (Player->WindowWidth() * Player->WindowHeight() * 4)) break; //memory overflow prevention
pOsd[pos + 4] = argb[(w * sy + sx) * 4 + 0];
pOsd[pos + 5] = argb[(w * sy + sx) * 4 + 1];
pOsd[pos + 6] = argb[(w * sy + sx) * 4 + 2];
pOsd[pos + 7] = argb[(w * sy + sx) * 4 + 3];

if ((pos + 3 + 4 * Player->WindowWidth()) > (Player->WindowWidth() * Player->WindowHeight() * 4)) break; //memory overflow prevention
pOsd[pos + 0 + 4 * Player->WindowWidth()] = argb[(w * sy + sx) * 4 + 0];
pOsd[pos + 1 + 4 * Player->WindowWidth()] = argb[(w * sy + sx) * 4 + 1];
pOsd[pos + 2 + 4 * Player->WindowWidth()] = argb[(w * sy + sx) * 4 + 2];
pOsd[pos + 3 + 4 * Player->WindowWidth()] = argb[(w * sy + sx) * 4 + 3];

if ((pos + 7 + 4 * Player->WindowWidth()) > (Player->WindowWidth() * Player->WindowHeight() * 4)) break; //memory overflow prevention
pOsd[pos + 4 + 4 * Player->WindowWidth()] = argb[(w * sy + sx) * 4 + 0];
pOsd[pos + 5 + 4 * Player->WindowWidth()] = argb[(w * sy + sx) * 4 + 1];
pOsd[pos + 6 + 4 * Player->WindowWidth()] = argb[(w * sy + sx) * 4 + 2];
pOsd[pos + 7 + 4 * Player->WindowWidth()] = argb[(w * sy + sx) * 4 + 3];
}
}
}
snprintf (cmd, sizeof(cmd), "overlay-add 1 0 0 @%d 0 \"bgra\" %d %d %d\n", fdOsd, sw, sh, sw*4);
snprintf (cmd, sizeof(cmd), "overlay-add 1 0 0 @%d 0 \"bgra\" %d %d %d\n", fdOsd, Player->WindowWidth(), Player->WindowHeight(), Player->WindowWidth() * 4);
Player->SendCommand (cmd);
}

Expand Down
10 changes: 10 additions & 0 deletions player.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,22 @@ void cMpvPlayer::PlayerHideCursor()
}
//hide cursor
if (VideoWindow) {
xcb_get_geometry_cookie_t geocookie;
xcb_get_geometry_reply_t *georeply;

xcb_create_pixmap(Connect, 1, pixmap, VideoWindow, 1, 1);
cursor = xcb_generate_id(Connect);
xcb_create_cursor(Connect, cursor, pixmap, pixmap, 0, 0, 0, 0, 0, 0, 1, 1);

values[0] = cursor;
xcb_change_window_attributes(Connect, VideoWindow, XCB_CW_CURSOR, values);
//get geometry
geocookie = xcb_get_geometry(Connect, VideoWindow);
georeply = xcb_get_geometry_reply(Connect, geocookie, NULL);
if (georeply) {
windowWidth = georeply->width;
windowHeight = georeply->height;
}
}
}
free(reply);
Expand Down
4 changes: 4 additions & 0 deletions player.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class cMpvPlayer:public cPlayer
vector<string> ListFilenames; // filenames in playlist
vector<string> ListTitles ; // titles in playlist
int isNetwork; // detect network stream
int windowWidth;
int windowHeight;

public:
cMpvPlayer(string Filename, bool Shuffle=false);
Expand Down Expand Up @@ -122,6 +124,8 @@ class cMpvPlayer:public cPlayer
string ListTitle(unsigned int pos) {if (pos <= ListTitles.size() && pos) return ListTitles[pos-1]; else return ""; }
string ListFilename(unsigned int pos) {if (pos <= ListFilenames.size() && pos) return ListFilenames[pos-1]; else return ""; }
int NetworkPlay() { return isNetwork; }
int WindowWidth() { return windowWidth; }
int WindowHeight() { return windowHeight; }
};

#endif

0 comments on commit 2302de3

Please sign in to comment.