void ElementaryStreamDescriptorBox::writeBox(BitStream& bitstr) const
{
    writeFullBoxHeader(bitstr);

    bitstr.write8Bits(mES_Descriptor.ES_DescrTag);

    bool esSizeConverged = false;
    std::uint64_t esSizeSize;
    std::uint32_t esDescriptorSize = mES_Descriptor.size;

    BitStream esBitstr;
    /* Write the whole stuff, then figure out if we wrote the correct
     * size for it (we allos mES_Descriptor to be incorrect); rewrite
     * everything with the correct size. However, this may increase
     * the size due to bigger size having been written and thus moving
     * the remaining of the data forward, so we may need to loop even
     * thrice. */
    while (!esSizeConverged)
    {
        esBitstr.clear();
        esSizeSize = writeSize(esBitstr, esDescriptorSize);
        esBitstr.write16Bits(mES_Descriptor.ES_ID);
        esBitstr.write8Bits(mES_Descriptor.flags);
        if (mES_Descriptor.flags & 0x80)  // streamDependenceFlag as defined in 7.2.6.5.1 of ISO/IEC 14486-1:2010(E)
        {
            esBitstr.write16Bits(mES_Descriptor.dependsOn_ES_ID);
        }

        if (mES_Descriptor.flags & 0x40)  // URL_Flag as defined in 7.2.6.5.1 of ISO/IEC 14486-1:2010(E)
        {
            esBitstr.write8Bits(mES_Descriptor.URLlength);
            if (mES_Descriptor.URLlength)
            {
                esBitstr.writeString(mES_Descriptor.URLstring);
            }
        }

        if (mES_Descriptor.flags & 0x20)  // OCRstreamFlag as defined in 7.2.6.5.1 of ISO/IEC 14486-1:2010(E)
        {
            esBitstr.write16Bits(mES_Descriptor.OCR_ES_Id);
        }

        esBitstr.write8Bits(mES_Descriptor.decConfigDescr.DecoderConfigDescrTag);

        BitStream decConfigBitstr;
        std::uint64_t decConfigSize = mES_Descriptor.decConfigDescr.size;
        std::uint64_t decConfigSizeSize;
        bool decConfigSizeConverged = false;
        while (!decConfigSizeConverged)
        {
            decConfigBitstr.clear();
            decConfigSizeSize = writeSize(decConfigBitstr, static_cast<uint32_t>(decConfigSize));
            decConfigBitstr.write8Bits(mES_Descriptor.decConfigDescr.objectTypeIndication);
            decConfigBitstr.write8Bits((mES_Descriptor.decConfigDescr.streamType << 2) | 0x01);
            decConfigBitstr.write24Bits(mES_Descriptor.decConfigDescr.bufferSizeDB);
            decConfigBitstr.write32Bits(mES_Descriptor.decConfigDescr.maxBitrate);
            decConfigBitstr.write32Bits(mES_Descriptor.decConfigDescr.avgBitrate);

            if (mES_Descriptor.decConfigDescr.decSpecificInfo.DecSpecificInfoTag == 5)
            {
                writeDecoderSpecificInfo(decConfigBitstr, mES_Descriptor.decConfigDescr.decSpecificInfo);
            }

            for (const auto& decSpecificInfo : mOtherDecSpecificInfo)
            {
                writeDecoderSpecificInfo(decConfigBitstr, decSpecificInfo);
            }

            decConfigSizeConverged = decConfigBitstr.getSize() == std::uint64_t(decConfigSize) + decConfigSizeSize;

            if (!decConfigSizeConverged)
            {
                decConfigSize = decConfigBitstr.getSize() - decConfigSizeSize;
            }
        }
        esBitstr.writeBitStream(decConfigBitstr);

        esSizeConverged = esBitstr.getSize() == std::uint64_t(esDescriptorSize) + esSizeSize;

        if (!esSizeConverged)
        {
            esDescriptorSize = std::uint32_t(esBitstr.getSize() - esSizeSize);
        }
    }
    bitstr.writeBitStream(esBitstr);
    updateSize(bitstr);
}
Esempio n. 2
0
void Enemigo::atacar(string& NickAtacado,PlayerManager& pm,ServerSocket& socks){
	BitStream bs;
	int danio = intRand(0,30);
	//resto danio si ataca a un golem o a un enemigo
	bool encontro = false;
	bool murio = false;
	for(auto it = pm.getEnemies().begin();it !=pm.getEnemies().end();it++) {
		Enemigo* unEnemigo = it->second;
		if(unEnemigo->getNick() == NickAtacado){
			unEnemigo->hacerDanio(danio);
			encontro = true;
			if(!it->second->estaVivo()){
				murio = true;
				pm.getEnemies().erase(it);
				break;
			}
		}
	}
	//para golem
	if(!encontro){
		for(auto it = pm.getGolems().begin();it !=pm.getGolems().end();it++) {
			Golem* unGolem = it->second;
			if(unGolem->getNick() == NickAtacado){
				unGolem->hacerDanio(danio);
			
				if(!it->second->estaVivo()){
					//aviso a los demas que murio enemigo
					murio = true;
					pm.getGolems().erase(it);
					break;
				}
			}
		}
	}
	//aviso del ataque
	for(auto it = socks.get_clients().begin();it !=socks.get_clients().end();it++) {
		//ataco con la danio
		bs.clear();
		bs << PROTO::ATACAR << this->getNick() << NickAtacado;
		it->second.send(bs.str());
		//mando danio
		bs.clear();
		bs << PROTO::DAMAGE << this->getNick() << NickAtacado << danio;
		it->second.send(bs.str());
		std::cout << "Update " << it->second.nick << " que " << this->getNick() << "->" << NickAtacado << endl;
		//aviso si murio
		if(murio){
			//Veo si termino la mision
			if (mision.getTipo() == Misiones::MISION_ENEMIGO) {
				if (mision.enemigoMision() == NickAtacado) {
					bs.clear();
					bs << PROTO::WINNER << pm.getEnemy(NickAtacado)->ultimoAtacante();
					it->second.send(bs.str());
				}
			} else {
				bs.clear();
				bs << PROTO::ENEMY_DEAD << NickAtacado;
				it->second.send(bs.str());
			}
		}
	}
	return;
}