-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
108 lines (92 loc) · 2.93 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "FakeMicWavPlayerLib.h"
#include <argparse/argparse.hpp>
#include <algorithm>
#include <iostream>
#include <string>
#include <cctype>
#include<signal.h>
#include<unistd.h>
void sig_handler(int signo)
{
if (signo == SIGINT)
std::cerr << "received SIGINT\n";
if (signo == SIGUSR1)
std::cerr << "received SIGUSR1\n";
else if (signo == SIGKILL)
std::cerr << "received SIGKILL\n";
else if (signo == SIGSTOP)
std::cerr << "received SIGSTOP\n";
FakeMicWavPlayer::clean();
exit(1);
}
int main(int argc, char *argv[]) {
signal(SIGINT, sig_handler);
signal(SIGUSR1, sig_handler);
signal(SIGKILL, sig_handler);
signal(SIGSTOP, sig_handler);
argparse::ArgumentParser program("FakeMicWavPlayer");
program.add_argument("<Source>")
.help("The source name to keep recording with");
program.add_argument("<Process Binary>")
.help("The binary name of the app to send the sound to.");
program.add_argument("-f", "--ogg-file")
.default_value("")
.help("The ogg audio file to play.");
program.add_argument("-a", "--application")
.default_value("")
.help("The application playing the sound to send");
program.add_argument("-s", "--sink-list")
.default_value("default")
.action([](const std::string& str){
std::string string(str);
string.erase(std::remove(string.begin(), string.end(), ' '), string.end());
return string;
})
.help("The comma-sepatated list of sinks to play the ogg file to.");
try {
program.parse_args(argc, argv);
}
catch (const std::runtime_error& err) {
std::cout << err.what() << std::endl;
std::cout << program;
return 1;
}
std::string ogg_file, application_name;
try {
ogg_file = program.get<std::string>("-f");
} catch (std::bad_any_cast&){}
try {
application_name = program.get<std::string>("-a");
} catch (std::bad_any_cast&){}
auto source = program.get<std::string>("<Source>");
std::string sourceProcessBinary = program.get<std::string>("<Process Binary>");
std::string combinedSlavesList = program.get<const char*>("-s");
FakeMicWavPlayer::clean();
if (ogg_file == "" && application_name == "") {
std::cerr << "[error] You need to provide either an ogg file to play or a application already playing sound.";
return 1;
}
if (ogg_file != "" && application_name != "") {
std::cerr << "[error] You can't stream both from an ogg file and an already playing app.";
return 1;
}
if (application_name != "") {
if (FakeMicWavPlayer::initWithSinkInput(application_name, source, combinedSlavesList,
sourceProcessBinary) != 0)
return 1;
return 0;
}
if (ogg_file != "") {
if (FakeMicWavPlayer::initWithAudioFile(ogg_file.c_str(), source, combinedSlavesList,
sourceProcessBinary) != 0)
return 1;
if (FakeMicWavPlayer::set_source_volume(90.0) != 0)
return 1;
if (FakeMicWavPlayer::set_user_volume(40.0) != 0)
return 1;
while (FakeMicWavPlayer::playNonBlocking() == 0);
FakeMicWavPlayer::cleanPlayer();
}
FakeMicWavPlayer::clean();
return 0;
}