// whenever action from bot is needed void GameState::parse_getaction( std::string line ) { std::vector<std::string> tokens = split(line, TOKEN_DELIM); int ntokens = tokens.size(); int ptr = GETACTION_POT_POS; //parse pot size this->_pot = boost::lexical_cast<int>(tokens[ptr]); //parse cards and calculate strength std::vector<std::string> all_cards = this->_my_cards; //copy my two cards ptr = GETACTION_NCARDS_POS; int ncards = boost::lexical_cast<int>(tokens[ptr++]); if( ncards > 0 ) { this->_round = ncards - 2; //3=flop,4=turn,5=river //int cards_begin = GETACTION_CARDS_POS for(int i=0; i<ncards; i++) { all_cards.push_back(tokens[ptr++]); } } this->_card_rank = score_cards(all_cards); //From utils //player stacks, get my for(int i=0; i<GameState::opp_number()+1; i++) { if( i+1==this->position() ) { this->_stack = boost::lexical_cast<int>(tokens[ptr]); } ptr++; } //active players, update position int nactive_players = boost::lexical_cast<int>(tokens[ptr++]); if( nactive_players > 0 ) { for(int i=0; i<GameState::opp_number()+1; i++) { bool is_active = (bool) tokens[ptr++].compare("false"); if( i+1<this->position() && !is_active ) { --this->_position; } } } //TODO update position, count FOLD?? //last actions int nlast_actions = boost::lexical_cast<int>(tokens[ptr++]); if( nlast_actions > 0 ) { for(int i=0; i<nlast_actions; i++) { ptr++; } } //get legal actions to do int nlegal_actions = boost::lexical_cast<int>(tokens[ptr++]); this->_possible_decisions.clear(); if( nlast_actions > 0 ) { for(int i=0; i<nlegal_actions; i++) { this->_possible_decisions.push_back( Decision(tokens[ptr++]) ); } } }
explicit const_partimator_generic( const Decision &decis = Decision(), const vertex &vtx = vertex()) : decis_(decis) , pit_(vtx) { decis_.init(); if (!pit_->the_end()) next_fit(); }
AdaptationST::Decision AdaptationST::selectRepresentation(bool ifBetaMinIncreasing, double beta, double rho, double rhoLast, unsigned completedRequests, unsigned minRequiredCompletedRequests, const Representation& r_last) { /* debug output */ DBGMSG("\nselectRepresentation(%s, beta: %.3f sec, rho: %.3f Mbit/sec, rhoLast: %.3f Mbit/sec, numComplReq: %u, minNumComplReq: %u, r_last: %s)", ifBetaMinIncreasing ? "beta_min incr." : "beta_min decr.", beta, rho / 1e6, rhoLast / 1e6, completedRequests, minRequiredCompletedRequests, r_last.ID.c_str()); /* current time since beginning of download */ const dash::Usec now = dash::Utilities::getTime(); /* verify that we already obtained a list of representations */ dp2p_assert(representations.size()); /* If we completed strictly less than a minimum number of requests, stay with the lowest representation */ if (completedRequests == 0 || completedRequests < minRequiredCompletedRequests) { DBGMSG("Number of completed GET requests is %u < %u. Selecting lowest representation.", completedRequests, minRequiredCompletedRequests); return Decision(representations.at(0), std::numeric_limits<double>::infinity(), NOT_ENOUGH_COMPLETED_REQUESTS); } /* Get indexes of some relevant representations for faster access. */ const unsigned iLowest = 0; const unsigned iLast = getIndex(r_last); const unsigned iHighest = representations.size() - 1; DBGMSG("Number of completed GET requests is %u >= %u.", completedRequests, minRequiredCompletedRequests); /* Are we in the initial increase phase? */ if (initialIncrease) { DBGMSG("We are in the initial increase phase."); /* Check if we shall terminate the initial increase phase. */ { /* Check if we already selected highest representation. */ if (initialIncrease && iLast == iHighest) { initialIncrease = false; DBGMSG("Terminating initial increase phase. Reached highest representation."); } /* Check if the discretized minimum buffer level had been decreasing. */ if (initialIncrease && !ifBetaMinIncreasing) { initialIncrease = false; DBGMSG("Terminating initial increase phase. Discretized min buffer level had been decreasing."); } /* Check if current representation is above alfa1 * rho. */ if (initialIncrease && representations.at(iLast).bandwidth > alfa1 * rho) { DBGMSG(lightred"Terminating initial increase phase. Bit-rate is above alfa1*rho (%u>%f*%f."rst, representations.at(iLast).bandwidth, alfa1, rho); initialIncrease = false; } } /* if we didn't terminate the initial increase phase, * act depending on buffer level and throughput. */ if (initialIncrease && beta < Bmin) { DBGMSG("We are in [0,Bmin)."); if (representations.at(iLast + 1).bandwidth <= alfa2 * rho) { DBGMSG("Have enough throughput. Increase bit-rate."); return Decision(representations.at(iLast + 1), std::numeric_limits<double>::infinity(), II1_UP); } else { DBGMSG("DO NOT have enough throughput. DO NOT increase encoding rate."); return Decision(representations.at(iLast), std::numeric_limits<double>::infinity(), II1_KEEP); } } else if (initialIncrease && beta < Blow) { DBGMSG("We are in [Bmin, Blow)."); if (representations.at(iLast + 1).bandwidth <= alfa3 * rho) { DBGMSG("Have enough throughput. Increase encoding rate."); return Decision(representations.at(iLast + 1), std::numeric_limits<double>::infinity(), II2_UP); } else { DBGMSG("DO NOT have enough throughput. DO NOT increase encoding rate."); return Decision(representations.at(iLast), std::numeric_limits<double>::infinity(), II2_KEEP); } } else if (initialIncrease) { DBGMSG("We are in [Blow, Inf)."); if (representations.at(iLast + 1).bandwidth <= alfa4 * rho) { DBGMSG("Have enough throughput. Increase encoding rate."); if(Bhigh - representations.at(iLast + 1).segmentDuration < beta) { DBGMSG("Delay until beta == %f.", Bhigh - representations.at(iLast + 1).segmentDuration); } return Decision(representations.at(iLast + 1), Bhigh - representations.at(iLast + 1).segmentDuration, II3_UP); } else { DBGMSG("DO NOT have enough throughput. DO NOT increase encoding rate."); if(Bhigh - representations.at(iLast).segmentDuration < beta) { DBGMSG("Delay until beta == %f.", Bhigh - representations.at(iLast + 1).segmentDuration); } return Decision(representations.at(iLast), Bhigh - representations.at(iLast).segmentDuration, II3_KEEP); } } else { /* we just left the initial increase phase */ initialIncreaseTerminationTime = now; } } /* if we are not in the initial increase phase, * act depending on buffer level and throughput. */ /* we are in [0, Bmin) */ if (beta < Bmin) { DBGMSG("We are in [0, Bmin): %.3f sec. Selecting lowest representation.", beta); return Decision(representations.at(iLowest), std::numeric_limits<double>::infinity(), NO0_LOWEST); } /* We are in [Bmin, Blow). */ else if (beta < Blow) { DBGMSG("We are in [Bmin, Blow): %.3f in [%.3f, %.3f].", beta, Bmin, Blow); if (iLast == iLowest) { DBGMSG("We are at lowest representation. Keep it."); return Decision(representations.at(iLast), std::numeric_limits<double>::infinity(), NO1_LOWEST); } else { DBGMSG("We are NOT at lowest representation. Checking if shall switch down."); if (rhoLast > (double)representations.at(iLast).bandwidth) { DBGMSG("Buffer is rising %f > %u. Not switching down.", rhoLast, representations.at(iLast).bandwidth); return Decision(representations.at(iLast), std::numeric_limits<double>::infinity(), NO1_KEEP); } else { DBGMSG("Buffer is falling %f <= %u. Switching down.", rhoLast, representations.at(iLast).bandwidth); return Decision(representations.at(iLast - 1), std::numeric_limits<double>::infinity(), NO1_DOWN); } } } /* we are in [Blow, Bhigh) */ else if (beta < Bhigh) { DBGMSG("We are in the target interval [%.3f, %.3f] sec.", Blow, Bhigh); DBGMSG("We are NOT in the initial increase phase. Keep current representation."); /* check if throughput is enough for next higher encoding rate. */ if(iLast == iHighest || representations.at(iLast + 1).bandwidth >= alfa5 * rho) { /* delay */ DBGMSG("Delay until beta == %f.", std::max<double>(beta - (double)representations.at(iLast).segmentDuration, 0.5 * (Blow + Bhigh))); return Decision(representations.at(iLast), std::max<double>(beta - (double)representations.at(iLast).segmentDuration, 0.5 * (Blow + Bhigh)), NO2_DELAY); } else { /* don't delay */ DBGMSG("Don't delay."); return Decision(representations.at(iLast), std::numeric_limits<double>::infinity(), NO2_NODELAY); } } /* we are in [Bhigh, Inf) */ else { DBGMSG("We are above the target interval: %.3f sec > %.3f sec.", beta, Bhigh); DBGMSG("We are NOT in the initial increase phase."); /* check if throughput is enough for next higher encoding rate. */ if(iLast == iHighest || representations.at(iLast + 1).bandwidth >= alfa5 * rho) { /* delay */ DBGMSG("Keep current representation. Delay until beta == %f.", std::max<double>(beta - (double)representations.at(iLast).segmentDuration, 0.5 * (Blow + Bhigh))); return Decision(representations.at(iLast), std::max<double>(beta - (double)representations.at(iLast).segmentDuration, 0.5 * (Blow + Bhigh)), NO3_DELAY); } else { /* don't delay */ DBGMSG("Don't delay. Switch to next higher representation."); return Decision(representations.at(iLast + 1), std::numeric_limits<double>::infinity(), NO3_UP); } } }
MHdl *MH_Rec_Component_Open_General( void(*handler)( MHdl *handle, Media_Event event ), MHPB_CompList const *pSwEncFunc, MHPB_CompList const *pDspEncFunc, kal_uint32 (*Decision)(void) ) { MHdl *hdl; MHPB_Internal *ihdl; SrcCapParam stCap; kal_uint32 uEncDecision = 0; MHPB_CompList const *pArray[2]; pArray[0] = &DirectPackFunc; pArray[1] = NULL; // Construct handle hdl = MH_Component_Construct(pArray); ihdl = (MHPB_Internal *)hdl; // Set default member function hdl->Record = GenCompRecord; hdl->Pause = GenCompRecPause; hdl->Resume = GenCompRecResume; hdl->Stop = GenCompRecStop; hdl->Close = GenCompRecClose; hdl->Process = GenCompProcess; // Store information ihdl->pSwEncFunc = pSwEncFunc; ihdl->pDspEncFunc = pDspEncFunc; ihdl->EncDecision = Decision; // Set alias ihdl->pNodeStart = ihdl->pNodeEnd = ihdl->pNodePack = &ihdl->NodeArray[0]; uEncDecision = Decision(); // Encoder { MHPB_CompList const *pEncFunc; if (uEncDecision & COMPONENT_ENCODER_DSP_REQUIRED) { pEncFunc = pDspEncFunc; ihdl->fDspEncode = KAL_TRUE; } else { pEncFunc = pSwEncFunc; ihdl->fDspEncode = KAL_FALSE; } ihdl->pNodeEncode = HookAndConstructComponent(ihdl, NULL, ihdl->pNodePack, pEncFunc); } if (uEncDecision & COMPONENT_SOURCE_REQUIRED) { //-- Consturct source component ihdl->pNodeSource = HookAndConstructComponent(ihdl, NULL, ihdl->pNodeEncode, &PcmSourceFunc); //-- Negotiation information // Get the capability of Encoder ihdl->pNodeEncode->curHdl->SetParameter(ihdl->pNodeEncode->curHdl, OMX_IndexParamMediaTekQueryEncodeSupportFormat, (OMX_PTR) &stCap); // Negotiate with Sourcer ihdl->pNodeSource->curHdl->SetParameter(ihdl->pNodeSource->curHdl, OMX_IndexParamMediaTekPcmSourceNegotiation, (OMX_PTR) &stCap); // Set the negotiated information to encoder ihdl->pNodeEncode->curHdl->SetParameter(ihdl->pNodeEncode->curHdl, OMX_IndexParamMediaTekSetEncodeFormat, (OMX_PTR) &stCap); //-- SRC (Sampling Rate Convert) part // Get the sampling rate and channel number of source and encoder ihdl->pNodeSource->curHdl->SetParameter(ihdl->pNodeSource->curHdl, OMX_IndexParamMediaTekQuerySetPcmSourceInfo, (OMX_PTR) &ihdl->stFormat); if ( (ihdl->stFormat.uOriChannelNum != ihdl->stFormat.uOutputChannelNum) || (ihdl->stFormat.uOriSamplingFreq != ihdl->stFormat.uOutputSamplingFreq) ) { //-- Hook SRC (Sampling Rate Convert) // Construct and set alias ihdl->pNodeSRC = HookAndConstructComponent(ihdl, ihdl->pNodeSource, ihdl->pNodeEncode, &SampleRateConvertFunc); // Set sampling rate and channel number information ihdl->pNodeSRC->curHdl->SetParameter(ihdl->pNodeSRC->curHdl, OMX_IndexParamMediaTekQuerySetPcmSourceInfo, (OMX_PTR) &ihdl->stFormat); } #if defined(__SPEECH_ENHENCEMENT_SWIP_SUPPORT__) if ( isNeedSphEnh() ) { //-- Hook speech enhancement AcHdlNode *pNext; if (ihdl->pNodeSRC) pNext = ihdl->pNodeSRC; else pNext = ihdl->pNodeEncode; // Construct and set alias ihdl->pNodeSphEnh = HookAndConstructComponent(ihdl, ihdl->pNodeSource, ipNext, &SpeechEnhanceFunc); // Set sampling rate and channel number information ihdl->pNodeSphEnh->curHdl->SetParameter(ihdl->pNodeSphEnh->curHdl, OMX_IndexParamMediaTekQuerySetPcmSourceInfo, (OMX_PTR) &ihdl->stFormat); } #endif } return hdl; }