• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

src/audio/src/util/alutOutputStream.cpp

Go to the documentation of this file.
00001 #include "alutInternal.h"
00002 #include <string.h>
00003 
00004 struct OutputStream_struct
00005 {
00006   char *data;
00007   char *current;
00008   size_t maximumLength;
00009 };
00010 
00011 /****************************************************************************
00012  * The functions below know the internal OutputStream representation.
00013  ****************************************************************************/
00014 
00015 OutputStream *
00016 _alutOutputStreamConstruct (size_t maximumLength)
00017 {
00018   OutputStream *stream = (OutputStream *) _alutMalloc (sizeof (OutputStream));
00019   if (stream == NULL)
00020     {
00021       return NULL;
00022     }
00023   stream->data = (char*)_alutMalloc (maximumLength);
00024   if (stream->data == NULL)
00025     {
00026       free (stream);
00027       return NULL;
00028     }
00029   stream->current = stream->data;
00030   stream->maximumLength = maximumLength;
00031   return stream;
00032 }
00033 
00034 ALboolean
00035 _alutOutputStreamDestroy (OutputStream *stream)
00036 {
00037   free (stream->data);
00038   free (stream);
00039   return AL_TRUE;
00040 }
00041 
00042 void *
00043 _alutOutputStreamGetData (OutputStream *stream)
00044 {
00045   return stream->data;
00046 }
00047 
00048 size_t
00049 _alutOutputStreamGetLength (OutputStream *stream)
00050 {
00051   return stream->current - stream->data;
00052 }
00053 
00054 static ALboolean
00055 streamWrite (OutputStream *stream, const void *ptr, size_t numBytesToWrite)
00056 {
00057   size_t remainingLength =
00058     stream->maximumLength - _alutOutputStreamGetLength (stream);
00059   if (remainingLength < numBytesToWrite)
00060     {
00061       /* this should never happen within our library */
00062       _alutSetError (ALUT_ERROR_IO_ERROR);
00063       return AL_FALSE;
00064     }
00065   memcpy (stream->current, ptr, numBytesToWrite);
00066   stream->current += numBytesToWrite;
00067   return AL_TRUE;
00068 }
00069 
00070 /****************************************************************************
00071  * The utility functions below do not know the internal OutputStream
00072  * representation.
00073  ****************************************************************************/
00074 
00075 ALboolean
00076 _alutOutputStreamWriteInt16BE (OutputStream *stream, Int16BigEndian value)
00077 {
00078   unsigned char buf[2];
00079   buf[0] = (unsigned char) (value >> 8);
00080   buf[1] = (unsigned char) value;
00081   return streamWrite (stream, buf, 2);
00082 }
00083 
00084 ALboolean
00085 _alutOutputStreamWriteInt32BE (OutputStream *stream, Int32BigEndian value)
00086 {
00087   unsigned char buf[4];
00088   buf[0] = (unsigned char) (value >> 24);
00089   buf[1] = (unsigned char) (value >> 16);
00090   buf[2] = (unsigned char) (value >> 8);
00091   buf[3] = (unsigned char) value;
00092   return streamWrite (stream, buf, 4);
00093 }

Generated on Fri Jun 18 2010 17:48:39 for Cannonball by  doxygen 1.7.0