ExoPlayer icon indicating copy to clipboard operation
ExoPlayer copied to clipboard

threading problem inside ExoPlayerImplInternal.java

Open Kening opened this issue 11 years ago • 6 comments

inside ExoPlayerImplInternal.java, we have

public void sendMessage(ExoPlayerComponent target, int messageType, Object message);

public synchronized void blockingSendMessage(ExoPlayerComponent target, int messageType, Object message)

sendMessage() is not synchronized. i ran into this problem when i first send

mExoPlayer.sendMessage(mVideoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface);

then send

mExoPlayer.blockingSendMessage(mVideoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, null);

my app is locked, it's inside blockingSendMessage() ,

int messageNumber = customMessagesSent++; handler.obtainMessage(MSG_CUSTOM, messageType, 0, Pair.create(target, message)).sendToTarget(); while (customMessagesProcessed <= messageNumber) { try { wait(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } }

customMessagesSent is incremented in sendMessage(), since it's not synchronized, before we can increment customMessagesProcessed in the playback thread, the blockingSendMessage() call run into this condition that customMessagesProcessed<= messageNumber. sendMessage() should be synchronized.

Kening avatar Mar 14 '15 03:03 Kening

That shouldn't be a problem. customMessagesProcessed will be incremented once for each of the two messages that you sent, and when the second increment happens blockingSendMessage should be unblocked.

ojw28 avatar Mar 14 '15 10:03 ojw28

ah, my bad, the name "blocking" is pretty obvious suggestion that it's a "blocked" version of sendMessage. thanks.

Kening avatar Mar 14 '15 13:03 Kening

Right. The correct behavior is that the method will block until the message has been successfully delivered on the playback thread (and then will be unblocked). Please re-open if that's not what you're seeing. Otherwise it's working as intended.

ojw28 avatar Mar 14 '15 18:03 ojw28

I ran into this problem that when I call blockSendMessage or release (which are both blocking call), I get stuck in wait() because another thread is locking the ExoPlayerImplInternal object. Base on the stack trace, it seems it's the MediaExtractor.setDataSource() which is calling nativeSetDataSource(). This happens when I start an activity which contains the ExoPlayer, it loads the video and play it, and I press back key to finish the activity. When I keep doing this for different video, eventually I run into this problem, it seem like a racing problem. Wonder by this description if you have any clue about what's happening. Thanks.

Kening avatar Mar 16 '15 13:03 Kening

Ah. The issue you describe is effectively the same as: https://github.com/google/ExoPlayer/issues/51

ojw28 avatar Mar 16 '15 13:03 ojw28

wow, your response is like instant, thanks a lot!

so before there's a fix, i probably can check the state and if it's not STATE_READY, do not call blockSendingMessage or release.

Kening avatar Mar 16 '15 13:03 Kening