/** stop all streams from being cast to the server */
  void doUnpublish() {
    for (String key : mLocalStream.keySet()) {
      final StreamDescription stream = mLocalStream.get(key);
      if (stream != null && stream.isLocal()) {
        stream.pc.removeStream(lMS);

        for (RoomObserver obs : mObservers) {
          obs.onStreamRemoved(stream);
        }

        if (mObservers.size() == 0) {
          destroy(stream);
        }
      }
    }
    mLocalStream.clear();

    if (lMS != null) {
      lMS.dispose();
    }
    if (mVideoCapturer != null) {
      mVideoCapturer.dispose();
    }

    lMS = null;
    mVideoCapturer = null;
    if (mVideoSource != null && !mVideoStopped) {
      mVideoSource.stop();
    }
    mVideoSource = null;
  }
Esempio n. 2
0
  private VideoTrack createVideoTrack(VideoCapturer capturer) {
    videoSource = factory.createVideoSource(capturer);
    capturer.startCapture(videoWidth, videoHeight, videoFps);

    localVideoTrack = factory.createVideoTrack(VIDEO_TRACK_ID, videoSource);
    localVideoTrack.setEnabled(renderVideo);
    localVideoTrack.addRenderer(new VideoRenderer(localRender));
    return localVideoTrack;
  }
 // Cycle through likely device names for the camera and return the first
 // capturer that works, or crash if none do.
 private VideoCapturer getVideoCapturer() {
   String[] cameraFacing = {"front", "back"};
   int[] cameraIndex = {0, 1};
   int[] cameraOrientation = {0, 90, 180, 270};
   for (String facing : cameraFacing) {
     for (int index : cameraIndex) {
       for (int orientation : cameraOrientation) {
         String name = "Camera " + index + ", Facing " + facing + ", Orientation " + orientation;
         VideoCapturer capturer = VideoCapturer.create(name);
         if (capturer != null) {
           logAndToast("Using camera: " + name);
           return capturer;
         }
       }
     }
   }
   throw new RuntimeException("Failed to open capturer");
 }