Trying to fix #311

git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-experimental@646 e54a6e83-5905-42d5-8d5c-058d10e6a962
This commit is contained in:
focus
2010-06-28 18:52:48 +00:00
parent 253324226e
commit d7c2303239
4 changed files with 37 additions and 55 deletions

View File

@@ -20,8 +20,6 @@ nicht gespeichert werden.
#include "lastchannel.h"
// // -- Init Class Contructor //
CLastChannel::CLastChannel (void)
: secs_diff_before_store(3)
, maxSize(11)
@@ -36,56 +34,45 @@ void CLastChannel::clear (void)
}
// -- Store a channelnumber in Buffer
// -- Store only if channel != last channel...
// -- and time store delay is large enough
// -- Store only if channel != last channel and time store delay is large enough
// forceStoreToLastChannels default to false
void CLastChannel::store (int channel, t_channel_id channel_id, bool forceStoreToLastChannels)
{
struct timeval tv;
unsigned long lastTimestamp(0);
unsigned long timeDiff;
std::list<_LastCh>::iterator It;
gettimeofday (&tv, NULL);
int lastChannel(-1);
t_channel_id lastChannel_id(0);
unsigned long lastTimestamp(0);
if (!this->lastChannels.empty())
{
lastChannel = this->lastChannels.front().channel;
lastChannel_id = this->lastChannels.front().channel_id;
lastTimestamp = this->lastChannels.front().timestamp;
}
if (((forceStoreToLastChannels || (tv.tv_sec - lastTimestamp) > secs_diff_before_store))
&& (lastChannel != channel) )
{
if (this->shallRemoveEqualChannel && (this->lastChannels.size() > 1))
{
std::list<_LastCh>::iterator It = this->lastChannels.begin();
++It;
for (; It != this->lastChannels.end() ; ++It) {
if (lastChannel_id == It->channel_id) {
this->lastChannels.erase(It);
break;
}
timeDiff = tv.tv_sec - lastTimestamp;
/* prev zap time was less than treshhold, remove prev channel */
if(!this->lastChannels.empty() && (timeDiff <= secs_diff_before_store))
this->lastChannels.pop_front();
/* push new channel to the head */
_LastCh newChannel = {channel, channel_id, tv.tv_sec};
this->lastChannels.push_front(newChannel);
/* this zap time was more than treshhold, it will stay, remove last in the list */
if ((timeDiff > secs_diff_before_store) && (this->lastChannels.size() > this->maxSize))
this->lastChannels.pop_back();
/* remove this channel at other than 0 position */
if(this->lastChannels.size() > 1) {
It = this->lastChannels.begin();
It++;
for (; It != this->lastChannels.end() ; It++) {
if (channel_id == It->channel_id) {
this->lastChannels.erase(It);
break;
}
}
// -- store channel on next pos (new channel)
_LastCh newChannel = {channel, channel_id, tv.tv_sec};
this->lastChannels.push_front(newChannel);
if (this->lastChannels.size() > this->maxSize)
{
this->lastChannels.pop_back();
}
}
// -- remember time (secs)
if (!this->lastChannels.empty())
{
this->lastChannels.front().channel = channel;
this->lastChannels.front().channel_id = channel_id;
this->lastChannels.front().timestamp = tv.tv_sec;
}
}
@@ -94,11 +81,9 @@ unsigned int CLastChannel::size () const
return this->lastChannels.size();
}
//
// -- Clear store time delay
// -- means: set last time stamp to zero
// -- means: store next channel with "store" always
//
void CLastChannel::clear_storedelay (void)
@@ -109,7 +94,6 @@ void CLastChannel::clear_storedelay (void)
}
}
//
// -- Get last Channel-Entry
// -- IN: n number of last channel in queue [0..]
// -- 0 = current channel
@@ -117,26 +101,20 @@ void CLastChannel::clear_storedelay (void)
t_channel_id CLastChannel::getlast (int n)
{
if ( (n < int(this->lastChannels.size()))
&&(n > -1)
&&(!this->lastChannels.empty())
)
if((n < int(this->lastChannels.size())) && (n > -1) && (!this->lastChannels.empty()))
{
std::list<_LastCh>::const_iterator It = this->lastChannels.begin();
std::advance(It, n);
//return It->channel;
return It->channel_id;
}
//return -1;
return 0;
}
//
// -- set delaytime in secs, for accepting a new value
// -- get returns the value
//
void CLastChannel::set_store_difftime (int secs)
{
secs_diff_before_store = secs;
@@ -147,4 +125,3 @@ int CLastChannel::get_store_difftime (void) const
{
return secs_diff_before_store;
}