Java Code Examples for org.webrtc.ThreadUtils#checkIsOnMainThread()

The following examples show how to use org.webrtc.ThreadUtils#checkIsOnMainThread() . 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: AppRTCBluetoothManager.java    From Conversations with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Stops and closes all components related to Bluetooth audio.
 */
public void stop() {
    ThreadUtils.checkIsOnMainThread();
    Log.d(Config.LOGTAG, "stop: BT state=" + bluetoothState);
    if (bluetoothAdapter == null) {
        return;
    }
    // Stop BT SCO connection with remote device if needed.
    stopScoAudio();
    // Close down remaining BT resources.
    if (bluetoothState == State.UNINITIALIZED) {
        return;
    }
    unregisterReceiver(bluetoothHeadsetReceiver);
    cancelTimer();
    if (bluetoothHeadset != null) {
        bluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, bluetoothHeadset);
        bluetoothHeadset = null;
    }
    bluetoothAdapter = null;
    bluetoothDevice = null;
    bluetoothState = State.UNINITIALIZED;
    Log.d(Config.LOGTAG, "stop done: BT state=" + bluetoothState);
}
 
Example 2
Source File: TextureViewRenderer.java    From VideoCRE with MIT License 5 votes vote down vote up
@Override
public boolean onSurfaceTextureDestroyed(final SurfaceTexture surface) {
  logD("onSurfaceTextureDestroyed: " + surface);
  ThreadUtils.checkIsOnMainThread();
  final CountDownLatch completionLatch = new CountDownLatch(1);
  eglRenderer.releaseEglSurface(new Runnable() {
    @Override
    public void run() {
      completionLatch.countDown();
    }
  });
  ThreadUtils.awaitUninterruptibly(completionLatch);
  return true;
}
 
Example 3
Source File: AppRTCBluetoothManager.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
protected AppRTCBluetoothManager(Context context, AppRTCAudioManager audioManager) {
    Log.d(Config.LOGTAG, "ctor");
    ThreadUtils.checkIsOnMainThread();
    apprtcContext = context;
    apprtcAudioManager = audioManager;
    this.audioManager = getAudioManager(context);
    bluetoothState = State.UNINITIALIZED;
    bluetoothServiceListener = new BluetoothServiceListener();
    bluetoothHeadsetReceiver = new BluetoothHeadsetBroadcastReceiver();
    handler = new Handler(Looper.getMainLooper());
}
 
Example 4
Source File: TextureViewRenderer.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public void init(@NonNull EglBase.Context sharedContext, @NonNull RendererCommon.RendererEvents rendererEvents, @NonNull int[] configAttributes, @NonNull RendererCommon.GlDrawer drawer) {
  ThreadUtils.checkIsOnMainThread();

  this.rendererEvents     = rendererEvents;
  this.rotatedFrameWidth  = 0;
  this.rotatedFrameHeight = 0;

  this.eglRenderer.init(sharedContext, this, configAttributes, drawer);
}
 
Example 5
Source File: TextureViewRenderer.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public void setScalingType(@NonNull RendererCommon.ScalingType scalingTypeMatchOrientation,
                           @NonNull RendererCommon.ScalingType scalingTypeMismatchOrientation)
{
  ThreadUtils.checkIsOnMainThread();

  videoLayoutMeasure.setScalingType(scalingTypeMatchOrientation, scalingTypeMismatchOrientation);

  requestLayout();
}
 
Example 6
Source File: TextureViewRenderer.java    From VideoCRE with MIT License 5 votes vote down vote up
@Override
protected void onMeasure(int widthSpec, int heightSpec) {
  ThreadUtils.checkIsOnMainThread();
  final Point size;
  synchronized (layoutLock) {
    size =
        videoLayoutMeasure.measure(widthSpec, heightSpec, rotatedFrameWidth, rotatedFrameHeight);
  }
  setMeasuredDimension(size.x, size.y);
  logD("onMeasure(). New size: " + size.x + "x" + size.y);
}
 
Example 7
Source File: TextureViewRenderer.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
  ThreadUtils.checkIsOnMainThread();

  eglRenderer.setLayoutAspectRatio((float)(right - left) / (float)(bottom - top));

  updateSurfaceSize();
}
 
Example 8
Source File: SurfaceTextureEglRenderer.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public void init(@Nullable EglBase.Context sharedContext, @Nullable RendererCommon.RendererEvents rendererEvents, @NonNull int[] configAttributes, @NonNull RendererCommon.GlDrawer drawer) {
  ThreadUtils.checkIsOnMainThread();
  this.rendererEvents = rendererEvents;
  synchronized (this.layoutLock) {
    this.isFirstFrameRendered = false;
    this.rotatedFrameWidth    = 0;
    this.rotatedFrameHeight   = 0;
    this.frameRotation        = 0;
  }

  super.init(sharedContext, configAttributes, drawer);
}
 
Example 9
Source File: AppRTCAudioManager.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Changes selection of the currently active audio device.
 */
public void selectAudioDevice(AudioDevice device) {
    ThreadUtils.checkIsOnMainThread();
    if (!audioDevices.contains(device)) {
        Log.e(Config.LOGTAG, "Can not select " + device + " from available " + audioDevices);
    }
    userSelectedAudioDevice = device;
    updateAudioDeviceState();
}
 
Example 10
Source File: AppRTCAudioManager.java    From Pix-Art-Messenger with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns the currently selected audio device.
 */
public AudioDevice getSelectedAudioDevice() {
    ThreadUtils.checkIsOnMainThread();
    return selectedAudioDevice;
}
 
Example 11
Source File: TextureViewRenderer.java    From VideoCRE with MIT License 4 votes vote down vote up
@Override
public void onSurfaceTextureSizeChanged(final SurfaceTexture surface, final int width,
        final int height) {
  logD("onSurfaceTextureSizeChanged: " + surface + " size: " + width + "x" + height);
  ThreadUtils.checkIsOnMainThread();
}
 
Example 12
Source File: AppRTCBluetoothManager.java    From Pix-Art-Messenger with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns the internal state.
 */
public State getState() {
    ThreadUtils.checkIsOnMainThread();
    return bluetoothState;
}
 
Example 13
Source File: AppRTCBluetoothManager.java    From Pix-Art-Messenger with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Cancels any outstanding timer tasks.
 */
private void cancelTimer() {
    ThreadUtils.checkIsOnMainThread();
    Log.d(Config.LOGTAG, "cancelTimer");
    handler.removeCallbacks(bluetoothTimeoutRunnable);
}
 
Example 14
Source File: AppRTCBluetoothManager.java    From Conversations with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Activates components required to detect Bluetooth devices and to enable
 * BT SCO (audio is routed via BT SCO) for the headset profile. The end
 * state will be HEADSET_UNAVAILABLE but a state machine has started which
 * will start a state change sequence where the final outcome depends on
 * if/when the BT headset is enabled.
 * Example of state change sequence when start() is called while BT device
 * is connected and enabled:
 * UNINITIALIZED --> HEADSET_UNAVAILABLE --> HEADSET_AVAILABLE -->
 * SCO_CONNECTING --> SCO_CONNECTED <==> audio is now routed via BT SCO.
 * Note that the AppRTCAudioManager is also involved in driving this state
 * change.
 */
public void start() {
    ThreadUtils.checkIsOnMainThread();
    Log.d(Config.LOGTAG, "start");
    if (!hasPermission(apprtcContext, android.Manifest.permission.BLUETOOTH)) {
        Log.w(Config.LOGTAG, "Process (pid=" + Process.myPid() + ") lacks BLUETOOTH permission");
        return;
    }
    if (bluetoothState != State.UNINITIALIZED) {
        Log.w(Config.LOGTAG, "Invalid BT state");
        return;
    }
    bluetoothHeadset = null;
    bluetoothDevice = null;
    scoConnectionAttempts = 0;
    // Get a handle to the default local Bluetooth adapter.
    bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (bluetoothAdapter == null) {
        Log.w(Config.LOGTAG, "Device does not support Bluetooth");
        return;
    }
    // Ensure that the device supports use of BT SCO audio for off call use cases.
    if (!audioManager.isBluetoothScoAvailableOffCall()) {
        Log.e(Config.LOGTAG, "Bluetooth SCO audio is not available off call");
        return;
    }
    logBluetoothAdapterInfo(bluetoothAdapter);
    // Establish a connection to the HEADSET profile (includes both Bluetooth Headset and
    // Hands-Free) proxy object and install a listener.
    if (!getBluetoothProfileProxy(
            apprtcContext, bluetoothServiceListener, BluetoothProfile.HEADSET)) {
        Log.e(Config.LOGTAG, "BluetoothAdapter.getProfileProxy(HEADSET) failed");
        return;
    }
    // Register receivers for BluetoothHeadset change notifications.
    IntentFilter bluetoothHeadsetFilter = new IntentFilter();
    // Register receiver for change in connection state of the Headset profile.
    bluetoothHeadsetFilter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);
    // Register receiver for change in audio connection state of the Headset profile.
    bluetoothHeadsetFilter.addAction(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED);
    registerReceiver(bluetoothHeadsetReceiver, bluetoothHeadsetFilter);
    Log.d(Config.LOGTAG, "HEADSET profile state: "
            + stateToString(bluetoothAdapter.getProfileConnectionState(BluetoothProfile.HEADSET)));
    Log.d(Config.LOGTAG, "Bluetooth proxy for headset profile has started");
    bluetoothState = State.HEADSET_UNAVAILABLE;
    Log.d(Config.LOGTAG, "start done: BT state=" + bluetoothState);
}
 
Example 15
Source File: AppRTCBluetoothManager.java    From Conversations with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Starts timer which times out after BLUETOOTH_SCO_TIMEOUT_MS milliseconds.
 */
private void startTimer() {
    ThreadUtils.checkIsOnMainThread();
    Log.d(Config.LOGTAG, "startTimer");
    handler.postDelayed(bluetoothTimeoutRunnable, BLUETOOTH_SCO_TIMEOUT_MS);
}
 
Example 16
Source File: AppRTCAudioManager.java    From Pix-Art-Messenger with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns current set of available/selectable audio devices.
 */
public Set<AudioDevice> getAudioDevices() {
    ThreadUtils.checkIsOnMainThread();
    return Collections.unmodifiableSet(new HashSet<>(audioDevices));
}
 
Example 17
Source File: AppRTCBluetoothManager.java    From Pix-Art-Messenger with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Activates components required to detect Bluetooth devices and to enable
 * BT SCO (audio is routed via BT SCO) for the headset profile. The end
 * state will be HEADSET_UNAVAILABLE but a state machine has started which
 * will start a state change sequence where the final outcome depends on
 * if/when the BT headset is enabled.
 * Example of state change sequence when start() is called while BT device
 * is connected and enabled:
 * UNINITIALIZED --> HEADSET_UNAVAILABLE --> HEADSET_AVAILABLE -->
 * SCO_CONNECTING --> SCO_CONNECTED <==> audio is now routed via BT SCO.
 * Note that the AppRTCAudioManager is also involved in driving this state
 * change.
 */
public void start() {
    ThreadUtils.checkIsOnMainThread();
    Log.d(Config.LOGTAG, "start");
    if (!hasPermission(apprtcContext, android.Manifest.permission.BLUETOOTH)) {
        Log.w(Config.LOGTAG, "Process (pid=" + Process.myPid() + ") lacks BLUETOOTH permission");
        return;
    }
    if (bluetoothState != State.UNINITIALIZED) {
        Log.w(Config.LOGTAG, "Invalid BT state");
        return;
    }
    bluetoothHeadset = null;
    bluetoothDevice = null;
    scoConnectionAttempts = 0;
    // Get a handle to the default local Bluetooth adapter.
    bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (bluetoothAdapter == null) {
        Log.w(Config.LOGTAG, "Device does not support Bluetooth");
        return;
    }
    // Ensure that the device supports use of BT SCO audio for off call use cases.
    if (!audioManager.isBluetoothScoAvailableOffCall()) {
        Log.e(Config.LOGTAG, "Bluetooth SCO audio is not available off call");
        return;
    }
    logBluetoothAdapterInfo(bluetoothAdapter);
    // Establish a connection to the HEADSET profile (includes both Bluetooth Headset and
    // Hands-Free) proxy object and install a listener.
    if (!getBluetoothProfileProxy(
            apprtcContext, bluetoothServiceListener, BluetoothProfile.HEADSET)) {
        Log.e(Config.LOGTAG, "BluetoothAdapter.getProfileProxy(HEADSET) failed");
        return;
    }
    // Register receivers for BluetoothHeadset change notifications.
    IntentFilter bluetoothHeadsetFilter = new IntentFilter();
    // Register receiver for change in connection state of the Headset profile.
    bluetoothHeadsetFilter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);
    // Register receiver for change in audio connection state of the Headset profile.
    bluetoothHeadsetFilter.addAction(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED);
    registerReceiver(bluetoothHeadsetReceiver, bluetoothHeadsetFilter);
    Log.d(Config.LOGTAG, "HEADSET profile state: "
            + stateToString(bluetoothAdapter.getProfileConnectionState(BluetoothProfile.HEADSET)));
    Log.d(Config.LOGTAG, "Bluetooth proxy for headset profile has started");
    bluetoothState = State.HEADSET_UNAVAILABLE;
    Log.d(Config.LOGTAG, "start done: BT state=" + bluetoothState);
}
 
Example 18
Source File: AppRTCAudioManager.java    From Conversations with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns the currently selected audio device.
 */
public AudioDevice getSelectedAudioDevice() {
    ThreadUtils.checkIsOnMainThread();
    return selectedAudioDevice;
}
 
Example 19
Source File: SurfaceTextureEglRenderer.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
  ThreadUtils.checkIsOnMainThread();
  createEglSurface(surface);
}
 
Example 20
Source File: TextureViewRenderer.java    From mollyim-android with GNU General Public License v3.0 3 votes vote down vote up
@Override
protected void onMeasure(int widthSpec, int heightSpec) {
  ThreadUtils.checkIsOnMainThread();

  Point size = videoLayoutMeasure.measure(widthSpec, heightSpec, this.rotatedFrameWidth, this.rotatedFrameHeight);

  setMeasuredDimension(size.x, size.y);

  Log.d(TAG, "onMeasure(). New size: " + size.x + "x" + size.y);
}