I'm playing a Live RTSP stream from VLC on a PC to Android MediaPlayer class (both on same local network). It plays smoothly with no errors - the problem is that the decoded video on screen is between around 5 and 7 seconds behind live.
From debug and callbacks I can see that the live data is arriving on the device < 1s after starting mMediaPlayer.prepareAsync()
. This is when the MediaPlayer class begins to work out what format the stream is with what dimensions etc. Then just before video is shown on screen (between 5 and 7 seconds later), onPrepared()
is called where I call mMediaPlayer.start()
. It looks like this start()
plays the video that was originally captured from the start of the prepare stage.
I've tried seekTo(5000)
both before and after start()
, but it has no effect on the lag at all.
For a live video calling app, the setup delay of a few seconds is perfectly fine, but this lag once video is presented is unaccaptable to me.
public void surfaceCreated(SurfaceHolder holder)
{
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mMediaPlayer.setOnInfoListener(this);
mMediaPlayer.setOnErrorListener(this);
mMediaPlayer.setOnVideoSizeChangedListener(this);
mMediaPlayer.setOnBufferingUpdateListener(this);
mMediaPlayer.setDataSource("rtsp://192.168.1.4:5544/test");
mMediaPlayer.setDisplay(holder);
mMediaPlayer.setScreenOnWhilePlaying(true);
mMediaPlayer.setOnPreparedListener(this);
mMediaPlayer.setOnCompletionListener(this);
mMediaPlayer.prepareAsync();
...
public void onPrepared(MediaPlayer mediaplayer)
{
mMediaPlayer.start();
...
Any ideas how I can reduce this lag, or seek to the end of what is buffered by MediaPlayer? My device is 3.1, minSdkVersion is 2.2.
EDIT:
I've found some high and low water-marks in AwesomePlayer.cpp (2s and 8s). As a quick test I have hacked the libstagefright.so to make these 0.1s and 1s. This however made no effect on the delay. My search continues...