threading problem inside ExoPlayerImplInternal.java
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.
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.
ah, my bad, the name "blocking" is pretty obvious suggestion that it's a "blocked" version of sendMessage. thanks.
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.
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.
Ah. The issue you describe is effectively the same as: https://github.com/google/ExoPlayer/issues/51
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.