vdr
2.0.4
Main Page
Namespaces
Classes
Files
File List
File Members
recording.h
Go to the documentation of this file.
1
/*
2
* recording.h: Recording file handling
3
*
4
* See the main source file 'vdr.c' for copyright information and
5
* how to reach the author.
6
*
7
* $Id: recording.h 2.46 2013/03/04 14:01:23 kls Exp $
8
*/
9
10
#ifndef __RECORDING_H
11
#define __RECORDING_H
12
13
#include <time.h>
14
#include "
channels.h
"
15
#include "
config.h
"
16
#include "
epg.h
"
17
#include "
thread.h
"
18
#include "
timers.h
"
19
#include "
tools.h
"
20
21
#define FOLDERDELIMCHAR '~'
22
23
extern
int
DirectoryPathMax
;
24
extern
int
DirectoryNameMax
;
25
extern
bool
DirectoryEncoding
;
26
extern
int
InstanceId
;
27
28
void
RemoveDeletedRecordings
(
void
);
29
void
AssertFreeDiskSpace
(
int
Priority = 0,
bool
Force =
false
);
34
35
class
cResumeFile
{
36
private
:
37
char
*
fileName
;
38
bool
isPesRecording
;
39
public
:
40
cResumeFile
(
const
char
*FileName,
bool
IsPesRecording);
41
~cResumeFile
();
42
int
Read
(
void
);
43
bool
Save
(
int
Index);
44
void
Delete
(
void
);
45
};
46
47
class
cRecordingInfo
{
48
friend
class
cRecording
;
49
private
:
50
tChannelID
channelID
;
51
char
*
channelName
;
52
const
cEvent
*
event
;
53
cEvent
*
ownEvent
;
54
char
*
aux
;
55
double
framesPerSecond
;
56
int
priority
;
57
int
lifetime
;
58
char
*
fileName
;
59
cRecordingInfo
(
const
cChannel
*Channel = NULL,
const
cEvent
*Event = NULL);
60
bool
Read
(FILE *f);
61
void
SetData
(
const
char
*
Title
,
const
char
*
ShortText
,
const
char
*
Description
);
62
void
SetAux
(
const
char
*
Aux
);
63
public
:
64
cRecordingInfo
(
const
char
*
FileName
);
65
~cRecordingInfo
();
66
tChannelID
ChannelID
(
void
)
const
{
return
channelID
; }
67
const
char
*
ChannelName
(
void
)
const
{
return
channelName
; }
68
const
cEvent
*
GetEvent
(
void
)
const
{
return
event
; }
69
const
char
*
Title
(
void
)
const
{
return
event
->Title(); }
70
const
char
*
ShortText
(
void
)
const
{
return
event
->ShortText(); }
71
const
char
*
Description
(
void
)
const
{
return
event
->Description(); }
72
const
cComponents
*
Components
(
void
)
const
{
return
event
->Components(); }
73
const
char
*
Aux
(
void
)
const
{
return
aux
; }
74
double
FramesPerSecond
(
void
)
const
{
return
framesPerSecond
; }
75
void
SetFramesPerSecond
(
double
FramesPerSecond
);
76
bool
Write
(FILE *f,
const
char
*Prefix =
""
)
const
;
77
bool
Read
(
void
);
78
bool
Write
(
void
)
const
;
79
};
80
81
class
cRecording
:
public
cListObject
{
82
friend
class
cRecordings
;
83
private
:
84
mutable
int
resume
;
85
mutable
char
*
titleBuffer
;
86
mutable
char
*
sortBufferName
;
87
mutable
char
*
sortBufferTime
;
88
mutable
char
*
fileName
;
89
mutable
char
*
name
;
90
mutable
int
fileSizeMB
;
91
mutable
int
numFrames
;
92
int
channel
;
93
int
instanceId
;
94
bool
isPesRecording
;
95
mutable
int
isOnVideoDirectoryFileSystem
;
// -1 = unknown, 0 = no, 1 = yes
96
double
framesPerSecond
;
97
cRecordingInfo
*
info
;
98
cRecording
(
const
cRecording
&);
// can't copy cRecording
99
cRecording
&
operator=
(
const
cRecording
&);
// can't assign cRecording
100
static
char
*
StripEpisodeName
(
char
*s,
bool
Strip);
101
char
*
SortName
(
void
)
const
;
102
void
ClearSortName
(
void
);
103
int
GetResume
(
void
)
const
;
104
time_t
start
;
105
int
priority
;
106
int
lifetime
;
107
time_t
deleted
;
108
public
:
109
cRecording
(
cTimer
*Timer,
const
cEvent
*Event);
110
cRecording
(
const
char
*
FileName
);
111
virtual
~cRecording
();
112
time_t
Start
(
void
)
const
{
return
start
; }
113
int
Priority
(
void
)
const
{
return
priority
; }
114
int
Lifetime
(
void
)
const
{
return
lifetime
; }
115
time_t
Deleted
(
void
)
const
{
return
deleted
; }
116
virtual
int
Compare
(
const
cListObject
&ListObject)
const
;
117
const
char
*
Name
(
void
)
const
{
return
name
; }
118
const
char
*
FileName
(
void
)
const
;
119
const
char
*
Title
(
char
Delimiter =
' '
,
bool
NewIndicator =
false
,
int
Level = -1)
const
;
120
const
cRecordingInfo
*
Info
(
void
)
const
{
return
info
; }
121
const
char
*
PrefixFileName
(
char
Prefix);
122
const
char
*
UpdateFileName
(
const
char
*
FileName
);
123
int
HierarchyLevels
(
void
)
const
;
124
void
ResetResume
(
void
)
const
;
125
double
FramesPerSecond
(
void
)
const
{
return
framesPerSecond
; }
126
int
NumFrames
(
void
)
const
;
129
int
LengthInSeconds
(
void
)
const
;
131
int
FileSizeMB
(
void
)
const
;
134
bool
IsNew
(
void
)
const
{
return
GetResume
() < 0; }
135
bool
IsEdited
(
void
)
const
;
136
bool
IsPesRecording
(
void
)
const
{
return
isPesRecording
; }
137
bool
IsOnVideoDirectoryFileSystem
(
void
)
const
;
138
void
ReadInfo
(
void
);
139
bool
WriteInfo
(
void
);
140
void
SetStartTime
(time_t
Start
);
148
bool
Delete
(
void
);
151
bool
Remove
(
void
);
154
bool
Undelete
(
void
);
158
};
159
160
class
cRecordings
:
public
cList
<cRecording>,
public
cThread
{
161
private
:
162
static
char
*
updateFileName
;
163
bool
deleted
;
164
time_t
lastUpdate
;
165
int
state
;
166
const
char
*
UpdateFileName
(
void
);
167
void
Refresh
(
bool
Foreground =
false
);
168
void
ScanVideoDir
(
const
char
*DirName,
bool
Foreground =
false
,
int
LinkLevel = 0);
169
protected
:
170
void
Action
(
void
);
171
public
:
172
cRecordings
(
bool
Deleted =
false
);
173
virtual
~cRecordings
();
174
bool
Load
(
void
) {
return
Update
(
true
); }
178
bool
Update
(
bool
Wait =
false
);
184
void
TouchUpdate
(
void
);
188
bool
NeedsUpdate
(
void
);
189
void
ChangeState
(
void
) {
state
++; }
190
bool
StateChanged
(
int
&State);
191
void
ResetResume
(
const
char
*ResumeFileName = NULL);
192
void
ClearSortNames
(
void
);
193
cRecording
*
GetByName
(
const
char
*FileName);
194
void
AddByName
(
const
char
*FileName,
bool
TriggerUpdate =
true
);
195
void
DelByName
(
const
char
*FileName,
bool
RemoveRecording =
true
);
196
void
UpdateByName
(
const
char
*FileName);
197
int
TotalFileSizeMB
(
void
);
198
double
MBperMinute
(
void
);
201
};
202
203
extern
cRecordings
Recordings
;
204
extern
cRecordings
DeletedRecordings
;
205
206
#define DEFAULTFRAMESPERSECOND 25.0
207
208
class
cMark
:
public
cListObject
{
209
friend
class
cMarks
;
// for sorting
210
private
:
211
double
framesPerSecond
;
212
int
position
;
213
cString
comment
;
214
public
:
215
cMark
(
int
Position
= 0,
const
char
*
Comment
= NULL,
double
FramesPerSecond =
DEFAULTFRAMESPERSECOND
);
216
virtual
~cMark
();
217
int
Position
(
void
)
const
{
return
position
; }
218
const
char
*
Comment
(
void
)
const
{
return
comment
; }
219
void
SetPosition
(
int
Position
) {
position
=
Position
; }
220
void
SetComment
(
const
char
*
Comment
) {
comment
=
Comment
; }
221
cString
ToText
(
void
);
222
bool
Parse
(
const
char
*s);
223
bool
Save
(FILE *f);
224
};
225
226
class
cMarks
:
public
cConfig
<cMark> {
227
private
:
228
cString
recordingFileName
;
229
cString
fileName
;
230
double
framesPerSecond
;
231
bool
isPesRecording
;
232
time_t
nextUpdate
;
233
time_t
lastFileTime
;
234
time_t
lastChange
;
235
public
:
236
bool
Load
(
const
char
*RecordingFileName,
double
FramesPerSecond =
DEFAULTFRAMESPERSECOND
,
bool
IsPesRecording =
false
);
237
bool
Update
(
void
);
238
bool
Save
(
void
);
239
void
Align
(
void
);
240
void
Sort
(
void
);
241
void
Add
(
int
Position);
242
cMark
*
Get
(
int
Position);
243
cMark
*
GetPrev
(
int
Position);
244
cMark
*
GetNext
(
int
Position);
245
cMark
*
GetNextBegin
(
cMark
*EndMark = NULL);
249
cMark
*
GetNextEnd
(
cMark
*BeginMark);
252
int
GetNumSequences
(
void
);
258
};
259
260
#define RUC_BEFORERECORDING "before"
261
#define RUC_AFTERRECORDING "after"
262
#define RUC_EDITEDRECORDING "edited"
263
#define RUC_DELETERECORDING "deleted"
264
265
class
cRecordingUserCommand
{
266
private
:
267
static
const
char
*
command
;
268
public
:
269
static
void
SetCommand
(
const
char
*Command) {
command
= Command; }
270
static
void
InvokeCommand
(
const
char
*State,
const
char
*RecordingFileName,
const
char
*SourceFileName = NULL);
271
};
272
273
// The maximum size of a single frame (up to HDTV 1920x1080):
274
#define MAXFRAMESIZE (KILOBYTE(1024) / TS_SIZE * TS_SIZE) // multiple of TS_SIZE to avoid breaking up TS packets
275
276
// The maximum file size is limited by the range that can be covered
277
// with a 40 bit 'unsigned int', which is 1TB. The actual maximum value
278
// used is 6MB below the theoretical maximum, to have some safety (the
279
// actual file size may be slightly higher because we stop recording only
280
// before the next independent frame, to have a complete Group Of Pictures):
281
#define MAXVIDEOFILESIZETS 1048570 // MB
282
#define MAXVIDEOFILESIZEPES 2000 // MB
283
#define MINVIDEOFILESIZE 100 // MB
284
#define MAXVIDEOFILESIZEDEFAULT MAXVIDEOFILESIZEPES
285
286
struct
tIndexTs
;
287
class
cIndexFileGenerator
;
288
289
class
cIndexFile
{
290
private
:
291
int
f
;
292
cString
fileName
;
293
int
size
,
last
;
294
tIndexTs
*
index
;
295
bool
isPesRecording
;
296
cResumeFile
resumeFile
;
297
cIndexFileGenerator
*
indexFileGenerator
;
298
cMutex
mutex
;
299
void
ConvertFromPes
(
tIndexTs
*IndexTs,
int
Count);
300
void
ConvertToPes
(
tIndexTs
*IndexTs,
int
Count);
301
bool
CatchUp
(
int
Index = -1);
302
public
:
303
cIndexFile
(
const
char
*FileName,
bool
Record,
bool
IsPesRecording =
false
,
bool
PauseLive =
false
);
304
~cIndexFile
();
305
bool
Ok
(
void
) {
return
index
!= NULL; }
306
bool
Write
(
bool
Independent, uint16_t FileNumber, off_t FileOffset);
307
bool
Get
(
int
Index, uint16_t *FileNumber, off_t *FileOffset,
bool
*Independent = NULL,
int
*Length = NULL);
308
int
GetNextIFrame
(
int
Index,
bool
Forward, uint16_t *FileNumber = NULL, off_t *FileOffset = NULL,
int
*Length = NULL);
309
int
GetClosestIFrame
(
int
Index);
314
int
Get
(uint16_t FileNumber, off_t FileOffset);
315
int
Last
(
void
) {
CatchUp
();
return
last
; }
317
int
GetResume
(
void
) {
return
resumeFile
.
Read
(); }
318
bool
StoreResume
(
int
Index) {
return
resumeFile
.
Save
(Index); }
319
bool
IsStillRecording
(
void
);
320
void
Delete
(
void
);
321
static
int
GetLength
(
const
char
*FileName,
bool
IsPesRecording =
false
);
324
static
cString
IndexFileName
(
const
char
*FileName,
bool
IsPesRecording);
325
};
326
327
class
cFileName
{
328
private
:
329
cUnbufferedFile
*
file
;
330
uint16_t
fileNumber
;
331
char
*
fileName
, *
pFileNumber
;
332
bool
record
;
333
bool
blocking
;
334
bool
isPesRecording
;
335
public
:
336
cFileName
(
const
char
*FileName,
bool
Record,
bool
Blocking =
false
,
bool
IsPesRecording =
false
);
337
~cFileName
();
338
const
char
*
Name
(
void
) {
return
fileName
; }
339
uint16_t
Number
(
void
) {
return
fileNumber
; }
340
bool
GetLastPatPmtVersions
(
int
&PatVersion,
int
&PmtVersion);
341
cUnbufferedFile
*
Open
(
void
);
342
void
Close
(
void
);
343
cUnbufferedFile
*
SetOffset
(
int
Number
, off_t Offset = 0);
// yes, Number is int for easier internal calculating
344
cUnbufferedFile
*
NextFile
(
void
);
345
};
346
347
cString
IndexToHMSF
(
int
Index,
bool
WithFrame =
false
,
double
FramesPerSecond =
DEFAULTFRAMESPERSECOND
);
348
// Converts the given index to a string, optionally containing the frame number.
349
int
HMSFToIndex
(
const
char
*HMSF,
double
FramesPerSecond =
DEFAULTFRAMESPERSECOND
);
350
// Converts the given string (format: "hh:mm:ss.ff") to an index.
351
int
SecondsToFrames
(
int
Seconds,
double
FramesPerSecond =
DEFAULTFRAMESPERSECOND
);
352
// Returns the number of frames corresponding to the given number of seconds.
353
354
int
ReadFrame
(
cUnbufferedFile
*f,
uchar
*b,
int
Length,
int
Max);
355
356
char
*
ExchangeChars
(
char
*s,
bool
ToFileSystem);
357
// Exchanges the characters in the given string to or from a file system
358
// specific representation (depending on ToFileSystem). The given string will
359
// be modified and may be reallocated if more space is needed. The return
360
// value points to the resulting string, which may be different from s.
361
362
bool
GenerateIndex
(
const
char
*FileName);
363
364
enum
eRecordingsSortMode
{
rsmName
,
rsmTime
};
365
extern
eRecordingsSortMode
RecordingsSortMode
;
366
bool
HasRecordingsSortMode
(
const
char
*Directory);
367
void
GetRecordingsSortMode
(
const
char
*Directory);
368
void
SetRecordingsSortMode
(
const
char
*Directory,
eRecordingsSortMode
SortMode);
369
void
IncRecordingsSortMode
(
const
char
*Directory);
370
371
#endif //__RECORDING_H
372
Generated by
1.8.3.1