Java Code Examples for org.webrtc.ThreadUtils

The following examples show how to use org.webrtc.ThreadUtils. These examples are extracted from open source projects. 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 Project: webrtc_android   Source File: WebRtcAudioTrack.java    License: MIT License 6 votes vote down vote up
private boolean stopPlayout() {
  threadChecker.checkIsOnValidThread();
  Logging.d(TAG, "stopPlayout");
  assertTrue(audioThread != null);
  logUnderrunCount();
  audioThread.stopThread();

  Logging.d(TAG, "Stopping the AudioTrackThread...");
  audioThread.interrupt();
  if (!ThreadUtils.joinUninterruptibly(audioThread, AUDIO_TRACK_THREAD_JOIN_TIMEOUT_MS)) {
    Logging.e(TAG, "Join of AudioTrackThread timed out.");
    WebRtcAudioUtils.logAudioState(TAG);
  }
  Logging.d(TAG, "AudioTrackThread has now been stopped.");
  audioThread = null;
  releaseAudioResources();
  return true;
}
 
Example 2
Source Project: webrtc_android   Source File: WebRtcAudioTrack.java    License: MIT License 6 votes vote down vote up
@CalledByNative
private boolean stopPlayout() {
  threadChecker.checkIsOnValidThread();
  volumeLogger.stop();
  Logging.d(TAG, "stopPlayout");
  assertTrue(audioThread != null);
  logUnderrunCount();
  audioThread.stopThread();

  Logging.d(TAG, "Stopping the AudioTrackThread...");
  audioThread.interrupt();
  if (!ThreadUtils.joinUninterruptibly(audioThread, AUDIO_TRACK_THREAD_JOIN_TIMEOUT_MS)) {
    Logging.e(TAG, "Join of AudioTrackThread timed out.");
    WebRtcAudioUtils.logAudioState(TAG, context, audioManager);
  }
  Logging.d(TAG, "AudioTrackThread has now been stopped.");
  audioThread = null;
  releaseAudioResources();
  return true;
}
 
Example 3
/**
 * 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 4
private AppRTCAudioManager(Context context, final SpeakerPhonePreference speakerPhonePreference) {
    Log.d(Config.LOGTAG, "ctor");
    ThreadUtils.checkIsOnMainThread();
    apprtcContext = context;
    audioManager = ((AudioManager) context.getSystemService(Context.AUDIO_SERVICE));
    bluetoothManager = AppRTCBluetoothManager.create(context, this);
    wiredHeadsetReceiver = new WiredHeadsetReceiver();
    amState = AudioManagerState.UNINITIALIZED;
    this.speakerPhonePreference = speakerPhonePreference;
    if (speakerPhonePreference == SpeakerPhonePreference.EARPIECE && hasEarpiece()) {
        defaultAudioDevice = AudioDevice.EARPIECE;
    } else {
        defaultAudioDevice = AudioDevice.SPEAKER_PHONE;
    }
    // Create and initialize the proximity sensor.
    // Tablet devices (e.g. Nexus 7) does not support proximity sensors.
    // Note that, the sensor will not be active until start() has been called.
    proximitySensor = AppRTCProximitySensor.create(context,
            // This method will be called each time a state change is detected.
            // Example: user holds his hand over the device (closer than ~5 cm),
            // or removes his hand from the device.
            this::onProximitySensorChangedState);
    Log.d(Config.LOGTAG, "defaultAudioDevice: " + defaultAudioDevice);
    AppRTCUtils.logDeviceInfo(Config.LOGTAG);
}
 
Example 5
@SuppressWarnings("deprecation")
public void stop() {
    Log.d(Config.LOGTAG, AppRTCAudioManager.class.getName() + ".stop()");
    ThreadUtils.checkIsOnMainThread();
    if (amState != AudioManagerState.RUNNING) {
        Log.e(Config.LOGTAG, "Trying to stop AudioManager in incorrect state: " + amState);
        return;
    }
    amState = AudioManagerState.UNINITIALIZED;
    unregisterReceiver(wiredHeadsetReceiver);
    bluetoothManager.stop();
    // Restore previously stored audio states.
    setSpeakerphoneOn(savedIsSpeakerPhoneOn);
    setMicrophoneMute(savedIsMicrophoneMute);
    audioManager.setMode(AudioManager.MODE_NORMAL);
    // Abandon audio focus. Gives the previous focus owner, if any, focus.
    audioManager.abandonAudioFocus(audioFocusChangeListener);
    audioFocusChangeListener = null;
    Log.d(Config.LOGTAG, "Abandoned audio focus for VOICE_CALL streams");
    if (proximitySensor != null) {
        proximitySensor.stop();
        proximitySensor = null;
    }
    audioManagerEvents = null;
}
 
Example 6
/**
 * Changes default audio device.
 * TODO(henrika): add usage of this method in the AppRTCMobile client.
 */
public void setDefaultAudioDevice(AudioDevice defaultDevice) {
    ThreadUtils.checkIsOnMainThread();
    switch (defaultDevice) {
        case SPEAKER_PHONE:
            defaultAudioDevice = defaultDevice;
            break;
        case EARPIECE:
            if (hasEarpiece()) {
                defaultAudioDevice = defaultDevice;
            } else {
                defaultAudioDevice = AudioDevice.SPEAKER_PHONE;
            }
            break;
        default:
            Log.e(Config.LOGTAG, "Invalid default audio device selection");
            break;
    }
    Log.d(Config.LOGTAG, "setDefaultAudioDevice(device=" + defaultAudioDevice + ")");
    updateAudioDeviceState();
}
 
Example 7
/**
 * 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 8
private AppRTCAudioManager(Context context, final SpeakerPhonePreference speakerPhonePreference) {
    Log.d(Config.LOGTAG, "ctor");
    ThreadUtils.checkIsOnMainThread();
    apprtcContext = context;
    audioManager = ((AudioManager) context.getSystemService(Context.AUDIO_SERVICE));
    bluetoothManager = AppRTCBluetoothManager.create(context, this);
    wiredHeadsetReceiver = new WiredHeadsetReceiver();
    amState = AudioManagerState.UNINITIALIZED;
    this.speakerPhonePreference = speakerPhonePreference;
    if (speakerPhonePreference == SpeakerPhonePreference.EARPIECE && hasEarpiece()) {
        defaultAudioDevice = AudioDevice.EARPIECE;
    } else {
        defaultAudioDevice = AudioDevice.SPEAKER_PHONE;
    }
    // Create and initialize the proximity sensor.
    // Tablet devices (e.g. Nexus 7) does not support proximity sensors.
    // Note that, the sensor will not be active until start() has been called.
    proximitySensor = AppRTCProximitySensor.create(context,
            // This method will be called each time a state change is detected.
            // Example: user holds his hand over the device (closer than ~5 cm),
            // or removes his hand from the device.
            this::onProximitySensorChangedState);
    Log.d(Config.LOGTAG, "defaultAudioDevice: " + defaultAudioDevice);
    AppRTCUtils.logDeviceInfo(Config.LOGTAG);
}
 
Example 9
@SuppressWarnings("deprecation")
public void stop() {
    Log.d(Config.LOGTAG, AppRTCAudioManager.class.getName() + ".stop()");
    ThreadUtils.checkIsOnMainThread();
    if (amState != AudioManagerState.RUNNING) {
        Log.e(Config.LOGTAG, "Trying to stop AudioManager in incorrect state: " + amState);
        return;
    }
    amState = AudioManagerState.UNINITIALIZED;
    unregisterReceiver(wiredHeadsetReceiver);
    bluetoothManager.stop();
    // Restore previously stored audio states.
    setSpeakerphoneOn(savedIsSpeakerPhoneOn);
    setMicrophoneMute(savedIsMicrophoneMute);
    audioManager.setMode(AudioManager.MODE_NORMAL);
    // Abandon audio focus. Gives the previous focus owner, if any, focus.
    audioManager.abandonAudioFocus(audioFocusChangeListener);
    audioFocusChangeListener = null;
    Log.d(Config.LOGTAG, "Abandoned audio focus for VOICE_CALL streams");
    if (proximitySensor != null) {
        proximitySensor.stop();
        proximitySensor = null;
    }
    audioManagerEvents = null;
}
 
Example 10
/**
 * Changes default audio device.
 * TODO(henrika): add usage of this method in the AppRTCMobile client.
 */
public void setDefaultAudioDevice(AudioDevice defaultDevice) {
    ThreadUtils.checkIsOnMainThread();
    switch (defaultDevice) {
        case SPEAKER_PHONE:
            defaultAudioDevice = defaultDevice;
            break;
        case EARPIECE:
            if (hasEarpiece()) {
                defaultAudioDevice = defaultDevice;
            } else {
                defaultAudioDevice = AudioDevice.SPEAKER_PHONE;
            }
            break;
        default:
            Log.e(Config.LOGTAG, "Invalid default audio device selection");
            break;
    }
    Log.d(Config.LOGTAG, "setDefaultAudioDevice(device=" + defaultAudioDevice + ")");
    updateAudioDeviceState();
}
 
Example 11
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 12
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
  ThreadUtils.checkIsOnMainThread();

  CountDownLatch completionLatch = new CountDownLatch(1);

  releaseEglSurface(completionLatch::countDown);
  ThreadUtils.awaitUninterruptibly(completionLatch);

  return true;
}
 
Example 13
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 14
public void setScalingType(@NonNull RendererCommon.ScalingType scalingTypeMatchOrientation,
                           @NonNull RendererCommon.ScalingType scalingTypeMismatchOrientation)
{
  ThreadUtils.checkIsOnMainThread();

  videoLayoutMeasure.setScalingType(scalingTypeMatchOrientation, scalingTypeMismatchOrientation);

  requestLayout();
}
 
Example 15
@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 16
private void updateSurfaceSize() {
  ThreadUtils.checkIsOnMainThread();

  if (!isAvailable()) {
    return;
  }

  if (this.enableFixedSize && this.rotatedFrameWidth != 0 && this.rotatedFrameHeight != 0 && this.getWidth() != 0 && this.getHeight() != 0) {

    float layoutAspectRatio = (float)this.getWidth() / (float)this.getHeight();
    float frameAspectRatio  = (float)this.rotatedFrameWidth / (float)this.rotatedFrameHeight;

    int drawnFrameWidth;
    int drawnFrameHeight;

    if (frameAspectRatio > layoutAspectRatio) {
      drawnFrameWidth  = (int)((float)this.rotatedFrameHeight * layoutAspectRatio);
      drawnFrameHeight = this.rotatedFrameHeight;
    } else {
      drawnFrameWidth  = this.rotatedFrameWidth;
      drawnFrameHeight = (int)((float)this.rotatedFrameWidth / layoutAspectRatio);
    }

    int width  = Math.min(this.getWidth(), drawnFrameWidth);
    int height = Math.min(this.getHeight(), drawnFrameHeight);

    Log.d(TAG, "updateSurfaceSize. Layout size: " + this.getWidth() + "x" + this.getHeight() + ", frame size: " + this.rotatedFrameWidth + "x" + this.rotatedFrameHeight + ", requested surface size: " + width + "x" + height + ", old surface size: " + this.surfaceWidth + "x" + this.surfaceHeight);

    if (width != this.surfaceWidth || height != this.surfaceHeight) {
      this.surfaceWidth  = width;
      this.surfaceHeight = height;
      getSurfaceTexture().setDefaultBufferSize(width, height);
    }
  } else {
    this.surfaceWidth = this.surfaceHeight = 0;
    this.getSurfaceTexture().setDefaultBufferSize(getMeasuredWidth(), getMeasuredHeight());
  }
}
 
Example 17
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
  ThreadUtils.checkIsOnMainThread();

  surfaceWidth  = 0;
  surfaceHeight = 0;

  updateSurfaceSize();

  eglRenderer.onSurfaceTextureAvailable(surface, width, height);
}
 
Example 18
Source Project: webrtc_android   Source File: VideoFileRenderer.java    License: MIT License 5 votes vote down vote up
public VideoFileRenderer(String outputFile, int outputFileWidth, int outputFileHeight,
                         final EglBase.Context sharedContext) throws IOException {
  if ((outputFileWidth % 2) == 1 || (outputFileHeight % 2) == 1) {
    throw new IllegalArgumentException("Does not support uneven width or height");
  }

  this.outputFileName = outputFile;
  this.outputFileWidth = outputFileWidth;
  this.outputFileHeight = outputFileHeight;

  outputFrameSize = outputFileWidth * outputFileHeight * 3 / 2;
  outputFrameBuffer = ByteBuffer.allocateDirect(outputFrameSize);

  videoOutFile = new FileOutputStream(outputFile);
  videoOutFile.write(
      ("YUV4MPEG2 C420 W" + outputFileWidth + " H" + outputFileHeight + " Ip F30:1 A1:1\n")
          .getBytes(Charset.forName("US-ASCII")));

  renderThread = new HandlerThread(TAG + "RenderThread");
  renderThread.start();
  renderThreadHandler = new Handler(renderThread.getLooper());

  fileThread = new HandlerThread(TAG + "FileThread");
  fileThread.start();
  fileThreadHandler = new Handler(fileThread.getLooper());

  ThreadUtils.invokeAtFrontUninterruptibly(renderThreadHandler, new Runnable() {
    @Override
    public void run() {
      eglBase = EglBase.create(sharedContext, EglBase.CONFIG_PIXEL_BUFFER);
      eglBase.createDummyPbufferSurface();
      eglBase.makeCurrent();
      yuvConverter = new YuvConverter();
    }
  });
}
 
Example 19
Source Project: webrtc_android   Source File: WebRtcAudioRecord.java    License: MIT License 5 votes vote down vote up
private boolean stopRecording() {
  Logging.d(TAG, "stopRecording");
  assertTrue(audioThread != null);
  audioThread.stopThread();
  if (!ThreadUtils.joinUninterruptibly(audioThread, AUDIO_RECORD_THREAD_JOIN_TIMEOUT_MS)) {
    Logging.e(TAG, "Join of AudioRecordJavaThread timed out");
    WebRtcAudioUtils.logAudioState(TAG);
  }
  audioThread = null;
  if (effects != null) {
    effects.release();
  }
  releaseAudioResources();
  return true;
}
 
Example 20
Source Project: webrtc_android   Source File: WebRtcAudioRecord.java    License: MIT License 5 votes vote down vote up
@CalledByNative
private boolean stopRecording() {
  Logging.d(TAG, "stopRecording");
  assertTrue(audioThread != null);
  audioThread.stopThread();
  if (!ThreadUtils.joinUninterruptibly(audioThread, AUDIO_RECORD_THREAD_JOIN_TIMEOUT_MS)) {
    Logging.e(TAG, "Join of AudioRecordJavaThread timed out");
    WebRtcAudioUtils.logAudioState(TAG, context, audioManager);
  }
  audioThread = null;
  effects.release();
  releaseAudioResources();
  return true;
}
 
Example 21
Source Project: VideoCRE   Source File: TextureViewRenderer.java    License: MIT License 5 votes vote down vote up
/**
 * Initialize this class, sharing resources with |sharedContext|. The custom |drawer| will be used
 * for drawing frames on the EGLSurface. This class is responsible for calling release() on
 * |drawer|. It is allowed to call init() to reinitialize the renderer after a previous
 * init()/release() cycle.
 */
public void init(final EglBase.Context sharedContext,
    RendererCommon.RendererEvents rendererEvents, final int[] configAttributes,
    RendererCommon.GlDrawer drawer) {
  ThreadUtils.checkIsOnMainThread();
  this.rendererEvents = rendererEvents;
  synchronized (layoutLock) {
    isFirstFrameRendered = false;
    rotatedFrameWidth = 0;
    rotatedFrameHeight = 0;
    frameRotation = 0;
  }
  eglRenderer.init(sharedContext, configAttributes, drawer);
}
 
Example 22
Source Project: VideoCRE   Source File: TextureViewRenderer.java    License: 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 23
Source Project: VideoCRE   Source File: TextureViewRenderer.java    License: MIT License 5 votes vote down vote up
@Override
public void onSurfaceTextureAvailable(final SurfaceTexture surface, final int width,
        final int height) {
  logD("onSurfaceTextureAvailable: " + surface + " size: " + width + "x" + height);
  ThreadUtils.checkIsOnMainThread();
  eglRenderer.createEglSurface(surface);
}
 
Example 24
Source Project: VideoCRE   Source File: TextureViewRenderer.java    License: 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 25
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 26
/**
 * Starts Bluetooth SCO connection with remote device.
 * Note that the phone application always has the priority on the usage of the SCO connection
 * for telephony. If this method is called while the phone is in call it will be ignored.
 * Similarly, if a call is received or sent while an application is using the SCO connection,
 * the connection will be lost for the application and NOT returned automatically when the call
 * ends. Also note that: up to and including API version JELLY_BEAN_MR1, this method initiates a
 * virtual voice call to the Bluetooth headset. After API version JELLY_BEAN_MR2 only a raw SCO
 * audio connection is established.
 * TODO(henrika): should we add support for virtual voice call to BT headset also for JBMR2 and
 * higher. It might be required to initiates a virtual voice call since many devices do not
 * accept SCO audio without a "call".
 */
public boolean startScoAudio() {
    ThreadUtils.checkIsOnMainThread();
    Log.d(Config.LOGTAG, "startSco: BT state=" + bluetoothState + ", "
            + "attempts: " + scoConnectionAttempts + ", "
            + "SCO is on: " + isScoOn());
    if (scoConnectionAttempts >= MAX_SCO_CONNECTION_ATTEMPTS) {
        Log.e(Config.LOGTAG, "BT SCO connection fails - no more attempts");
        return false;
    }
    if (bluetoothState != State.HEADSET_AVAILABLE) {
        Log.e(Config.LOGTAG, "BT SCO connection fails - no headset available");
        return false;
    }
    // Start BT SCO channel and wait for ACTION_AUDIO_STATE_CHANGED.
    Log.d(Config.LOGTAG, "Starting Bluetooth SCO and waits for ACTION_AUDIO_STATE_CHANGED...");
    // The SCO connection establishment can take several seconds, hence we cannot rely on the
    // connection to be available when the method returns but instead register to receive the
    // intent ACTION_SCO_AUDIO_STATE_UPDATED and wait for the state to be SCO_AUDIO_STATE_CONNECTED.
    bluetoothState = State.SCO_CONNECTING;
    audioManager.startBluetoothSco();
    audioManager.setBluetoothScoOn(true);
    scoConnectionAttempts++;
    startTimer();
    Log.d(Config.LOGTAG, "startScoAudio done: BT state=" + bluetoothState + ", "
            + "SCO is on: " + isScoOn());
    return true;
}
 
Example 27
/**
 * Stops Bluetooth SCO connection with remote device.
 */
public void stopScoAudio() {
    ThreadUtils.checkIsOnMainThread();
    Log.d(Config.LOGTAG, "stopScoAudio: BT state=" + bluetoothState + ", "
            + "SCO is on: " + isScoOn());
    if (bluetoothState != State.SCO_CONNECTING && bluetoothState != State.SCO_CONNECTED) {
        return;
    }
    cancelTimer();
    audioManager.stopBluetoothSco();
    audioManager.setBluetoothScoOn(false);
    bluetoothState = State.SCO_DISCONNECTING;
    Log.d(Config.LOGTAG, "stopScoAudio done: BT state=" + bluetoothState + ", "
            + "SCO is on: " + isScoOn());
}
 
Example 28
/**
 * Called when start of the BT SCO channel takes too long time. Usually
 * happens when the BT device has been turned on during an ongoing call.
 */
private void bluetoothTimeout() {
    ThreadUtils.checkIsOnMainThread();
    if (bluetoothState == State.UNINITIALIZED || bluetoothHeadset == null) {
        return;
    }
    Log.d(Config.LOGTAG, "bluetoothTimeout: BT state=" + bluetoothState + ", "
            + "attempts: " + scoConnectionAttempts + ", "
            + "SCO is on: " + isScoOn());
    if (bluetoothState != State.SCO_CONNECTING) {
        return;
    }
    // Bluetooth SCO should be connecting; check the latest result.
    boolean scoConnected = false;
    List<BluetoothDevice> devices = bluetoothHeadset.getConnectedDevices();
    if (devices.size() > 0) {
        bluetoothDevice = devices.get(0);
        if (bluetoothHeadset.isAudioConnected(bluetoothDevice)) {
            Log.d(Config.LOGTAG, "SCO connected with " + bluetoothDevice.getName());
            scoConnected = true;
        } else {
            Log.d(Config.LOGTAG, "SCO is not connected with " + bluetoothDevice.getName());
        }
    }
    if (scoConnected) {
        // We thought BT had timed out, but it's actually on; updating state.
        bluetoothState = State.SCO_CONNECTED;
        scoConnectionAttempts = 0;
    } else {
        // Give up and "cancel" our request by calling stopBluetoothSco().
        Log.w(Config.LOGTAG, "BT failed to connect after timeout");
        stopScoAudio();
    }
    updateAudioDeviceState();
    Log.d(Config.LOGTAG, "bluetoothTimeout done: BT state=" + bluetoothState);
}
 
Example 29
/**
 * 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 30
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());
}