Example #1
0
HRESULT CBlock::Write(IStream* pStream)
{
    HeaderWrite(pStream);
    TrackNumber.Write(pStream);
    short t = (short)TimeCode;
    bswap((BYTE*)&t, 2);
    pStream->Write(&t, 2, nullptr);
    BYTE Lacing = 0;
    BYTE n = (BYTE)BlockData.GetCount();
    if (n > 1) {
        Lacing |= 2;
    }
    pStream->Write(&Lacing, 1, nullptr);
    if (n > 1) {
        pStream->Write(&n, 1, nullptr);
        POSITION pos = BlockData.GetHeadPosition();
        while (pos) {
            CBinary* b = BlockData.GetNext(pos);
            if (pos) {
                INT_PTR len = b->GetCount();
                while (len >= 0) {
                    n = (BYTE)std::min<INT_PTR>(len, 255);
                    pStream->Write(&n, 1, nullptr);
                    len -= 255;
                }
            }
        }
    }
    POSITION pos = BlockData.GetHeadPosition();
    while (pos) {
        CBinary* b = BlockData.GetNext(pos);
        pStream->Write(b->GetData(), (ULONG)b->GetCount(), nullptr);
    }
    return S_OK;
}
Example #2
0
HRESULT CBlock::Write(IStream* pStream)
{
	HeaderWrite(pStream);
	TrackNumber.Write(pStream);
	short t = (short)TimeCode;
	bswap((BYTE*)&t, 2);
	pStream->Write(&t, 2, NULL);
	BYTE Lacing = 0;
	BYTE n = BlockData.GetCount();
	if(n > 1) Lacing |= 2;
	pStream->Write(&Lacing, 1, NULL);
	if(n > 1)
	{
		pStream->Write(&n, 1, NULL);
		POSITION pos = BlockData.GetHeadPosition();
		while(pos)
		{
			CBinary* b = BlockData.GetNext(pos);
			if(pos)
			{
				int len = b->GetCount();
				while(len >= 0)
				{
					n = min(len, 255);
					pStream->Write(&n, 1, NULL);
					len -= 255;
				}
			}
		}
	}
	POSITION pos = BlockData.GetHeadPosition();
	while(pos)
	{
		CBinary* b = BlockData.GetNext(pos);
		pStream->Write(b->GetData(), b->GetCount(), NULL);
	}
	return S_OK;
}