diff options
author | randomdan <randomdan@localhost> | 2014-03-20 23:56:18 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2014-03-20 23:56:18 +0000 |
commit | c6df1ea3d9f4ac3ffa85c3eefc3f30a84df6f8d7 (patch) | |
tree | f45b31a3ea600f6370200432256e1ba8147b4064 /p2pvr/daemon | |
parent | Remove the pointless maint functions for program map and program associations... (diff) | |
download | p2pvr-c6df1ea3d9f4ac3ffa85c3eefc3f30a84df6f8d7.tar.bz2 p2pvr-c6df1ea3d9f4ac3ffa85c3eefc3f30a84df6f8d7.tar.xz p2pvr-c6df1ea3d9f4ac3ffa85c3eefc3f30a84df6f8d7.zip |
Basic support for streaming services (slow, thanks ffmpeg) and recordings (assumes storage endpoint) through the web frontend - implemented as two project2 stream sources
Diffstat (limited to 'p2pvr/daemon')
-rw-r--r-- | p2pvr/daemon/recorder.cpp | 2 | ||||
-rw-r--r-- | p2pvr/daemon/storage.cpp | 44 | ||||
-rw-r--r-- | p2pvr/daemon/storage.h | 2 |
3 files changed, 47 insertions, 1 deletions
diff --git a/p2pvr/daemon/recorder.cpp b/p2pvr/daemon/recorder.cpp index bdd18c6..ccb975e 100644 --- a/p2pvr/daemon/recorder.cpp +++ b/p2pvr/daemon/recorder.cpp @@ -16,7 +16,7 @@ DECLARE_OPTIONS(Recorder, "P2PVR Recorder options") ("p2pvr.recorder.extension", Options::value(&extension, "mpg"), "File extension to save with (default: avi)") ("p2pvr.recorder.muxercommand", Options::value(&muxerCommand, "/usr/bin/ffmpeg -f mpegts -i - -f dvd -codec copy -"), - "File extension to save with (default: '/usr/bin/ffmpeg -f mpegts -i - -f dvd -codec copy -')") + "Command to perform TS->PS muxing (default: '/usr/bin/ffmpeg -f mpegts -i - -f dvd -codec copy -')") END_OPTIONS(Recorder); Recorder::Recorder(Ice::ObjectAdapterPtr a, IceUtil::TimerPtr t) : diff --git a/p2pvr/daemon/storage.cpp b/p2pvr/daemon/storage.cpp index 9d9345d..79280a1 100644 --- a/p2pvr/daemon/storage.cpp +++ b/p2pvr/daemon/storage.cpp @@ -273,3 +273,47 @@ Storage::DeleteFrom(const fs::path & path, const fs::path & from) } } +void +Storage::Send(const std::string & id, const P2PVR::RawDataClientPrx & target, Ice::Long start, Ice::Long len, const Ice::Current &) +{ + fs::path path = root / byAll / id; + path.replace_extension(FindExtension(id)); + auto fd = open(path.string().c_str(), O_RDONLY | O_LARGEFILE); + if (fd < 0) { + Logger()->messagebf(LOG_ERR, "%s: Failed to open file for reading at %s (%d:%s)", __PRETTY_FUNCTION__, + path, errno, strerror(errno)); + throw P2PVR::StorageException(path.string(), strerror(errno)); + } + lseek(fd, start, SEEK_SET); + auto end = std::min<off_t>(fs::file_size(path), start + len); + while (start < end) { + P2PVR::Data buf(16 * 1024); + auto r = read(fd, &buf.front(), std::min<size_t>(buf.size(), end - start)); + if (r < 0) { + Logger()->messagebf(LOG_ERR, "%s: Failed to read file %s (%d:%s)", __PRETTY_FUNCTION__, + path, errno, strerror(errno)); + close(fd); + throw P2PVR::StorageException(path.string(), strerror(errno)); + } + if (target->NewData(buf)) { + close(fd); + return; + } + start += r; + } + close(fd); +} + +Ice::Long +Storage::FileSize(const std::string & id, const Ice::Current &) +{ + fs::path path = root / byAll / id; + try { + path.replace_extension(FindExtension(id)); + return fs::file_size(path); + } + catch (...) { + throw P2PVR::StorageException(path.string(), "Couldn't get file size"); + } +} + diff --git a/p2pvr/daemon/storage.h b/p2pvr/daemon/storage.h index 093e00d..86bc76a 100644 --- a/p2pvr/daemon/storage.h +++ b/p2pvr/daemon/storage.h @@ -13,6 +13,8 @@ class Storage : public P2PVR::Storage { P2PVR::RawDataClientPrx OpenForWrite(const std::string &, const Ice::Current &); void Close(const P2PVR::RawDataClientPrx & file, const Ice::Current &); void Delete(const std::string &, const Ice::Current &); + Ice::Long FileSize(const std::string &, const Ice::Current &); + void Send(const std::string &, const P2PVR::RawDataClientPrx & target, Ice::Long start, Ice::Long len, const Ice::Current &); INITOPTIONS; |