Esempio n. 1
0
luint ID3_Tag::Size( void )
{
	luint			bytesUsed	= 0;
	ID3_Elem		*cur		= frameList;
	ID3_TagHeader	header;

	header.SetVersion ( m_nVersion, m_nRevision );
	bytesUsed += header.Size();

	while( cur )
	{	
		// PL
		if( ( cur->frame->GetID() <= 0 ) || (cur->frame->GetID() > ID3FID_CRYPTOREG ))
		{

//			TRACE( "Invalide FrameID\n" );
			cur = cur->next;
			continue;
		}

		// End PL

		if( cur->frame )
		{
			cur->frame->SetVersion ( m_nVersion, m_nRevision );
			bytesUsed += cur->frame->Size();
		}

		cur = cur->next;
	}

	// add 30% for sync
	if	( m_bSyncOn )
		bytesUsed += bytesUsed / 3;

	bytesUsed += PaddingSize ( bytesUsed );

	return bytesUsed;
}
Esempio n. 2
0
luint ID3_Tag::Render( uchar *buffer )
{
	luint	bytesUsed	= 0;

	if	( buffer )
	{
		ID3_Elem		*cur	= frameList;
		ID3_TagHeader	header;

		SetVersion ( ID3_TAGVERSION, ID3_TAGREVISION );

		header.SetVersion ( m_nVersion, m_nRevision );
		bytesUsed += header.Size();

		// set up the encryption and grouping IDs

		// ...

		while( cur )
		{
			// PL
			// Check that frame has a valid FrameID
			if( ( cur->frame->GetID() <= 0 ) || (cur->frame->GetID() > ID3FID_CRYPTOREG ))
			{
//				TRACE( "Invalide FrameID\n" );
				cur = cur->next;
				continue;
			}
			// End PL

			if	( cur->frame )
			{
				cur->frame->compression = m_bCompression;
				cur->frame->SetVersion ( m_nVersion, m_nRevision );
				bytesUsed += cur->frame->Render ( &buffer[ bytesUsed ] );
			}

			cur = cur->next;
		}

		if	( m_bSyncOn )
		{
			uchar	*tempz;
			luint	newTagSize;

			newTagSize = GetUnSyncSize ( &buffer[ header.Size() ], bytesUsed - header.Size() );

			if	( newTagSize > 0 && ( newTagSize + header.Size() ) > bytesUsed )
			{
#ifdef _DEBUG
//				ASSERT( newTagSize < MAX_ALLOC ); // PL
#endif
				if	( tempz = new uchar[ newTagSize ] )
				{
					UnSync ( tempz, newTagSize, &buffer[ header.Size() ], bytesUsed - header.Size() );
					header.SetFlags ( ID3HF_UNSYNC );

					memcpy ( &buffer[ header.Size() ], tempz, newTagSize );
					bytesUsed = newTagSize + header.Size();
					delete[] tempz;
				}
				else
					ID3_THROW ( ID3E_NoMemory );
			}
		}

		// zero the remainder of the buffer so that our
		// padding bytes are zero
		for	( luint i = 0; i < PaddingSize ( bytesUsed ); i++ )
			buffer[ bytesUsed + i ] = 0;

		bytesUsed += PaddingSize ( bytesUsed );

		header.SetDataSize ( bytesUsed - header.Size() );
		header.Render ( buffer );
	}
	else
		ID3_THROW ( ID3E_NoBuffer );

	// set the flag which says that the tag hasn't changed
	m_bHasChanged = false;

	return bytesUsed;
}