From b6e2b5cc5b71986b06cbd9c471b63eb5878a7aea Mon Sep 17 00:00:00 2001 From: Rajneesh Chowdury Date: Fri, 25 Feb 2011 22:59:46 -0800 Subject: [PATCH] Fix for memory leak with single audio player instance Change-Id: Idb0d24ac1a4fbe21c5f63871a4c7da2beb90e516 --- libvideoeditor/lvpp/PreviewPlayer.cpp | 5 +++++ libvideoeditor/lvpp/VideoEditorAudioPlayer.cpp | 23 ++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/libvideoeditor/lvpp/PreviewPlayer.cpp b/libvideoeditor/lvpp/PreviewPlayer.cpp index 8a3576ccd8..d538eaee1a 100644 --- a/libvideoeditor/lvpp/PreviewPlayer.cpp +++ b/libvideoeditor/lvpp/PreviewPlayer.cpp @@ -526,6 +526,11 @@ status_t PreviewPlayer::setAudioPlayer(AudioPlayer *audioPlayer) { DummyAudioSource *pDummyAudioSource = (DummyAudioSource*)pMediaSrc; //Increment the duration of audio source pDummyAudioSource->setDuration((int64_t)((mPlayEndTimeMsec)*1000)); + + // Stop the new audio source + // since we continue using old source + LOGV("setAudioPlayer: stop new audio source"); + mAudioSource->stop(); } } } diff --git a/libvideoeditor/lvpp/VideoEditorAudioPlayer.cpp b/libvideoeditor/lvpp/VideoEditorAudioPlayer.cpp index f33bd0afb3..3c9ffa3b7b 100755 --- a/libvideoeditor/lvpp/VideoEditorAudioPlayer.cpp +++ b/libvideoeditor/lvpp/VideoEditorAudioPlayer.cpp @@ -64,6 +64,28 @@ VideoEditorAudioPlayer::~VideoEditorAudioPlayer() { } void VideoEditorAudioPlayer::setSource(const sp &source) { Mutex::Autolock autoLock(mLock); + + // Before setting source, stop any existing source. + // Make sure to release any buffer we hold onto so that the + // source is able to stop(). + + if (mFirstBuffer != NULL) { + mFirstBuffer->release(); + mFirstBuffer = NULL; + } + + if (mInputBuffer != NULL) { + LOGV("VideoEditorAudioPlayer releasing input buffer."); + + mInputBuffer->release(); + mInputBuffer = NULL; + } + + if (mSource != NULL) { + mSource->stop(); + mSource.clear(); + } + mSource = source; mReachedEOS = false; } @@ -79,7 +101,6 @@ void VideoEditorAudioPlayer::setObserver(AwesomePlayer *observer) { mObserver = observer; } - bool VideoEditorAudioPlayer::isStarted() { return mStarted; } -- 2.11.0