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
|
/*
* common.cpp: A plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
* $Id$
*/
#include "common.h"
cMarkAdCommon::cMarkAdCommon(int RecvNumber,MarkAdContext *maContext)
{
macontext=maContext;
recvnumber=RecvNumber;
mark.Comment=NULL;
mark.Position=0;
}
cMarkAdCommon::~cMarkAdCommon()
{
ResetMark();
}
void cMarkAdCommon::ResetMark()
{
if (mark.Comment) free(mark.Comment);
mark.Comment=NULL;
mark.Position=0;
}
bool cMarkAdCommon::AddMark(int Position, const char *Comment)
{
if (!Comment) return false;
if (mark.Comment)
{
int oldlen=strlen(mark.Comment);
mark.Comment=(char *) realloc(mark.Comment,oldlen+10+strlen(Comment));
if (!mark.Comment)
{
mark.Position=0;
return false;
}
strcat(mark.Comment," [");
strcat(mark.Comment,Comment);
strcat(mark.Comment,"]");
}
else
{
mark.Comment=strdup(Comment);
}
mark.Position=Position;
return true;
}
void cMarkAdCommon::SetTimerMarks(int LastIFrame)
{
if (!macontext) return;
if ((time(NULL)>macontext->General.StartTime) && (!macontext->State.ContentStarted))
{
char *buf=NULL;
asprintf(&buf,"start of %s content (%i)",
macontext->General.ManualRecording ? "user" : "event",LastIFrame);
if (buf)
{
isyslog("markad [%i]: %s",recvnumber,buf);
AddMark(LastIFrame,buf);
free(buf);
}
macontext->State.ContentStarted=LastIFrame;
}
if ((time(NULL)>macontext->General.EndTime) &&
(macontext->State.ContentStarted) && (!macontext->State.ContentStopped))
{
char *buf=NULL;
asprintf(&buf,"stop of %s content (%i)",
macontext->General.ManualRecording ? "user" : "event",LastIFrame);
if (buf)
{
isyslog("markad [%i]: %s",recvnumber,buf);
AddMark(LastIFrame,buf);
free(buf);
}
macontext->State.ContentStopped=LastIFrame;
}
}
MarkAdMark *cMarkAdCommon::Process(int LastIFrame)
{
ResetMark();
if (!LastIFrame) return NULL;
SetTimerMarks(LastIFrame);
return &mark;
}
|