[pulseaudio-discuss] How to capture one of multiple radios that these radios play at the same time?
Colin Guthrie
gmane at colin.guthr.ie
Fri Nov 19 03:33:22 PST 2010
'Twas brillig, and Tsai Yu-Chin at 19/11/10 02:29 did gyre and gimble:
> Thank you for your help.
> I refer to source code of pavucontrol and I program a simple code below:
Ultimately what your code is doing is thus:
1. Get the Sink Index the stream is using.
2. Get the Monitor Source for the Sink.
3. Record from the Monitor of the Sink.
The sink monitor will contain the product of *all* streams playing on
the sink. There is a special "Sink Input Monitor" that you can connect
to for your recording. It's will just contain the sound for the Sink
Input itself. You still need to get the Monitor for the sink to which
your stream is attached, but you pass this in to the
pa_stream_connect_record function as a string.
In pavucontrol's mainwindow.cc see the method:
MainWindow::createMonitorStreamForSinkInput()
int sink_input_index = ?; /* You should have this value already in your
code */
int sink_monitor_source_index = ?; /* You should have this value already
in your code */
char dev[16];
pa_stream *stream;
/* assume variable "ss" is your sample spec and "attr" is your buffer
attributes */
if (!(stream = pa_stream_new(context, _("Single Radio Snooper!"), &ss,
NULL))) {
/* ERROR */
return;
}
/* Put the source which we'll record here (i.e. the montior of the sink
the stream is playing on) */
dev = snprintf(dev, sizeof(dev), "%u", sink_monitor_source_index);
/* restrict the recording to just one monitor stream */
pa_stream_set_monitor_stream(stream, sink_input_index);
/* Set callbacks */
pa_stream_set_read_callback(stream, ....);
pa_stream_set_suspended_callback(stream, ....);
if (pa_stream_connect_record(stream, dev, &attr, (pa_stream_flags_t)
(PA_STREAM_DONT_MOVE|PA_STREAM_ADJUST_LATENCY)) < 0) {
/* ERROR */
pa_stream_unref(stream);
stream = NULL;
return;
}
Obviously if the user moves your stream to another device you have to
tear down and recreate your stream against the new monitor source. Not
ideal, but should be fine in most circumstances. Sadly there isn't a way
to record the radio fully across device moves as far as I know...
although perhaps not setting the PA_STREAM_DONT_MOVE flag will allow the
record stream to automatically move if the stream is moved? I don't know...
HTHs
--
Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/
Day Job:
Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
Mageia Contributor [http://www.mageia.org/]
PulseAudio Hacker [http://www.pulseaudio.org/]
Trac Hacker [http://trac.edgewall.org/]
More information about the pulseaudio-discuss
mailing list