Skip to content

Commit cf20c81

Browse files
committedJan 29, 2021
Gestionar las prioridades de los directorios de grabación (dvlvidprefer.patch)
1 parent b06621f commit cf20c81

File tree

5 files changed

+309
-1
lines changed

5 files changed

+309
-1
lines changed
 

‎vdr-m7x0/config.c

+44
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,14 @@ cSetup::cSetup(void)
428428
LircRepeatFreq = 100;
429429
LircRepeatTimeout = 500;
430430
CapitalizeFilenames = 0; // default = disabled
431+
UseVidPrefer = 0; // default = disabled
432+
nVidPrefer = 1;
433+
for (int zz = 1; zz < DVLVIDPREFER_MAX; zz++) {
434+
VidPreferPrio[ zz ] = 50;
435+
VidPreferSize[ zz ] = 100;
436+
}
437+
VidPreferSize[ 0 ] = 800;
438+
VidPreferPrio[ 0 ] = 50;
431439
}
432440

433441
cSetup& cSetup::operator= (const cSetup &s)
@@ -645,6 +653,32 @@ bool cSetup::Parse(const char *Name, const char *Value)
645653
else if (!strcasecmp(Name, "LircRepeatFreq")) LircRepeatFreq = atoi(Value);
646654
else if (!strcasecmp(Name, "LircRepeatTimeout")) LircRepeatTimeout = atoi(Value);
647655
else if (!strcasecmp(Name, "CapitalizeFilenames")) CapitalizeFilenames = atoi(Value);
656+
else if (!strcasecmp(Name, "UseVidPrefer")) UseVidPrefer = atoi(Value);
657+
else if (!strcasecmp(Name, "nVidPrefer")) nVidPrefer = atoi(Value);
658+
else if (strstr(Name, "VidPrefer") == Name) {
659+
char *x = (char *)&Name[ strlen(Name) - 1 ];
660+
int vN;
661+
662+
if (isdigit(*x) != 0) {
663+
while (isdigit(*x) != 0)
664+
x--;
665+
x++;
666+
}
667+
668+
vN = atoi(x);
669+
if (vN < DVLVIDPREFER_MAX) {
670+
if (strstr(Name, "VidPreferPrio") == Name) {
671+
VidPreferPrio[ vN ] = atoi(Value);
672+
if (VidPreferPrio[ vN ] > 99)
673+
VidPreferPrio[ vN ] = 99;
674+
}
675+
else if (strstr(Name, "VidPreferSize") == Name) {
676+
VidPreferSize[ vN ] = atoi(Value);
677+
}
678+
else
679+
return false;
680+
}
681+
}
648682
else
649683
return false;
650684
return true;
@@ -772,6 +806,16 @@ bool cSetup::Save(void)
772806
Store("LircRepeatFreq", LircRepeatFreq);
773807
Store("LircRepeatTimeout", LircRepeatTimeout);
774808
Store("CapitalizeFilenames", CapitalizeFilenames);
809+
Store ("UseVidPrefer", UseVidPrefer);
810+
Store ("nVidPrefer", nVidPrefer);
811+
812+
char vidBuf[32];
813+
for (int zz = 0; zz < nVidPrefer; zz++) {
814+
sprintf(vidBuf, "VidPreferPrio%d", zz);
815+
Store (vidBuf, VidPreferPrio[zz]);
816+
sprintf(vidBuf, "VidPreferSize%d", zz);
817+
Store (vidBuf, VidPreferSize[zz]);
818+
}
775819

776820
Sort();
777821

‎vdr-m7x0/config.h

+6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
#define MINPRIORITY (-MAXPRIORITY)
4646
#define MAXLIFETIME 99
4747

48+
#define DVLVIDPREFER_MAX 12
49+
4850
#define MINOSDWIDTH 480
4951
#define MAXOSDWIDTH 672
5052
#define MINOSDHEIGHT 324
@@ -328,6 +330,10 @@ class cSetup : public cConfig<cSetupLine> {
328330
int LircRepeatFreq;
329331
int LircRepeatTimeout;
330332
int CapitalizeFilenames;
333+
int UseVidPrefer; // 0 = VDR's default, 1 = use
334+
int nVidPrefer;
335+
int VidPreferPrio[DVLVIDPREFER_MAX];
336+
int VidPreferSize[DVLVIDPREFER_MAX];
331337
int __EndData__;
332338
cSetup(void);
333339
cSetup& operator= (const cSetup &s);

‎vdr-m7x0/i18n.c

+88
Original file line numberDiff line numberDiff line change
@@ -10277,6 +10277,94 @@ const tI18nPhrase Phrases[] = {
1027710277
"",
1027810278
},
1027910279
#endif
10280+
{ "Setup.Recording$Video directory policy",
10281+
"",
10282+
"",
10283+
"",
10284+
"",
10285+
"",
10286+
"",
10287+
"",
10288+
"",
10289+
"",
10290+
"Política de directorio de grabación",
10291+
"",
10292+
"",
10293+
"",
10294+
"",
10295+
"",
10296+
"",
10297+
"",
10298+
"",
10299+
"",
10300+
"",
10301+
},
10302+
{ "Setup.Recording$ Number of video directories", // note the leading blank!
10303+
"",
10304+
"",
10305+
"",
10306+
"",
10307+
"",
10308+
"",
10309+
"",
10310+
"",
10311+
"",
10312+
" Número de directorios de grabación",
10313+
"",
10314+
"",
10315+
"",
10316+
"",
10317+
"",
10318+
"",
10319+
"",
10320+
"",
10321+
"",
10322+
"",
10323+
},
10324+
{ "Setup.Recording$ Video %d - Priority", // note the leading blanks!
10325+
"",
10326+
"",
10327+
"",
10328+
"",
10329+
"",
10330+
"",
10331+
"",
10332+
"",
10333+
"",
10334+
" Directorio %d - Prioridad",
10335+
"",
10336+
"",
10337+
"",
10338+
"",
10339+
"",
10340+
"",
10341+
"",
10342+
"",
10343+
"",
10344+
"",
10345+
},
10346+
{ "Setup.Recording$ Video %d - Min. free MB", // note the leading blanks!
10347+
"",
10348+
"",
10349+
"",
10350+
"",
10351+
"",
10352+
"",
10353+
"",
10354+
"",
10355+
"",
10356+
" Directorio %d - Mín. MB libres",
10357+
"",
10358+
"",
10359+
"",
10360+
"",
10361+
"",
10362+
"",
10363+
"",
10364+
"",
10365+
"",
10366+
"",
10367+
},
1028010368
{ "Setup.Recording$Sort recordings by",
1028110369
"Aufnahmen sortieren nach",
1028210370
"",

‎vdr-m7x0/menu.c

+45
Original file line numberDiff line numberDiff line change
@@ -3566,11 +3566,42 @@ class cMenuSetupRecord : public cMenuSetupBase {
35663566
const char *pauseKeyHandlingTexts[3];
35673567
const char *delTimeshiftRecTexts[3];
35683568
const char *RecordingsSortModeTexts[MAXSORTMODES];
3569+
void Set(void);
3570+
int tmpNVidPrefer,
3571+
tmpUseVidPrefer;
35693572
public:
35703573
cMenuSetupRecord(void);
3574+
eOSState ProcessKey(eKeys key);
35713575
};
35723576

35733577
cMenuSetupRecord::cMenuSetupRecord(void)
3578+
{
3579+
Set();
3580+
}
3581+
3582+
eOSState cMenuSetupRecord::ProcessKey(eKeys key)
3583+
{
3584+
eOSState s = cMenuSetupBase::ProcessKey(key);;
3585+
3586+
if (key != kNone) {
3587+
if (tmpNVidPrefer != data.nVidPrefer || tmpUseVidPrefer != data.UseVidPrefer) {
3588+
int cur = Current();
3589+
3590+
tmpNVidPrefer = data.nVidPrefer;
3591+
tmpUseVidPrefer = data.UseVidPrefer;
3592+
3593+
Clear();
3594+
Set();
3595+
SetCurrent(Get(cur));
3596+
Display();
3597+
cMenuSetupBase::ProcessKey(kNone);
3598+
return osContinue;
3599+
}
3600+
}
3601+
return s;
3602+
}
3603+
3604+
void cMenuSetupRecord::Set(void)
35743605
{
35753606
pauseKeyHandlingTexts[0] = tr("do not pause live video");
35763607
pauseKeyHandlingTexts[1] = tr("confirm pause live video");
@@ -3592,6 +3623,20 @@ cMenuSetupRecord::cMenuSetupRecord(void)
35923623
Add(new cMenuEditStraItem(tr("Setup.Recording$Pause key handling"), &data.PauseKeyHandling, 3, pauseKeyHandlingTexts));
35933624
Add(new cMenuEditIntItem( tr("Setup.Recording$Pause priority"), &data.PausePriority, 0, MAXPRIORITY));
35943625
Add(new cMenuEditIntItem( tr("Setup.Recording$Pause lifetime (d)"), &data.PauseLifetime, 0, MAXLIFETIME));
3626+
tmpNVidPrefer = data.nVidPrefer;
3627+
tmpUseVidPrefer = data.UseVidPrefer;
3628+
3629+
Add(new cMenuEditBoolItem(tr("Setup.Recording$Video directory policy"), &data.UseVidPrefer));
3630+
if (data.UseVidPrefer != 0) {
3631+
char tmp[ 64 ];
3632+
Add(new cMenuEditIntItem(tr("Setup.Recording$ Number of video directories"), &data.nVidPrefer, 1, DVLVIDPREFER_MAX));
3633+
for (int zz = 0; zz < data.nVidPrefer; zz++) {
3634+
sprintf(tmp, tr("Setup.Recording$ Video %d - Priority"), zz);
3635+
Add(new cMenuEditIntItem(tmp, &data.VidPreferPrio[ zz ], 0, 99));
3636+
sprintf(tmp, tr("Setup.Recording$ Video %d - Min. free MB"), zz);
3637+
Add(new cMenuEditIntItem(tmp, &data.VidPreferSize[ zz ], -1, 99999));
3638+
}
3639+
}
35953640
Add(new cMenuEditBoolItem(tr("Setup.Recording$Use episode name"), &data.UseSubtitle));
35963641
Add(new cMenuEditBoolItem(tr("Setup.Recording$Capitalize filenames"), &data.CapitalizeFilenames));
35973642
Add(new cMenuEditStraItem(tr("Setup.Recording$Delete timeshift recording"),&data.DelTimeshiftRec, 3, delTimeshiftRecTexts));

‎vdr-m7x0/videodir.c

+126-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ class cVideoDirectory {
3838
bool Next(void);
3939
void Store(void);
4040
const char *Adjust(const char *FileName);
41+
char *GetVidPath(int nVid);
42+
bool GetPreferedVideoDir(void);
43+
bool IsVidDirOK(int nVid, int *freeMB = NULL);
4144
};
4245

4346
cVideoDirectory::cVideoDirectory(void)
@@ -119,6 +122,7 @@ cUnbufferedFile *OpenVideoFile(const char *FileName, int Flags)
119122
if ((Flags & O_CREAT) != 0) {
120123
cVideoDirectory Dir;
121124
if (Dir.IsDistributed()) {
125+
if (Setup.UseVidPrefer == 0) {
122126
// Find the directory with the most free space:
123127
int MaxFree = Dir.FreeMB();
124128
while (Dir.Next()) {
@@ -128,11 +132,13 @@ cUnbufferedFile *OpenVideoFile(const char *FileName, int Flags)
128132
MaxFree = Free;
129133
}
130134
}
135+
}
136+
else Dir.GetPreferedVideoDir();
131137
if (Dir.Stored()) {
132138
ActualFileName = Dir.Adjust(FileName);
133139
if (!MakeDirs(ActualFileName, false))
134140
return NULL; // errno has been set by MakeDirs()
135-
if (symlink(ActualFileName, FileName) < 0) {
141+
if (strcmp(ActualFileName, FileName) != 0 && symlink(ActualFileName, FileName) < 0) {
136142
LOG_ERROR_STR(FileName);
137143
return NULL;
138144
}
@@ -381,3 +387,122 @@ void RemoveEmptyVideoDirectories(void)
381387
} while (Dir.Next());
382388
}
383389

390+
// returns path to nVid'th video directory or NULL if not existing
391+
char *cVideoDirectory::GetVidPath(int nVid)
392+
{
393+
char *b = strdup(VideoDirectory);
394+
int l = strlen(b), di, n;
395+
396+
while (l-- > 0 && isdigit(b[ l ]));
397+
398+
l++;
399+
di = strlen(b) - l;
400+
401+
// di == number of digits
402+
n = atoi(&b[ l ]);
403+
if (n != 0)
404+
return NULL;
405+
406+
// add requested number to dir name
407+
sprintf(&b[ l ], "%0*d", di, nVid);
408+
409+
if (DirectoryOk(b) == true)
410+
return b;
411+
412+
free(b);
413+
return NULL;
414+
}
415+
416+
// checks if a video dir is 'valid'
417+
bool cVideoDirectory::IsVidDirOK(int nVid, int *freeMB)
418+
{
419+
char *dn;
420+
int fMB;
421+
422+
if (nVid >= Setup.nVidPrefer)
423+
return false;
424+
425+
if (Setup.VidPreferSize[ nVid ] == -1)
426+
return false;
427+
428+
dn = GetVidPath(nVid);
429+
if (dn == NULL)
430+
return false;
431+
432+
fMB = FreeDiskSpaceMB(dn, NULL);
433+
if (freeMB != NULL)
434+
*freeMB = fMB;
435+
436+
free(dn);
437+
438+
if (Setup.VidPreferSize[ nVid ] >= fMB)
439+
return false;
440+
return true;
441+
}
442+
443+
// calculates which video dir to use
444+
bool cVideoDirectory::GetPreferedVideoDir(void)
445+
{
446+
cVideoDirectory d;
447+
int nDirs = 1,
448+
vidUse = Setup.nVidPrefer;
449+
int i, top, topFree, x;
450+
451+
if (name == NULL)
452+
return(false);
453+
454+
// count available video dirs
455+
while (d.Next() == true)
456+
nDirs++;
457+
458+
if (vidUse > nDirs)
459+
vidUse = nDirs;
460+
461+
// check for prefered video dir
462+
for (i = 0, top = -1, topFree = 0; i < vidUse; i++) {
463+
if (IsVidDirOK(i, &x) == true) {
464+
if (top == -1) {
465+
// nothing set yet, use first 'ok' dir
466+
top = i;
467+
topFree = x;
468+
}
469+
else {
470+
// check if we got a higher priority
471+
if (Setup.VidPreferPrio[ i ] >= Setup.VidPreferPrio[ top ]) {
472+
top = i;
473+
topFree = x;
474+
}
475+
// check if we got same priority but more space
476+
else if (Setup.VidPreferPrio[ i ] == Setup.VidPreferPrio[ top ] && x >= topFree) {
477+
top = i;
478+
topFree = x;
479+
}
480+
}
481+
}
482+
}
483+
484+
if (top == -1) {
485+
isyslog("VidPrefer: no prefered video directory could be determined!");
486+
487+
// something went wrong here...
488+
// let VDR determine the video directory
489+
int MaxFree = FreeMB();
490+
491+
while (Next()) {
492+
int Free = FreeDiskSpaceMB(Name());
493+
494+
if (Free > MaxFree) {
495+
Store();
496+
MaxFree = Free;
497+
}
498+
}
499+
}
500+
else {
501+
isyslog("VidPrefer: prefered video directory '%d' set.", top);
502+
if (stored != NULL)
503+
free(stored);
504+
stored = GetVidPath(top);
505+
}
506+
507+
return true;
508+
}

0 commit comments

Comments
 (0)
Please sign in to comment.