From 1c9747a4653aec1395c2bd6896c9b87cb5447837 Mon Sep 17 00:00:00 2001 From: James Dong Date: Fri, 30 Jul 2010 17:41:22 -0700 Subject: File writer has a designated writer thread now + This reduces the file I/O block time for audio/video track processing - Since the file writer is buffering some output samples, the memory usage would go up, depending on how many output samples are buffered. Change-Id: I780cc5b26f4b53a5efbd643fcf9505dfc19cd4cd --- include/media/stagefright/MPEG4Writer.h | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'include/media') diff --git a/include/media/stagefright/MPEG4Writer.h b/include/media/stagefright/MPEG4Writer.h index d0c2dca..2e1e8d8 100644 --- a/include/media/stagefright/MPEG4Writer.h +++ b/include/media/stagefright/MPEG4Writer.h @@ -75,6 +75,7 @@ private: uint32_t mInterleaveDurationUs; int32_t mTimeScale; int64_t mStartTimestampUs; + Mutex mLock; List mTracks; @@ -87,6 +88,46 @@ private: size_t numTracks(); int64_t estimateMoovBoxSize(int32_t bitRate); + struct Chunk { + Track *mTrack; // Owner + int64_t mTimeStampUs; // Timestamp of the 1st sample + List mSamples; // Sample data + + // Convenient constructor + Chunk(Track *track, int64_t timeUs, List samples) + : mTrack(track), mTimeStampUs(timeUs), mSamples(samples) { + } + + }; + struct ChunkInfo { + Track *mTrack; // Owner + List mChunks; // Remaining chunks to be written + }; + + bool mIsFirstChunk; + volatile bool mDone; // Writer thread is done? + pthread_t mThread; // Thread id for the writer + List mChunkInfos; // Chunk infos + Condition mChunkReadyCondition; // Signal that chunks are available + + // Writer thread handling + status_t startWriterThread(); + void stopWriterThread(); + static void *ThreadWrapper(void *me); + void threadFunc(); + + // Buffer a single chunk to be written out later. + void bufferChunk(const Chunk& chunk); + + // Write all buffered chunks from all tracks + void writeChunks(); + + // Write a chunk if there is one + status_t writeOneChunk(); + + // Write the first chunk from the given ChunkInfo. + void writeFirstChunk(ChunkInfo* info); + void lock(); void unlock(); -- cgit v1.1