diff options
author | Glenn Kasten <gkasten@google.com> | 2014-05-09 13:37:29 -0700 |
---|---|---|
committer | Glenn Kasten <gkasten@google.com> | 2014-05-09 16:34:46 -0700 |
commit | c26d923712a59e669d18191d93fbe3696789d592 (patch) | |
tree | 735e84b0df3d43ff26b192e89beb756ac952b4bc | |
parent | 110135b9610fee8bfa5bac2d9ef4fc4c24991c36 (diff) | |
download | frameworks_av-c26d923712a59e669d18191d93fbe3696789d592.zip frameworks_av-c26d923712a59e669d18191d93fbe3696789d592.tar.gz frameworks_av-c26d923712a59e669d18191d93fbe3696789d592.tar.bz2 |
Allow placement of Pipe buffer to be specified
Change-Id: I2f6b68089ecfe85cd975d29ad0d0afd13c487002
-rw-r--r-- | include/media/nbaio/Pipe.h | 7 | ||||
-rw-r--r-- | media/libnbaio/Pipe.cpp | 11 |
2 files changed, 13 insertions, 5 deletions
diff --git a/include/media/nbaio/Pipe.h b/include/media/nbaio/Pipe.h index c784129..eba37bc 100644 --- a/include/media/nbaio/Pipe.h +++ b/include/media/nbaio/Pipe.h @@ -30,7 +30,11 @@ class Pipe : public NBAIO_Sink { public: // maxFrames will be rounded up to a power of 2, and all slots are available. Must be >= 2. - Pipe(size_t maxFrames, const NBAIO_Format& format); + // buffer is an optional parameter specifying the virtual address of the pipe buffer, + // which must be of size roundup(maxFrames) * Format_frameSize(format) bytes. + Pipe(size_t maxFrames, const NBAIO_Format& format, void *buffer = NULL); + + // If a buffer was specified in the constructor, it is not automatically freed by destructor. virtual ~Pipe(); // NBAIO_Port interface @@ -57,6 +61,7 @@ private: void * const mBuffer; volatile int32_t mRear; // written by android_atomic_release_store volatile int32_t mReaders; // number of PipeReader clients currently attached to this Pipe + const bool mFreeBufferInDestructor; }; } // namespace android diff --git a/media/libnbaio/Pipe.cpp b/media/libnbaio/Pipe.cpp index 28a034c..6e0ec8c 100644 --- a/media/libnbaio/Pipe.cpp +++ b/media/libnbaio/Pipe.cpp @@ -25,19 +25,22 @@ namespace android { -Pipe::Pipe(size_t maxFrames, const NBAIO_Format& format) : +Pipe::Pipe(size_t maxFrames, const NBAIO_Format& format, void *buffer) : NBAIO_Sink(format), mMaxFrames(roundup(maxFrames)), - mBuffer(malloc(mMaxFrames * Format_frameSize(format))), + mBuffer(buffer == NULL ? malloc(mMaxFrames * Format_frameSize(format)) : buffer), mRear(0), - mReaders(0) + mReaders(0), + mFreeBufferInDestructor(buffer == NULL) { } Pipe::~Pipe() { ALOG_ASSERT(android_atomic_acquire_load(&mReaders) == 0); - free(mBuffer); + if (mFreeBufferInDestructor) { + free(mBuffer); + } } ssize_t Pipe::write(const void *buffer, size_t count) |