Libstreaming - 使用VLC作为RTSP客户端

时间:2015-10-01 12:50:53

标签: java android rtsp rtsp-client libstreaming

我试图将VLC用作RTSP客户端。 RTSP服务器基于libstreaming库。我使用1rst example提供的代码:

        // Sets the port of the RTSP server to 1234
        Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
        editor.putString(RtspServer.KEY_PORT, String.valueOf(1234));
        editor.commit();

        // Configures the SessionBuilder
        SessionBuilder.getInstance()
        .setSurfaceView(mSurfaceView)
        .setPreviewOrientation(90)
        .setContext(getApplicationContext())
        .setAudioEncoder(SessionBuilder.AUDIO_NONE)
        .setVideoEncoder(SessionBuilder.VIDEO_H264);

        // Starts the RTSP server
        this.startService(new Intent(this,RtspServer.class));

Android应用程序启动;我尝试使用VLC(open a stream)和此URL访问流:

rtsp://192.168.43.250:1234

设备连接到同一网络(我可以ping通),但Android应用程序没有任何反应,VLC显示"连接失败"窗口。

知道问题出在哪里?也许是一个糟糕的网址,但我无法找到这种情况的任何详细示例。

4 个答案:

答案 0 :(得分:4)

抛出空指针,检查logcat。

你必须提供网址为rtsp:// ip:1234?h264 = 200-20-320-240

200 - buf 20 - fps 320 - 分辨率w 240 - 分辨率h

答案 1 :(得分:1)

我有类似的问题。这是我的解决方案。

  1. 确保您已通过android studio

  2. 将库导入为导入的模块
  3. 授予您的清单使用所需资源的权限

  4. 为您使用此代码MainActivity:

    public class MainActivity extends AppCompatActivity implements SurfaceHolder.Callback, RtspServer.CallbackListener, Session.Callback{
    
        private final static String TAG = "MainActivity";
    
        private SurfaceView mSurfaceView;
        private  Session mSession;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    
    
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            requestWindowFeature(Window.FEATURE_NO_TITLE);
    
            setContentView(R.layout.activity_main);
    
            mSurfaceView = (SurfaceView) findViewById(R.id.surface);
    
    
    
    
            // Sets the port of the RTSP server to 1234
            SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
            editor.putString(  RtspServer.KEY_PORT, String.valueOf(1234));
            editor.commit();
    
    
    
            // Configures the SessionBuilder
           mSession =  SessionBuilder.getInstance()
                .setCallback(this)
                .setSurfaceView((net.majorkernelpanic.streaming.gl.SurfaceView) mSurfaceView)
                .setPreviewOrientation(90)
                .setContext(getApplicationContext())
                .setAudioEncoder(SessionBuilder.AUDIO_AAC)
                .setAudioQuality(new AudioQuality(8000, 16000))
                .setVideoEncoder(SessionBuilder.VIDEO_H264)
                //.setVideoQuality(new VideoQuality(320,240,20,500000))
                .build();
    
            mSurfaceView.getHolder().addCallback(this);
    
            ((net.majorkernelpanic.streaming.gl.SurfaceView) mSurfaceView).setAspectRatioMode(net.majorkernelpanic.streaming.gl.SurfaceView.ASPECT_RATIO_PREVIEW);
            String ip, port, path;
    
            // Starts the RTSP server
            this.startService(new Intent(this,RtspServer.class));
    
            Log.d("test", "1");
    
    
    
            mSession.startPreview(); //camera preview on phone surface
            mSession.start();
    
        }
    
        @Override
        public void onResume()
        {
            super.onResume();
            mSession.stopPreview();
        }
    
        @Override
        public void onDestroy()
        {
            super.onDestroy();
            mSession.release();
            mSurfaceView.getHolder().removeCallback(this);
        }
    
        //region   ----------------------------------implement methods required
        @Override
        public void onError(RtspServer server, Exception e, int error) {
            Log.e("Server", e.toString());
        }
    
        @Override
        public void onMessage(RtspServer server, int message) {
            Log.e("Server", "unkown message");
        }
    
        @Override
        public void onBitrateUpdate(long bitrate) {
    
        }
    
        @Override
        public void onSessionError(int reason, int streamType, Exception e) {
    
        }
    
        @Override
        public void onPreviewStarted() {
    
        }
    
        @Override
        public void onSessionConfigured() {
    
        }
    
        @Override
        public void onSessionStarted() {
    
        }
    
        @Override
        public void onSessionStopped() {
    
        }
    
        @Override
        public void surfaceCreated(SurfaceHolder holder) {
    
        }
    
        @Override
        public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    
        }
    
        @Override
        public void surfaceDestroyed(SurfaceHolder holder) {
    
        }
    
        //endregion
    }
    
  5. 使用VLC播放器打开开放网络流并输入

  6. rtsp:// android设备的ip:1234< - 此端口是硬编码的,所以不要改变

答案 2 :(得分:0)

当我使用libstreaming& VLC我花了很多时间来解决同样的问题。我的解决方案是使用其他VLC版本。例如,它在vlc ver上为我工作。 1.0.5,但许多其他版本没有播放流。

答案 3 :(得分:0)

)))第一个例子是服务器(对于库的作者,服务器是接受流但不给出的人) 你需要使用2或3个例子...... 2例子很好,因为你只需要一个VLK播放器...

  1. 找出你的IP(cmd-> ipconfig)(了解设备必须有外部IP地址或者在同一网络中很重要)

    1. 在mEditText中指定收到的PC的IP地址(mSession.setDestination();)
    2. 启动应用程序后,按开始按钮。日志中的工作室将返回内容以创建sdp格式文件(TAG,mSession.getSessionDescription());
    3. 创建一个falix例如1.sdp通过指定getSessionDescription的内容来编辑它(删除多余的空格) 然后,我们需要指定我们要将流发送到的那个的IP ...

      现在主要的事情!在任何一个例子中,它都不会简单地输入rtsp://192.168.43.250:1234并获得视频! - 0)))))))

      在Session类中,你会发现mOrigin =“127.0.0.1”; ok SessionBuilder .... setOrigin(“192.xxx.xxx.xx”)

      此外,您的逻辑可能建议您只需要找到端口,也许您会找到SessionBuilder Session build()video.setDestinationPorts(5006); 但这不是端口)))

      在这个库中没有rtsp服务器实现(我正在编写服务器,因为它意味着我们想在设备上为ip cam引发服务器) 你可以在RtspClient类中找到提示(注意库的作者,这是给出它的人)并且作者写信给我们 * RFC 2326。 *基本和异步RTSP客户端。 RTSP客户端与Wowza兼容。 *它根据RFC 2069实现摘要访问身份验证。