Creating RTP Packets from Android Camera to Send

早过忘川 提交于 2019-12-28 03:34:25

问题


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 where i have to put address and port information. I know the code above still need correction from you any master. Thanks for advance..


回答1:


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.



来源:https://stackoverflow.com/questions/7332532/creating-rtp-packets-from-android-camera-to-send

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!