Search code examples
javac#udplive-streaming

Useful APIs to Live Video Stream between Windows C# and Android Java?


Following this approach. I want a Client to Live Stream Video to a server using IP communication. Requirements are Android Studio Java Client and Visual Studio C# Server and this is why I didn't find exact situation on StackOverFlow. I set up a basic UDP Datagram between Android Java and Windows C# and it's up and running two-way sending short messages. Where do I start with Video Streaming?

Shall I figure it out myself how to get the images frame by frame in the server, break each frame into byte[] order them and send over using UDP, then in the client's side, rebuild each frame using byte[] data received? Is't fine to use UDP? What are useful APIs on both C# and Java? Is it going to be easier on the long run to set both as Java? Do I need time to adapt Windows Java IDEs now and start from there? Is it the same as Android?

Two many questions on my head and I don't have enough knowledge. I have never done "big" nor "networking" application before. I feel lost on what to do. Finding APIs would really be helpful. Thanks in advance


Solution

  • Don't invent your own protocols, use existing ones like RTP, RTSP (or even a HTTP server).

    For instance RTSP (Real-Time Streaming Protocol):

    With this project (https://net7mma.codeplex.com/), you're able to set up RTSP server which serves a media file in exactly 5 lines of Code in C#.

    using(Rtsp.RtspServer server = new Rtsp.RtspServer(555)){    
        Media.Rtsp.Server.Media.RtspSource source = 
              new Media.Rtsp.Server.Media.RtspSource("RtspSourceTest", "rtsp://1.2.3.4/mpeg4/media.amp");
    
       //If the stream had a username and password
       //source.Client.Credential = new System.Net.NetworkCredential("user", "password");
    
       //Add the stream to the server
       server.AddMedia(source);
    
       //Start the server and underlying streams
       server.Start();
    } 
    

    And according to the project page:

    The RtspServer does successfully aggregate live Rtsp video streams in ANY container or codec to a compatible RtspClient or Player (VLC, Mplayer Darwin Streaming Server and QuickTime have been tested)

    This lets you turn your Web Camera or Digital Camera or source of images into a LIVE Rtsp Stream!

    With this server side written in C# as a general RTSP server, you can use existing objects like a normal VideoView (https://stackoverflow.com/a/10461150/5296568) on the Java/Android side to connect and view that live stream without problems.