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
|
<%pre>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <tnt/httperror.h>
#include <tnt/httpheader.h>
#include <vdr/recording.h>
#include "setup.h"
#include "recman.h"
using namespace std;
using namespace vdrlive;
off_t RecSize(cRecording const * recording)
{
cFileName recFile(recording->FileName(), false, false);
off_t recSize = 0;
for (cUnbufferedFile *recData = recFile.Open(); recData; recData = recFile.NextFile()) {
struct stat buf;
if (0 == stat(recFile.Name(), &buf)) {
recSize += buf.st_size;
// dsyslog("LIVE: size of recording part %s is %ld", recFile.Name(), buf.st_size);
}
else {
esyslog("LIVE: can't determine size of %s", recFile.Name());
}
}
// dsyslog("LIVE: total size of %s is %ld", recording->FileName(), recSize);
return recSize;
}
</%pre>
<%args>
string recid;
</%args>
<%session scope="global">
bool logged_in(false);
</%session>
<%cpp>
//if (!logged_in && LiveSetup().UseAuth()) return reply.redirect("login.html");
cRecording const * recording = LiveRecordingsManager()->GetByMd5Hash(recid);
if (recording) {
reply.setKeepAliveHeader();
reply.setContentLengthHeader(RecSize(recording));
reply.setDirectMode();
cFileName recFile(recording->FileName(), false, false);
// dsyslog("LIVE: start send video data.");
for (cUnbufferedFile *recData = recFile.Open(); recData; recData = recFile.NextFile()) {
char buffer[KILOBYTE(16)];
ssize_t bytesRead = 0;
// dsyslog("LIVE: send file %s", recFile->Name());
while (0 < (bytesRead = recData->Read(buffer, sizeof(buffer)))) {
// dsyslog("LIVE: copy %zd bytes", bytesRead);
reply.out().write(buffer, bytesRead);
if (!reply.out()) {
return HTTP_GONE;
}
}
// dsyslog("LIVE: bytesRead = %zd", bytesRead);
if (bytesRead < 0) {
return HTTP_PARTIAL_CONTENT;
}
}
// dsyslog("LIVE: finished send video data.");
reply.out() << std::flush;
return HTTP_OK;
}
return DECLINED;
</%cpp>
|