ekoshairy
ekoshairy

Reputation: 21

Video Streaming from Android device camera

I am trying to build an application on Android that streams a video from device camera to a streaming server.

I have looked at different posts and solutions and here is my current state, with the help of (I used Sipdroid, jboss-netty, and analyzing packets on wireshark)

  1. I built the RTSP Stack and I successfully connect to the server
    2.I am able theoretically able to create an rtp packet and sent it to the server

My problem is in capturing the frame and sending the data in the RTP packet. I have 2 directions:

1- Use the camera and AuidoRecorder to capture the raw media data and send it using rtp, the problem is should this data be encoded according to the .sdp file description in the ANNOUNCE of the RTSP ??? as I understand the data from the camera and mic will be raw data that is not encoded Anorther thing is how can I formulate this raw data in the RTP packet properly.

2- The Media recorder already encodes the data and I am able to set the encoding as defined in the .sdp file .. I tried to find a way to read from the output file but this would require me to transform the .mp4 file data to stream data which seems like a complicated task.

My question is am I over complicating things is it enough to send the raw data of video and audio in RTP packets and the streaming server would handle the rest ???? Please I would appreciate any help and guidance in that matter..

Thanks

Upvotes: 2

Views: 5140

Answers (1)

shawn
shawn

Reputation: 21

Firstly you must encode your data as it described by the .sdp file. Would you like to try MediaRecorder rather than AuidoRecord? MediaRecorder allows you to set the encoding of the data you'll get.

Besides, I suggest you create a FileDescriptor by a Socket so that the data can be transport via socket stream rather than a static file. The code may like this:

Socket socket = new Socket(serverAddr, serverPort);
socket.setTcpNoDelay(true);
ParcelFileDescriptor pfd = ParcelFileDescriptor.fromSocket(socket);
Camera camera = Camera.open();
camera.unlock();
MediaRecorder recorder = new MediaRecorder();
recorder.setCamera(camera);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);
recorder.setOutputFile(pfd.getFileDescriptor());
recorder.setPreviewDisplay(surfaceView.getHolder().getSurface());
recorder.setVideoFrameRate(15);
recorder.setVideoSize(480, 320);
recorder.prepare();
recorder.start();

The method to transport in RTP is just what troubles me now.

Upvotes: 2

Related Questions