"rate=<sample rate> "
"channels=<number of channels> "
"channel_map=<channel map> "
+ "use_volume_sharing=<yes or no> "
+ "force_flat_volume=<yes or no> "
));
#define MEMBLOCKQ_MAXLENGTH (16*1024*1024)
struct userdata {
pa_module *module;
+ /* FIXME: Uncomment this and take "autoloaded" as a modarg if this is a filter */
+ /* pa_bool_t autoloaded; */
+
pa_sink *sink;
pa_sink_input *sink_input;
"rate",
"channels",
"channel_map",
+ "use_volume_sharing",
+ "force_flat_volume",
NULL
};
return;
/* Just hand this one over to the master sink */
- pa_sink_input_request_rewind(u->sink_input, s->thread_info.rewind_nbytes + pa_memblockq_get_length(u->memblockq), TRUE, FALSE, FALSE);
+ pa_sink_input_request_rewind(u->sink_input,
+ s->thread_info.rewind_nbytes +
+ pa_memblockq_get_length(u->memblockq), TRUE, FALSE, FALSE);
}
/* Called from I/O thread context */
size_t fs;
unsigned n, c;
pa_memchunk tchunk;
- pa_usec_t curr_latency;
+ pa_usec_t current_latency PA_GCC_UNUSED;
pa_sink_input_assert_ref(i);
pa_assert(chunk);
/* Hmm, process any rewind request that might be queued up */
pa_sink_process_rewind(u->sink, 0);
+ /* (1) IF YOU NEED A FIXED BLOCK SIZE USE
+ * pa_memblockq_peek_fixed_size() HERE INSTEAD. NOTE THAT FILTERS
+ * WHICH CAN DEAL WITH DYNAMIC BLOCK SIZES ARE HIGHLY
+ * PREFERRED. */
while (pa_memblockq_peek(u->memblockq, &tchunk) < 0) {
pa_memchunk nchunk;
pa_memblock_unref(nchunk.memblock);
}
+ /* (2) IF YOU NEED A FIXED BLOCK SIZE, THIS NEXT LINE IS NOT
+ * NECESSARY */
tchunk.length = PA_MIN(nbytes, tchunk.length);
pa_assert(tchunk.length > 0);
fs = pa_frame_size(&i->sample_spec);
- //n = (unsigned) (PA_MIN(tchunk.length, u->block_size) / fs);
n = (unsigned) (tchunk.length / fs);
pa_assert(n > 0);
chunk->index = 0;
chunk->length = n*fs;
chunk->memblock = pa_memblock_new(i->sink->core->mempool, chunk->length);
- pa_assert( chunk->memblock );
pa_memblockq_drop(u->memblockq, chunk->length);
src = (float*) ((uint8_t*) pa_memblock_acquire(tchunk.memblock) + tchunk.index);
dst = (float*) pa_memblock_acquire(chunk->memblock);
- /* PUT YOUR CODE HERE TO DO SOMETHING WITH THE DATA */
- /* example, copy input to output */
+ /* (3) PUT YOUR CODE HERE TO DO SOMETHING WITH THE DATA */
+
+ /* As an example, copy input to output */
for (c = 0; c < u->channels; c++) {
- pa_sample_clamp(PA_SAMPLE_FLOAT32NE,dst+c, u->channels*sizeof(float),
- src+c, u->channels*sizeof(float),n);
+ pa_sample_clamp(PA_SAMPLE_FLOAT32NE,
+ dst+c, u->channels * sizeof(float),
+ src+c, u->channels * sizeof(float),
+ n);
}
+
pa_memblock_release(tchunk.memblock);
pa_memblock_release(chunk->memblock);
pa_memblock_unref(tchunk.memblock);
-
- curr_latency =
+ /* (4) IF YOU NEED THE LATENCY FOR SOMETHING ACQUIRE IT LIKE THIS: */
+ current_latency =
/* Get the latency of the master sink */
pa_sink_get_latency_within_thread(i->sink) +
/* Add the latency internal to our sink input on top */
pa_bytes_to_usec(pa_memblockq_get_length(i->thread_info.render_memblockq), &i->sink->sample_spec);
- /* FIXME: do something with the latency */
-
-
return 0;
}
if (amount > 0) {
pa_memblockq_seek(u->memblockq, - (int64_t) amount, PA_SEEK_RELATIVE, TRUE);
- /* NEED TO RESET POST-PROCESSING HERE */
+ /* (5) PUT YOUR CODE HERE TO RESET YOUR FILTER */
}
}
pa_sink_input_assert_ref(i);
pa_assert_se(u = i->userdata);
+ /* (6) IF YOU NEED A FIXED BLOCK SIZE ROUND nbytes UP TO MULTIPLES
+ * OF IT HERE. THE PA_ROUND_UP MACRO IS USEFUL FOR THAT. */
+
pa_sink_set_max_request_within_thread(u->sink, nbytes);
}
pa_sink_input_assert_ref(i);
pa_assert_se(u = i->userdata);
+ /* (7) IF YOU NEED A FIXED BLOCK SIZE ADD THE LATENCY FOR ONE
+ * BLOCK MINUS ONE SAMPLE HERE. pa_usec_to_bytes_round_up() IS
+ * USEFUL FOR THAT. */
+
pa_sink_set_fixed_latency_within_thread(u->sink, i->sink->thread_info.fixed_latency);
}
pa_sink_set_rtpoll(u->sink, i->sink->thread_info.rtpoll);
pa_sink_set_latency_range_within_thread(u->sink, i->sink->thread_info.min_latency, i->sink->thread_info.max_latency);
+
+ /* (8.1) IF YOU NEED A FIXED BLOCK SIZE ADD THE LATENCY FOR ONE
+ * BLOCK MINUS ONE SAMPLE HERE. SEE (7) */
pa_sink_set_fixed_latency_within_thread(u->sink, i->sink->thread_info.fixed_latency);
+
+ /* (8.2) IF YOU NEED A FIXED BLOCK SIZE ROUND
+ * pa_sink_input_get_max_request(i) UP TO MULTIPLES OF IT
+ * HERE. SEE (6) */
pa_sink_set_max_request_within_thread(u->sink, pa_sink_input_get_max_request(i));
pa_sink_set_max_rewind_within_thread(u->sink, pa_sink_input_get_max_rewind(i));
pa_sink *master=NULL;
pa_sink_input_new_data sink_input_data;
pa_sink_new_data sink_data;
- pa_bool_t *use_default = NULL;
+ pa_bool_t use_volume_sharing = FALSE;
+ pa_bool_t force_flat_volume = FALSE;
+ pa_memchunk silence;
pa_assert(m);
goto fail;
}
+ if (pa_modargs_get_value_boolean(ma, "use_volume_sharing", &use_volume_sharing) < 0) {
+ pa_log("use_volume_sharing= expects a boolean argument");
+ goto fail;
+ }
- u = pa_xnew0(struct userdata, 1);
- if (!u) {
- pa_log("Failed to alloc userdata");
+ if (pa_modargs_get_value_boolean(ma, "force_flat_volume", &force_flat_volume) < 0) {
+ pa_log("force_flat_volume= expects a boolean argument");
goto fail;
}
- u->module = m;
- m->userdata = u;
- u->memblockq = pa_memblockq_new(0, MEMBLOCKQ_MAXLENGTH, 0, pa_frame_size(&ss), 1, 1, 0, NULL);
- if (!u->memblockq) {
- pa_log("Failed to create sink memblockq.");
+
+ if (use_volume_sharing && force_flat_volume) {
+ pa_log("Flat volume can't be forced when using volume sharing.");
goto fail;
}
+
+ u = pa_xnew0(struct userdata, 1);
+ u->module = m;
+ m->userdata = u;
u->channels = ss.channels;
/* Create sink */
pa_proplist_setf(sink_data.proplist, PA_PROP_DEVICE_DESCRIPTION, "Virtual Sink %s on %s", sink_data.name, z ? z : master->name);
}
- u->sink = pa_sink_new(m->core, &sink_data,
- PA_SINK_HW_MUTE_CTRL|PA_SINK_HW_VOLUME_CTRL|PA_SINK_DECIBEL_VOLUME|
- (master->flags & (PA_SINK_LATENCY|PA_SINK_DYNAMIC_LATENCY)));
+ u->sink = pa_sink_new(m->core, &sink_data, (master->flags & (PA_SINK_LATENCY|PA_SINK_DYNAMIC_LATENCY))
+ | (use_volume_sharing ? PA_SINK_SHARE_VOLUME_WITH_MASTER : 0)
+ | (force_flat_volume ? PA_SINK_FLAT_VOLUME : 0));
pa_sink_new_data_done(&sink_data);
if (!u->sink) {
u->sink->set_state = sink_set_state_cb;
u->sink->update_requested_latency = sink_update_requested_latency_cb;
u->sink->request_rewind = sink_request_rewind_cb;
- u->sink->set_volume = sink_set_volume_cb;
+ u->sink->set_volume = use_volume_sharing ? NULL : sink_set_volume_cb;
u->sink->set_mute = sink_set_mute_cb;
u->sink->userdata = u;
sink_input_data.driver = __FILE__;
sink_input_data.module = m;
sink_input_data.sink = master;
- pa_proplist_sets(sink_input_data.proplist, PA_PROP_MEDIA_NAME, "Virtual Sink Stream");
+ sink_input_data.origin_sink = u->sink;
+ pa_proplist_setf(sink_input_data.proplist, PA_PROP_MEDIA_NAME, "Virtual Sink Stream from %s", pa_proplist_gets(u->sink->proplist, PA_PROP_DEVICE_DESCRIPTION));
pa_proplist_sets(sink_input_data.proplist, PA_PROP_MEDIA_ROLE, "filter");
pa_sink_input_new_data_set_sample_spec(&sink_input_data, &ss);
pa_sink_input_new_data_set_channel_map(&sink_input_data, &map);
u->sink_input->state_change = sink_input_state_change_cb;
u->sink_input->may_move_to = sink_input_may_move_to_cb;
u->sink_input->moving = sink_input_moving_cb;
- u->sink_input->volume_changed = sink_input_volume_changed_cb;
+ u->sink_input->volume_changed = use_volume_sharing ? NULL : sink_input_volume_changed_cb;
u->sink_input->mute_changed = sink_input_mute_changed_cb;
u->sink_input->userdata = u;
- //pa_sink_input_set_requested_latency(u->sink_input, 5000);
+ u->sink->input_to_master = u->sink_input;
+
+ pa_sink_input_get_silence(u->sink_input, &silence);
+ u->memblockq = pa_memblockq_new(0, MEMBLOCKQ_MAXLENGTH, 0, pa_frame_size(&ss), 1, 1, 0, &silence);
+ pa_memblock_unref(silence.memblock);
+
+ /* (9) INITIALIZE ANYTHING ELSE YOU NEED HERE */
pa_sink_put(u->sink);
pa_sink_input_put(u->sink_input);
pa_modargs_free(ma);
- pa_xfree(use_default);
-
return 0;
- fail:
+fail:
if (ma)
pa_modargs_free(ma);
- pa_xfree(use_default);
-
pa__done(m);
return -1;
if (u->sink)
pa_sink_unref(u->sink);
-
if (u->memblockq)
pa_memblockq_free(u->memblockq);
-
pa_xfree(u);
}