Exemple #1
0
void CVPU1::Cmd_DIRECT(StreamType& stream, CODE nCommand)
{
	uint32 nSize = stream.GetAvailableReadBytes();
	nSize = std::min<uint32>(m_CODE.nIMM * 0x10, nSize);
	assert((nSize & 0x0F) == 0);

	if(nSize != 0)
	{
		uint8* packet = reinterpret_cast<uint8*>(alloca(nSize));
		stream.Read(packet, nSize);

		int32 remainingLength = nSize;
		while(remainingLength > 0)
		{
			uint32 processed = m_vif.GetGif().ProcessPacket(packet, 0, remainingLength, CGsPacketMetadata(2));
			packet += processed;
			remainingLength -= processed;
			assert(remainingLength >= 0);
		}
	}

	m_CODE.nIMM -= (nSize / 0x10);
	if((m_CODE.nIMM == 0) && (nSize != 0))
	{
		m_STAT.nVPS = 0;
	}
	else
	{
		m_STAT.nVPS = 1;
	}
}
void print_stream_state( const StreamType &stream )
{
    cout << "good: " << stream.good() << endl;
    cout << "eof: " << stream.eof() << endl;
    cout << "fail: " << stream.fail() << endl;
    cout << "bad: " << stream.bad() << endl;
    cout << bitset<4>(stream.rdstate()).to_string() << endl;
}
Exemple #3
0
bool CVPU::Unpack_V32(StreamType& stream, uint128& result, unsigned int fields)
{
	if(stream.GetAvailableReadBytes() < (fields * 4)) return false;

	stream.Read(&result, (fields * 4));

	return true;
}
Exemple #4
0
bool CVPU::Unpack_S32(StreamType& stream, uint128& result)
{
	if(stream.GetAvailableReadBytes() < 4) return false;

	uint32 word = 0;
	stream.Read(&word, 4);

	for(unsigned int i = 0; i < 4; i++)
	{
		result.nV[i] = word;
	}

	return true;
}
Exemple #5
0
bool CVPU::Unpack_V45(StreamType& stream, uint128& result)
{
	if(stream.GetAvailableReadBytes() < 2) return false;

	uint16 nColor = 0;
	stream.Read(&nColor, 2);

	result.nV0 = ((nColor >>  0) & 0x1F) << 3;
	result.nV1 = ((nColor >>  5) & 0x1F) << 3;
	result.nV2 = ((nColor >> 10) & 0x1F) << 3;
	result.nV3 = ((nColor >> 15) & 0x01) << 7;

	return true;
}
Exemple #6
0
void CVPU::ProcessPacket(StreamType& stream)
{
	while(stream.GetAvailableReadBytes())
	{
		if(m_STAT.nVPS == 1)
		{
			//Command is waiting for more data...
			ExecuteCommand(stream, m_CODE);

			if((m_STAT.nVPS == 1) && (stream.GetAvailableReadBytes() != 0))
			{
				//We have data in our FIFO but we still need more than what's available
				break;
			}
			else
			{
				continue;
			}
		}
		if(m_STAT.nVEW == 1)
		{
			if(IsRunning()) break;
			m_STAT.nVEW = 0;
			//Command is waiting for micro-program to end.
			ExecuteCommand(stream, m_CODE);
			continue;
		}

#ifdef DELAYED_MSCAL
		m_previousCODE = m_CODE;
#endif
		stream.Read(&m_CODE, sizeof(CODE));

		assert(m_CODE.nI == 0);

		m_NUM = m_CODE.nNUM;

		ExecuteCommand(stream, m_CODE);
	}

#ifdef DELAYED_MSCAL
	if(stream.GetAvailableReadBytes() == 0)
	{
		ResumeDelayedMicroProgram();
	}
#endif
}
Exemple #7
0
void CVPU::Cmd_MPG(StreamType& stream, CODE nCommand)
{
	uint32 nSize = stream.GetAvailableReadBytes();

	uint32 nNum			= (m_NUM == 0) ? (256) : (m_NUM);
	uint32 nCodeNum		= (m_CODE.nNUM == 0) ? (256) : (m_CODE.nNUM);
	uint32 nTransfered	= (nCodeNum - nNum) * 8;

	nCodeNum *= 8;
	nNum *= 8;

	nSize = std::min<uint32>(nNum, nSize);

	uint32 nDstAddr = (m_CODE.nIMM * 8) + nTransfered;

	//Check if microprogram is running
	if(IsRunning())
	{
		m_STAT.nVEW = 1;
		return;
	}

	if(nSize != 0)
	{
		uint8* microProgram = reinterpret_cast<uint8*>(alloca(nSize));
		stream.Read(microProgram, nSize);

		//Check if there's a change
		if(memcmp(m_microMem + nDstAddr, microProgram, nSize) != 0)
		{
			m_executor.ClearActiveBlocks();
			memcpy(m_microMem + nDstAddr, microProgram, nSize);
		}
	}

	m_NUM -= static_cast<uint8>(nSize / 8);
	if((m_NUM == 0) && (nSize != 0))
	{
		m_STAT.nVPS = 0;
	}
	else
	{
		m_STAT.nVPS = 1;
	}
}
Exemple #8
0
bool CVPU::Unpack_V16(StreamType& stream, uint128& result, unsigned int fields, bool zeroExtend)
{
	if(stream.GetAvailableReadBytes() < (fields * 2)) return false;

	for(unsigned int i = 0; i < fields; i++)
	{
		uint32 temp = 0;
		stream.Read(&temp, 2);
		if(!zeroExtend)
		{
			temp = static_cast<int16>(temp);
		}

		result.nV[i] = temp;
	}

	return true;
}
Exemple #9
0
bool CVPU::Unpack_S8(StreamType& stream, uint128& result, bool zeroExtend)
{
	if(stream.GetAvailableReadBytes() < 1) return false;

	uint32 temp = 0;
	stream.Read(&temp, 1);
	if(!zeroExtend)
	{
		temp = static_cast<int8>(temp);
	}

	for(unsigned int i = 0; i < 4; i++)
	{
		result.nV[i] = temp;
	}

	return true;
}
Exemple #10
0
const BSONObj* DBController::insert(const char* db, const char* ns, BSONObj* obj, const BSONObj* options) {
	if (_logger->isDebug()) _logger->debug(2, "DBController::insert ns: %s, bson: %s", ns, obj->toChar());
	StreamType* streamData = StreamManager::getStreamManager()->open(db, ns, DATA_FTYPE);

	DBController::fillRequiredFields(obj);

	//    long crcStructure = checkStructure(obj);

	//    char* text = obj->toChar();
	//    streamData->writeChars(text, strlen(text));
	//    free(text);

	insertIndex(db, ns, obj, streamData->currentPos());

	writeBSON(streamData, obj);

	//CacheManager::objectCache()->add(id, new BSONObj(*obj));
	//
	return obj;
}
Exemple #11
0
void DBController::update(const char* db, const char* ns, BSONObj* obj, const BSONObj* options) {
	if (_logger->isDebug()) _logger->debug(2, "DBController::update ns: %s, bson: %s", ns, obj->toChar());
	StreamType* streamData = StreamManager::getStreamManager()->open(db, ns, DATA_FTYPE);

	Index* index = findIndex(db, ns, obj);

	long currentPos = streamData->currentPos();

	// Moves to the record to update
	streamData->seek(index->posData);

	BSONObj* previous = readBSON(streamData);
	previous->add("_status", 3); // Updated

	streamData->seek(index->posData);
	writeBSON(streamData, previous);

	// Back to the end of the stream
	streamData->seek(currentPos);

	updateIndex(db, ns, obj, streamData->currentPos());

	obj->add("_status", 1); // Active

	writeBSON(streamData, obj);

	//std::string id = obj->getDJString("_id");

	//CacheManager::objectCache()->add(id, new BSONObj(*obj));
}
Exemple #12
0
void DBController::remove(const char* db, const char* ns, const char* documentId, const char* revision, const BSONObj* options) {
	if (_logger->isDebug()) _logger->debug(2, "DBController::update db: %s, ns: %s, documentId: %s, revision: %s", db, ns, documentId, revision);
	StreamType* streamData = StreamManager::getStreamManager()->open(db, ns, DATA_FTYPE);

	IndexAlgorithm* impl = IndexFactory::indexFactory.index(db, ns, "_id");

	BSONObj indexBSON;
	indexBSON.add("_id", documentId);
	Index* index = impl->find(&indexBSON);
	if (index != NULL) {

		// TODO check the revision id
		StreamType* out = StreamManager::getStreamManager()->open(db, ns, DATA_FTYPE);
		out->flush();

		long currentPos = out->currentPos();

		out->seek(index->posData);

		BSONObj* obj = readBSON(out);
		obj->add("_status", 2); // DELETED

		// Get back to the record start
		out->seek(index->posData);
		writeBSON(out, obj);

		// restores the last position
		out->seek(currentPos);

		//std::string id = obj->getDJString("_id");

		//CacheManager::objectCache()->remove(id);
		delete obj;
	}
}
Exemple #13
0
void CVPU::Cmd_STMASK(StreamType& stream, CODE command)
{
	if(m_NUM == 0)
	{
		m_NUM = 1;
	}

	while(m_NUM != 0 && stream.GetAvailableReadBytes())
	{
		stream.Read(&m_MASK, 4);
		m_NUM--;
	}

	if(m_NUM == 0)
	{
		m_STAT.nVPS = 0;
	}
	else
	{
		m_STAT.nVPS = 1;
	}
}
Exemple #14
0
void CVPU::Cmd_STCOL(StreamType& stream, CODE nCommand)
{
	if(m_NUM == 0)
	{
		m_NUM = 4;
	}

	while(m_NUM != 0 && stream.GetAvailableReadBytes())
	{
		assert(m_NUM <= 4);
		stream.Read(&m_C[4 - m_NUM], 4);
		m_NUM--;
	}

	if(m_NUM == 0)
	{
		m_STAT.nVPS = 0;
	}
	else
	{
		m_STAT.nVPS = 1;
	}
}
Exemple #15
0
void CVif1::Cmd_DIRECT(StreamType& stream, CODE nCommand)
{
    uint32 nSize = stream.GetAvailableReadBytes();
    nSize = std::min<uint32>(m_CODE.nIMM * 0x10, nSize);
    assert((nSize & 0x0F) == 0);

    if(nSize != 0)
    {
        if(m_directBuffer.size() < nSize)
        {
            m_directBuffer.resize(nSize);
        }

        auto packet = m_directBuffer.data();
        stream.Read(packet, nSize);

        int32 remainingLength = nSize;
        while(remainingLength > 0)
        {
            uint32 processed = m_gif.ProcessPacket(packet, 0, remainingLength, CGsPacketMetadata(2));
            packet += processed;
            remainingLength -= processed;
            assert(remainingLength >= 0);
        }
    }

    m_CODE.nIMM -= (nSize / 0x10);
    if((m_CODE.nIMM == 0) && (nSize != 0))
    {
        m_STAT.nVPS = 0;
    }
    else
    {
        m_STAT.nVPS = 1;
    }
}
Exemple #16
0
    std::ios_base::iostate handle_error(StreamType& strm) const
        {
        std::ios_base::iostate err(error_m);

        try { throw; }

        catch (std::bad_alloc&)
            {
            set_bad();

            std::ios_base::iostate exception_mask(strm.exceptions());
            
            if (exception_mask & std::ios_base::failbit && !(exception_mask & std::ios_base::badbit))
                strm.setstate(err);
            else if (exception_mask & std::ios_base::badbit)
                {
                try { strm.setstate(err); }
                catch (std::ios_base::failure&) { }
                throw;
                }
            }
        catch (...)
            {
            set_fail();

            std::ios_base::iostate exception_mask(strm.exceptions());

            if ((exception_mask & std::ios_base::badbit) && (err & std::ios_base::badbit))
                strm.setstate(err);
            else if (exception_mask & std::ios_base::failbit)
                {
                try { strm.setstate(err); }
                catch (std::ios_base::failure&) { }
                throw;
                }
            }

        return err;
        }
Exemple #17
0
void details::showinfo()
{
    pp = p.getTSPacket(packet);
    int l = 0, c=0;
    for(int i = 0; i<packet.length; i++)
    {
        if(i%16 == 0)
        {
            l+=30;
            c = 0;
        }
        if(i%8 == 0)
            c+=30;
    io = new QGraphicsTextItem;
    io->setPos(c+(i%16)*30,l);
    st = QString::number(pp.rawData[i],16).toUpper();
    io->setPlainText(st);
    io->setToolTip(QString::number(pp.rawData[i],2));
    io->font().setPointSize(30);
    sc->addItem(io);
    }
    pst = p.getPIDList();




    StreamType *streamTypes = new StreamType();
    QString typ = streamTypes->getStreamType(pst[packet.pid].streamType);
    st = QString::number(packet.pid,16).toUpper();

    tw->setGeometry(20,20,550,150);
    tw->setHeaderLabel("Packet");

    //ts header
    twi = new QTreeWidgetItem();
    twi->setText(0,"MPEG-TS Header");
    QTreeWidgetItem *ch = new QTreeWidgetItem();
    ch->setText(0,"Sync Byte: 0x47");
    twi->addChild(ch);
    ch = new QTreeWidgetItem();
    ch->setText(0,QString("Transport Error Indicator: %1 ").arg(pp.tsheader.transportErrorIndicator));
    twi->addChild(ch);
    ch = new QTreeWidgetItem();
    ch->setText(0,QString("Payload Unit Start Indicator: %1 ").arg(pp.tsheader.payloadUnitStartIndicator));
    twi->addChild(ch);
    ch = new QTreeWidgetItem();
    ch->setText(0,QString("Transport Priority: %1 ").arg(pp.tsheader.transportPriority));
    twi->addChild(ch);
    ch = new QTreeWidgetItem();
    ch->setText(0,QString("PID: 0x%1 ").arg(QString::number(pp.tsheader.pid,16)));
    twi->addChild(ch);
    ch = new QTreeWidgetItem();
    ch->setText(0,QString("Scrambling Control: %1 ").arg(pp.tsheader.scramblingControl));
    twi->addChild(ch);
    ch = new QTreeWidgetItem();
    ch->setText(0,QString("Adaptation Field Control: %1 ").arg(pp.tsheader.adaptationFieldControl));
    twi->addChild(ch);
    ch = new QTreeWidgetItem();
    ch->setText(0,QString("Continuity Counter: %1 ").arg(pp.tsheader.continuityCounter));
    twi->addChild(ch);
    tw->addTopLevelItem(twi);

    //adaptation field
    if(pp.tsheader.adaptationFieldControl > 1)
    {
        twi = new QTreeWidgetItem();
        twi->setText(0,"Adaptation Field");
        ch = new QTreeWidgetItem();
        ch->setText(0,QString("Adaptation Field Lenght: %1 ").arg(pp.afheader.length));
        twi->addChild(ch);
        ch = new QTreeWidgetItem();
        ch->setText(0,QString("Discontinuity Indicator: %1 ").arg(pp.afheader.discontinuityIndicator));
        twi->addChild(ch);
        ch = new QTreeWidgetItem();
        ch->setText(0,QString("Random Access Indicator: %1 ").arg(pp.afheader.randomAccessIndicator));
        twi->addChild(ch);
        ch = new QTreeWidgetItem();
        ch->setText(0,QString("Elementary stream priority indicator: %1 ").arg(pp.afheader.elementaryStreamPriorityIndicator));
        twi->addChild(ch);
        ch = new QTreeWidgetItem();
        ch->setText(0,QString("PCR Flag: %1 ").arg(pp.afheader.pcrFlag));
        twi->addChild(ch);
        ch = new QTreeWidgetItem();
        ch->setText(0,QString("OPCR Flag: %1 ").arg(pp.afheader.opcrFlag));
        twi->addChild(ch);
        ch = new QTreeWidgetItem();
        ch->setText(0,QString("Splicing Point Flag: %1 ").arg(pp.afheader.splicingPointFlag));
        twi->addChild(ch);
        ch = new QTreeWidgetItem();
        ch->setText(0,QString("Transport Private Data Flag: %1 ").arg(pp.afheader.transportPrivateDataFlag));
        twi->addChild(ch);
        ch = new QTreeWidgetItem();
        ch->setText(0,QString("Adaptation Field Extension Flag: %1 ").arg(pp.afheader.extensionFlag));
        twi->addChild(ch);
        ch = new QTreeWidgetItem();
        ch->setText(0,"Adaptation Field Extension");
        twi->addChild(ch);
     //   QTreeWidgetItem *afex = new QTreeWidgetItem();

        tw->addTopLevelItem(twi);
    }

}
Exemple #18
0
void CVPU::Cmd_UNPACK(StreamType& stream, CODE nCommand, uint32 nDstAddr)
{
	assert((nCommand.nCMD & 0x60) == 0x60);

	bool usn = (m_CODE.nIMM & 0x4000) != 0;
	bool useMask = (nCommand.nCMD & 0x10) != 0;
	uint32 cl = m_CYCLE.nCL;
	uint32 wl = m_CYCLE.nWL;

	if(m_NUM == nCommand.nNUM)
	{
		m_readTick = 0;
		m_writeTick = 0;
	}

	uint32 currentNum = (m_NUM == 0) ? 256 : m_NUM;
	uint32 codeNum = (m_CODE.nNUM == 0) ? 256 : m_CODE.nNUM;
	uint32 transfered = codeNum - currentNum;
	assert(transfered == 0 || cl == wl);	//The value above is only valid for specific combinations of cl and wl

	nDstAddr += transfered;
	nDstAddr *= 0x10;

	uint128* dst = reinterpret_cast<uint128*>(&m_vuMem[nDstAddr]);

	while((currentNum != 0) && stream.GetAvailableReadBytes())
	{
		bool mustWrite = false;
		uint128 writeValue;
		memset(&writeValue, 0, sizeof(writeValue));

		if(cl >= wl)
		{
			if(m_readTick < wl || wl == 0)
			{
				bool success = Unpack_ReadValue(nCommand, stream, writeValue, usn);
				if(!success) break;
				mustWrite = true;
			}
		}
		else
		{
			if(m_writeTick < cl)
			{
				bool success = Unpack_ReadValue(nCommand, stream, writeValue, usn);
				if(!success) break;
			}

			mustWrite = true;
		}

		if(mustWrite)
		{
			for(unsigned int i = 0; i < 4; i++)
			{
				uint32 maskOp = useMask ? GetMaskOp(i, m_writeTick) : MASK_DATA;

				if(maskOp == MASK_DATA)
				{
					if(m_MODE == MODE_OFFSET)
					{
						writeValue.nV[i] += m_R[i];
					}
					else if(m_MODE == MODE_DIFFERENCE)
					{
						assert(0);
					}

					dst->nV[i] = writeValue.nV[i];
				}
				else if(maskOp == MASK_ROW)
				{
					dst->nV[i] = m_R[i];
				}
				else if(maskOp == MASK_COL)
				{
					int index = (m_writeTick > 3) ? 3 : m_writeTick;
					dst->nV[i] = m_C[index];
				}
				else if(maskOp == MASK_MASK)
				{
					//Don't write anything
				}
				else
				{
					assert(0);
				}
			}
			
			currentNum--;
		}

		if(cl >= wl)
		{
			m_writeTick = std::min<uint32>(m_writeTick + 1, wl);
			m_readTick = std::min<uint32>(m_readTick + 1, cl);

			if(m_readTick == cl)
			{
				m_writeTick = 0;
				m_readTick = 0;
			}
		}
		else
		{
			m_writeTick = std::min<uint32>(m_writeTick + 1, wl);
			m_readTick = std::min<uint32>(m_readTick + 1, cl);

			if(m_writeTick == wl)
			{
				m_writeTick = 0;
				m_readTick = 0;
			}
		}

		dst++;
	}

	if(currentNum != 0)
	{
		m_STAT.nVPS = 1;
	}
	else
	{
//        assert((m_cmdBuffer.GetReadCount() & 0x03) == 0);
		stream.Align32();
		m_STAT.nVPS = 0;
	}

	m_NUM = static_cast<uint8>(currentNum);
}
Exemple #19
0
void DBController::initialize(std::string dataDir) {
	if (_logger->isInfo()) _logger->info("DBController initializing. Data dir: %s", dataDir.c_str());

	_dataDir = dataDir;

	if (_logger->isDebug()) _logger->debug(0, "data dir = %s", _dataDir.c_str());

	if (!existDir(_dataDir.c_str())) {
		makeDir(_dataDir.c_str());
	}

	if (!checkFileCreation(_dataDir.c_str())) {
		_logger->error("An error ocurred using the data folder: %s. Please check that the user has permissions for writing over that directory. Error: %s", _dataDir.c_str(), lastErrorDescription()); 
		exit(1);
	}

	StreamManager::getStreamManager()->setDataDir(_dataDir);
	StreamManager::getStreamManager()->setInitializing(true);

	std::auto_ptr<FileInputStream> fis(new FileInputStream((_dataDir + "djondb.dat").c_str(), "rb"));
	while (!fis->eof()) {
		std::string* db = fis->readString();
		std::string* ns = fis->readString();
		int streams = fis->readInt();
		for (int x = 0; x < streams; x++) {
			FILE_TYPE type = static_cast<FILE_TYPE>(fis->readInt());
			StreamType* stream = StreamManager::getStreamManager()->open(db->c_str(), ns->c_str(), type);

			if (type == INDEX_FTYPE) {
				StreamType* dbstream = StreamManager::getStreamManager()->open(db->c_str(), ns->c_str(), DATA_FTYPE);
				std::set<std::string> skeys;
				skeys.insert("_id");

				IndexAlgorithm* impl = IndexFactory::indexFactory.index(db->c_str(), ns->c_str(), skeys);
				// If the database is version lesser than 0.3 then the indexes should
				// be migrated to the new format
				Version vindex("0.300000000");
				if (*dbstream->version() < vindex) {
					migrateIndex0_3(db->c_str(), ns->c_str(), stream, impl);
					removeFile(stream->fileName().c_str());
					((DBFileStream*)dbstream)->updateVersion(&vindex);
				}
				/* 
					long currentPos = stream->currentPos();
					stream->seek(0);

					int records = 0;
					while (!stream->eof()) {
					BSONObj* obj = readBSON(stream);

					if (!impl) {
					std::set<std::string> skeys;
					for (BSONObj::const_iterator i = obj->begin(); i != obj->end(); i++) {
					std::string key = i->first;
					skeys.insert(key);
					}
					}
					long indexPos = stream->readLong();
					long posData = stream->readLong();
					if (obj->has("_id")) {
					impl->add(*obj, obj->getDJString("_id"), posData, indexPos);
					records++;
					}
					delete obj;
					}
					stream->seek(currentPos);

					if (_logger->isInfo()) _logger->info("db: %s, ns: %s, Index initialized. Records: %d", db->c_str(), ns->c_str(), records);
					*/
			}
		}
	}
	fis->close();
	StreamManager::getStreamManager()->setInitializing(false);
}
bool bad_stream( const StreamType &stream )
{ return (stream.fail() || stream.bad()); }