1

I'm using the code below to display a live RTSP stream on android device. it works fine but the problem is the video is late about 2-4 sec from reality and 2sec late from Xmeye application. I receive tones of "picture is too late to be displayed" in android studio log and none of libvlc configurations (commented out in the code) was helpful so far. The libvlc version is 2.5.4 and it is implemented as a module in my project.

Is there any configuration or alternative solution to overcome this problem?

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    Window window = getWindow();
    window.setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
//        args.add("--ffmpeg-hw");
//        args.add("--avcodec-fast");
//        args.add("--avcodec-dr");
//        args.add("--avcodec-skiploopfilter=4");
//        args.add("--rtsp-frame-buffer-size=947483647");
//        args.add("--rtsp-frame-buffer-size=13107200");
//        args.add("--network-caching=2000"); // reduces the quality
//        args.add("--live-caching==2000");
//        args.add("--no-plugins-cache");// prevent from working
//        args.add("--sout-rtp-caching=1000"); // prevent from working
    mLibVLC = new LibVLC(this, args);
    mMediaPlayer = new MediaPlayer(mLibVLC);
    ...
    }
  @Override
protected void onStart() {
    super.onStart();

    final IVLCVout vlcVout = mMediaPlayer.getVLCVout();

    if (mVideoSurface != null) {
        vlcVout.setVideoView(mVideoSurface);
        if (mSubtitlesSurface != null)
            vlcVout.setSubtitlesView(mSubtitlesSurface);
    } else
        vlcVout.setVideoView(mVideoTexture);
    vlcVout.attachViews(this);
    startVideo();
}

private void startVideo() {
    setMedia();

    if (mOnLayoutChangeListener == null) {
        mOnLayoutChangeListener = new View.OnLayoutChangeListener() {
            private final Runnable mRunnable = new Runnable() {
                @Override
                public void run() {
                    updateVideoSurfaces();
                }
            };

            @Override
            public void onLayoutChange(View v, int left, int top, int right,
                                       int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
                if (left != oldLeft || top != oldTop || right != oldRight || bottom != oldBottom) {
                    mHandler.removeCallbacks(mRunnable);
                    mHandler.post(mRunnable);
                }
            }
        };
    }
    mVideoSurfaceFrame.addOnLayoutChangeListener(mOnLayoutChangeListener);
}

private void setMedia() {
    try {
        final Media media = new Media(mLibVLC, Uri.parse(getRTSPURL()));
        mMediaPlayer.setMedia(media);
        media.release();
    } catch (Exception e) {
        throw new RuntimeException("Invalid asset folder");
    }
    mMediaPlayer.play();

most of the code is from vlc android java-sample. ref

Update

thanks to mtz comment, I updated the libvlc to 3.0.0 and added this line of code.

media.addOption(":codec=mediacodec_ndk,mediacodec_jni,none");

Now, the "picture is too late to be displayed" error occurs only a few times in the beginning or with sd quality videos besides I receive the error below repeatedly.

E/VLC-std: Sending request: 
GET_PARAMETER
rtsp://192.168.1.12:554/user=admin_password=tlJwpbo6_channel=1_stream=0.sdp
RTSP/1.0
CSeq: 10
User-Agent: LibVLC/3.0.0-git (LIVE555 Streaming Media v2015.11.09)
Session: 3914750
E/VLC-std: Received 50 new bytes of response data.
Received a complete GET_PARAMETER response:
RTSP/1.0 200 OK
Server: H264DVR 1.0
Cseq: 10

and when a Bluetooth device is connected to the phone I mostly get this error and there is no outpout

core decoder: buffer deadlock prevented
Amir jodat
  • 569
  • 6
  • 13

0 Answers0