pedroSG94 / RootEncoder

RootEncoder for Android (rtmp-rtsp-stream-client-java) is a stream encoder to push video/audio to media servers using protocols RTMP, RTSP, SRT and UDP with all code written in Java/Kotlin
Apache License 2.0
2.55k stars 773 forks source link

Camera onConfigureFailed #48

Closed Shanmugamsundarrajan closed 7 years ago

Shanmugamsundarrajan commented 7 years ago

Trying to stream RTSP To Rtsp server set at our office:

I am trying since 1 month, but i am facing the issue of cameraDevice.createCaptureSession is leading to onConfigureFailed.

Need your help to resolve the same

I am using the android build as below (android version in the device is 5.1.1) { compileSdkVersion 25 buildToolsVersion "25.0.2"

defaultConfig { applicationId "com.pedro.rtmpstreamer" minSdkVersion 21 targetSdkVersion 25 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } }

dependencies { compile project(':rtplibrary') compile 'com.android.support:appcompat-v7:25.3.1' compile 'com.android.support:design:25.3.1' }

Logcat print as below:

startPreview: called 09-12 08:47:22.852 8557-8670/com.pedro.rtmpstreamer I/sixth.Camera2ApiManager: addPreviewSurface: addPreviewSurface in surface view 09-12 08:47:22.852 8557-8670/com.pedro.rtmpstreamer I/sixth.Camera2ApiManager: addPreviewSurface: addPreviewSurface in sufaceview.width : 0 , sufaceview.height : 0 09-12 08:47:22.853 8557-8670/com.pedro.rtmpstreamer I/sixth.Camera2ApiManager: startPreview: addPreviewSurface 09-12 08:47:22.853 8557-8670/com.pedro.rtmpstreamer I/sixth.Camera2ApiManager: startPreview: before add surface 09-12 08:47:22.853 8557-8670/com.pedro.rtmpstreamer I/sixth.Camera2ApiManager: startPreview: after add surface 09-12 08:47:22.861 8557-8670/com.pedro.rtmpstreamer I/sixth.Camera2ApiManager: camera opened 09-12 08:47:22.862 8557-8670/com.pedro.rtmpstreamer E/sixth.Camera2ApiManager: configuration failed

Shanmugamsundarrajan commented 7 years ago

While setting up the connection, the server is responding with two ports for Audio and two ports for video. Also it send the client port as 5000 and 5001 for audio (trackID = 0) and 5002 and 5003 for video (trackID = 1).

So our server guy is telling that you sending port id should 5000/5001 for audio and 5002/5003 for video.

When we see the wireshark the sending port is different.

audio setup response RTSP/1.0 200 OK CSeq: 3 Cache-Control: no-cache Date: Thu, 21 Sep 2017, 12:49:06 GMT Expires: Thu, 21 Sep 2017, 12:49:06 GMT Session: 768b8b0097721e804f2aeaad1a45b372_sc20 Transport: RTP/AVP/UDP;unicast;client_port=5000-5001;server_port=47487-52573;ssrc=6b8b4567

video setup response RTSP/1.0 200 OK CSeq: 4 Cache-Control: no-cache Date: Thu, 21 Sep 2017, 13:03:52 GMT Expires: Thu, 21 Sep 2017, 13:03:52 GMT Session: 768b8b0097721e804f2aeaad1a45b372_sc20 Transport: RTP/AVP/UDP;unicast;client_port=5002-5003;server_port=41556-37015;ssrc=327b23c6

pedroSG94 commented 7 years ago

No no. Your server tell you that ports are: Audio server_port=47487-52573 Video server_port=41556-37015

Anyway if you are sure that are the ports you can comment this lines: https://github.com/pedroSG94/rtmp-rtsp-stream-client-java/blob/master/rtsp/src/main/java/com/pedro/rtsp/rtsp/RtspClient.java#L397 https://github.com/pedroSG94/rtmp-rtsp-stream-client-java/blob/master/rtsp/src/main/java/com/pedro/rtsp/rtsp/RtspClient.java#L399

Shanmugamsundarrajan commented 7 years ago

Source port for audio is 5000-5001 Source port for video is 5002-5003

Destination port for audio is 47487-52573 Destination port for video is 41556-37015

But while streaming RTP packet over UDP in the wireshark both the audio and video ports are different then the one sent over SETUP.

Shanmugamsundarrajan commented 7 years ago

The Destination port are not same always, it change dynamically for each connection setup. So we cannot comment the line But my question, the destination port got from the response should be used while sending the UPD packet , isn't it.

Shanmugamsundarrajan commented 7 years ago

I have made a change in audio port setting and video port setting , while reading the same from the response i.e., audioPorts[i] = Integer.parseInt(s[i].substring(0, 4)); to audioPorts[i] = Integer.parseInt(s[i].substring(0, 5));

similarly for video port. Now the destination ports are coming correctly in the wireshark,

but the source ports are different (instead of 5000 for audio and 5002 for video)

pedroSG94 commented 7 years ago

I did a fix for sessionId and udp ports. Clone last version and test.

Shanmugamsundarrajan commented 7 years ago

Thanks for the same,

Our server provider has asked to send RTCP sender report first before the RTP packet for video and audio. But in this code the RTP is sent first before the RTCP. How can we do this

pedroSG94 commented 7 years ago

If you go to: https://github.com/pedroSG94/rtmp-rtsp-stream-client-java/blob/master/rtsp/src/main/java/com/pedro/rtsp/rtp/sockets/RtpSocketUdp.java In run method you can see that rtcp packets are send before rtp. RTCP send

senderReportUdp.update(mPackets[mBufferOut].getLength(),
(mTimestamps[mBufferOut] / 100L) * (mClock / 1000L) / 10000L, mPort);

RTP send mSocket.send(mPackets[mBufferOut]);

Shanmugamsundarrajan commented 7 years ago

Yeah, but initially the interval is 3000 and delta is 0. So the RTCP will be sent after the 3 secs only

pedroSG94 commented 7 years ago

If you change delta value to 3000 that should be fixed. Go to: https://github.com/pedroSG94/rtmp-rtsp-stream-client-java/blob/master/rtsp/src/main/java/com/pedro/rtsp/rtcp/BaseSenderReport.java#L61

Replace with:

now = old = 0;
delta = 3000;
Shanmugamsundarrajan commented 7 years ago

Ok thanks