org.webrtc.StatsObserver Java Examples

The following examples show how to use org.webrtc.StatsObserver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PeerConnectionClient.java    From restcomm-android-sdk with GNU Affero General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("deprecation") // TODO(sakal): getStats is deprecated.
public boolean getStats() {
  if (peerConnection == null || isError) {
    return false;
  }
  boolean success = peerConnection.getStats(new StatsObserver() {
    @Override
    public void onComplete(final StatsReport[] reports) {
      events.onPeerConnectionStatsReady(reports);
    }
  }, null);
  if (!success) {
    Log.e(TAG, "getStats() returns false!");
    return false;
  }
  return true;
}
 
Example #2
Source File: PeerConnectionClient.java    From sample-videoRTC with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation") // TODO(sakal): getStats is deprecated.
private void getStats() {
  if (peerConnection == null || isError) {
    return;
  }
  boolean success = peerConnection.getStats(new StatsObserver() {
    @Override
    public void onComplete(final StatsReport[] reports) {
      events.onPeerConnectionStatsReady(reports);
    }
  }, null);
  if (!success) {
    Log.e(TAG, "getStats() returns false!");
  }
}
 
Example #3
Source File: PeerConnectionClient.java    From janus-gateway-android with MIT License 5 votes vote down vote up
private void getStats(final BigInteger handleId) {
  PeerConnection peerConnection = peerConnectionMap.get(handleId).peerConnection;
  boolean success = peerConnection.getStats(new StatsObserver() {
    @Override
    public void onComplete(final StatsReport[] reports) {
      events.onPeerConnectionStatsReady(reports);
    }
  }, null);
  if (!success) {
    Log.e(TAG, "getStats() returns false!");
  }
}
 
Example #4
Source File: PeerConnectionClient.java    From Yahala-Messenger with MIT License 5 votes vote down vote up
private void getStats() {
    if (peerConnection == null || isError) {
        return;
    }
    boolean success = peerConnection.getStats(new StatsObserver() {
        @Override
        public void onComplete(final StatsReport[] reports) {
            events.onPeerConnectionStatsReady(reports);
        }
    }, null);
    if (!success) {
        Log.e(TAG, "getStats() returns false!");
    }
}
 
Example #5
Source File: PeerConnectionClient.java    From voip_android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void getStats() {
    if (peerConnection == null || isError) {
        return;
    }
    boolean success = peerConnection.getStats(new StatsObserver() {
        @Override
        public void onComplete(final StatsReport[] reports) {
            events.onPeerConnectionStatsReady(reports);
        }
    }, null);
    if (!success) {
        Log.e(TAG, "getStats() returns false!");
    }
}
 
Example #6
Source File: AppRTCDemoActivity.java    From WebRTCDemo with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void onIceServers(List<PeerConnection.IceServer> iceServers) {
  factory = new PeerConnectionFactory();

  MediaConstraints pcConstraints = appRtcClient.pcConstraints();
  pcConstraints.optional.add(
      new MediaConstraints.KeyValuePair("RtpDataChannels", "true"));
  pc = factory.createPeerConnection(iceServers, pcConstraints, pcObserver);

  createDataChannelToRegressionTestBug2302(pc);  // See method comment.

  // Uncomment to get ALL WebRTC tracing and SENSITIVE libjingle logging.
  // NOTE: this _must_ happen while |factory| is alive!
  // Logging.enableTracing(
  //     "logcat:",
  //     EnumSet.of(Logging.TraceLevel.TRACE_ALL),
  //     Logging.Severity.LS_SENSITIVE);

  {
    final PeerConnection finalPC = pc;
    final Runnable repeatedStatsLogger = new Runnable() {
        public void run() {
          synchronized (quit[0]) {
            if (quit[0]) {
              return;
            }
            final Runnable runnableThis = this;
            if (hudView.getVisibility() == View.INVISIBLE) {
              vsv.postDelayed(runnableThis, 1000);
              return;
            }
            boolean success = finalPC.getStats(new StatsObserver() {
                public void onComplete(final StatsReport[] reports) {
                  runOnUiThread(new Runnable() {
                      public void run() {
                        updateHUD(reports);
                      }
                    });
                  for (StatsReport report : reports) {
                    Log.d(TAG, "Stats: " + report.toString());
                  }
                  vsv.postDelayed(runnableThis, 1000);
                }
              }, null);
            if (!success) {
              throw new RuntimeException("getStats() return false!");
            }
          }
        }
      };
    vsv.postDelayed(repeatedStatsLogger, 1000);
  }

  {
    logAndToast("Creating local video source...");
    MediaStream lMS = factory.createLocalMediaStream("ARDAMS");
    if (appRtcClient.videoConstraints() != null) {
      VideoCapturer capturer = getVideoCapturer();
      videoSource = factory.createVideoSource(
          capturer, appRtcClient.videoConstraints());
      VideoTrack videoTrack =
          factory.createVideoTrack("ARDAMSv0", videoSource);
      videoTrack.addRenderer(new VideoRenderer(localRender));
      lMS.addTrack(videoTrack);
    }
    if (appRtcClient.audioConstraints() != null) {
      lMS.addTrack(factory.createAudioTrack(
          "ARDAMSa0",
          factory.createAudioSource(appRtcClient.audioConstraints())));
    }
    pc.addStream(lMS, new MediaConstraints());
  }
  logAndToast("Waiting for ICE candidates...");
}
 
Example #7
Source File: AppRTCDemoActivity.java    From droidkit-webrtc with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void onIceServers(List<PeerConnection.IceServer> iceServers) {
  factory = new PeerConnectionFactory();

  MediaConstraints pcConstraints = appRtcClient.pcConstraints();
  pcConstraints.optional.add(
      new MediaConstraints.KeyValuePair("RtpDataChannels", "true"));
  pc = factory.createPeerConnection(iceServers, pcConstraints, pcObserver);

  createDataChannelToRegressionTestBug2302(pc);  // See method comment.

  // Uncomment to get ALL WebRTC tracing and SENSITIVE libjingle logging.
  // NOTE: this _must_ happen while |factory| is alive!
  // Logging.enableTracing(
  //     "logcat:",
  //     EnumSet.of(Logging.TraceLevel.TRACE_ALL),
  //     Logging.Severity.LS_SENSITIVE);

  {
    final PeerConnection finalPC = pc;
    final Runnable repeatedStatsLogger = new Runnable() {
        public void run() {
          synchronized (quit[0]) {
            if (quit[0]) {
              return;
            }
            final Runnable runnableThis = this;
            if (hudView.getVisibility() == View.INVISIBLE) {
              vsv.postDelayed(runnableThis, 1000);
              return;
            }
            boolean success = finalPC.getStats(new StatsObserver() {
                public void onComplete(final StatsReport[] reports) {
                  runOnUiThread(new Runnable() {
                      public void run() {
                        updateHUD(reports);
                      }
                    });
                  for (StatsReport report : reports) {
                    Log.d(TAG, "Stats: " + report.toString());
                  }
                  vsv.postDelayed(runnableThis, 1000);
                }
              }, null);
            if (!success) {
              throw new RuntimeException("getStats() return false!");
            }
          }
        }
      };
    vsv.postDelayed(repeatedStatsLogger, 1000);
  }

  {
    logAndToast("Creating local video source...");
    MediaStream lMS = factory.createLocalMediaStream("ARDAMS");
    if (appRtcClient.videoConstraints() != null) {
      VideoCapturer capturer = getVideoCapturer();
      videoSource = factory.createVideoSource(
          capturer, appRtcClient.videoConstraints());
      VideoTrack videoTrack =
          factory.createVideoTrack("ARDAMSv0", videoSource);
      videoTrack.addRenderer(new VideoRenderer(localRender));
      lMS.addTrack(videoTrack);
    }
    if (appRtcClient.audioConstraints() != null) {
      lMS.addTrack(factory.createAudioTrack(
          "ARDAMSa0",
          factory.createAudioSource(appRtcClient.audioConstraints())));
    }
    pc.addStream(lMS, new MediaConstraints());
  }
  logAndToast("Waiting for ICE candidates...");
}