~ubuntu-branches/ubuntu/saucy/vdr-plugin-live/saucy-proposed

« back to all changes in this revision

Viewing changes to pages/recstream.ecpp

  • Committer: Package Import Robot
  • Author(s): Tobias Grimm
  • Date: 2012-01-15 10:22:53 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20120115102253-hixwx4gbcpyhtt2m
Tags: 0.2.0+git20120114-1
* New Upstream Snapshot (commit d2a85a6) (Closes: #654879)
* Dropped 02_timers_colon patch - fixed upstream
* Dropped 04_tntnet-2.0.patch - fixed upstream
* Dropped 01_ipv6.patch - fixed upstream
* Dropped 03_live-0.2.0-fix-INCLUDES.patch - fixed upstream
* Build-depend on libpcre3-dev
* Updated debian/copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<%pre>
 
2
#include <string>
 
3
#include <iostream>
 
4
#include <fstream>
 
5
#include <algorithm>
 
6
#include <tnt/httperror.h>
 
7
#include <tnt/httpheader.h>
 
8
#include <vdr/recording.h>
 
9
#include "tntfeatures.h"
 
10
#include "setup.h"
 
11
#include "recman.h"
 
12
 
 
13
using namespace std;
 
14
using namespace vdrlive;
 
15
 
 
16
off_t RecSize(cRecording const * recording)
 
17
{
 
18
    cFileName recFile(recording->FileName(), false, false);
 
19
    off_t recSize = 0;
 
20
    for (cUnbufferedFile *recData = recFile.Open(); recData; recData = recFile.NextFile()) {
 
21
        struct stat buf;
 
22
        if (0 == stat(recFile.Name(), &buf)) {
 
23
            recSize += buf.st_size;
 
24
            // dsyslog("LIVE: size of recording part %s is %ld", recFile.Name(), buf.st_size);
 
25
        }
 
26
        else {
 
27
            esyslog("LIVE: can't determine size of %s", recFile.Name());
 
28
        }
 
29
    }
 
30
    // dsyslog("LIVE: total size of %s is %ld", recording->FileName(), recSize);
 
31
    return recSize;
 
32
}
 
33
 
 
34
</%pre>
 
35
<%args>
 
36
    string recid;
 
37
</%args>
 
38
<%session scope="global">
 
39
bool logged_in(false);
 
40
</%session>
 
41
<%cpp>
 
42
//if (!logged_in && LiveSetup().UseAuth()) return reply.redirect("login.html");
 
43
 
 
44
cRecording const * recording = LiveRecordingsManager()->GetByMd5Hash(recid);
 
45
if (recording) {
 
46
        reply.setContentType("video/mpeg");
 
47
    reply.setKeepAliveHeader();
 
48
    reply.setContentLengthHeader(RecSize(recording));
 
49
    reply.setDirectMode();
 
50
 
 
51
    cFileName recFile(recording->FileName(), false, false);
 
52
    // dsyslog("LIVE: start send video data.");
 
53
    for (cUnbufferedFile *recData = recFile.Open(); recData; recData = recFile.NextFile()) {
 
54
        char buffer[KILOBYTE(16)];
 
55
        ssize_t bytesRead = 0;
 
56
        // dsyslog("LIVE: send file %s", recFile->Name());
 
57
        while (0 < (bytesRead = recData->Read(buffer, sizeof(buffer)))) {
 
58
            // dsyslog("LIVE: copy %zd bytes", bytesRead);
 
59
            reply.out().write(buffer, bytesRead);
 
60
            if (!reply.out()) {
 
61
                return HTTP_GONE;
 
62
            }
 
63
#if TNT_WATCHDOG_SILENCE
 
64
            request.touch(); // retrigger the watchdog.
 
65
#endif
 
66
        }
 
67
        // dsyslog("LIVE: bytesRead = %zd", bytesRead);
 
68
        if (bytesRead < 0) {
 
69
            return HTTP_PARTIAL_CONTENT;
 
70
        }
 
71
    }
 
72
    // dsyslog("LIVE: finished send video data.");
 
73
    reply.out() << std::flush;
 
74
    return HTTP_OK;
 
75
}
 
76
return DECLINED;
 
77
</%cpp>