<%pre> #include #include #include #include #include #include #include #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; } <%args> string recid; <%session scope="global"> bool logged_in(false); <%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;