File: recstream.ecpp

package info (click to toggle)
vdr-plugin-live 3.5.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,128 kB
  • sloc: cpp: 12,995; javascript: 3,234; makefile: 241; sh: 40
file content (76 lines) | stat: -rw-r--r-- 2,206 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
<%pre>

#include <recman.h>
#include <tntfeatures.h>

using namespace vdrlive;

off_t RecSize(cFileName &recFile)
{
  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>
    std::string recid;
</%args>
<%session scope="global">
bool logged_in(false);
</%session>
<%cpp>
std::string recording_FileName;
bool recording_IsPesRecording = false;
{
  LOCK_RECORDINGS_READ;
  const cRecording *recording = RecordingsManager::GetByHash(recid, Recordings);
  if (recording) {
    recording_FileName = recording->FileName();
    recording_IsPesRecording = recording->IsPesRecording();
  }
}
if (!recording_FileName.empty() ) {
  cFileName recFile_l(recording_FileName.c_str(), false, false, recording_IsPesRecording);
  reply.setContentType("video/mpeg");
  reply.setKeepAliveHeader();
  reply.setContentLengthHeader(RecSize(recFile_l));
  reply.setDirectMode();

  // dsyslog("live: start send video data.");
  cFileName recFile(recording_FileName.c_str(), false, false, recording_IsPesRecording);
  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;
      }
#if TNT_WATCHDOG_SILENCE
      request.touch(); // retrigger the watchdog.
#endif
    }
    // 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>