diff options
author | randomdan <randomdan@localhost> | 2013-12-15 20:12:25 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2013-12-15 20:12:25 +0000 |
commit | dae84f496492ccce1659b1becc928fc80e5e7509 (patch) | |
tree | 736246e6f302401eb572ea6e7264a38e10a0a1d4 | |
parent | Fixups around the schema of services and it's other columns (diff) | |
download | p2pvr-dae84f496492ccce1659b1becc928fc80e5e7509.tar.bz2 p2pvr-dae84f496492ccce1659b1becc928fc80e5e7509.tar.xz p2pvr-dae84f496492ccce1659b1becc928fc80e5e7509.zip |
Add a simple muxer that just wraps around an ffmpeg process
-rw-r--r-- | p2pvr/lib/muxer.cpp | 68 | ||||
-rw-r--r-- | p2pvr/lib/muxer.h | 20 |
2 files changed, 88 insertions, 0 deletions
diff --git a/p2pvr/lib/muxer.cpp b/p2pvr/lib/muxer.cpp new file mode 100644 index 0000000..886806e --- /dev/null +++ b/p2pvr/lib/muxer.cpp @@ -0,0 +1,68 @@ +#include "muxer.h" +#include <misc.h> +#include <logger.h> +#include <poll.h> + +Muxer::Muxer(const P2PVR::RawDataClientPrx & t) : + target(t) +{ + std::vector<const char *> cmd; + cmd.push_back("/usr/bin/ffmpeg"); + cmd.push_back("-f"); + cmd.push_back("mpegts"); + cmd.push_back("-i"); + cmd.push_back("-"); + cmd.push_back("-f"); + cmd.push_back("mpeg"); + cmd.push_back("-codec"); + cmd.push_back("copy"); + cmd.push_back("-"); + cmd.push_back(NULL); + popenrw(&cmd.front(), fds); +} + +Muxer::~Muxer() +{ + close(fds[0]); + ReadMuxerAndSend(); + close(fds[1]); +} + +bool +Muxer::NewData(const P2PVR::Data & data, const Ice::Current &) +{ + ReadMuxerAndSend(); + if (write(fds[0], &data.front(), data.size()) < 1) { + return true; + } + return ReadMuxerAndSend(); +} + +bool +Muxer::ReadMuxerAndSend() const +{ + while (true) { + pollfd fd = { fds[1], POLLIN, 0 }; + const timespec timeout = {0, 0}; + auto p = ppoll(&fd, 1, &timeout, NULL); + if (p < 0) { + // error + return true; + } + else if (p == 0) { + // all ok + return false; + } + else if (p > 0) { + P2PVR::Data buf(BUFSIZ); + auto len = read(fds[1], &buf.front(), buf.size()); + if (len < 0) { + // error + return true; + } + buf.resize(len); + target->NewData(buf); + } + } +} + diff --git a/p2pvr/lib/muxer.h b/p2pvr/lib/muxer.h new file mode 100644 index 0000000..5c8ef8e --- /dev/null +++ b/p2pvr/lib/muxer.h @@ -0,0 +1,20 @@ +#ifndef MUXER_H +#define MUXER_H + +#include <p2pvr.h> + +class Muxer : public P2PVR::RawDataClient { + public: + Muxer(const P2PVR::RawDataClientPrx & target); + ~Muxer(); + + bool NewData(const P2PVR::Data &, const Ice::Current &); + + private: + bool ReadMuxerAndSend() const; + const P2PVR::RawDataClientPrx & target; + int fds[2]; +}; + +#endif + |