Exemple #1
0
uint64 EbmlMaster::UpdateSize(bool bWithDefault, bool bForceRender)
{
	SetSize_(0);

	if (!IsFiniteSize())
		return (0-1);

	if (!bForceRender) {
		assert(CheckMandatory());
    }
	
	size_t Index;
	
	for (Index = 0; Index < ElementList.size(); Index++) {
		if (!bWithDefault && (ElementList[Index])->IsDefaultValue())
			continue;
		(ElementList[Index])->UpdateSize(bWithDefault, bForceRender);
		uint64 SizeToAdd = (ElementList[Index])->ElementSize(bWithDefault);
#if defined(LIBEBML_DEBUG)
		if (static_cast<int64>(SizeToAdd) == (0-1))
			return (0-1);
#endif // LIBEBML_DEBUG
		SetSize_(GetSize() + SizeToAdd);
	}
	if (bChecksumUsed) {
		SetSize_(GetSize() + Checksum.ElementSize());
	}

	return GetSize();
}
uint64 EbmlSInteger::UpdateSize(bool bWithDefault, bool bForceRender)
{
	if (!bWithDefault && IsDefaultValue())
		return 0;

	if (Value <= 0x7F && Value >= (-0x80)) {
		SetSize_(1);
	} else if (Value <= 0x7FFF && Value >= (-0x8000)) {
		SetSize_(2);
	} else if (Value <= 0x7FFFFF && Value >= (-0x800000)) {
		SetSize_(3);
	} else if (Value <= 0x7FFFFFFF && Value >= (-0x80000000)) {
		SetSize_(4);
	} else if (Value <= EBML_PRETTYLONGINT(0x7FFFFFFFFF) &&
		   Value >= EBML_PRETTYLONGINT(-0x8000000000)) {
		SetSize_(5);
	} else if (Value <= EBML_PRETTYLONGINT(0x7FFFFFFFFFFF) &&
		   Value >= EBML_PRETTYLONGINT(-0x800000000000)) {
		SetSize_(6);
	} else if (Value <= EBML_PRETTYLONGINT(0x7FFFFFFFFFFFFF) &&
		   Value >= EBML_PRETTYLONGINT(-0x80000000000000)) {
		SetSize_(7);
	} else {
		SetSize_(8);
	}

	if (GetDefaultSize() > GetSize()) {
		SetSize_(GetDefaultSize());
	}

	return GetSize();
}
uint64 EbmlUInteger::UpdateSize(bool bWithDefault, bool /* bForceRender */)
{
	if (!bWithDefault && IsDefaultValue())
		return 0;

	if (Value <= 0xFF) {
		SetSize_(1);
	} else if (Value <= 0xFFFF) {
		SetSize_(2);
	} else if (Value <= 0xFFFFFF) {
		SetSize_(3);
	} else if (Value <= 0xFFFFFFFF) {
		SetSize_(4);
	} else if (Value <= EBML_PRETTYLONGINT(0xFFFFFFFFFF)) {
		SetSize_(5);
	} else if (Value <= EBML_PRETTYLONGINT(0xFFFFFFFFFFFF)) {
		SetSize_(6);
	} else if (Value <= EBML_PRETTYLONGINT(0xFFFFFFFFFFFFFF)) {
		SetSize_(7);
	} else {
		SetSize_(8);
	}

	if (GetDefaultSize() > GetSize()) {
		SetSize_(GetDefaultSize());
	}

	return GetSize();
}
uint64 EbmlString::UpdateSize(bool bWithDefault, bool bForceRender)
{
	if (!bWithDefault && IsDefaultValue())
		return 0;

	if (Value.length() < GetDefaultSize()) {
		SetSize_(GetDefaultSize());
	} else {
		SetSize_(Value.length());
	}
	return GetSize();
}
Exemple #5
0
filepos_t KaxInternalBlock::UpdateSize(bool bSaveDefault, bool bForceRender)
{
	LacingType LacingHere;
    assert(EbmlBinary::GetBuffer() == NULL); // Data is not used for KaxInternalBlock
	assert(TrackNumber < 0x4000); // no more allowed for the moment
	unsigned int i;

	// compute the final size of the data
	switch (myBuffers.size()) {
		case 0:
			SetSize_(0);
			break;
		case 1:
			SetSize_(4 + myBuffers[0]->Size());
			break;
		default:
			SetSize_(4 + 1); // 1 for the lacing head
			if (mLacing == LACING_AUTO)
				LacingHere = GetBestLacingType();
			else
				LacingHere = mLacing;
			switch (LacingHere)
			{
			case LACING_XIPH:
				for (i=0; i<myBuffers.size()-1; i++) {
					SetSize_(GetSize() + myBuffers[i]->Size() + (myBuffers[i]->Size() / 0xFF + 1));
				}
				break;
			case LACING_EBML:
				SetSize_(GetSize() + myBuffers[0]->Size() + CodedSizeLength(myBuffers[0]->Size(), 0, IsFiniteSize()));
				for (i=1; i<myBuffers.size()-1; i++) {
					SetSize_(GetSize() + myBuffers[i]->Size() + CodedSizeLengthSigned(int64(myBuffers[i]->Size()) - int64(myBuffers[i-1]->Size()), 0));
				}
				break;
			case LACING_FIXED:
				for (i=0; i<myBuffers.size()-1; i++) {
					SetSize_(GetSize() + myBuffers[i]->Size());
				}
				break;
			default:
				assert(0);
			}
			// Size of the last frame (not in lace)
			SetSize_(GetSize() + myBuffers[i]->Size());
			break;
	}

	if (TrackNumber >= 0x80)
		SetSize_(GetSize() + 1); // the size will be coded with one more octet

	return GetSize();
}
Exemple #6
0
EbmlCrc32::EbmlCrc32()
{
	ResetCRC();
	SetDefaultSize(4);
	m_crc_final = 0;
	SetSize_(4);
	//This EbmlElement has been set
//	SetValueIsSet();
}
Exemple #7
0
/*!
	\todo more optimisation is possible (render the Block head and don't copy the buffer in memory, care should be taken with the allocation of Data)
	\todo the actual timecode to write should be retrieved from the Cluster from here
*/
filepos_t KaxInternalBlock::RenderData(IOCallback & output, bool bForceRender, bool bSaveDefault)
{
	if (myBuffers.size() == 0) {
		return 0;
	} else {
		assert(TrackNumber < 0x4000);
		binary BlockHead[5], *cursor = BlockHead;
		unsigned int i;

		if (myBuffers.size() == 1) {
			SetSize_(4);
			mLacing = LACING_NONE;
		} else {
			if (mLacing == LACING_NONE)
				mLacing = LACING_EBML; // supposedly the best of all
			SetSize_(4 + 1); // 1 for the lacing head (number of laced elements)
		}
		if (TrackNumber > 0x80)
			SetSize_(GetSize() + 1);

		// write Block Head
		if (TrackNumber < 0x80) {
			*cursor++ = TrackNumber | 0x80; // set the first bit to 1 
		} else {
			*cursor++ = (TrackNumber >> 8) | 0x40; // set the second bit to 1
			*cursor++ = TrackNumber & 0xFF;
		}

		assert(ParentCluster != NULL);
		int16 ActualTimecode = ParentCluster->GetBlockLocalTimecode(Timecode);
		big_int16 b16(ActualTimecode);
		b16.Fill(cursor);
		cursor += 2;

		*cursor = 0; // flags

		if (mLacing == LACING_AUTO) {
			mLacing = GetBestLacingType();
		}

		// invisible flag
		if (mInvisible)
			*cursor = 0x08;

		if (bIsSimple) {
			if (bIsKeyframe)
				*cursor |= 0x80;
			if (bIsDiscardable)
				*cursor |= 0x01;
		}
		
		// lacing flag
		switch (mLacing)
		{
		case LACING_XIPH:
			*cursor++ |= 0x02;
			break;
		case LACING_EBML:
			*cursor++ |= 0x06;
			break;
		case LACING_FIXED:
			*cursor++ |= 0x04;
			break;
		case LACING_NONE:
			break;
	    default:
			assert(0);
		}

		output.writeFully(BlockHead, 4 + ((TrackNumber > 0x80) ? 1 : 0));

		binary tmpValue;
		switch (mLacing)
		{
		case LACING_XIPH:
			// number of laces
			tmpValue = myBuffers.size()-1;
			output.writeFully(&tmpValue, 1);

			// set the size of each member in the lace
			for (i=0; i<myBuffers.size()-1; i++) {
				tmpValue = 0xFF;
				uint16 tmpSize = myBuffers[i]->Size();
				while (tmpSize >= 0xFF) {
					output.writeFully(&tmpValue, 1);
					SetSize_(GetSize() + 1);
					tmpSize -= 0xFF;
				}
				tmpValue = binary(tmpSize);
				output.writeFully(&tmpValue, 1);
				SetSize_(GetSize() + 1);
			}
			break;
		case LACING_EBML:
			// number of laces
			tmpValue = myBuffers.size()-1;
			output.writeFully(&tmpValue, 1);

			{
				int64 _Size;
				int _CodedSize;
				binary _FinalHead[8]; // 64 bits max coded size

				_Size = myBuffers[0]->Size();

				_CodedSize = CodedSizeLength(_Size, 0, IsFiniteSize());

				// first size in the lace is not a signed
				CodedValueLength(_Size, _CodedSize, _FinalHead);
				output.writeFully(_FinalHead, _CodedSize);
				SetSize_(GetSize() + _CodedSize);

				// set the size of each member in the lace
				for (i=1; i<myBuffers.size()-1; i++) {
					_Size = int64(myBuffers[i]->Size()) - int64(myBuffers[i-1]->Size());
					_CodedSize = CodedSizeLengthSigned(_Size, 0);
					CodedValueLengthSigned(_Size, _CodedSize, _FinalHead);
					output.writeFully(_FinalHead, _CodedSize);
					SetSize_(GetSize() + _CodedSize);
				}
			}
			break;
		case LACING_FIXED:
			// number of laces
			tmpValue = myBuffers.size()-1;
			output.writeFully(&tmpValue, 1);
			break;
		case LACING_NONE:
			break;
	    default:
			assert(0);
		}

		// put the data of each frame
		for (i=0; i<myBuffers.size(); i++) {
			output.writeFully(myBuffers[i]->Buffer(), myBuffers[i]->Size());
			SetSize_(GetSize() + myBuffers[i]->Size());
		}
	}

	return GetSize();
}