1
0
mirror of https://github.com/rofafor/vdr-plugin-iptv.git synced 2023-10-10 13:37:03 +02:00
vdr-plugin-iptv/streamer.c

99 lines
2.3 KiB
C
Raw Normal View History

2007-09-12 19:28:59 +02:00
/*
* streamer.c: IPTV plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
2007-10-05 21:00:44 +02:00
* $Id: streamer.c,v 1.17 2007/10/05 19:00:44 ajhseppa Exp $
2007-09-12 19:28:59 +02:00
*/
#include <vdr/thread.h>
#include <vdr/ringbuffer.h>
#include "common.h"
#include "streamer.h"
2007-09-14 17:44:25 +02:00
cIptvStreamer::cIptvStreamer(cRingBufferLinear* RingBuffer, cMutex* Mutex)
2007-09-12 19:28:59 +02:00
: cThread("IPTV streamer"),
2007-09-14 17:44:25 +02:00
ringBuffer(RingBuffer),
2007-09-12 19:28:59 +02:00
mutex(Mutex),
2007-09-14 17:44:25 +02:00
protocol(NULL)
2007-09-12 19:28:59 +02:00
{
debug("cIptvStreamer::cIptvStreamer()\n");
}
cIptvStreamer::~cIptvStreamer()
{
debug("cIptvStreamer::~cIptvStreamer()\n");
2007-09-14 17:44:25 +02:00
// Close the protocol
Close();
2007-09-12 19:28:59 +02:00
}
2007-09-13 18:58:22 +02:00
void cIptvStreamer::Action(void)
2007-09-12 19:28:59 +02:00
{
debug("cIptvStreamer::Action(): Entering\n");
2007-09-13 18:58:22 +02:00
// Do the thread loop
2007-09-12 19:28:59 +02:00
while (Running()) {
2007-09-21 23:50:52 +02:00
if (ringBuffer && mutex && protocol && ringBuffer->Free()) {
unsigned char *buffer = NULL;
int length = protocol->Read(&buffer);
2007-09-14 17:44:25 +02:00
if (length >= 0) {
2007-10-05 21:00:44 +02:00
dataBytes += length; // Statistics update
2007-09-13 18:58:22 +02:00
mutex->Lock();
int p = ringBuffer->Put(buffer, length);
2007-09-13 18:58:22 +02:00
if (p != length && Running())
2007-09-14 17:44:25 +02:00
ringBuffer->ReportOverflow(length - p);
2007-09-13 18:58:22 +02:00
mutex->Unlock();
2007-09-14 17:44:25 +02:00
}
else
cCondWait::SleepMs(100); // to reduce cpu load
2007-09-13 18:58:22 +02:00
}
else
cCondWait::SleepMs(100); // and avoid busy loop
2007-09-12 19:28:59 +02:00
}
debug("cIptvStreamer::Action(): Exiting\n");
}
2007-09-14 17:44:25 +02:00
bool cIptvStreamer::Open(void)
{
2007-09-14 17:44:25 +02:00
debug("cIptvStreamer::Open()\n");
// Open the protocol
if (protocol)
if(!protocol->Open())
return false;
2007-09-13 18:58:22 +02:00
// Start thread
Start();
return true;
}
2007-09-14 17:44:25 +02:00
bool cIptvStreamer::Close(void)
2007-09-13 18:58:22 +02:00
{
2007-09-14 17:44:25 +02:00
debug("cIptvStreamer::Close()\n");
2007-09-13 18:58:22 +02:00
// Stop thread
if (Running())
Cancel(3);
2007-09-14 17:44:25 +02:00
// Close the protocol
if (protocol)
protocol->Close();
2007-09-12 19:28:59 +02:00
return true;
}
2007-09-14 17:44:25 +02:00
bool cIptvStreamer::Set(const char* Address, const int Port, cIptvProtocolIf* Protocol)
2007-09-12 19:28:59 +02:00
{
2007-09-14 17:44:25 +02:00
debug("cIptvStreamer::Set(): %s:%d\n", Address, Port);
if (!isempty(Address)) {
// Update protocol; Close the existing one if changed
if (protocol != Protocol) {
if (protocol)
protocol->Close();
protocol = Protocol;
if (protocol)
protocol->Open();
}
// Set protocol address and port
if (protocol)
2007-09-14 17:44:25 +02:00
protocol->Set(Address, Port);
}
2007-09-12 19:28:59 +02:00
return true;
}