2018-05-28 22:03:39 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* libretroshare/src/pqi: pqiqosstreamer.cc *
|
|
|
|
* *
|
|
|
|
* libretroshare: retroshare core library *
|
|
|
|
* *
|
|
|
|
* Copyright (C) 2012-2012 Cyril Soler <csoler@users.sourceforge.net> *
|
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Lesser General Public License as *
|
|
|
|
* published by the Free Software Foundation, either version 3 of the *
|
|
|
|
* License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU Lesser General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License *
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
2012-06-23 12:10:41 +00:00
|
|
|
#include "pqiqosstreamer.h"
|
|
|
|
|
2016-06-25 19:12:35 +01:00
|
|
|
//#define DEBUG_PQIQOSSTREAMER 1
|
|
|
|
|
2016-03-29 21:22:14 +02:00
|
|
|
const float pqiQoSstreamer::PQI_QOS_STREAMER_ALPHA = 2.0f ;
|
|
|
|
|
2014-03-17 20:56:06 +00:00
|
|
|
pqiQoSstreamer::pqiQoSstreamer(PQInterface *parent, RsSerialiser *rss, const RsPeerId& peerid, BinInterface *bio_in, int bio_flagsin)
|
2013-10-02 03:21:04 +00:00
|
|
|
: pqithreadstreamer(parent,rss,peerid,bio_in,bio_flagsin), pqiQoS(PQI_QOS_STREAMER_MAX_LEVELS, PQI_QOS_STREAMER_ALPHA)
|
2012-06-23 12:10:41 +00:00
|
|
|
{
|
|
|
|
_total_item_size = 0 ;
|
|
|
|
_total_item_count = 0 ;
|
|
|
|
}
|
|
|
|
|
|
|
|
int pqiQoSstreamer::getQueueSize(bool in)
|
|
|
|
{
|
|
|
|
if(in)
|
|
|
|
return pqistreamer::getQueueSize(in) ;
|
|
|
|
else
|
2013-10-01 10:11:34 +00:00
|
|
|
{
|
|
|
|
RsStackMutex stack(mStreamerMtx); /**** LOCKED MUTEX ****/
|
2012-06-23 12:10:41 +00:00
|
|
|
return qos_queue_size() ;
|
2013-10-01 10:11:34 +00:00
|
|
|
}
|
2012-06-23 12:10:41 +00:00
|
|
|
}
|
|
|
|
|
2015-07-12 04:04:18 +00:00
|
|
|
//int pqiQoSstreamer::locked_gatherStatistics(std::vector<uint32_t>& per_service_count,std::vector<uint32_t>& per_priority_count) const // extracting data.
|
|
|
|
//{
|
|
|
|
// return pqiQoS::gatherStatistics(per_service_count,per_priority_count) ;
|
|
|
|
//}
|
2014-10-31 21:24:42 +00:00
|
|
|
|
2016-04-23 17:10:25 -04:00
|
|
|
void pqiQoSstreamer::locked_storeInOutputQueue(void *ptr,int size,int priority)
|
2012-06-23 12:10:41 +00:00
|
|
|
{
|
2016-04-20 22:42:09 -04:00
|
|
|
_total_item_size += size ;
|
2012-06-23 12:10:41 +00:00
|
|
|
++_total_item_count ;
|
|
|
|
|
2016-04-20 22:42:09 -04:00
|
|
|
pqiQoS::in_rsItem(ptr,size,priority) ;
|
2012-06-23 12:10:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pqiQoSstreamer::locked_clear_out_queue()
|
|
|
|
{
|
2016-06-25 19:12:35 +01:00
|
|
|
#ifdef DEBUG_PQIQOSSTREAMER
|
|
|
|
if(qos_queue_size() > 0)
|
|
|
|
std::cerr << " pqiQoSstreamer::locked_clear_out_queue(): clearing " << qos_queue_size() << " pending outqueue elements." << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2012-06-23 12:10:41 +00:00
|
|
|
pqiQoS::clear() ;
|
|
|
|
_total_item_size = 0 ;
|
|
|
|
_total_item_count = 0 ;
|
|
|
|
}
|
|
|
|
|
2016-04-25 23:37:02 -04:00
|
|
|
void *pqiQoSstreamer::locked_pop_out_data(uint32_t max_slice_size, uint32_t& size, bool& starts, bool& ends, uint32_t& packet_id)
|
2012-06-23 12:10:41 +00:00
|
|
|
{
|
2016-04-25 23:37:02 -04:00
|
|
|
void *out = pqiQoS::out_rsItem(max_slice_size,size,starts,ends,packet_id) ;
|
2012-06-23 12:10:41 +00:00
|
|
|
|
|
|
|
if(out != NULL)
|
|
|
|
{
|
2017-03-10 15:36:50 +01:00
|
|
|
_total_item_size -= size ;
|
2016-04-25 23:37:02 -04:00
|
|
|
|
|
|
|
if(ends)
|
|
|
|
--_total_item_count ;
|
2012-06-23 12:10:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return out ;
|
|
|
|
}
|
|
|
|
|