OSDN Git Service

Fix for memory leak with single audio player instance
authorRajneesh Chowdury <rajneeshc@google.com>
Sat, 26 Feb 2011 06:59:46 +0000 (22:59 -0800)
committerRajneesh Chowdury <rajneeshc@google.com>
Mon, 28 Feb 2011 03:17:14 +0000 (19:17 -0800)
Change-Id: Idb0d24ac1a4fbe21c5f63871a4c7da2beb90e516

libvideoeditor/lvpp/PreviewPlayer.cpp
libvideoeditor/lvpp/VideoEditorAudioPlayer.cpp

index 8a3576c..d538eae 100644 (file)
@@ -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();
                 }
             }
         }
index f33bd0a..3c9ffa3 100755 (executable)
@@ -64,6 +64,28 @@ VideoEditorAudioPlayer::~VideoEditorAudioPlayer() {
 }
 void VideoEditorAudioPlayer::setSource(const sp<MediaSource> &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;
 }