/* * streamer.c: IPTV plugin for the Video Disk Recorder * * See the README file for copyright information and how to reach the author. * */ #include #include #include "common.h" #include "streamer.h" cIptvStreamer::cIptvStreamer(cRingBufferLinear* ringBufferP, unsigned int packetLenP) : cThread("IPTV streamer"), ringBufferM(ringBufferP), packetBufferLenM(packetLenP), protocolM(NULL) { debug("cIptvStreamer::cIptvStreamer(%d)\n", packetBufferLenM); // Allocate packet buffer packetBufferM = MALLOC(unsigned char, packetBufferLenM); if (packetBufferM) memset(packetBufferM, 0, packetBufferLenM); else error("MALLOC() failed for packet buffer"); } cIptvStreamer::~cIptvStreamer() { debug("cIptvStreamer::~cIptvStreamer()\n"); // Close the protocol Close(); protocolM = NULL; ringBufferM = NULL; // Free allocated memory free(packetBufferM); } void cIptvStreamer::Action(void) { debug("cIptvStreamer::Action(): Entering\n"); // Increase priority //SetPriority(-1); // Do the thread loop while (packetBufferM && Running()) { int length = -1; if (protocolM) length = protocolM->Read(packetBufferM, min((unsigned int)ringBufferM->Free(), packetBufferLenM)); if (length > 0) { AddStreamerStatistic(length); if (ringBufferM) { int p = ringBufferM->Put(packetBufferM, length); if (p != length) ringBufferM->ReportOverflow(length - p); } } else sleepM.Wait(10); // to avoid busy loop and reduce cpu load } debug("cIptvStreamer::Action(): Exiting\n"); } bool cIptvStreamer::Open(void) { debug("cIptvStreamer::Open()\n"); // Open the protocol if (protocolM && !protocolM->Open()) return false; // Start thread Start(); return true; } bool cIptvStreamer::Close(void) { debug("cIptvStreamer::Close()\n"); // Stop thread sleepM.Signal(); if (Running()) Cancel(3); // Close the protocol if (protocolM) protocolM->Close(); return true; } bool cIptvStreamer::Set(const char* locationP, const int parameterP, const int indexP, cIptvProtocolIf* protocolP) { debug("cIptvStreamer::Set('%s', %d, %d)\n", locationP, parameterP, indexP); if (!isempty(locationP)) { // Update protocol and set location and parameter; Close the existing one if changed if (protocolM != protocolP) { if (protocolM) protocolM->Close(); protocolM = protocolP; if (protocolM) { protocolM->Set(locationP, parameterP, indexP); protocolM->Open(); } } else if (protocolM) protocolM->Set(locationP, parameterP, indexP); } return true; } cString cIptvStreamer::GetInformation(void) { //debug("cIptvStreamer::GetInformation()"); cString s; if (protocolM) s = protocolM->GetInformation(); return s; }