home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2004 March / PCWELT_3_2004.ISO / pcwsoft / flaskmpeg_078_39_src.z.exe / flaskmpeg / AsyncBuffer.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-10-28  |  2.3 KB  |  75 lines

  1. /* 
  2.  *  AsyncBuffer.cpp 
  3.  *
  4.  *    Copyright (C) Alberto Vigata - January 2000
  5.  *
  6.  *  This file is part of FlasKMPEG, a free MPEG to MPEG/AVI converter
  7.  *    
  8.  *  FlasKMPEG is free software; you can redistribute it and/or modify
  9.  *  it under the terms of the GNU General Public License as published by
  10.  *  the Free Software Foundation; either version 2, or (at your option)
  11.  *  any later version.
  12.  *   
  13.  *  FlasKMPEG is distributed in the hope that it will be useful,
  14.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  *  GNU General Public License for more details.
  17.  *   
  18.  *  You should have received a copy of the GNU General Public License
  19.  *  along with GNU Make; see the file COPYING.  If not, write to
  20.  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  21.  *
  22.  */
  23.  
  24. // AsyncBuffer.cpp: implementation of the CAsyncBuffer class.
  25. //
  26. //////////////////////////////////////////////////////////////////////
  27.  
  28. #include "AsyncBuffer.h"
  29. #include <malloc.h>
  30. #include <stdio.h>
  31.  
  32. //////////////////////////////////////////////////////////////////////
  33. // Construction/Destruction
  34. //////////////////////////////////////////////////////////////////////
  35.  
  36. //Reads arbitrary bytes from a source that gives a fixed number
  37. // of bytes 
  38. CAsyncBuffer::CAsyncBuffer(CDataSource *src, int inputLenght, int bufferFillness)
  39. {
  40.     CAsyncBuffer::source=src;
  41.     CAsyncBuffer::inputLenght=inputLenght;
  42.              maxInputLength = inputLenght;
  43.        this->bufferFillness = bufferFillness;
  44.     BufferSize=maxInputLength*bufferFillness*2;
  45.     Buffer= (char *)malloc(BufferSize);
  46.     BufferTop=BufferPtr=0;
  47. }
  48.  
  49. int CAsyncBuffer::ReadBuffer(char **outData, int nItems)
  50. {
  51.     int i,j,val;
  52.     
  53.     if( (BufferTop - BufferPtr) < nItems ){
  54.             //There are some samples left at the top of the buffer
  55.             for(i=BufferPtr,j=0; i<BufferTop; i++,j++){
  56.                 Buffer[j]=Buffer[i];
  57.             }
  58.             BufferPtr=0;
  59.             BufferTop=j;
  60.             val=1;
  61.             while( (BufferTop < maxInputLength* bufferFillness) &&  val){
  62.                     inputLenght=val=source->read(&Buffer[BufferTop]);
  63.                     BufferTop += inputLenght;
  64.             }
  65.     }
  66.     *outData=&Buffer[BufferPtr];
  67.     BufferPtr+=nItems;
  68.     return inputLenght;
  69. }
  70.  
  71. CAsyncBuffer::~CAsyncBuffer()
  72. {
  73.     free(Buffer);
  74. }
  75.