美文网首页
Android端推送WebRTC流到SRS服务器

Android端推送WebRTC流到SRS服务器

作者: 陆笪_刑道荣 | 来源:发表于2023-01-02 09:45 被阅读0次

    引库

    implementation 'org.webrtc:google-webrtc:1.0.32006'
    

    采集摄像头

                    captureAndroid = CameraUtil.createVideoCapture(context);
                    surfaceTextureHelper = SurfaceTextureHelper.create("CaptureThread", eglBase.getEglBaseContext());
                    videoSource = peerConnectionFactory.createVideoSource(false);
    
                    captureAndroid.initialize(surfaceTextureHelper, context, videoSource.getCapturerObserver());
                    captureAndroid.startCapture(VIDEO_RESOLUTION_WIDTH, VIDEO_RESOLUTION_HEIGHT, FPS);
    
                    localVideoTrack = peerConnectionFactory.createVideoTrack(VIDEO_TRACK_ID, videoSource);
                    localVideoTrack.setEnabled(true);
                    if (surfaceViewRenderer != null) {
                        ProxyVideoSink videoSink = new ProxyVideoSink();
                        videoSink.setTarget(surfaceViewRenderer);
                        localVideoTrack.addSink(videoSink);
                    }
    

    采集本地录制

    1.开启屏幕共享服务

        private void DeviceManager(Context context) {
            AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
            BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
            if (Build.VERSION.SDK_INT >= 21) {
                mediaProjectionManager = (MediaProjectionManager) context.getSystemService(Context.MEDIA_PROJECTION_SERVICE);
            } else {
                Toast.makeText(context, "您的设备不支持屏幕共享", Toast.LENGTH_SHORT).show();
            }
        }
    

    2.获取屏幕录制的流

        public void startScreenCapture(Activity activity) {
            if (mediaProjectionManager == null) {
                Toast.makeText(this, "截屏服务不可用", Toast.LENGTH_SHORT).show();
                return;
            }
            Intent intent = null;
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
                intent = mediaProjectionManager.createScreenCaptureIntent();
                activity.startActivityForResult(intent, SCREEN_CODE);
            }
    
        }
    

    3.推送本地屏幕录制

                    captureAndroid = new ScreenCapturerAndroid(intent, new MediaProjection.Callback() {
                        @Override
                        public void onStop() {
                            super.onStop();
                        }
                    });
                    videoSource = peerConnectionFactory.createVideoSource(true);
                    surfaceTextureHelper = SurfaceTextureHelper.create("CaptureThread", eglBase.getEglBaseContext());
                    captureAndroid.initialize(surfaceTextureHelper, context, videoSource.getCapturerObserver());
                    captureAndroid.startCapture(VIDEO_RESOLUTION_WIDTH, VIDEO_RESOLUTION_HEIGHT, FPS);
                    localVideoTrack = peerConnectionFactory.createVideoTrack(VIDEO_TRACK_ID, videoSource);
                    localVideoTrack.setEnabled(true);
    

    相关文章

      网友评论

          本文标题:Android端推送WebRTC流到SRS服务器

          本文链接:https://www.haomeiwen.com/subject/iyphcdtx.html