Skip to content

Commit

Permalink
optionally take PulseAudio source name
Browse files Browse the repository at this point in the history
  • Loading branch information
ammen99 committed Mar 28, 2019
1 parent 19ba9b4 commit 3a7a5c2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,14 +484,14 @@ int main(int argc, char *argv[])
{ "codec-param", required_argument, NULL, 'p' },
{ "device", required_argument, NULL, 'd' },
{ "log", no_argument, NULL, 'l' },
{ "enable-audio", no_argument, NULL, 'a' },
{ "audio", optional_argument, NULL, 'a' },
{ 0, 0, NULL, 0 }
};

int c, i;
std::string param;
size_t pos;
while((c = getopt_long(argc, argv, "o:f:g:c:p:d:la", opts, &i)) != -1)
while((c = getopt_long(argc, argv, "o:f:g:c:p:d:la::", opts, &i)) != -1)
{
switch(c)
{
Expand Down Expand Up @@ -521,6 +521,7 @@ int main(int argc, char *argv[])

case 'a':
params.enable_audio = true;
pulseParams.audio_source = optarg ? strdup(optarg) : NULL;
break;

case 'p':
Expand Down
12 changes: 7 additions & 5 deletions src/pulse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ PulseReader::PulseReader(PulseReaderParams _p)
};

int perr;
pa = pa_simple_new(NULL, "wf-recorder", PA_STREAM_RECORD, NULL,
"wf-recorder", &sample_spec, &map, &attr, &perr);
std::cout << "Using PulseAudio device: " << (params.audio_source ?: "default") << std::endl;
pa = pa_simple_new(NULL, "wf-recorder3", PA_STREAM_RECORD, params.audio_source,
"wf-recorder3", &sample_spec, &map, &attr, &perr);

if (!pa)
{
std::cerr << "Failed to connect to PulseAudio,"
<< " recording won't have audio" << std::endl;
std::cerr << "Failed to connect to PulseAudio: " << pa_strerror(perr)
<< "\nRecording won't have audio" << std::endl;
}
}

Expand All @@ -48,7 +49,8 @@ bool PulseReader::loop()
int perr;
if (pa_simple_read(pa, buffer.data(), buffer.size(), &perr) < 0)
{
std::cerr << "Failed to read from PulseAudio stream!" << std::endl;
std::cerr << "Failed to read from PulseAudio stream: "
<< pa_strerror(perr) << std::endl;
return false;
}

Expand Down
2 changes: 2 additions & 0 deletions src/pulse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
struct PulseReaderParams
{
size_t audio_frame_size;
/* Can be NULL */
char *audio_source;
};

class PulseReader
Expand Down

0 comments on commit 3a7a5c2

Please sign in to comment.