Esempio n. 1
0
void change_sel_vol(pa_context * c, vol_change_t vol_change)
{
    view_entry_t view_entry = view_selected_item();

    if(view_entry.type == VIEW_SINK) {
        sink_t * sink = (sink_t *) view_entry.ref;
        if(sink != NULL) {
            /* averge all channel volumes of local copy */
            pa_volume_t vol;
            vol = pa_cvolume_avg(&sink->volume);
            vol = modify_volume(vol, vol_change);
            pa_cvolume_set(&sink->volume, sink->volume.channels, vol);
            pa_context_set_sink_volume_by_index(c, sink->index, &sink->volume, NULL, NULL);
        }
    }

    if(view_entry.type == VIEW_SINK_INPUT) {
        sink_input_t * sink_input = (sink_input_t *) view_entry.ref;
        if(sink_input != NULL) {
            /* averge all channel volumes of local copy */
            pa_volume_t vol;
            vol = pa_cvolume_avg(&sink_input->volume);
            vol = modify_volume(vol, vol_change);
            pa_cvolume_set(&sink_input->volume, sink_input->volume.channels, vol);
            pa_context_set_sink_input_volume(c, sink_input->index, &sink_input->volume, NULL, NULL);
        }
    }
}
Esempio n. 2
0
void AudioOutputPulseAudio::SetVolumeChannel(int channel, int volume)
{
    QString fn_log_tag = "SetVolumeChannel, ";

    if (channel < 0 || channel > PULSE_MAX_CHANNELS || volume < 0)
    {
        VBERROR(fn_log_tag + QString("bad volume params, channel %1, volume %2")
                .arg(channel).arg(volume));
        return;
    }

    volume_control.values[channel] =
        (float)volume / 100.0f * (float)PA_VOLUME_NORM;

    volume = min(100, volume);
    volume = max(0, volume);

    uint32_t sink_index = pa_stream_get_device_index(pstream);
    pa_threaded_mainloop_lock(mainloop);
    pa_operation *op =
        pa_context_set_sink_volume_by_index(pcontext, sink_index,
                                            &volume_control,
                                            OpCompletionCallback, this);
    pa_threaded_mainloop_unlock(mainloop);
    if (op)
        pa_operation_unref(op);
    else
        VBERROR(fn_log_tag +
                QString("set sink volume operation failed, sink %1, error %2 ")
                .arg(sink_index).arg(pa_strerror(pa_context_errno(pcontext))));
}
Esempio n. 3
0
void Sink::setVolume(pa_cvolume v)
{
    pa_operation *o;
    this->d->svolume = v;
    o = pa_context_set_sink_volume_by_index(d->context->cObject(),
			(Device::d)->index, &d->svolume, Sink::volume_cb, this);
    pa_operation_unref(o);
}
Esempio n. 4
0
void
xvd_update_volume (XvdInstance        *i,
                   XvdVolStepDirection d)
{
  pa_operation *op = NULL;

  if (!i || !i->pulse_context)
    {
      g_warning ("xvd_update_volume: pulseaudio context is null");
      return;
    }

  if (pa_context_get_state (i->pulse_context) != PA_CONTEXT_READY)
    {
      g_warning ("xvd_update_volume: pulseaudio context isn't ready");
      return;
    }

  if (i->sink_index == PA_INVALID_INDEX)
    {
      g_warning ("xvd_update_volume: undefined sink");
      return;
    }

  /* backup */
  old_volume = i->volume;

  switch (d)
    {
      case XVD_UP:
        pa_cvolume_inc_clamp (&i->volume,
                              XVD_PA_VOLUME_STEP(i->vol_step),
                              PA_VOLUME_NORM);
      break;
      case XVD_DOWN:
        pa_cvolume_dec (&i->volume,
                        XVD_PA_VOLUME_STEP(i->vol_step));
      break;
      default:
        g_warning ("xvd_update_volume: invalid direction");
        return;
      break;
    }

  op = pa_context_set_sink_volume_by_index (i->pulse_context,
                                            i->sink_index,
                                            &i->volume,
                                            xvd_notify_volume_callback,
                                            i);

  if (!op)
    {
      g_warning ("xvd_update_volume: failed");
      return;
    }
  pa_operation_unref (op);
}
static PyObject* PulseAudio_set_volume(output_PulseAudio *self, PyObject *args)
{
    pa_cvolume cvolume;
    pa_operation *op;
    struct get_volume_cb_data cb_data = {self->mainloop, &cvolume};
    double new_volume_d;
    pa_volume_t new_volume;

    if (!PyArg_ParseTuple(args, "d", &new_volume_d))
        return NULL;

    /*ensure output stream is still running*/
    /*FIXME*/

    /*convert volume to integer pa_volume_t value between
      PA_VOLUME_MUTED and PA_VOLUME_NORM*/
    new_volume = round(new_volume_d * PA_VOLUME_NORM);

    pa_threaded_mainloop_lock(self->mainloop);

    /*query stream info for current sink*/
    op = pa_context_get_sink_info_by_index(
        self->context,
        pa_stream_get_device_index(self->stream),
        (pa_sink_info_cb_t)get_volume_callback,
        &cb_data);

    /*wait for callback to complete*/
    while (pa_operation_get_state(op) == PA_OPERATION_RUNNING) {
        pa_threaded_mainloop_wait(self->mainloop);
    }

    pa_operation_unref(op);

    /*scale values using the new volume setting*/
    pa_cvolume_scale(&cvolume, new_volume);

    /*set sink's volume values*/
    op = pa_context_set_sink_volume_by_index(
        self->context,
        pa_stream_get_device_index(self->stream),
        &cvolume,
        (pa_context_success_cb_t)set_volume_callback,
        self->mainloop);

    /*wait for callback to complete*/
    while (pa_operation_get_state(op) == PA_OPERATION_RUNNING) {
        pa_threaded_mainloop_wait(self->mainloop);
    }

    pa_operation_unref(op);

    pa_threaded_mainloop_unlock(self->mainloop);

    Py_INCREF(Py_None);
    return Py_None;
}
Esempio n. 6
0
static void
gst_pulsemixer_ctrl_timeout_event (pa_mainloop_api * a, pa_time_event * e,
    const struct timeval *tv, void *userdata)
{
  pa_operation *o;
  GstPulseMixerCtrl *c = GST_PULSEMIXER_CTRL (userdata);

  if (c->update_volume) {
    if (c->type == GST_PULSEMIXER_SINK)
      o = pa_context_set_sink_volume_by_index (c->context, c->index, &c->volume,
          NULL, NULL);
    else
      o = pa_context_set_source_volume_by_index (c->context, c->index,
          &c->volume, NULL, NULL);

    if (!o)
      GST_WARNING_OBJECT (c->object, "Failed to set device volume: %s",
          pa_strerror (pa_context_errno (c->context)));
    else
      pa_operation_unref (o);

    c->update_volume = FALSE;
  }

  if (c->update_mute) {
    if (c->type == GST_PULSEMIXER_SINK)
      o = pa_context_set_sink_mute_by_index (c->context, c->index, !!c->muted,
          NULL, NULL);
    else
      o = pa_context_set_source_mute_by_index (c->context, c->index, !!c->muted,
          NULL, NULL);

    if (!o)
      GST_WARNING_OBJECT (c->object, "Failed to set device mute: %s",
          pa_strerror (pa_context_errno (c->context)));
    else
      pa_operation_unref (o);

    c->update_mute = FALSE;
  }

  /* Make sure that all outstanding queries are being ignored */
  c->ignore_queries = c->outstandig_queries;

  g_assert (e == c->time_event);
  a->time_free (e);
  c->time_event = NULL;
}
Esempio n. 7
0
void pulseaudio_volume(menu_info_item_t* mii, int inc)
{
    g_debug("pulseaudio_volume(%s, %i)", mii->name, inc);

    /* increment/decrement in 2% steps */
    pa_cvolume* volume;
    if(inc < 0)
        volume = pa_cvolume_dec(mii->volume, -inc * PA_VOLUME_NORM / 50);
    else if(inc > 0)
    {
        int volume_max = mii->menu_info->menu_infos->settings.volume_max;
        if(volume_max > 0)
            volume = pa_cvolume_inc_clamp(mii->volume, inc * PA_VOLUME_NORM / 50,
                    PA_VOLUME_NORM * volume_max / 100);
        else
            volume = pa_cvolume_inc(mii->volume, inc * PA_VOLUME_NORM / 50);
    }
    else
        return;

    pa_operation* o = NULL;

    switch(mii->menu_info->type)
    {
        case MENU_SERVER:
        case MENU_MODULE:
            /* nothing to do here */
            break;
        case MENU_SINK:
            o = pa_context_set_sink_volume_by_index(context, mii->index,
                    volume, pulseaudio_set_volume_success_cb, mii);
            break;
        case MENU_SOURCE:
            o = pa_context_set_source_volume_by_index(context, mii->index,
                    volume, pulseaudio_set_volume_success_cb, mii);
            break;
        case MENU_INPUT:
            o = pa_context_set_sink_input_volume(context, mii->index,
                    volume, pulseaudio_set_volume_success_cb, mii);
            break;
        case MENU_OUTPUT:
            o = pa_context_set_source_output_volume(context, mii->index,
                    volume, pulseaudio_set_volume_success_cb, mii);
            break;
    }
    if(o)
        pa_operation_unref(o);
}
Esempio n. 8
0
static void m_set_sink_volume(int idx, int volume) 
{
    pa_operation *pa_op = NULL;
    pa_cvolume sink_volume;
    int i;

    printf("DEBUG m_set_sink_volume channel_num %d\n", m_channel_num);
    sink_volume.channels = m_channel_num;
    for (i = 0; i < m_channel_num; i++) {
        sink_volume.values[i] = volume;
    }

    pa_op = pa_context_set_sink_volume_by_index(m_pa_ctx, idx, &sink_volume, NULL, NULL);
    if (!pa_op) {
        printf("pa_context_set_sink_volume_by_index() failed");
        return;
    }
    pa_operation_unref(pa_op);
    pa_op = NULL;
}
Esempio n. 9
0
void backend_volume_setall(context_t *c, backend_entry_type type, uint32_t idx, int *v, int chnum) {
    pa_cvolume volume;
    volume.channels = chnum;
    for(int i = 0; i < chnum; ++i) {
        volume.values[i] = v[i];
    }
    switch(type) {
        case SINK:
            pa_context_set_sink_volume_by_index(c->context, idx, &volume, NULL, NULL);
            break;
        case SINK_INPUT:
            pa_context_set_sink_input_volume(c->context, idx, &volume, NULL, NULL);
            break;
        case SOURCE:
            pa_context_set_source_volume_by_index(c->context, idx, &volume, NULL, NULL);
            break;
        case SOURCE_OUTPUT:
            pa_context_set_source_output_volume(c->context, idx, &volume, NULL, NULL);
            break;
        default:
            break;
    }
}