www.pudn.com > XvidQP.rar > AVIStripeSystem.cpp


//	VirtualDub - Video processing and capture application 
//	Copyright (C) 1998-2001 Avery Lee 
// 
//	This program is free software; you can redistribute it and/or modify 
//	it under the terms of the GNU General Public License as published by 
//	the Free Software Foundation; either version 2 of the License, or 
//	(at your option) any later version. 
// 
//	This program is distributed in the hope that it will be useful, 
//	but WITHOUT ANY WARRANTY; without even the implied warranty of 
//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
//	GNU General Public License for more details. 
// 
//	You should have received a copy of the GNU General Public License 
//	along with this program; if not, write to the Free Software 
//	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
 
#include "VirtualDub.h" 
 
#include  
#include  
#include  
 
#include  
#include  
 
//#include "ProgressDialog.h" 
#include "Error.h" 
 
#include "AVIStripeSystem.h" 
 
/////////////////////////////////////////////////////////////////////////// 
// 
//	AVIStripe 
// 
/////////////////////////////////////////////////////////////////////////// 
 
void *AVIStripe::operator new(size_t stSize, int iNameBytes) { 
	return malloc(stSize + iNameBytes); 
} 
 
/////////////////////////////////////////////////////////////////////////// 
// 
//	AVIStripeSystem 
// 
/////////////////////////////////////////////////////////////////////////// 
 
void AVIStripeSystem::_construct(int nStripes) { 
	int i; 
 
	this->nStripes = nStripes; 
 
	if (!(stripe = new AVIStripe *[nStripes])) 
		throw MyMemoryError(); 
 
	for(i=0; ilBufferSize = lBuffer; 
			stripe[cur]->lChunkSize	= lChunk; 
			stripe[cur]->iNameLen	= t+1-s; 
			stripe[cur]->cStripeMode	= cMode[0]; 
			stripe[cur]->scPriority	= iPri; 
			strcpy(stripe[cur]->szName, s); 
 
			++lineno; 
		} 
	} catch(...) { 
		if (f) fclose(f); 
		_destruct(); 
		throw; 
	} 
	fclose(f); 
} 
 
void AVIStripeSystem::_destruct() { 
	int i; 
 
	if (stripe) 
		for(i=0; iStart()) 
			|| -1 == (lEnd = pasIndex->End())) 
 
			throw MyError("Stripe index: can't get start/end of index stream"); 
 
//		ProgressDialog pd(NULL, "AVI Striped Import Filter", "Reading stripe index", lEnd-lStart, true); 
 
//		pd.setValueFormat("Frame %ld/%ld"); 
 
		index_table_size = lEnd - lStart; 
 
		if (!(index_table = new AVIStripeIndexEntry[index_table_size])) 
			throw MyMemoryError(); 
 
		asieptr = index_table; 
 
		pasIndex->BeginStreaming(lStart, lEnd, 100000); 
 
		lCur = lStart; 
 
		while(lCur < lEnd) { 
			HRESULT err; 
			LONG lActualBytes, lActualSamples; 
 
			err = pasIndex->Read(lCur, lEnd-lCur, asieptr, sizeof(AVIStripeIndexEntry)*(lEnd-lCur), &lActualBytes, &lActualSamples); 
 
			if (err == AVIERR_OK && !lActualSamples) 
				err = AVIERR_FILEREAD; 
 
			if (err != AVIERR_OK) throw MyAVIError("AVIStripeIndex",err); 
 
			if (lActualBytes != lActualSamples * sizeof(AVIStripeIndexEntry)) 
				throw MyError("Stripe index: bad index marks! (not 16 bytes)"); 
 
			lCur += lActualSamples; 
			asieptr += lActualSamples; 
 
//			pd.advance(lCur); 
//			pd.check(); 
		} 
 
		pasIndex->EndStreaming(); 
 
	} catch(...) { 
		delete index_table; 
		throw; 
	} 
} 
 
AVIStripeIndexLookup::~AVIStripeIndexLookup() { 
	delete index_table; 
} 
 
AVIStripeIndexEntry *AVIStripeIndexLookup::lookup(long sample) { 
	long l, pivot, r; 
 
//	_RPT1(0, "AVIStripeIndexEntry: looking up %ld\n", sample); 
 
	l = 0; 
	r = index_table_size-1; 
 
	while(l <= r) { 
		pivot = (l+r)/2; 
 
		if (sample > index_table[pivot]) 
			l = pivot+1; 
		else if (sample < index_table[pivot]) 
			r = pivot-1; 
		else { 
//			_RPT2(0,"\tFound in stripe %ld at %ld\n", index_table[pivot].lStripe+1, index_table[pivot].lStripeSample); 
			return &index_table[pivot]; 
		} 
	} 
 
	_RPT0(0,"\tNot found!\n"); 
 
	return NULL; 
}