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

Fixed prebuffering.

This commit is contained in:
Rolf Ahrenberg 2007-09-21 21:50:52 +00:00
parent 6d0f27e710
commit 067ba7c505
3 changed files with 83 additions and 72 deletions

View File

@ -3,7 +3,7 @@
* *
* See the README file for copyright information and how to reach the author. * See the README file for copyright information and how to reach the author.
* *
* $Id: device.c,v 1.29 2007/09/20 22:01:42 rahrenbe Exp $ * $Id: device.c,v 1.30 2007/09/21 21:50:52 rahrenbe Exp $
*/ */
#include "common.h" #include "common.h"
@ -26,13 +26,9 @@ cIptvDevice::cIptvDevice(unsigned int Index)
{ {
debug("cIptvDevice::cIptvDevice(%d)\n", deviceIndex); debug("cIptvDevice::cIptvDevice(%d)\n", deviceIndex);
tsBuffer = new cRingBufferLinear(MEGABYTE(IptvConfig.GetTsBufferSize()), tsBuffer = new cRingBufferLinear(MEGABYTE(IptvConfig.GetTsBufferSize()),
(TS_SIZE * 2), false, "IPTV"); (TS_SIZE * 10), false, "IPTV");
tsBuffer->SetTimeouts(100, 100); tsBuffer->SetTimeouts(100, 100);
// pad prefill to multiple of TS_SIZE ResetBuffering();
tsBufferPrefill = MEGABYTE(IptvConfig.GetTsBufferSize()) *
IptvConfig.GetTsBufferPrefillRatio() / 100;
tsBufferPrefill -= (tsBufferPrefill % TS_SIZE);
//debug("Buffer=%d Prefill=%d\n", MEGABYTE(IptvConfig.GetTsBufferSize()), tsBufferPrefill);
pUdpProtocol = new cIptvProtocolUdp(); pUdpProtocol = new cIptvProtocolUdp();
pHttpProtocol = new cIptvProtocolHttp(); pHttpProtocol = new cIptvProtocolHttp();
pFileProtocol = new cIptvProtocolFile(); pFileProtocol = new cIptvProtocolFile();
@ -166,10 +162,6 @@ bool cIptvDevice::SetChannelDevice(const cChannel *Channel, bool LiveView)
error("ERROR: Unrecognized IPTV channel settings: %s", Channel->PluginParam()); error("ERROR: Unrecognized IPTV channel settings: %s", Channel->PluginParam());
return false; return false;
} }
// pad prefill to multiple of TS_SIZE
tsBufferPrefill = MEGABYTE(IptvConfig.GetTsBufferSize()) *
IptvConfig.GetTsBufferPrefillRatio() / 100;
tsBufferPrefill -= (tsBufferPrefill % TS_SIZE);
pIptvStreamer->Set(addr, port, protocol); pIptvStreamer->Set(addr, port, protocol);
return true; return true;
} }
@ -225,6 +217,7 @@ bool cIptvDevice::OpenDvr(void)
isPacketDelivered = false; isPacketDelivered = false;
tsBuffer->Clear(); tsBuffer->Clear();
mutex.Unlock(); mutex.Unlock();
ResetBuffering();
pIptvStreamer->Open(); pIptvStreamer->Open();
isOpenDvr = true; isOpenDvr = true;
return true; return true;
@ -250,17 +243,34 @@ void cIptvDevice::CloseDvr(void)
bool cIptvDevice::HasLock(int TimeoutMs) bool cIptvDevice::HasLock(int TimeoutMs)
{ {
debug("cIptvDevice::HasLock(%d): %d\n", deviceIndex, TimeoutMs); //debug("cIptvDevice::HasLock(%d): %d\n", deviceIndex, TimeoutMs);
return (!IsBuffering());
}
void cIptvDevice::ResetBuffering(void)
{
debug("cIptvDevice::ResetBuffering(%d)\n", deviceIndex);
// pad prefill to multiple of TS_SIZE
tsBufferPrefill = MEGABYTE(IptvConfig.GetTsBufferSize()) *
IptvConfig.GetTsBufferPrefillRatio() / 100;
tsBufferPrefill -= (tsBufferPrefill % TS_SIZE);
}
bool cIptvDevice::IsBuffering(void)
{
//debug("cIptvDevice::IsBuffering(%d): %d\n", deviceIndex);
if (tsBufferPrefill && tsBuffer->Available() < tsBufferPrefill) if (tsBufferPrefill && tsBuffer->Available() < tsBufferPrefill)
return false;
tsBufferPrefill = 0;
return true; return true;
else
tsBufferPrefill = 0;
return false;
} }
bool cIptvDevice::GetTSPacket(uchar *&Data) bool cIptvDevice::GetTSPacket(uchar *&Data)
{ {
int Count = 0; int Count = 0;
//debug("cIptvDevice::GetTSPacket(%d)\n", deviceIndex); //debug("cIptvDevice::GetTSPacket(%d)\n", deviceIndex);
if (!IsBuffering()) {
if (isPacketDelivered) { if (isPacketDelivered) {
tsBuffer->Del(TS_SIZE); tsBuffer->Del(TS_SIZE);
isPacketDelivered = false; isPacketDelivered = false;
@ -286,8 +296,7 @@ bool cIptvDevice::GetTSPacket(uchar *&Data)
if (filters[i].active) { if (filters[i].active) {
section *filtered = get_filt_sec(&filter, i); section *filtered = get_filt_sec(&filter, i);
if (filtered->found) { if (filtered->found) {
// Select on the fifo emptyness. Using null timeout to return // Select on the fifo emptyness. Using null timeout to return immediately
// immediately
struct timeval tv; struct timeval tv;
tv.tv_sec = 0; tv.tv_sec = 0;
tv.tv_usec = 0; tv.tv_usec = 0;
@ -299,8 +308,7 @@ bool cIptvDevice::GetTSPacket(uchar *&Data)
if (retval < 0) { if (retval < 0) {
char tmp[64]; char tmp[64];
error("ERROR: select(): %s", strerror_r(errno, tmp, sizeof(tmp))); error("ERROR: select(): %s", strerror_r(errno, tmp, sizeof(tmp)));
// VDR has probably closed the filter file descriptor, so clear // VDR has probably closed the filter file descriptor, so clear the filter
// the filter
close(filters[i].fifoDesc); close(filters[i].fifoDesc);
unlink(filters[i].pipeName); unlink(filters[i].pipeName);
memset(filters[i].pipeName, '\0', sizeof(filters[i].pipeName)); memset(filters[i].pipeName, '\0', sizeof(filters[i].pipeName));
@ -321,6 +329,7 @@ bool cIptvDevice::GetTSPacket(uchar *&Data)
} }
return true; return true;
} }
}
Data = NULL; Data = NULL;
return true; return true;
} }

View File

@ -3,7 +3,7 @@
* *
* See the README file for copyright information and how to reach the author. * See the README file for copyright information and how to reach the author.
* *
* $Id: device.h,v 1.13 2007/09/20 22:01:42 rahrenbe Exp $ * $Id: device.h,v 1.14 2007/09/21 21:50:52 rahrenbe Exp $
*/ */
#ifndef __IPTV_DEVICE_H #ifndef __IPTV_DEVICE_H
@ -57,10 +57,12 @@ public:
cIptvDevice(unsigned int DeviceIndex); cIptvDevice(unsigned int DeviceIndex);
virtual ~cIptvDevice(); virtual ~cIptvDevice();
// for channel parsing // for channel parsing & buffering
private: private:
cString GetChannelSettings(const char *Param, int *IpPort, cIptvProtocolIf* *Protocol); cString GetChannelSettings(const char *Param, int *IpPort, cIptvProtocolIf* *Protocol);
bool ProvidesIptv(const char *Param) const; bool ProvidesIptv(const char *Param) const;
void ResetBuffering(void);
bool IsBuffering(void);
// for channel selection // for channel selection
public: public:

View File

@ -3,7 +3,7 @@
* *
* See the README file for copyright information and how to reach the author. * See the README file for copyright information and how to reach the author.
* *
* $Id: streamer.c,v 1.13 2007/09/15 21:27:00 rahrenbe Exp $ * $Id: streamer.c,v 1.14 2007/09/21 21:50:52 rahrenbe Exp $
*/ */
#include <vdr/thread.h> #include <vdr/thread.h>
@ -33,7 +33,7 @@ void cIptvStreamer::Action(void)
debug("cIptvStreamer::Action(): Entering\n"); debug("cIptvStreamer::Action(): Entering\n");
// Do the thread loop // Do the thread loop
while (Running()) { while (Running()) {
if (ringBuffer && mutex && protocol) { if (ringBuffer && mutex && protocol && ringBuffer->Free()) {
unsigned char *buffer = NULL; unsigned char *buffer = NULL;
int length = protocol->Read(&buffer); int length = protocol->Read(&buffer);
if (length >= 0) { if (length >= 0) {