// Test that Init() calls DisconnectAllSupportedDevices().
TEST_F(AudioDeviceHandlerTest, InitCallsDisconnectAllSupportedDevices) {
  EXPECT_CALL(handler_,
              NotifyAudioPolicyService(
                  _, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE)).Times(3);
  EXPECT_CALL(handler_, TriggerCallback(
      AudioDeviceHandlerMock::DeviceConnectionState::kDevicesDisconnected))
      .Times(AtLeast(1));
  EXPECT_CALL(handler_,
              NotifyAudioPolicyService(
                  _, AUDIO_POLICY_DEVICE_STATE_AVAILABLE)).Times(AnyNumber());
  EXPECT_CALL(handler_, TriggerCallback(
      AudioDeviceHandlerMock::DeviceConnectionState::kDevicesConnected))
      .Times(AnyNumber());
  handler_.Init(nullptr);
}
Ejemplo n.º 2
0
/**
 * Perform a Get and Set on a variable
 *
 * \param p_this: The object that hold the variable
 * \param psz_name: the name of the variable
 * \param i_action: the action to perform
 * \param p_val: The action parameter
 * \return vlc error codes
 */
int var_GetAndSet( vlc_object_t *p_this, const char *psz_name, int i_action,
                   vlc_value_t *p_val )
{
    variable_t *p_var;
    vlc_value_t oldval;

    assert( p_this );
    assert( p_val );

    vlc_object_internals_t *p_priv = vlc_internals( p_this );

    p_var = Lookup( p_this, psz_name );
    if( p_var == NULL )
    {
        vlc_mutex_unlock( &p_priv->var_lock );
        return VLC_ENOVAR;
    }

    WaitUnused( p_this, p_var );

    /* Duplicated data if needed */
    //p_var->ops->pf_dup( &val );

    /* Backup needed stuff */
    oldval = p_var->val;

    /* depending of the action requiered */
    switch( i_action )
    {
    case VLC_VAR_BOOL_TOGGLE:
        assert( ( p_var->i_type & VLC_VAR_BOOL ) == VLC_VAR_BOOL );
        p_var->val.b_bool = !p_var->val.b_bool;
        break;
    case VLC_VAR_INTEGER_ADD:
        assert( ( p_var->i_type & VLC_VAR_INTEGER ) == VLC_VAR_INTEGER );
        p_var->val.i_int += p_val->i_int;
        break;
    case VLC_VAR_INTEGER_OR:
        assert( ( p_var->i_type & VLC_VAR_INTEGER ) == VLC_VAR_INTEGER );
        p_var->val.i_int |= p_val->i_int;
        break;
    case VLC_VAR_INTEGER_NAND:
        assert( ( p_var->i_type & VLC_VAR_INTEGER ) == VLC_VAR_INTEGER );
        p_var->val.i_int &= ~p_val->i_int;
        break;
    default:
        vlc_mutex_unlock( &p_priv->var_lock );
        return VLC_EGENERIC;
    }

    /*  Check boundaries */
    CheckValue( p_var, &p_var->val );
    *p_val = p_var->val;

    /* Deal with callbacks.*/
    TriggerCallback( p_this, p_var, psz_name, oldval );

    vlc_mutex_unlock( &p_priv->var_lock );
    return VLC_SUCCESS;
}
Ejemplo n.º 3
0
/**
 * Trigger callback on a variable
 *
 * \param p_this The object that hold the variable
 * \param psz_name The name of the variable
 */
int var_TriggerCallback( vlc_object_t *p_this, const char *psz_name )
{
    int i_ret;
    variable_t *p_var;

    assert( p_this );

    vlc_object_internals_t *p_priv = vlc_internals( p_this );

    vlc_mutex_lock( &p_priv->var_lock );

    p_var = Lookup( p_this, psz_name );
    if( p_var == NULL )
    {
        vlc_mutex_unlock( &p_priv->var_lock );
        return VLC_ENOVAR;
    }

    WaitUnused( p_this, p_var );

    /* Deal with callbacks. Tell we're in a callback, release the lock,
     * call stored functions, retake the lock. */
    i_ret = TriggerCallback( p_this, p_var, psz_name, p_var->val );

    vlc_mutex_unlock( &p_priv->var_lock );
    return i_ret;
}
// Test GetInitialAudioDeviceState() without any devices connected to the audio
// jack. No need to call NotifyAudioPolicyService() since that's already handled
// by Init().
TEST_F(AudioDeviceHandlerTest, InitialAudioStateNone) {
  WriteToH2WFile(0);
  EXPECT_CALL(handler_, TriggerCallback(_));
  handler_.GetInitialAudioDeviceState(h2w_file_path_);
  EXPECT_EQ(handler_.connected_input_devices_.size(), 0);
  EXPECT_EQ(handler_.connected_output_devices_.size(), 0);
  EXPECT_EQ(handler_.changed_devices_.size(), 0);
}
// Test UpdateAudioSystem() without any devices connected.
TEST_F(AudioDeviceHandlerTest, UpdateAudioSystemNone) {
  EXPECT_CALL(handler_,
              NotifyAudioPolicyService(
                  _, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE)).Times(0);
  EXPECT_CALL(handler_, TriggerCallback(
      AudioDeviceHandlerMock::DeviceConnectionState::kDevicesDisconnected));
  handler_.UpdateAudioSystem(handler_.headphone_, handler_.microphone_);
  EXPECT_EQ(handler_.changed_devices_.size(), 0);
}
// Test ProcessEvent() with an empty input_event arg.
TEST_F(AudioDeviceHandlerTest, ProcessEventEmpty) {
  struct input_event event;
  event.type = 0;
  event.code = 0;
  event.value = 0;
  EXPECT_CALL(handler_, TriggerCallback(_));
  handler_.ProcessEvent(event);
  EXPECT_FALSE(handler_.headphone_);
  EXPECT_FALSE(handler_.microphone_);
}
Ejemplo n.º 7
0
int var_SetChecked( vlc_object_t *p_this, const char *psz_name,
                    int expected_type, vlc_value_t val )
{
    int i_ret = VLC_SUCCESS;
    variable_t *p_var;
    vlc_value_t oldval;

    assert( p_this );

    vlc_object_internals_t *p_priv = vlc_internals( p_this );

    vlc_mutex_lock( &p_priv->var_lock );

    p_var = Lookup( p_this, psz_name );
    if( p_var == NULL )
    {
        vlc_mutex_unlock( &p_priv->var_lock );
        return VLC_ENOVAR;
    }

    assert( expected_type == 0 ||
            (p_var->i_type & VLC_VAR_CLASS) == expected_type );
#ifndef NDEBUG
        /* Alert if the type is VLC_VAR_VOID */
        if( ( p_var->i_type & VLC_VAR_TYPE ) == VLC_VAR_VOID )
            msg_Warn( p_this, "Calling var_Set on the void variable '%s' (0x%04x)", psz_name, p_var->i_type );
#endif


    WaitUnused( p_this, p_var );

    /* Duplicate data if needed */
    p_var->ops->pf_dup( &val );

    /* Backup needed stuff */
    oldval = p_var->val;

    /* Check boundaries and list */
    CheckValue( p_var, &val );

    /* Set the variable */
    p_var->val = val;

    /* Deal with callbacks */
    i_ret = TriggerCallback( p_this, p_var, psz_name, oldval );

    /* Free data if needed */
    p_var->ops->pf_free( &oldval );

    vlc_mutex_unlock( &p_priv->var_lock );

    return i_ret;
}
// Test UpdateAudioSystem() when connecting a headphone.
TEST_F(AudioDeviceHandlerTest, UpdateAudioSystemConnectHeadphone) {
  handler_.headphone_ = true;
  EXPECT_CALL(handler_,
              NotifyAudioPolicyService(AUDIO_DEVICE_OUT_WIRED_HEADPHONE,
                                       AUDIO_POLICY_DEVICE_STATE_AVAILABLE));
  EXPECT_CALL(handler_, TriggerCallback(
      AudioDeviceHandlerMock::DeviceConnectionState::kDevicesConnected));
  handler_.UpdateAudioSystem(handler_.headphone_, handler_.microphone_);
  EXPECT_EQ(handler_.connected_input_devices_.size(), 0);
  EXPECT_EQ(handler_.connected_output_devices_.size(), 1);
  EXPECT_EQ(handler_.changed_devices_.size(), 1);
  EXPECT_EQ(handler_.changed_devices_[0], AUDIO_DEVICE_OUT_WIRED_HEADPHONE);
}
Ejemplo n.º 9
0
/**
 * Trigger callback on a variable
 *
 * \param p_this The object that hold the variable
 * \param psz_name The name of the variable
 */
void var_TriggerCallback( vlc_object_t *p_this, const char *psz_name )
{
    vlc_object_internals_t *p_priv = vlc_internals( p_this );
    variable_t *p_var = Lookup( p_this, psz_name );
    if( p_var != NULL )
    {
        WaitUnused( p_this, p_var );

        /* Deal with callbacks. Tell we're in a callback, release the lock,
         * call stored functions, retake the lock. */
        TriggerCallback( p_this, p_var, psz_name, p_var->val );
    }
    vlc_mutex_unlock( &p_priv->var_lock );
}
// Test UpdateAudioSystem() when disconnecting a microphone.
TEST_F(AudioDeviceHandlerTest, UpdateAudioSystemDisconnectMic) {
  audio_devices_t device = AUDIO_DEVICE_IN_WIRED_HEADSET;
  handler_.connected_input_devices_.insert(device);
  EXPECT_CALL(handler_,
              NotifyAudioPolicyService(device,
                                       AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE));
  EXPECT_CALL(handler_, TriggerCallback(
      AudioDeviceHandlerMock::DeviceConnectionState::kDevicesDisconnected));
  handler_.UpdateAudioSystem(handler_.headphone_, handler_.microphone_);
  EXPECT_EQ(handler_.connected_input_devices_.size(), 0);
  EXPECT_EQ(handler_.connected_output_devices_.size(), 0);
  EXPECT_EQ(handler_.changed_devices_.size(), 1);
  EXPECT_EQ(handler_.changed_devices_[0], device);
}
// Test GetInitialAudioDeviceState() with just a microphone.
TEST_F(AudioDeviceHandlerTest, InitialAudioStateMic) {
  WriteToH2WFile(2);
  EXPECT_CALL(handler_,
              NotifyAudioPolicyService(AUDIO_DEVICE_IN_WIRED_HEADSET,
                                       AUDIO_POLICY_DEVICE_STATE_AVAILABLE));
  EXPECT_CALL(handler_, TriggerCallback(
      AudioDeviceHandlerMock::DeviceConnectionState::kDevicesConnected));
  handler_.GetInitialAudioDeviceState(h2w_file_path_);
  EXPECT_NE(
      handler_.connected_input_devices_.find(AUDIO_DEVICE_IN_WIRED_HEADSET),
      handler_.connected_input_devices_.end());
  EXPECT_EQ(handler_.connected_output_devices_.size(), 0);
  EXPECT_EQ(handler_.changed_devices_.size(), 1);
  EXPECT_EQ(handler_.changed_devices_[0], AUDIO_DEVICE_IN_WIRED_HEADSET);
}
TEST_F(AudioVolumeHandlerTest, GetSetVolumeIndex) {
  SetupHandlerVolumeFile();
  EXPECT_CALL(handler_, TriggerCallback(AUDIO_STREAM_MUSIC, _, 0));
  EXPECT_EQ(handler_.SetVolumeIndex(
                AUDIO_STREAM_MUSIC, AUDIO_DEVICE_OUT_WIRED_HEADSET, 0),
            0);
  EXPECT_CALL(handler_, TriggerCallback(AUDIO_STREAM_MUSIC, 0, 50));
  EXPECT_EQ(handler_.SetVolumeIndex(
                AUDIO_STREAM_MUSIC, AUDIO_DEVICE_OUT_WIRED_HEADSET, 50),
            0);
  EXPECT_CALL(handler_, TriggerCallback(AUDIO_STREAM_MUSIC, 50, 100));
  EXPECT_EQ(handler_.SetVolumeIndex(
                AUDIO_STREAM_MUSIC, AUDIO_DEVICE_OUT_WIRED_HEADSET, 100),
            0);
  EXPECT_EQ(handler_.SetVolumeIndex(
                AUDIO_STREAM_MUSIC, AUDIO_DEVICE_OUT_WIRED_HEADSET, -1),
            EINVAL);
  EXPECT_EQ(handler_.SetVolumeIndex(
                AUDIO_STREAM_MUSIC, AUDIO_DEVICE_OUT_WIRED_HEADSET, 101),
            EINVAL);
  EXPECT_EQ(handler_.SetVolumeMaxSteps(AUDIO_STREAM_MUSIC, 10), 0);
  EXPECT_EQ(handler_.GetVolumeIndex(AUDIO_STREAM_MUSIC,
                                    AUDIO_DEVICE_OUT_WIRED_HEADSET),
            10);
  EXPECT_EQ(handler_.SetVolumeIndex(
                AUDIO_STREAM_MUSIC, AUDIO_DEVICE_OUT_WIRED_HEADSET, 11),
            EINVAL);
  EXPECT_CALL(handler_, TriggerCallback(AUDIO_STREAM_MUSIC, 100, 50));
  EXPECT_EQ(handler_.SetVolumeIndex(
                AUDIO_STREAM_MUSIC, AUDIO_DEVICE_OUT_WIRED_HEADSET, 5),
            0);
  EXPECT_EQ(handler_.SetVolumeMaxSteps(AUDIO_STREAM_MUSIC, 20), 0);
  EXPECT_EQ(handler_.GetVolumeIndex(AUDIO_STREAM_MUSIC,
                                    AUDIO_DEVICE_OUT_WIRED_HEADSET),
            10);
}
Ejemplo n.º 13
0
int var_SetChecked( vlc_object_t *p_this, const char *psz_name,
                    int expected_type, vlc_value_t val )
{
    variable_t *p_var;
    vlc_value_t oldval;

    assert( p_this );

    vlc_object_internals_t *p_priv = vlc_internals( p_this );

    p_var = Lookup( p_this, psz_name );
    if( p_var == NULL )
    {
        vlc_mutex_unlock( &p_priv->var_lock );
        return VLC_ENOVAR;
    }

    assert( expected_type == 0 ||
            (p_var->i_type & VLC_VAR_CLASS) == expected_type );
    assert ((p_var->i_type & VLC_VAR_CLASS) != VLC_VAR_VOID);

    WaitUnused( p_this, p_var );

    /* Duplicate data if needed */
    p_var->ops->pf_dup( &val );

    /* Backup needed stuff */
    oldval = p_var->val;

    /* Check boundaries and list */
    CheckValue( p_var, &val );

    /* Set the variable */
    p_var->val = val;

    /* Deal with callbacks */
    TriggerCallback( p_this, p_var, psz_name, oldval );

    /* Free data if needed */
    p_var->ops->pf_free( &oldval );

    vlc_mutex_unlock( &p_priv->var_lock );
    return VLC_SUCCESS;
}
Ejemplo n.º 14
0
void ElementExpanderImpl::ScheduleAnimation(ElementOfInterest* eoi)
{
	TriggerCallback(MSG_FINGERTOUCH_ANIMATE);
}