File: vps.cpp

package info (click to toggle)
vdr-plugin-markad 4.2.15-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,084 kB
  • sloc: cpp: 22,441; python: 613; makefile: 270; sh: 95
file content (108 lines) | stat: -rw-r--r-- 3,614 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
 * vps.cpp: A program for the Video Disk Recorder
 *
 * See the README file for copyright information and how to reach the author.
 *
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "vps.h"
#include "debug.h"


cVPS::cVPS(const char *directory) {
    if (!directory) return;

    char *fpath = nullptr;
    if (asprintf(&fpath, "%s/%s", directory, "markad.vps") == -1) return;
    FILE *mf;
    mf = fopen(fpath, "r+");
    if (!mf) {
        dsyslog("cVPS::cVPS(): %s not found", fpath);
        free(fpath);
        return;
    }
    free(fpath);

    char   *line       = nullptr;
    size_t length      = 0;
    char   typeVPS[16] = "";
    char   timeVPS[21] = "";
    int    offsetVPS   = 0;
    while (getline(&line, &length,mf) != -1) {
        sscanf(line, "%15s %20s %d", reinterpret_cast<char *>(&typeVPS), reinterpret_cast<char *>(&timeVPS), &offsetVPS);
        if (strcmp(typeVPS, "START:") == 0) {
            if (offsetVPS <= 5) esyslog("cVPS::cVPS(): VPS START       event at offset %5ds is invalid, maybe recording restart", offsetVPS);
            else {
                vpsStart = offsetVPS;
                dsyslog("cVPS::cVPS(): VPS START       event at offset %5ds", vpsStart);
            }
        };
        if (strcmp(typeVPS, "STOP:") == 0) {
            vpsStop = offsetVPS;
            dsyslog("cVPS::cVPS(): VPS STOP        event at offset %5ds", vpsStop);
        };
        if (strcmp(typeVPS, "PAUSE_START:") == 0) {
            vpsPauseStart = offsetVPS;
            dsyslog("cVPS::cVPS(): VPS PAUSE START event at offset %5ds", vpsPauseStart);
        };
        if (strcmp(typeVPS, "PAUSE_STOP:") == 0) {
            vpsPauseStop = offsetVPS;
            dsyslog("cVPS::cVPS(): VPS PAUSE STOP  event at offset %5ds", vpsPauseStop);
        };
        if (strcmp(typeVPS, "VPSTIMER=YES") == 0) {
            isVPStimer = true;
            dsyslog("cVPS::cVPS(): VPS controlled timer");
        }
    }
    if (line) free(line);
    fclose(mf);
}


cVPS::~cVPS() {
}


void cVPS::LogMatch(char *channel, cMarks *marks) const {
    if (!marks) return;
    if (!channel) return;

    int diffStart = -1;
    int diffStop  = -1;

    int startVPS = GetStart();
    if (startVPS >= 0) {
        const cMark *start = marks->GetFirst();
        if (start && ((start->type & 0x0F) == MT_START) && (start->type != MT_VPSSTART) && (start->oldType != MT_VPSSTART)) {
            int startMark = start->GetTimeSeconds();
            if (startMark >= 0) {
                diffStart = abs(startMark - startVPS);
                dsyslog("VPS start:      %s: event: %6ds, mark: %6ds, difference: %5ds", channel, startVPS, startMark, diffStart);
            }
        }
    }
    int stopVPS = GetStop();
    if (stopVPS >= 0) {
        const cMark *stop = marks->GetLast();
        if (stop && ((stop->type & 0x0F) == MT_STOP) && (stop->type != MT_VPSSTOP) && (stop->oldType != MT_VPSSTOP)) {
            int stopMark = stop->GetTimeSeconds();
            if (stopMark >= 0) {
                diffStop = abs(stopMark - stopVPS);
                dsyslog("VPS stop:       %s: event: %6ds, mark: %6ds, difference: %5ds", channel, stopVPS, stopMark, diffStop);
            }
        }
    }
    if ((diffStart >= 0) && (diffStop >= 0)) dsyslog("VPS difference: %s: %6ds", channel, diffStart + diffStop);
}

int cVPS::Length() const {
    if ((vpsStart >= 0) && (vpsStop >= 0)) {
        int length = vpsStop - vpsStart;
        if ((vpsPauseStart >= 0) && (vpsPauseStop >= 0)) length -= (vpsPauseStop - vpsPauseStart);
        return length;
    }
    else return -1;
}