diff options
author | handbrake <[email protected]> | 2006-01-14 13:05:49 +0000 |
---|---|---|
committer | handbrake <[email protected]> | 2006-01-14 13:05:49 +0000 |
commit | 5824c4979fbc54ae3d3015c07cbf6fa4aea7516d (patch) | |
tree | 49ba3bbe1f8d8166fa4f7f964055d4011d2deca0 /core/Fifo.cpp | |
parent | f013e3544c0bdf17348d617a467af0e4fde0f545 (diff) |
HandBrake 0.5
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@7 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'core/Fifo.cpp')
-rw-r--r-- | core/Fifo.cpp | 120 |
1 files changed, 0 insertions, 120 deletions
diff --git a/core/Fifo.cpp b/core/Fifo.cpp deleted file mode 100644 index d1d051c33..000000000 --- a/core/Fifo.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* $Id: Fifo.cpp,v 1.15 2003/10/13 14:12:18 titer Exp $ - - This file is part of the HandBrake source code. - Homepage: <http://beos.titer.org/handbrake/>. - It may be used under the terms of the GNU General Public License. */ - -#include "Fifo.h" -#include "Thread.h" - -HBBuffer::HBBuffer( uint32_t size ) -{ - fAllocSize = size; - fSize = size; - fKeyFrame = false; - fData = (uint8_t*) malloc( size ); - fPosition = 0; - - if( !fData ) - { - Log( "HBBuffer::HBBuffer() : malloc() failed, gonna crash soon" ); - } -} - -HBBuffer::~HBBuffer() -{ - free( fData ); -} - -void HBBuffer::ReAlloc( uint32_t size ) -{ - fData = (uint8_t*) realloc( fData, size ); - - if( !fData ) - { - Log( "HBBuffer::ReAlloc() : realloc() failed, gonna crash soon" ); - } - - fAllocSize = size; -} - -/* Constructor */ -HBFifo::HBFifo( int capacity ) -{ - fCapacity = capacity; - - fWhereToPush = 0; - fWhereToPop = 0; - fBuffers = (HBBuffer**) malloc( ( fCapacity + 1 ) * sizeof( void* ) ); - fLock = new HBLock(); -} - -HBFifo::~HBFifo() -{ - Log( "HBFifo::~HBFifo: trashing %d buffer%s", - Size(), Size() ? "s" : "" ); - - /* Empty the fifo */ - while( fWhereToPush != fWhereToPop ) - { - HBBuffer * buffer = fBuffers[fWhereToPop]; - fWhereToPop++; - fWhereToPop %= ( fCapacity + 1 ); - delete buffer; - } - - /* Cleaning */ - free( fBuffers ); - - delete fLock; -} - -/* Size() : returns how much the fifo is currently filled */ -int HBFifo::Size() -{ - return ( fCapacity + 1 + fWhereToPush - fWhereToPop ) % - ( fCapacity + 1 ); -} - -/* Capacity() : simply returns the fifo capacity... */ -int HBFifo::Capacity() -{ - return fCapacity; -} - -/* Push() - returns immediatly (true if successful, false otherwise ) */ -bool HBFifo::Push( HBBuffer * buffer ) -{ - fLock->Lock(); - - if( Size() < fCapacity ) - { - fBuffers[fWhereToPush] = buffer; - fWhereToPush++; - fWhereToPush %= ( fCapacity + 1 ); - fLock->Unlock(); - return true; - } - - fLock->Unlock(); - return false; -} - -/* Pop() - returns immediatly (a pointer to a buffer if successful, - NULL otherwise ) */ -HBBuffer * HBFifo::Pop() -{ - fLock->Lock(); - - if( fWhereToPush != fWhereToPop ) - { - HBBuffer * buffer = fBuffers[fWhereToPop]; - fWhereToPop++; - fWhereToPop %= ( fCapacity + 1 ); - fLock->Unlock(); - return buffer; - } - - fLock->Unlock(); - return NULL; -} |