Only play rtsp video using VideoView or MediaPlayer after 3 minutes or more

772 views Asked by At

I tried to develop an application that play rtsp video from CCTV. At first, I am using VideoView to play the video but it is a black screen. Then I changed to using MediaPlayer to play the video on the SurfaceView and the result is same, black screen. However, after same time later, around 3 minutes ++ (some time it take more than 10 minutes), suddenly the video play correctly. I changed back to Videoview and it is same, it can play after more than 3 minutes.

My code on media player as below:

    MediaPlayer mp = new MediaPlayer();

    FrameLayout layout = (FrameLayout) findViewById(R.id.framePreview1);

    mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mp.setOnErrorListener(new MediaPlayer.OnErrorListener() {

        @Override
        public boolean onError(MediaPlayer mp, int what, int extra) {
            log.error("Error " + what + " " + extra);
            return false;
        }
    });
    mp.setOnBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener() {

        @Override
        public void onBufferingUpdate(MediaPlayer mp, int percent) {
            log.debug("percentage-->" + percent);
        }
    });

    mp.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

        @Override
        public void onPrepared(MediaPlayer mp) {
            log.debug("prepared!!!");
            mp.start();
        }
    });

    mp.setOnInfoListener(new MediaPlayer.OnInfoListener() {

        @Override
        public boolean onInfo(MediaPlayer mp, int what, int extra) {
            log.info("what " + what + " " + extra);
            return false;
        }
    });

    mp.setDataSource("rtsp://192.168.1.11/h264_2");
    mp.prepareAsync();

    layout.addView(new VideoSurfaceView(this, mp));

In logcat, there are no error found.

06-11 09:33:55.571: D/GuestFormActivity(31089): OnStartPreview
06-11 09:33:55.571: W/ContextImpl(3184): Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1699 com.android.server.InputMethodManagerService$6.run:2733 java.lang.Thread.run:818 <bottom of call stack> <bottom of call stack> 
06-11 09:33:55.576: V/MediaPlayer-JNI(31089): native_setup
06-11 09:33:55.576: V/MediaPlayer(31089): constructor
06-11 09:33:55.586: V/MediaPlayer(31089): setListener
06-11 09:33:55.586: V/MediaPlayer-JNI(31089): setAudioStreamType: 3
06-11 09:33:55.586: V/MediaPlayer(31089): MediaPlayer::setAudioStreamType
06-11 09:33:55.591: V/MediaPlayerService(2580): MediaFader constructor
06-11 09:33:55.591: V/MediaPlayerService(2580): Create new client(290) from pid 31089, uid 10390, 
06-11 09:33:55.591: V/MediaPlayerService(2580): fade IDLE before wait
06-11 09:33:55.591: I/MediaPlayerService(2580): Setting player type to NuPlayer
06-11 09:33:55.591: V/MediaPlayerService(2580): player type = 4
06-11 09:33:55.591: V/NuPlayerDriver(2580): NuPlayerDriver(0xae312240)
06-11 09:33:55.591: V/AudioSink(2580): AudioOutput(477)
06-11 09:33:55.596: V/NuPlayerDriver(2580): setDataSource(0xae312240) url(rtsp://<suppressed>)
06-11 09:33:55.596: V/NuPlayer(2580): kWhatSetAudioSink
06-11 09:33:55.596: V/NuPlayer(2580): kWhatSetDataSource
06-11 09:33:55.596: V/MediaPlayerService(2580): [290] setParameter(1604)
06-11 09:33:55.596: V/NuPlayer(2580): setParameter = 1604
06-11 09:33:55.596: V/MediaPlayerService(2580): [290] getParameter(1700)
06-11 09:33:55.596: V/MediaPlayer(31089): setVideoSurfaceTexture
06-11 09:33:55.596: V/MediaPlayerService(2580): [290] setVideoSurfaceTexture(0x0)
06-11 09:33:55.596: V/MediaPlayer(31089): prepareAsync
06-11 09:33:55.596: V/MediaPlayerService(2580): [290] setAudioStreamType(3)
06-11 09:33:55.596: V/MediaPlayerService(2580): [290] prepareAsync
06-11 09:33:55.596: V/NuPlayerDriver(2580): prepareAsync(0xae312240)
06-11 09:33:55.596: I/ARTSPConnection(2580): host: 192.168.1.11
06-11 09:33:55.596: I/ARTSPConnection(2580): mProxyName is empty
06-11 09:33:55.596: I/ARTSPConnection(2580): Set No Proxy
06-11 09:33:55.596: I/ARTSPConnection(2580): Server IP addresses:
06-11 09:33:55.596: I/ARTSPConnection(2580): IPv4: 192.168.1.11
06-11 09:33:55.596: I/ARTSPConnection(2580): Device IP addresses:
06-11 09:33:55.596: I/ARTSPConnection(2580): IPv6: ::
06-11 09:33:55.596: I/ARTSPConnection(2580): IPv4: 0.0.0.0
06-11 09:33:55.596: I/ARTSPConnection(2580): Server IP_family 2, Device IP family 10
06-11 09:33:55.596: I/ARTSPConnection(2580): Server IP_family 2, Device IP family 2
06-11 09:33:55.601: I/qtaguid(2580): Tagging socket 33 with tag 5053545200000000{1347638354,0} uid 10390, pid: 2580, getuid(): 1013
06-11 09:33:55.601: I/qtaguid(2580): File not found /data/system/uidapn
06-11 09:33:55.621: I/SurfaceFlinger(2571): id=2821 createSurf (900x900),4 flag=404, TurfaceView
06-11 09:33:55.626: V/MediaPlayer(31089): setVideoSurfaceTexture
06-11 09:33:55.626: V/MediaPlayerService(2580): [290] setVideoSurfaceTexture(0xb2b06ca0)
06-11 09:33:55.626: V/NuPlayerDriver(2580): setVideoSurfaceTexture(0xae312240)
06-11 09:33:55.626: V/NuPlayer(2580): kWhatSetVideoNativeWindow
06-11 09:33:55.626: V/NuPlayer(2580): performDecoderShutdown audio=1, video=1
06-11 09:33:55.626: V/NuPlayer(2580): performSetSurface
06-11 09:33:55.626: V/NuPlayerDriver(2580): notifySetSurfaceComplete(0xae312240)
06-11 09:33:55.631: V/NuPlayer(2580): performScanSources
06-11 09:33:55.706: I/MyHandler(2580): connection request completed with result 0 (Success)
06-11 09:33:55.711: W/ARTSPConnection(2580): User-Agent:  Samsung GT-I9500 stagefright/Beyonce/1.1.9 (Linux;Android 5.0.1)

06-11 09:33:55.711: I/ARTSPConnection(2580): status: RTSP/1.0 200 OK
06-11 09:33:55.716: I/MyHandler(2580): OPTIONS completed with result 0 (Success)
06-11 09:33:55.716: I/ARTSPConnection(2580): status: RTSP/1.0 200 OK
06-11 09:33:55.721: I/MyHandler(2580): DESCRIBE completed with result 0 (Success)
06-11 09:33:55.721: I/ASessionDescription(2580): v=0
06-11 09:33:55.721: I/ASessionDescription(2580): o=- 1275721151200462 1 IN IP4 0.0.0.0
06-11 09:33:55.721: I/ASessionDescription(2580): s=Session streamed by "nessyMediaServer"
06-11 09:33:55.721: I/ASessionDescription(2580): i=h264_2
06-11 09:33:55.721: I/ASessionDescription(2580): t=0 0
06-11 09:33:55.721: I/ASessionDescription(2580): a=tool:Streaming Media v2010.04.09
06-11 09:33:55.721: I/ASessionDescription(2580): a=type:broadcast
06-11 09:33:55.721: I/ASessionDescription(2580): a=control:*
06-11 09:33:55.721: I/ASessionDescription(2580): a=range:npt=0-
06-11 09:33:55.721: I/ASessionDescription(2580): a=x-qt-text-nam:Session streamed by "nessyMediaServer"
06-11 09:33:55.721: I/ASessionDescription(2580): a=x-qt-text-inf:h264_2
06-11 09:33:55.721: I/ASessionDescription(2580): m=video 0 RTP/AVP 99
06-11 09:33:55.721: I/ASessionDescription(2580): c=IN IP4 0.0.0.0
06-11 09:33:55.721: I/ASessionDescription(2580): a=rtpmap:99 H264/90000
06-11 09:33:55.721: I/ASessionDescription(2580): a=fmtp:99 packetization-mode=1;profile-level-id=4D0020; sprop-parameter-sets=Z00AIJpmAoAQP//gCAAFrcBAQFAAAD6AAAw1DoYAIJQACCULvLjQwAQSgAEEoXeXCgA=,aO48gA==
06-11 09:33:55.721: I/ASessionDescription(2580): a=control:track1
06-11 09:33:55.721: I/ASessionDescription(2580): a=cliprect:0,0,1024,1280
06-11 09:33:55.721: I/ASessionDescription(2580): a=framerate:13.000000
06-11 09:33:55.721: I/ASessionDescription(2580): a=x-bufferdelay:0
06-11 09:33:55.721: I/ASessionDescription(2580): m=application 0 RTP/AVP 107
06-11 09:33:55.721: I/ASessionDescription(2580): a=rtpmap:107 vnd.onvif.metadata/90000/
06-11 09:33:55.721: I/ASessionDescription(2580): a=control:track2
06-11 09:33:55.721: W/MyHandler(2580): mBaseURL is change to rtsp://192.168.1.11/h264_2/ from 'content-base'
06-11 09:33:55.721: W/MyHandler(2580): Property [net.connectivity.qosbw] NOT Found, bwQoS=2147483647
06-11 09:33:55.721: W/APacketSource(2580): Format:video 0 RTP/AVP 99  / MIME-Type:H264/90000
06-11 09:33:55.721: I/APacketSource(2580): dimensions 1280x1024
06-11 09:33:55.721: I/ARTPConnection(2580): Start:15650
06-11 09:33:55.721: I/qtaguid(2580): Tagging socket 35 with tag 5f50545200000000{1599099986,0} uid 10390, pid: 2580, getuid(): 1013
06-11 09:33:55.721: I/qtaguid(2580): File not found /data/system/uidapn
06-11 09:33:55.721: I/qtaguid(2580): Tagging socket 37 with tag 5f50545200000000{1599099986,0} uid 10390, pid: 2580, getuid(): 1013
06-11 09:33:55.721: I/qtaguid(2580): File not found /data/system/uidapn
06-11 09:33:55.721: W/ASessionDescription(2580): system prop 3gpp-ra option is not found
06-11 09:33:55.731: I/ARTSPConnection(2580): status: RTSP/1.0 200 OK
06-11 09:33:55.731: I/MyHandler(2580): SETUP(1) completed with result 0 (Success)
06-11 09:33:55.731: W/MyHandler(2580): successfully poked holes (Server IP : 192.168.1.11, rtp port : 6970, rtcp port : 6971)
06-11 09:33:55.741: I/ARTSPConnection(2580): status: RTSP/1.0 200 OK
06-11 09:33:55.741: I/MyHandler(2580): PLAY completed with result 0 (Success)
06-11 09:33:55.741: W/MyHandler(2580): set mInitialSeqNum to 31394 - by RTP-Info
06-11 09:33:55.741: I/MyHandler(2580): Time now established for all tracks.
06-11 09:33:55.746: W/MyHandler(2580): seq-rollover detection by RTP-Info (mInitialSeqNum 31394, recved seqNum 0)
06-11 09:33:55.746: I/MyHandler(2580): PLAY CASE: posting postOnDemandAUBufferRequest for the first time
06-11 09:33:56.071: I/ARTPSource(2580): Format: video 0 RTP/AVP 99 / MIME-Type: H264/90000
06-11 09:33:56.281: E/ActivityManager(3184): checkUser: useridlist=null, currentuser=0
06-11 09:33:56.281: E/ActivityManager(3184): checkUser: useridlist=null, currentuser=0
06-11 09:33:56.281: E/ActivityManager(3184): checkUser: useridlist=null, currentuser=0
06-11 09:33:56.281: E/ActivityManager(3184): checkUser: useridlist=null, currentuser=0
06-11 09:33:56.296: E/Zygote(32485): MountEmulatedStorage()
06-11 09:33:56.296: E/Zygote(32485): v2

Every around 1 minutes, I found that the device having log below:

06-11 09:36:55.766: W/MyHandler(2580):  Sending OPTIONS request 
06-11 09:36:55.766: W/MyHandler(2580): successfully poked holes (Server IP : 192.168.1.11, rtp port : 6970, rtcp port : 6971)
06-11 09:36:55.771: I/ARTSPConnection(2580): status: RTSP/1.0 200 OK
06-11 09:36:55.776: I/MyHandler(2580): OPTIONS completed with result 0 (Success)

Anything I missed?

0

There are 0 answers