From e33ae316fae37681296790fcd638be29f1c88459 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 18 Jun 2011 17:02:44 -0700 Subject: [PATCH] Add a function to get the number of samples from a stream --- include/AL/alure.h | 2 ++ include/main.h | 2 ++ src/stream.cpp | 22 ++++++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/include/AL/alure.h b/include/AL/alure.h index 98e1f77..b0e3df1 100644 --- a/include/AL/alure.h +++ b/include/AL/alure.h @@ -85,6 +85,7 @@ ALURE_API alureStream* ALURE_APIENTRY alureCreateStreamFromCallback( ALuint (*callback)(void *userdata, ALubyte *data, ALuint bytes), void *userdata, ALenum format, ALuint samplerate, ALsizei chunkLength, ALsizei numBufs, ALuint *bufs); +ALURE_API alureInt64 ALURE_APIENTRY alureGetStreamLength(alureStream *stream); ALURE_API ALsizei ALURE_APIENTRY alureGetStreamFrequency(alureStream *stream); ALURE_API ALsizei ALURE_APIENTRY alureBufferDataFromStream(alureStream *stream, ALsizei numBufs, ALuint *bufs); ALURE_API ALboolean ALURE_APIENTRY alureRewindStream(alureStream *stream); @@ -137,6 +138,7 @@ typedef alureStream* (ALURE_APIENTRY *LPALURECREATESTREAMFROMFILE)(const ALch typedef alureStream* (ALURE_APIENTRY *LPALURECREATESTREAMFROMMEMORY)(const ALubyte*,ALuint,ALsizei,ALsizei,ALuint*); typedef alureStream* (ALURE_APIENTRY *LPALURECREATESTREAMFROMSTATICMEMORY)(const ALubyte*,ALuint,ALsizei,ALsizei,ALuint*); typedef alureStream* (ALURE_APIENTRY *LPALURECREATESTREAMFROMCALLBACK)(ALuint(*)(void*,ALubyte*,ALuint),void*,ALenum,ALuint,ALsizei,ALsizei,ALuint*); +typedef alureInt64 (ALURE_APIENTRY *LPALUREGETSTREAMLENGTH)(alureStream*); typedef ALsizei (ALURE_APIENTRY *LPALUREGETSTREAMFREQUENCY)(alureStream*); typedef ALsizei (ALURE_APIENTRY *LPALUREBUFFERDATAFROMSTREAM)(alureStream*,ALsizei,ALuint*); typedef ALboolean (ALURE_APIENTRY *LPALUREREWINDSTREAM)(alureStream*); diff --git a/include/main.h b/include/main.h index 94423bc..54a5aa2 100644 --- a/include/main.h +++ b/include/main.h @@ -157,6 +157,8 @@ struct alureStream { } virtual bool SetPatchset(const char*) { return true; } + virtual alureInt64 GetLength() + { return 0; } alureStream(std::istream *_stream) : data(NULL), fstream(_stream) diff --git a/src/stream.cpp b/src/stream.cpp index c18e523..4607489 100644 --- a/src/stream.cpp +++ b/src/stream.cpp @@ -533,6 +533,28 @@ ALURE_API ALboolean ALURE_APIENTRY alureSetStreamPatchset(alureStream *stream, c return stream->SetPatchset(patchset); } +/* Function: alureGetStreamLength + * + * Retrieves an approximate number of samples for the stream. Not all streams + * or decoders can return such info, and may return 0 if the stream length is + * unknown. + * + * Returns: + * -1 on error. + * + * *Version Added*: 1.2 + */ +ALURE_API alureInt64 ALURE_APIENTRY alureGetStreamLength(alureStream *stream) +{ + if(!alureStream::Verify(stream)) + { + SetError("Invalid stream pointer"); + return -1; + } + + return stream->GetLength(); +} + /* Function: alureDestroyStream * * Closes an opened stream. For convenience, it will also delete the given -- 2.11.4.GIT