void
BluetoothProfileController::SetupProfiles(bool aAssignServiceClass)
{
    MOZ_ASSERT(NS_IsMainThread());

    /**
     * When a service class is assigned, only its corresponding profile is put
     * into array.
     */
    if (aAssignServiceClass) {
        AddProfileWithServiceClass(mTarget.service);
        return;
    }

    // For a disconnect request, all connected profiles are put into array.
    if (!mConnect) {
        AddProfile(BluetoothHidManager::Get(), true);
        AddProfile(BluetoothOppManager::Get(), true);
        AddProfile(BluetoothA2dpManager::Get(), true);
        AddProfile(BluetoothHfpManager::Get(), true);
        return;
    }

    /**
     * For a connect request, put multiple profiles into array and connect to
     * all of them sequencely.
     */
    bool hasAudio = HAS_AUDIO(mTarget.cod);
    bool hasObjectTransfer = HAS_OBJECT_TRANSFER(mTarget.cod);
    bool hasRendering = HAS_RENDERING(mTarget.cod);
    bool isPeripheral = IS_PERIPHERAL(mTarget.cod);

    NS_ENSURE_TRUE_VOID(hasAudio || hasObjectTransfer ||
                        hasRendering || isPeripheral);

    /**
     * Connect to HFP/HSP first. Then, connect A2DP if Rendering bit is set.
     * It's almost impossible to send file to a remote device which is an Audio
     * device or a Rendering device, so we won't connect OPP in that case.
     */
    if (hasAudio) {
        AddProfile(BluetoothHfpManager::Get());
    }
    if (hasRendering) {
        AddProfile(BluetoothA2dpManager::Get());
    }
    if (hasObjectTransfer && !hasAudio && !hasRendering) {
        AddProfile(BluetoothOppManager::Get());
    }
    if (isPeripheral) {
        AddProfile(BluetoothHidManager::Get());
    }
}
Ejemplo n.º 2
0
static int tc_vorbis_encode_audio(TCModuleInstance *self,
                                  TCFrameAudio *inframe,
                                  TCFrameAudio *outframe)
{
    VorbisPrivateData *pd = NULL;
    int ret, eos = TC_FALSE, has_aud = HAS_AUDIO(inframe);

    TC_MODULE_SELF_CHECK(self, "encode_audio");

    pd = self->userdata;

#ifdef TC_VORBIS_DEBUG
    tc_log_info(MOD_NAME, "(%s) START ENCODE AUDIO FRAME", __func__);
    tc_log_info(MOD_NAME, "(%s) invoked in=%p out=%p", __func__, inframe, outframe);
#endif

    if (!has_aud) {
        if (pd->flush_flag && !pd->end_of_stream) {
            /* 
             * End of file. Tell the library we're at end of stream so that it 
             * can handle the  last frame and mark end of stream in the output 
             * properly 
             */
            vorbis_analysis_wrote(&pd->vd, 0);
            eos = TC_TRUE;
        }
    } else {
        int16_t *aptr = (int16_t*)inframe->audio_buf;
        int bps = (pd->channels * pd->bits) / 8;
        int samples = inframe->audio_size / bps;
        int i = 0;
        float **buffer = vorbis_analysis_buffer(&pd->vd, samples);

        if (pd->channels == 1) {
            for (i = 0; i < samples; i++) {
               buffer[0][i] = aptr[i        ]/MAX_S16F;
            }
        } else { /* if (pd->channels == 2 ) */
            for (i = 0; i < samples; i++) {
               buffer[0][i] = aptr[i * 2    ]/MAX_S16F;
               buffer[1][i] = aptr[i * 2 + 1]/MAX_S16F;
            }
        }

        vorbis_analysis_wrote(&pd->vd, samples);
    }
    ret = tc_vorbis_outframe(pd, outframe);
    pd->end_of_stream = eos; /* this must be set AFTER last frame processed */
    return ret;
}
Ejemplo n.º 3
0
void
BluetoothProfileController::SetupProfiles(bool aAssignServiceClass)
{
    MOZ_ASSERT(NS_IsMainThread());

    /**
     * When a service class is assigned, only its corresponding profile is put
     * into array.
     */
    if (aAssignServiceClass) {
        AddProfileWithServiceClass(mTarget.service);
        return;
    }

    // For a disconnect request, all connected profiles are put into array.
    if (!mConnect) {
        AddProfile(BluetoothHidManager::Get(), true);
        AddProfile(BluetoothA2dpManager::Get(), true);
        AddProfile(BluetoothHfpManager::Get(), true);
        return;
    }

    /**
     * For a connect request, put multiple profiles into array and connect to
     * all of them sequencely.
     */
    bool hasAudio = HAS_AUDIO(mTarget.cod);
    bool hasRendering = HAS_RENDERING(mTarget.cod);
    bool isPeripheral = IS_PERIPHERAL(mTarget.cod);

    NS_ENSURE_TRUE_VOID(hasAudio || hasRendering || isPeripheral);

    /**
     * Connect to HFP/HSP first. Then, connect A2DP if Rendering bit is set.
     */
    if (hasAudio) {
        AddProfile(BluetoothHfpManager::Get());
    }
    if (hasRendering) {
        AddProfile(BluetoothA2dpManager::Get());
    }
    if (isPeripheral) {
        AddProfile(BluetoothHidManager::Get());
    }
}
Ejemplo n.º 4
0
void
BluetoothProfileController::SetupProfiles(bool aAssignServiceClass)
{
  MOZ_ASSERT(NS_IsMainThread());

  /**
   * When a service class is assigned, only its corresponding profile is put
   * into array.
   */
  if (aAssignServiceClass) {
    AddProfileWithServiceClass(mTarget.service);
    return;
  }

  // For a disconnect request, all connected profiles are put into array.
  if (!mConnect) {
    AddProfile(BluetoothHidManager::Get(), true);
    AddProfile(BluetoothAvrcpManager::Get(), true);
    AddProfile(BluetoothA2dpManager::Get(), true);
    AddProfile(BluetoothHfpManager::Get(), true);
    return;
  }

  /**
   * For a connect request, put multiple profiles into array and connect to
   * all of them sequencely.
   */
  bool hasAudio = HAS_AUDIO(mTarget.cod);
  bool hasRendering = HAS_RENDERING(mTarget.cod);
  bool isPeripheral = IS_PERIPHERAL(mTarget.cod);
  bool isRemoteControl = IS_REMOTE_CONTROL(mTarget.cod);
  bool isKeyboard = IS_KEYBOARD(mTarget.cod);
  bool isPointingDevice = IS_POINTING_DEVICE(mTarget.cod);
  bool isInvalid = IS_INVALID(mTarget.cod);

  // The value of CoD is invalid. Since the device didn't declare its class of
  // device properly, we assume the device may support all of these profiles.
  // Note the invalid CoD from bluedroid callback usually results from
  // NFC-triggered direct pairing for no EIR query records.
  if (isInvalid) {
    AddProfile(BluetoothHfpManager::Get());
    AddProfile(BluetoothA2dpManager::Get());
    AddProfile(BluetoothAvrcpManager::Get()); // register after A2DP
    return;
  }

  NS_ENSURE_TRUE_VOID(hasAudio || hasRendering || isPeripheral);

  // Audio bit should be set if remote device supports HFP/HSP.
  if (hasAudio) {
    AddProfile(BluetoothHfpManager::Get());
  }

  // Rendering bit should be set if remote device supports A2DP.
  // A device which supports AVRCP should claim that it's a peripheral and it's
  // a remote control.
  if (hasRendering || (isPeripheral && isRemoteControl)) {
    AddProfile(BluetoothA2dpManager::Get());
    AddProfile(BluetoothAvrcpManager::Get()); // register after A2DP
  }

  // A device which supports HID should claim that it's a peripheral and it's
  // either a keyboard, a pointing device, or both.
  if (isPeripheral && (isKeyboard || isPointingDevice)) {
    AddProfile(BluetoothHidManager::Get());
  }
}