4 * PWLib application source file for PluginTest
6 * Main program entry point.
8 * Copyright 2003 Equivalence
11 * Revision 1.3 2003/11/12 07:00:09 csoutheren
12 * Changed make compile under Windows
14 * Revision 1.2 2003/11/12 06:35:12 csoutheren
15 * Initial main version
17 * Revision 1.1.2.6 2003/10/20 21:15:33 dereksmithies
18 * Tidy up text output. Fix calls to Usage() function.
20 * Revision 1.1.2.5 2003/10/20 03:22:46 dereksmithies
21 * Add checks on validity of function returned.
23 * Revision 1.1.2.4 2003/10/13 02:46:02 dereksmithies
24 * Now generates sound through dynamically loaded OSS sound channel.
26 * Revision 1.1.2.3 2003/10/12 21:22:12 dereksmithies
27 * Add ability to play sample sound out PSoundChannel - illustrating operation of plugins.
29 * Revision 1.1.2.2 2003/10/08 03:55:54 dereksmithies
30 * Add lots of debug statements, fix option parsing, improve Usage() function.
32 * Revision 1.1.2.1 2003/10/07 01:52:39 csoutheren
33 * Test program for plugins
35 * Revision 1.3 2003/04/22 23:25:13 craigs
36 * Changed help message for SRV records
38 * Revision 1.2 2003/04/15 08:15:16 craigs
39 * Added single string form of GetSRVRecords
41 * Revision 1.1 2003/04/15 04:12:38 craigs
47 #include <ptlib/pluginmgr.h>
48 #include <ptlib/sound.h>
54 #define M_PI 3.1415926
57 PCREATE_PROCESS(PluginTest
);
61 PluginTest::PluginTest()
62 : PProcess("Equivalence", "PluginTest", 1, 0, AlphaCode
, 1)
68 PError
<< "usage: plugintest dir\n \n"
69 << "-l List ALL plugins regardless of type\n"
70 << "-s Show the list of loaded PSoundChannel drivers\n"
71 << "-d dir Set the directory from which plugins are loaded\n"
72 << "-x Attempt to load the OSS sound plugin\n"
73 << "-t (more t's for more detail) logging on\n"
74 << "-o output file for logging \n"
75 << "-p play a beep beep beep sound, and test created PSoundChannel\n"
76 << " Requires that you have specified -x also\n"
77 << "-h print this help\n";
81 void PluginTest::Main()
83 PArgList
& args
= GetArguments();
99 PTrace::Initialise(args
.GetOptionCount('t'),
100 args
.HasOption('o') ? (const char *)args
.GetOptionString('o') : NULL
,
101 PTrace::Blocks
| PTrace::Timestamp
| PTrace::Thread
| PTrace::FileAndLine
);
103 if (args
.HasOption('d')) {
104 PPluginManager
& pluginMgr
= PPluginManager::GetPluginManager();
105 pluginMgr
.LoadPluginDirectory(args
.GetOptionString('d'));
108 if (args
.HasOption('h')) {
113 if (args
.HasOption('l')) {
114 cout
<< "List available plugin types" << endl
;
115 PPluginManager
& pluginMgr
= PPluginManager::GetPluginManager();
116 PStringList plugins
= pluginMgr
.GetPluginTypes();
117 if (plugins
.GetSize() == 0)
118 cout
<< "No plugins loaded" << endl
;
120 cout
<< plugins
.GetSize() << " plugin types available:" << endl
;
121 for (int i
= 0; i
< plugins
.GetSize(); i
++) {
122 cout
<< " " << plugins
[i
] << " : ";
123 PStringList services
= pluginMgr
.GetPluginsProviding(plugins
[i
]);
124 if (services
.GetSize() == 0)
125 cout
<< "None available" << endl
;
127 cout
<< setfill(',') << services
<< setfill(' ') << endl
;
133 if (args
.HasOption('s')) {
134 cout
<< "Available " << args
.GetOptionString('s') << " :" <<endl
;
135 cout
<< "Sound plugin names = " << setfill(',') << PSoundChannel::GetDriverNames() << setfill(' ') << endl
;
137 //cout << "Default device names = " << setfill(',') << PSoundChannel::GetDeviceNames(PSoundChannel::Player) << setfill(' ') << endl;
138 //PSoundChannel * snd = new PSoundChannel();
139 //cout << "PSoundChannel has a name of \"" << snd->GetClass() << "\"" << endl
144 if (args
.HasOption('a')) {
145 PString service
= args
.GetOptionString('a');
147 if (args
.GetCount() > 0)
149 else if (service
!= "default") {
150 PStringList deviceList
= PSoundChannel::GetDeviceNames(service
, PSoundChannel::Player
);
151 if (deviceList
.GetSize() == 0) {
152 cout
<< "No devices for sound service " << service
<< endl
;
155 device
= deviceList
[0];
158 cout
<< "Using sound service " << service
<< " with device " << device
<< endl
;
161 if (service
== "default") {
162 snd
= new PSoundChannel();
163 device
= PSoundChannel::GetDefaultDevice(PSoundChannel::Player
);
166 snd
= PSoundChannel::CreateChannel(service
);
168 cout
<< "Failed to create sound service " << service
<< " with device " << device
<< endl
;
173 cout
<< "Opening sound service " << service
<< " with device " << device
<< endl
;
175 if (!snd
->Open(device
, PSoundChannel::Player
)) {
176 cout
<< "Failed to open sound service " << service
<< " with device " << device
<< endl
;
180 if (!snd
->IsOpen()) {
181 cout
<< "Sound device " << device
<< " not open" << endl
;
185 if (!snd
->SetBuffers(SAMPLES
, 2)) {
186 cout
<< "Failed to set samples to " << SAMPLES
<< " and 2 buffers. End program now." << endl
;
192 PWORDArray
audio(SAMPLES
);
193 int i
, pointsPerCycle
= 8;
197 for (i
= 0; i
< SAMPLES
; i
++) {
198 angle
= M_PI
* 2 * (double)(i
% pointsPerCycle
)/pointsPerCycle
;
199 if ((i
% 4000) < 3000)
200 audio
[i
] = (unsigned short) ((16384 * cos(angle
) * volume
)/100);
205 if (!snd
->Write((unsigned char *)audio
.GetPointer(), SAMPLES
* 2)) {
206 cout
<< "Failed to write " << SAMPLES
/8000 << " seconds of beep beep. End program now." << endl
;
210 snd
->WaitForPlayCompletion();
214 // End of File ///////////////////////////////////////////////////////////////