aboutsummaryrefslogtreecommitdiff
path: root/src/myriad.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/myriad.cpp')
-rw-r--r--src/myriad.cpp69
1 files changed, 56 insertions, 13 deletions
diff --git a/src/myriad.cpp b/src/myriad.cpp
index d3914df..a1a5c38 100644
--- a/src/myriad.cpp
+++ b/src/myriad.cpp
@@ -77,14 +77,18 @@ void Bu::Myriad::initialize()
77 iBlocks = iSize/iBlockSize; 77 iBlocks = iSize/iBlockSize;
78 sio << "Myriad: iSize=" << iSize << ", iBlockSize=" << iBlockSize 78 sio << "Myriad: iSize=" << iSize << ", iBlockSize=" << iBlockSize
79 << ", iBlocks=" << iBlocks << ", iStreams=" << iStreams << sio.nl; 79 << ", iBlocks=" << iBlocks << ", iStreams=" << iStreams << sio.nl;
80 80
81 // Don't do this, just read the damn header.
82 sio << "Myriad: Don't do this, just read the damn header (line 82)"
83 << sio.nl;
84
81 int iHeaderSize = 14 + 8 + 4; 85 int iHeaderSize = 14 + 8 + 4;
82 int iHeaderBlocks = blkDiv( iHeaderSize+4, iBlockSize ); 86 int iHeaderBlocks = 0; //blkDiv( iHeaderSize+4, iBlockSize );
83 87
84 while( iHeaderSize > iHeaderBlocks*iBlockSize ) 88 while( iHeaderSize > iHeaderBlocks*iBlockSize )
85 { 89 {
86 iHeaderSize = 14 + 8 + 4*iHeaderBlocks;
87 iHeaderBlocks = blkDiv( iHeaderSize+4, iBlockSize ); 90 iHeaderBlocks = blkDiv( iHeaderSize+4, iBlockSize );
91 iHeaderSize = 14 + 8 + 4*iHeaderBlocks;
88 } 92 }
89 93
90 sio << "Myriad: iHeaderSize=" << iHeaderSize 94 sio << "Myriad: iHeaderSize=" << iHeaderSize
@@ -102,7 +106,8 @@ void Bu::Myriad::initialize()
102 sStore.read( &s.iId, 4 ); 106 sStore.read( &s.iId, 4 );
103 sStore.read( &s.iSize, 4 ); 107 sStore.read( &s.iSize, 4 );
104 int iSBlocks = blkDiv(s.iSize, iBlockSize); 108 int iSBlocks = blkDiv(s.iSize, iBlockSize);
105 sio << "Myriad: - Stream::iId=" << s.iId << ", Stream::iSize=" << s.iSize 109 sio << "Myriad: - Stream::iId=" << s.iId
110 << ", Stream::iSize=" << s.iSize
106 << ", Stream::aBlocks=" << iSBlocks 111 << ", Stream::aBlocks=" << iSBlocks
107 << ", sStore.tell()=" << sStore.tell() << sio.nl; 112 << ", sStore.tell()=" << sStore.tell() << sio.nl;
108 for( int k = 0; k < iSBlocks; k++ ) 113 for( int k = 0; k < iSBlocks; k++ )
@@ -133,7 +138,7 @@ void Bu::Myriad::initialize()
133 } 138 }
134 } 139 }
135 140
136 sio << bsBlockUsed.toString() << sio.nl; 141 sio << "Myriad: Blocks used: " << bsBlockUsed.toString() << sio.nl;
137 142
138 //printf("%d blocks, %db each, %db block offset\n", 143 //printf("%d blocks, %db each, %db block offset\n",
139 // iBlocks, iBlockSize, iBlockStart ); 144 // iBlocks, iBlockSize, iBlockStart );
@@ -143,7 +148,7 @@ void Bu::Myriad::initialize()
143void Bu::Myriad::initialize( int iBlockSize, int iPreAllocate ) 148void Bu::Myriad::initialize( int iBlockSize, int iPreAllocate )
144{ 149{
145 int iHeaderSize = 14 + 8 + 4; 150 int iHeaderSize = 14 + 8 + 4;
146 int iHeaderBlocks = blkDiv( iHeaderSize+4, iBlockSize ); 151 int iHeaderBlocks = 0; //blkDiv( iHeaderSize+4, iBlockSize );
147 char cBuf = 1; 152 char cBuf = 1;
148 int iBuf = 0; 153 int iBuf = 0;
149 154
@@ -152,13 +157,13 @@ void Bu::Myriad::initialize( int iBlockSize, int iPreAllocate )
152 157
153 while( iHeaderSize > iHeaderBlocks*iBlockSize ) 158 while( iHeaderSize > iHeaderBlocks*iBlockSize )
154 { 159 {
155 iHeaderSize = 14 + 8 + 4*iHeaderBlocks;
156 iHeaderBlocks = blkDiv( iHeaderSize+4, iBlockSize ); 160 iHeaderBlocks = blkDiv( iHeaderSize+4, iBlockSize );
161 iHeaderSize = 14 + 8 + 4*iHeaderBlocks;
157 } 162 }
158 163
159 iPreAllocate += iHeaderBlocks; 164 iPreAllocate += iHeaderBlocks;
160 165
161 sio << "Myriad: iHeaderSize=" << iHeaderSize << ", iBlockSize=" 166 sio << "Myriad: iHeaderSize=" << iHeaderSize << ", iBlockSize="
162 << iBlockSize << ", iHeaderBlocks=" << iHeaderBlocks << sio.nl; 167 << iBlockSize << ", iHeaderBlocks=" << iHeaderBlocks << sio.nl;
163 168
164 bsBlockUsed.setSize( iPreAllocate, true ); 169 bsBlockUsed.setSize( iPreAllocate, true );
@@ -204,6 +209,7 @@ void Bu::Myriad::initialize( int iBlockSize, int iPreAllocate )
204 this->iBlocks = iPreAllocate; 209 this->iBlocks = iPreAllocate;
205 210
206 pStr->iSize = sStore.tell(); 211 pStr->iSize = sStore.tell();
212 sio << "Myriad: Actual end of header stream = " << pStr->iSize << sio.nl;
207 213
208 //hStreams.insert( 0, BlockArray( 0 ) ); 214 //hStreams.insert( 0, BlockArray( 0 ) );
209} 215}
@@ -229,9 +235,9 @@ int Bu::Myriad::createStream( int iPreAllocate )
229 for( int j = 0; j < iPreAllocate; j++ ) 235 for( int j = 0; j < iPreAllocate; j++ )
230 { 236 {
231 int iFreeBlock = findEmptyBlock(); 237 int iFreeBlock = findEmptyBlock();
232 sio << "Myriad: Adding block " << j << sio.nl; 238 sio << "Myriad: Adding block " << iFreeBlock << sio.nl;
233 pStr->aBlocks.append( j ); 239 pStr->aBlocks.append( iFreeBlock );
234 bsBlockUsed.setBit( j ); 240 bsBlockUsed.setBit( iFreeBlock );
235 } 241 }
236 242
237 return 0; 243 return 0;
@@ -261,9 +267,9 @@ void Bu::Myriad::deleteStream( int /*iID*/ )
261{ 267{
262} 268}
263 269
264Bu::MyriadStream Bu::Myriad::openStream( int iID ) 270Bu::MyriadStream Bu::Myriad::openStream( int iId )
265{ 271{
266 return MyriadStream( *this, iID ); 272 return MyriadStream( *this, findStream( iId ) );
267} 273}
268 274
269int Bu::Myriad::getBlockSize() 275int Bu::Myriad::getBlockSize()
@@ -281,4 +287,41 @@ int Bu::Myriad::getNumUsedBlocks()
281 return iUsed; 287 return iUsed;
282} 288}
283 289
290Bu::Myriad::Stream *Bu::Myriad::findStream( int iId )
291{
292 for( StreamArray::iterator i = aStreams.begin(); i; i++ )
293 {
294 if( (*i)->iId == iId )
295 return *i;
296 }
297
298 return NULL;
299}
300
301Bu::Myriad::Block *Bu::Myriad::getBlock( int iBlock )
302{
303 sio << "Myriad: Reading block " << iBlock << ", bytes "
304 << iBlockSize*iBlock << "-" << iBlockSize*(iBlock+1) << sio.nl;
305 Block *pBlock = new Block;
306 pBlock->pData = new char[iBlockSize];
307 sStore.setPos( iBlockSize * iBlock );
308 sStore.read( pBlock->pData, iBlockSize );
309 pBlock->bChanged = false;
310 pBlock->iBlockIndex = iBlock;
311
312 return pBlock;
313}
314
315void Bu::Myriad::releaseBlock( Bu::Myriad::Block *pBlock )
316{
317 sio << "Myriad: Releasing block " << pBlock->iBlockIndex << sio.nl;
318 if( pBlock->bChanged )
319 {
320 sio << "Myriad: - Block changed, writing back to stream." << sio.nl;
321 sStore.setPos( iBlockSize * pBlock->iBlockIndex );
322 sStore.write( pBlock->pData, iBlockSize );
323 }
324 delete[] pBlock->pData;
325 delete pBlock;
326}
284 327