コード例 #1
0
int cmtspeech_create_source_output(struct userdata *u)
{
    pa_source_output_new_data data;
    char t[256];

    pa_assert(u);
    pa_assert(!u->source);
    ENTER();

    if (u->source_output) {
        pa_log_info("Create called but output already exists");
        return 1;
    }

    if (!(u->source = pa_namereg_get(u->core, u->source_name, PA_NAMEREG_SOURCE))) {
        pa_log_error("Couldn't find source %s", u->source_name);
        return 2;
    }

    if (cmtspeech_check_source_api(u->source))
        return 3;

    pa_source_output_new_data_init(&data);
    data.driver = __FILE__;
    data.module = u->module;
    data.source = u->source;
    snprintf(t, sizeof(t), "Cellular call up link");
    pa_proplist_sets(data.proplist, PA_PROP_MEDIA_NAME, t);
    snprintf(t, sizeof(t), "phone");
    pa_proplist_sets(data.proplist, PA_PROP_MEDIA_ROLE, t);
    snprintf(t, sizeof(t), "cmtspeech module");
    pa_proplist_sets(data.proplist, PA_PROP_APPLICATION_NAME, t);
    pa_source_output_new_data_set_sample_spec(&data, &u->ss);
    pa_source_output_new_data_set_channel_map(&data, &u->map);
    data.flags = PA_SOURCE_OUTPUT_DONT_MOVE|PA_SOURCE_OUTPUT_START_CORKED;

    pa_source_output_new(&u->source_output, u->core, &data);
    pa_source_output_new_data_done(&data);

    if (!u->source_output) {
        pa_log("Creating cmtspeech source output failed");
        return -1;
    }

    u->source_output->push = cmtspeech_source_output_push_cb;
    u->source_output->kill = cmtspeech_source_output_kill_cb;
    u->source_output->attach = cmtspeech_source_output_attach_cb;
    u->source_output->detach = cmtspeech_source_output_detach_cb;
    u->source_output->moving = cmtspeech_source_output_moving_cb;
    u->source_output->state_change = cmtspeech_source_output_state_change_cb;
    u->source_output->may_move_to = cmtspeech_source_output_may_move_to_cb;
    u->source_output->userdata = u;

    pa_source_output_put(u->source_output);

    pa_log_info("cmtspeech source-output created");

    return 0;
}
コード例 #2
0
/* Called from main context */
static pa_bool_t cmtspeech_source_output_may_move_to_cb(pa_source_output *o, pa_source *dest) {
  struct userdata *u;
  ENTER();

  pa_source_output_assert_ref(o);
  pa_assert_se(u = o->userdata);

  if (cmtspeech_check_source_api(dest))
      return FALSE;

  return TRUE;
}
コード例 #3
0
int pa__init(pa_module*m) {
    pa_modargs *ma = NULL;
    struct userdata *u;
    const char *sink_name, *source_name, *dbus_type;
    pa_sink *sink = NULL;
    pa_source *source = NULL;

    pa_assert(m);

    if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
        pa_log_error("Failed to parse module arguments");
        goto fail;
    }

    sink_name = pa_modargs_get_value(ma, "sink", NULL);
    source_name = pa_modargs_get_value(ma, "source", NULL);
    dbus_type = pa_modargs_get_value(ma, "dbus_type", "session");

    pa_log_debug("Got arguments: sink=\"%s\" source=\"%s\" dbus_type=\"%s\"",
                 sink_name, source_name, dbus_type);

    u = pa_xnew0(struct userdata, 1);
    m->userdata = u;
    u->core = m->core;
    u->module = m;

    u->ss.format = PA_SAMPLE_S16NE;
    u->ss.rate = CMTSPEECH_SAMPLERATE;
    u->ss.channels = 1;
    pa_channel_map_init_mono(&u->map);
    /* The result is rounded down incorrectly thus +1 */
    u->dl_frame_size = pa_usec_to_bytes(VOICE_SINK_FRAMESIZE+1, &u->ss);
    u->ul_frame_size = pa_usec_to_bytes(VOICE_SOURCE_FRAMESIZE+1, &u->ss);

    if (!(source = pa_namereg_get(m->core, source_name, PA_NAMEREG_SOURCE))) {
        pa_log_error("Source \"%s\" not found", source_name);
        goto fail;
    }

    if (!(sink = pa_namereg_get(m->core, sink_name, PA_NAMEREG_SINK))) {
        pa_log_error("Sink \"%s\" not found", sink_name);
        goto fail;
    }

    u->sink_name = pa_xstrdup(sink_name);
    u->source_name = pa_xstrdup(source_name);

    if (cmtspeech_check_source_api(source))
        goto fail;

    if (cmtspeech_check_sink_api(sink))
        goto fail;

    u->sink_input = NULL;
    u->source_output = NULL;

    u->local_sideinfoq = pa_queue_new();
    u->voice_sideinfoq = NULL;
    u->continuous_dl_stream = false,
    u->dl_memblockq =
	pa_memblockq_new("cmtspeech dl_memblockq", 0, 4*u->dl_frame_size, 0, &u->ss, 0, 0, 0, NULL);

    u->mainloop_handler = cmtspeech_mainloop_handler_new(u);

    if (cmtspeech_dbus_init(u, dbus_type))
        goto fail;

    if (cmtspeech_connection_init(u))
	goto fail;

    pa_modargs_free(ma);

    return 0;
fail:
    if (ma)
        pa_modargs_free(ma);

    pa__done(m);
    return -1;
}