[Android] libvlc: always retain when returning a VLCObject
Thomas Guillem
git at videolan.org
Fri May 29 09:51:58 CEST 2015
vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Fri May 29 09:51:46 2015 +0200| [a6a1db55a1297017d6b7fbac92cffef9ad87a394] | committer: Thomas Guillem
libvlc: always retain when returning a VLCObject
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=a6a1db55a1297017d6b7fbac92cffef9ad87a394
---
libvlc/src/org/videolan/libvlc/Media.java | 3 ++-
libvlc/src/org/videolan/libvlc/MediaDiscoverer.java | 3 ++-
libvlc/src/org/videolan/libvlc/MediaList.java | 5 ++++-
libvlc/src/org/videolan/libvlc/MediaPlayer.java | 5 +++--
libvlc/src/org/videolan/libvlc/util/MediaBrowser.java | 15 ++++++++++-----
.../src/org/videolan/vlc/MediaWrapperListPlayer.java | 12 +++++++++---
6 files changed, 30 insertions(+), 13 deletions(-)
diff --git a/libvlc/src/org/videolan/libvlc/Media.java b/libvlc/src/org/videolan/libvlc/Media.java
index 3255afa..f62b295 100644
--- a/libvlc/src/org/videolan/libvlc/Media.java
+++ b/libvlc/src/org/videolan/libvlc/Media.java
@@ -327,11 +327,12 @@ public class Media extends VLCObject {
/**
* Get the subItems MediaList associated with the Media.
*
- * @return subItems as a MediaList, Should NOT be released.
+ * @return subItems as a MediaList. This MediaList should be released with {@link #release()}.
*/
public synchronized MediaList subItems() {
if (mSubItems == null && !isReleased())
mSubItems = new MediaList(this);
+ mSubItems.retain();
return mSubItems;
}
diff --git a/libvlc/src/org/videolan/libvlc/MediaDiscoverer.java b/libvlc/src/org/videolan/libvlc/MediaDiscoverer.java
index 15254f2..df823a1 100644
--- a/libvlc/src/org/videolan/libvlc/MediaDiscoverer.java
+++ b/libvlc/src/org/videolan/libvlc/MediaDiscoverer.java
@@ -63,11 +63,12 @@ public class MediaDiscoverer extends VLCObject {
/**
* Get the MediaList associated with the MediaDiscoverer.
*
- * @return MediaList, Should NOT be released.
+ * @return MediaList. This MediaList should be released with {@link #release()}.
*/
public synchronized MediaList getMediaList() {
if (mMediaList == null && !isReleased())
mMediaList = new MediaList(this);
+ mMediaList.retain();
return mMediaList;
}
diff --git a/libvlc/src/org/videolan/libvlc/MediaList.java b/libvlc/src/org/videolan/libvlc/MediaList.java
index 56e81d2..673e581 100644
--- a/libvlc/src/org/videolan/libvlc/MediaList.java
+++ b/libvlc/src/org/videolan/libvlc/MediaList.java
@@ -136,11 +136,14 @@ public class MediaList extends VLCObject {
* Get a Media at specified index.
*
* @param index
- * @return Media hold by MediaList, Should NOT be released.
+ * @return Media hold by MediaList. This Media should be released with {@link #release()}.
*/
public synchronized Media getMediaAt(int index) {
if (index < 0 || index >= getCount())
throw new IndexOutOfBoundsException();
+ final Media media = mMediaArray.get(index);
+ media.retain();
+ return media;
}
@Override
diff --git a/libvlc/src/org/videolan/libvlc/MediaPlayer.java b/libvlc/src/org/videolan/libvlc/MediaPlayer.java
index 335c3f3..a6c7f2b 100644
--- a/libvlc/src/org/videolan/libvlc/MediaPlayer.java
+++ b/libvlc/src/org/videolan/libvlc/MediaPlayer.java
@@ -91,12 +91,13 @@ public class MediaPlayer extends VLCObject {
}
/**
- * Get the Media used by this MediaPlayer.
- * This Media is owned by the MediaPlayer, it shouldn't be released.
+ * Get the Media used by this MediaPlayer. This Media should be released with {@link #release()}.
*
* @return
*/
public synchronized Media getMedia() {
+ if (mMedia != null)
+ mMedia.retain();
return mMedia;
}
diff --git a/libvlc/src/org/videolan/libvlc/util/MediaBrowser.java b/libvlc/src/org/videolan/libvlc/util/MediaBrowser.java
index 59d8c7d..fdcb43d 100644
--- a/libvlc/src/org/videolan/libvlc/util/MediaBrowser.java
+++ b/libvlc/src/org/videolan/libvlc/util/MediaBrowser.java
@@ -89,9 +89,11 @@ public class MediaBrowser {
mMedia.release();
mMedia = null;
}
- /* don't need to release the MediaList since it's either
- * associated with a Media or a MediaDiscoverer that will release it */
- mBrowserMediaList = null;
+
+ if (mBrowserMediaList != null) {
+ mBrowserMediaList.release();
+ mBrowserMediaList = null;
+ }
}
/**
@@ -116,6 +118,7 @@ public class MediaBrowser {
mMediaDiscoverers.add(md);
final MediaList ml = md.getMediaList();
ml.setEventListener(mDiscovererMediaListEventListener);
+ ml.release();
md.start();
}
@@ -184,13 +187,15 @@ public class MediaBrowser {
}
/**
- * Get a media at a specified index.
+ * Get a media at a specified index. Should be released with {@link #release()}.
*/
public synchronized Media getMediaAt(int index) {
if (index < 0 || index >= getMediaCount())
throw new IndexOutOfBoundsException();
- return mBrowserMediaList != null ? mBrowserMediaList.getMediaAt(index) :
+ final Media media = mBrowserMediaList != null ? mBrowserMediaList.getMediaAt(index) :
mDiscovererMediaArray.get(index);
+ media.retain();
+ return media;
}
private MediaList.EventListener mBrowserMediaListEventListener = new MediaList.EventListener() {
diff --git a/vlc-android/src/org/videolan/vlc/MediaWrapperListPlayer.java b/vlc-android/src/org/videolan/vlc/MediaWrapperListPlayer.java
index 2ce32d8..601d6a0 100644
--- a/vlc-android/src/org/videolan/vlc/MediaWrapperListPlayer.java
+++ b/vlc-android/src/org/videolan/vlc/MediaWrapperListPlayer.java
@@ -98,17 +98,23 @@ public class MediaWrapperListPlayer {
public int expand() {
final Media media = VLCInstance.getMainMediaPlayer().getMedia();
final MediaList ml = media.subItems();
+ media.release();
+ int ret;
if (ml.getCount() > 0) {
mMediaList.remove(mPlayerIndex);
for (int i = 0; i < ml.getCount(); ++i) {
final Media child = ml.getMediaAt(i);
child.parse();
+ child.release();
mMediaList.insert(mPlayerIndex, new MediaWrapper(child));
}
- return 0;
- } else
- return -1;
+ ret = 0;
+ } else {
+ ret = -1;
+ }
+ ml.release();
+ return ret;
}
public int expand(int index) {
More information about the Android
mailing list