开发者

Creating RTP Packets from Android Camera to Send

开发者 https://www.devze.com 2023-04-03 18:12 出处:网络
I\'m new to Android and socket programming. I want to create an android application that transfer video live from device camera to PC. What first i do is to get a raw video data from PreviewCallback a

I'm new to Android and socket programming. I want to create an android application that transfer video live from device camera to PC. What first i do is to get a raw video data from PreviewCallback arguments and convert it to an RTP Packet. I was just using JLibRTP to do this. Regarding to transfer the packet i think, there are some related class: RtpPkt, RtpSession, and RtpSocket.

Here is my glance code:

DatagramSocket rtpSocket = new DatagramSocket();
DatagramSocket rtcpSocket = new new DatagramSocket();
RtpSession rtpSession = new RtpSession(rtpSocket, rtcpSocket);

public void surfaceCreated(SurfaceHolder holder) {
    try {
            camera = Camera.open();
            camera.setPreviewCallback(new PreviewCallback() {
                public void onPreviewFrame(byte[] _data, Camera _camera) {
                int height = 240;
                    try {
                        rtps.sendData(_data);
                     } catch (Exception e) {
                        e.printStackTrace();
                        Toast.makeText(getApplicationContext(), e.toString(),
                        Toast.LENGTH_SHORT).show();
                    }
                }
            });
            camera.setPreviewDisplay(holder);
            camera.startPreview();
    } catch (IOException e) {
            Log.d("CAMERA", e.getMessage());
    }
}

I'm still wondering开发者_Python百科 where i have to put address and port information. I know the code above still need correction from you any master. Thanks for advance..


I don't know if this library includes something to stream the packets to the pc, but if not, you've a problem, because android only supports RTP streaming since version 3.1 (API level 12). if your level is lower, you have to write your own "rtp-server" which is able to stream the packets from your device to the pc.

for more information check out the sipdroid project. they have created their own "rtp-server": http://code.google.com/p/sipdroid/source/browse/trunk/src/org/sipdroid/sipua/ui/VideoCamera.java

UPDATE:

another possibility is to use the ffserver from the ffmpeg libraries, but therefore you have to compile the libraries for android. here is a small tutorial how to do this and how to work with the libraries: How to Build FFmpeg for Android

UPDATE2:

the spydroid application is a very good example to stream videos from an android device without any external libraries.

0

精彩评论

暂无评论...
验证码 换一张
取 消