2

The same question might have been asked but I didn't find any solutions available for me.

I'm trying to play RTSP stream in android and the server is Darwin streaming server. For now I’ve tried VideoView and MediaPlayer, both of which always work fine when I use 3G but have problems when I use Wifi sometimes, specifically when I use Wifi at my workplace, and the error in LogCat:

PlayerDriver( 31): buffering (0)

I have googled around and guess the reason maybe the Wifi hotspot is behind the firewall and the UDP port is blocked, and the Opencore media framework only supports RTP over UDP. Correct me if I am wrong.

Then, here is my question, how can I solve it if i cannot change the firewall situation. If using the build-in VideoView/MediaPlayer is not possible, then how to write my own rtsp client.

Any suggestion will be appreciated:)

Thanks in advance!

Bolton

Bolton
  • 2,226
  • 3
  • 25
  • 29

3 Answers3

2

I don't think that you can do much with this... Heres my idea:

Make an app that will be started in the same LAN as Darvin, then it will get Darvin's RTP stream which goes over UDP (in LAN) and then transmit that over TCP to WAN, so you can access it. You can easily write that app in C#... and it will work perfectly. Or if you have some Linux distro, you can write a complex Bash script that will use NC to do the same...

So this is basically the idea: enter image description here

Cipi
  • 11,055
  • 9
  • 47
  • 60
  • For now I want to change my client to solve the problem, I think it's possible because I can use VLC to access the RTSP stream via the same WiFi. But thanks for your help, I will try it if I could not solve it by changing the client:) – Bolton Mar 24 '11 at 16:59
  • Can you be sure that VLC is using UDP to transfer the stream? Maybe it is getting it over TCP, and your Android App wants to go over UDP? Can you scan network activity on the client PC when you start the stream (using Wireshark)? Or in some other way confirm that VLC is getting stream over UDP? – Cipi Mar 24 '11 at 19:35
  • Yes, you are right, VLC is using TCP. And I am wondering if i could do something to change my Android App to get the stream over TCP, like using some open source RTSP library in jni, etc. – Bolton Mar 25 '11 at 02:35
  • Well now you can do that... but I dont know how. You will have to google... or edit you question so someone that does know, responds. :D Or, you can do what I did: configure server to only accept TCP-unicast and TCP-interleaved connections, so Android will go on TCP when Server responds with BAD TRANSPORT Error, when it tries to get stream over UDP. Now, I wrote my rtsp server from a ground up, and I dont know how to configure Darvin. So... :DD – Cipi Mar 25 '11 at 07:38
  • Thank you very much for your help Cipi:) I will try to change my client, and the answer is accepted and I hope it may help others. – Bolton Mar 28 '11 at 02:52
  • @Cipi Hi Cipi, sorry to bother you angin. I've tried to modify my client but it may take too much time, so I decided to change my server, when you say BAD TRANSPORT Error, what's that mean? I modified my server to response 461(Unsupported Transport) but the client seemed to ignore. can you plz help me, [my new question](http://stackoverflow.com/questions/5660741/opencore-rtsp-via-tcp) – Bolton Apr 14 '11 at 09:09
  • That's the one - UNSUPPORTED TRANSPORT. xD I put 461 in enum under "BAD TRANSPORT"... sorry about that. Well upon receiving that, client should stop trying to get the stream over current transport, and switch to another one! What happens with the connection after you send 461? Is it still open? (RTSP connection) – Cipi Apr 14 '11 at 10:06
  • Er..My fault angin. In fact the client does send SETUP request via TCP. It's because the server shut down the connection when I response the Error code and the following SETUP Request does not reach the server. – Bolton Apr 15 '11 at 03:22
  • Well, the connection should stay open until timeout expires or client terminates the connection... Can you post here the RTSP 461 ERROR response from the server? Can you can configure Darvin not to terminate connection on all RTSP errors? – Cipi Apr 15 '11 at 07:43
  • Sorry for replying late. It's weird everything is OK when I'm at home. The server response like below: `RTSP/1.0 461 Unsupported Transport\r\n Server: DSS/5.5.5 (Build/489.16; Platform/Win32; Release/Darwin; state/beta; )\r\n Cseq: 2\r\n \r\n` and the client get it. and then the playback is OK. I am curious why the SETUP request always got sent twice even the first one get the 200 response. – Bolton Apr 17 '11 at 09:23
0

Its quite easy and interesting task in android.

Just Follow the instructions.

1- Install VLC on your computer (SERVER) and go to Media->Streaming (Ctrl+S) 2- select a file to stream or if you want to stream your webcam or... click on "Capture Device" tab and do the configuration and finally click on "Stream" button. 3- here you should do the streaming server configuration, just go to "Option" tab and past the following command:

:sout=#transcode{vcodec=mp4v,vb=400,fps=10,width=176,height=144,acodec=mp4a,ab=32,channels =1,samplerate=22050}:rtp{sdp=rtsp://YOURCOMPUTER_SERVER_IP_ADDR:5544/}

NOTE: replace YOURCOMPUTER_SERVER_IP_ADDR with your computer IP address or any server which is running VLC...

NOTE: You can see, the video codec is MP4V which is supported by android.

4- go to eclipse and create a new project for media playbak. create a VideoView object and in the OnCreate() function write some code like this:

mVideoView = (VideoView) findViewById(R.id.surface_view);

mVideoView.setVideoPath("rtsp://YOURCOMPUTER_SERVER_IP_ADDR:5544/");
mVideoView.setMediaController(new MediaController(this));

5- run the apk on the device (not simulator, i did not check it) and wait for the playback to be started. please consider the buffering process will take about 10 seconds...

Sathish
  • 1,455
  • 1
  • 16
  • 22
0

Using the MediaPlayer is recommended way to go with RTSP. but as you said that the problem persist with the WiFi firewall, in such case you have to have enable the ports or configure the needful. I think there is no solution for this as the problem is with network not your code. So the ball is not in your court.

Rohit Mandiwal
  • 10,258
  • 5
  • 70
  • 83
  • Thanks rohit, but I saw some other apps that can play RTSP stream via the same WiFi hotspot, so I think there should be some solution for this. – Bolton Mar 22 '11 at 07:53