#include #include "muxer.h" #include #include #include Muxer::Muxer(const P2PVR::RawDataClientPrx & t) : target(t) { std::vector 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); } } }