Permalink
Browse files

Merge branch 'release/v4.2.2'

  • Loading branch information...
2 parents c0d74f9 + 1c534da commit 05423b6cb19898e8fd98c72a94c81dd4f4457eba @protyposis committed Jan 7, 2017
@@ -38,7 +38,7 @@ publish {
publishVersion = libraryVersionString()
desc = 'MediaPlayer-Extended DASH extension module'
website = 'https://github.com/protyposis/MediaPlayer-Extended'
- licences = ['GPL-3.0']
+ licences = ['Apache-2.0']
}
//apply from: "../gitversioning.gradle"
@@ -30,7 +30,7 @@ publish {
publishVersion = libraryVersionString()
desc = 'MediaPlayer-Extended core module'
website = 'https://github.com/protyposis/MediaPlayer-Extended'
- licences = ['GPL-3.0']
+ licences = ['Apache-2.0']
}
//apply from: "../gitversioning.gradle"
@@ -134,6 +134,12 @@ public void init(MediaFormat format) {
AudioFormat.ENCODING_PCM_16BIT,
mPlaybackBufferSize, // at least twice the size to enable double buffering (according to docs)
AudioTrack.MODE_STREAM, mAudioSessionId);
+
+ if(mAudioTrack.getState() != AudioTrack.STATE_INITIALIZED) {
+ stopAndRelease();
+ throw new IllegalStateException("audio track init failed");
+ }
+
mAudioSessionId = mAudioTrack.getAudioSessionId();
mAudioStreamType = mAudioTrack.getStreamType();
setStereoVolume(mVolumeLeft, mVolumeRight);
@@ -173,7 +179,7 @@ public int getAudioStreamType() {
}
public boolean isInitialized() {
- return mAudioTrack != null;
+ return mAudioTrack != null && mAudioTrack.getState() == AudioTrack.STATE_INITIALIZED;
}
public void play() {
@@ -272,9 +278,14 @@ public void write(ByteBuffer audioData, long presentationTimeUs) {
}
private void stopAndRelease(boolean killThread) {
- if(isInitialized()) {
- if(killThread) mAudioThread.interrupt();
- mAudioTrack.stop();
+ if(killThread && mAudioThread != null) {
+ mAudioThread.interrupt();
+ }
+
+ if(mAudioTrack != null) {
+ if(isInitialized()) {
+ mAudioTrack.stop();
+ }
mAudioTrack.release();
}
mAudioTrack = null;
@@ -118,7 +118,13 @@ public MediaCodecAudioDecoder getAudioDecoder() {
*/
public void release() {
for (MediaCodecDecoder decoder : mDecoders) {
- decoder.release();
+ // Catch decoder.release() exceptions to avoid breaking the release loop on the first
+ // exception and leaking unreleased decoders.
+ try {
+ decoder.release();
+ } catch (Exception e) {
+ Log.e(TAG, "release failed", e);
+ }
}
mDecoders.clear();
}
Oops, something went wrong.

0 comments on commit 05423b6

Please sign in to comment.