Skip to content

Commit

Permalink
Gestionar las prioridades de los directorios de grabación (dvlvidpref…
Browse files Browse the repository at this point in the history
…er.patch)
  • Loading branch information
bittor7x0 committed Jan 29, 2021
1 parent b06621f commit cf20c81
Show file tree
Hide file tree
Showing 5 changed files with 309 additions and 1 deletion.
44 changes: 44 additions & 0 deletions vdr-m7x0/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,14 @@ cSetup::cSetup(void)
LircRepeatFreq = 100;
LircRepeatTimeout = 500;
CapitalizeFilenames = 0; // default = disabled
UseVidPrefer = 0; // default = disabled
nVidPrefer = 1;
for (int zz = 1; zz < DVLVIDPREFER_MAX; zz++) {
VidPreferPrio[ zz ] = 50;
VidPreferSize[ zz ] = 100;
}
VidPreferSize[ 0 ] = 800;
VidPreferPrio[ 0 ] = 50;
}

cSetup& cSetup::operator= (const cSetup &s)
Expand Down Expand Up @@ -645,6 +653,32 @@ bool cSetup::Parse(const char *Name, const char *Value)
else if (!strcasecmp(Name, "LircRepeatFreq")) LircRepeatFreq = atoi(Value);
else if (!strcasecmp(Name, "LircRepeatTimeout")) LircRepeatTimeout = atoi(Value);
else if (!strcasecmp(Name, "CapitalizeFilenames")) CapitalizeFilenames = atoi(Value);
else if (!strcasecmp(Name, "UseVidPrefer")) UseVidPrefer = atoi(Value);
else if (!strcasecmp(Name, "nVidPrefer")) nVidPrefer = atoi(Value);
else if (strstr(Name, "VidPrefer") == Name) {
char *x = (char *)&Name[ strlen(Name) - 1 ];
int vN;

if (isdigit(*x) != 0) {
while (isdigit(*x) != 0)
x--;
x++;
}

vN = atoi(x);
if (vN < DVLVIDPREFER_MAX) {
if (strstr(Name, "VidPreferPrio") == Name) {
VidPreferPrio[ vN ] = atoi(Value);
if (VidPreferPrio[ vN ] > 99)
VidPreferPrio[ vN ] = 99;
}
else if (strstr(Name, "VidPreferSize") == Name) {
VidPreferSize[ vN ] = atoi(Value);
}
else
return false;
}
}
else
return false;
return true;
Expand Down Expand Up @@ -772,6 +806,16 @@ bool cSetup::Save(void)
Store("LircRepeatFreq", LircRepeatFreq);
Store("LircRepeatTimeout", LircRepeatTimeout);
Store("CapitalizeFilenames", CapitalizeFilenames);
Store ("UseVidPrefer", UseVidPrefer);
Store ("nVidPrefer", nVidPrefer);

char vidBuf[32];
for (int zz = 0; zz < nVidPrefer; zz++) {
sprintf(vidBuf, "VidPreferPrio%d", zz);
Store (vidBuf, VidPreferPrio[zz]);
sprintf(vidBuf, "VidPreferSize%d", zz);
Store (vidBuf, VidPreferSize[zz]);
}

Sort();

Expand Down
6 changes: 6 additions & 0 deletions vdr-m7x0/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
#define MINPRIORITY (-MAXPRIORITY)
#define MAXLIFETIME 99

#define DVLVIDPREFER_MAX 12

#define MINOSDWIDTH 480
#define MAXOSDWIDTH 672
#define MINOSDHEIGHT 324
Expand Down Expand Up @@ -328,6 +330,10 @@ class cSetup : public cConfig<cSetupLine> {
int LircRepeatFreq;
int LircRepeatTimeout;
int CapitalizeFilenames;
int UseVidPrefer; // 0 = VDR's default, 1 = use
int nVidPrefer;
int VidPreferPrio[DVLVIDPREFER_MAX];
int VidPreferSize[DVLVIDPREFER_MAX];
int __EndData__;
cSetup(void);
cSetup& operator= (const cSetup &s);
Expand Down
88 changes: 88 additions & 0 deletions vdr-m7x0/i18n.c
Original file line number Diff line number Diff line change
Expand Up @@ -10277,6 +10277,94 @@ const tI18nPhrase Phrases[] = {
"",
},
#endif
{ "Setup.Recording$Video directory policy",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"Política de directorio de grabación",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
},
{ "Setup.Recording$ Number of video directories", // note the leading blank!
"",
"",
"",
"",
"",
"",
"",
"",
"",
" Número de directorios de grabación",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
},
{ "Setup.Recording$ Video %d - Priority", // note the leading blanks!
"",
"",
"",
"",
"",
"",
"",
"",
"",
" Directorio %d - Prioridad",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
},
{ "Setup.Recording$ Video %d - Min. free MB", // note the leading blanks!
"",
"",
"",
"",
"",
"",
"",
"",
"",
" Directorio %d - Mín. MB libres",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
},
{ "Setup.Recording$Sort recordings by",
"Aufnahmen sortieren nach",
"",
Expand Down
45 changes: 45 additions & 0 deletions vdr-m7x0/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -3566,11 +3566,42 @@ class cMenuSetupRecord : public cMenuSetupBase {
const char *pauseKeyHandlingTexts[3];
const char *delTimeshiftRecTexts[3];
const char *RecordingsSortModeTexts[MAXSORTMODES];
void Set(void);
int tmpNVidPrefer,
tmpUseVidPrefer;
public:
cMenuSetupRecord(void);
eOSState ProcessKey(eKeys key);
};

cMenuSetupRecord::cMenuSetupRecord(void)
{
Set();
}

eOSState cMenuSetupRecord::ProcessKey(eKeys key)
{
eOSState s = cMenuSetupBase::ProcessKey(key);;

if (key != kNone) {
if (tmpNVidPrefer != data.nVidPrefer || tmpUseVidPrefer != data.UseVidPrefer) {
int cur = Current();

tmpNVidPrefer = data.nVidPrefer;
tmpUseVidPrefer = data.UseVidPrefer;

Clear();
Set();
SetCurrent(Get(cur));
Display();
cMenuSetupBase::ProcessKey(kNone);
return osContinue;
}
}
return s;
}

void cMenuSetupRecord::Set(void)
{
pauseKeyHandlingTexts[0] = tr("do not pause live video");
pauseKeyHandlingTexts[1] = tr("confirm pause live video");
Expand All @@ -3592,6 +3623,20 @@ cMenuSetupRecord::cMenuSetupRecord(void)
Add(new cMenuEditStraItem(tr("Setup.Recording$Pause key handling"), &data.PauseKeyHandling, 3, pauseKeyHandlingTexts));
Add(new cMenuEditIntItem( tr("Setup.Recording$Pause priority"), &data.PausePriority, 0, MAXPRIORITY));
Add(new cMenuEditIntItem( tr("Setup.Recording$Pause lifetime (d)"), &data.PauseLifetime, 0, MAXLIFETIME));
tmpNVidPrefer = data.nVidPrefer;
tmpUseVidPrefer = data.UseVidPrefer;

Add(new cMenuEditBoolItem(tr("Setup.Recording$Video directory policy"), &data.UseVidPrefer));
if (data.UseVidPrefer != 0) {
char tmp[ 64 ];
Add(new cMenuEditIntItem(tr("Setup.Recording$ Number of video directories"), &data.nVidPrefer, 1, DVLVIDPREFER_MAX));
for (int zz = 0; zz < data.nVidPrefer; zz++) {
sprintf(tmp, tr("Setup.Recording$ Video %d - Priority"), zz);
Add(new cMenuEditIntItem(tmp, &data.VidPreferPrio[ zz ], 0, 99));
sprintf(tmp, tr("Setup.Recording$ Video %d - Min. free MB"), zz);
Add(new cMenuEditIntItem(tmp, &data.VidPreferSize[ zz ], -1, 99999));
}
}
Add(new cMenuEditBoolItem(tr("Setup.Recording$Use episode name"), &data.UseSubtitle));
Add(new cMenuEditBoolItem(tr("Setup.Recording$Capitalize filenames"), &data.CapitalizeFilenames));
Add(new cMenuEditStraItem(tr("Setup.Recording$Delete timeshift recording"),&data.DelTimeshiftRec, 3, delTimeshiftRecTexts));
Expand Down
127 changes: 126 additions & 1 deletion vdr-m7x0/videodir.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class cVideoDirectory {
bool Next(void);
void Store(void);
const char *Adjust(const char *FileName);
char *GetVidPath(int nVid);
bool GetPreferedVideoDir(void);
bool IsVidDirOK(int nVid, int *freeMB = NULL);
};

cVideoDirectory::cVideoDirectory(void)
Expand Down Expand Up @@ -119,6 +122,7 @@ cUnbufferedFile *OpenVideoFile(const char *FileName, int Flags)
if ((Flags & O_CREAT) != 0) {
cVideoDirectory Dir;
if (Dir.IsDistributed()) {
if (Setup.UseVidPrefer == 0) {
// Find the directory with the most free space:
int MaxFree = Dir.FreeMB();
while (Dir.Next()) {
Expand All @@ -128,11 +132,13 @@ cUnbufferedFile *OpenVideoFile(const char *FileName, int Flags)
MaxFree = Free;
}
}
}
else Dir.GetPreferedVideoDir();
if (Dir.Stored()) {
ActualFileName = Dir.Adjust(FileName);
if (!MakeDirs(ActualFileName, false))
return NULL; // errno has been set by MakeDirs()
if (symlink(ActualFileName, FileName) < 0) {
if (strcmp(ActualFileName, FileName) != 0 && symlink(ActualFileName, FileName) < 0) {
LOG_ERROR_STR(FileName);
return NULL;
}
Expand Down Expand Up @@ -381,3 +387,122 @@ void RemoveEmptyVideoDirectories(void)
} while (Dir.Next());
}

// returns path to nVid'th video directory or NULL if not existing
char *cVideoDirectory::GetVidPath(int nVid)
{
char *b = strdup(VideoDirectory);
int l = strlen(b), di, n;

while (l-- > 0 && isdigit(b[ l ]));

l++;
di = strlen(b) - l;

// di == number of digits
n = atoi(&b[ l ]);
if (n != 0)
return NULL;

// add requested number to dir name
sprintf(&b[ l ], "%0*d", di, nVid);

if (DirectoryOk(b) == true)
return b;

free(b);
return NULL;
}

// checks if a video dir is 'valid'
bool cVideoDirectory::IsVidDirOK(int nVid, int *freeMB)
{
char *dn;
int fMB;

if (nVid >= Setup.nVidPrefer)
return false;

if (Setup.VidPreferSize[ nVid ] == -1)
return false;

dn = GetVidPath(nVid);
if (dn == NULL)
return false;

fMB = FreeDiskSpaceMB(dn, NULL);
if (freeMB != NULL)
*freeMB = fMB;

free(dn);

if (Setup.VidPreferSize[ nVid ] >= fMB)
return false;
return true;
}

// calculates which video dir to use
bool cVideoDirectory::GetPreferedVideoDir(void)
{
cVideoDirectory d;
int nDirs = 1,
vidUse = Setup.nVidPrefer;
int i, top, topFree, x;

if (name == NULL)
return(false);

// count available video dirs
while (d.Next() == true)
nDirs++;

if (vidUse > nDirs)
vidUse = nDirs;

// check for prefered video dir
for (i = 0, top = -1, topFree = 0; i < vidUse; i++) {
if (IsVidDirOK(i, &x) == true) {
if (top == -1) {
// nothing set yet, use first 'ok' dir
top = i;
topFree = x;
}
else {
// check if we got a higher priority
if (Setup.VidPreferPrio[ i ] >= Setup.VidPreferPrio[ top ]) {
top = i;
topFree = x;
}
// check if we got same priority but more space
else if (Setup.VidPreferPrio[ i ] == Setup.VidPreferPrio[ top ] && x >= topFree) {
top = i;
topFree = x;
}
}
}
}

if (top == -1) {
isyslog("VidPrefer: no prefered video directory could be determined!");

// something went wrong here...
// let VDR determine the video directory
int MaxFree = FreeMB();

while (Next()) {
int Free = FreeDiskSpaceMB(Name());

if (Free > MaxFree) {
Store();
MaxFree = Free;
}
}
}
else {
isyslog("VidPrefer: prefered video directory '%d' set.", top);
if (stored != NULL)
free(stored);
stored = GetVidPath(top);
}

return true;
}

0 comments on commit cf20c81

Please sign in to comment.