3
* Ekiga -- A VoIP and Video-Conferencing application
4
* Copyright (C) 2000-2008 Damien Sandras
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or (at
9
* your option) any later version. This program is distributed in the hope
10
* that it will be useful, but WITHOUT ANY WARRANTY; without even the
11
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
* See the GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License along
15
* with this program; if not, write to the Free Software Foundation, Inc.,
16
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
18
* Ekiga is licensed under the GPL license and as a special exception, you
19
* have permission to link or otherwise combine this program with the
20
* programs OPAL, OpenH323 and PWLIB, and distribute the combination, without
21
* applying the requirements of the GNU GPL to the OPAL, OpenH323 and PWLIB
22
* programs, as long as you do follow the requirements of the GNU GPL for all
23
* the rest of the software thus combined.
28
* audiooutput-manager-ptlib.cpp - description
29
* ------------------------------------------
30
* begin : written in 2008 by Matthias Schneider
31
* copyright : (c) 2008 by Matthias Schneider
32
* description : declaration of the interface of a audiooutput core.
33
* A audioinput core manages AudioOutputManagers.
37
#include "audiooutput-manager-ptlib.h"
38
#include "ptbuildopts.h"
41
#define DEVICE_TYPE "PTLIB"
43
GMAudioOutputManager_ptlib::GMAudioOutputManager_ptlib (Ekiga::ServiceCore & _core)
45
runtime (*(dynamic_cast<Ekiga::Runtime *> (_core.get ("runtime"))))
47
current_state[Ekiga::primary].opened = false;
48
current_state[Ekiga::secondary].opened = false;
49
output_device[Ekiga::primary] = NULL;
50
output_device[Ekiga::secondary] = NULL;
53
void GMAudioOutputManager_ptlib::get_devices(std::vector <Ekiga::AudioOutputDevice> & devices)
55
PStringArray audio_sources;
56
PStringArray audio_devices;
60
Ekiga::AudioOutputDevice device;
61
device.type = DEVICE_TYPE;
63
audio_sources = PSoundChannel::GetDriverNames ();
64
sources_array = audio_sources.ToCharArray ();
65
for (PINDEX i = 0; sources_array[i] != NULL; i++) {
67
device.source = sources_array[i];
69
if (device.source != "EKIGA") {
70
audio_devices = PSoundChannel::GetDeviceNames (device.source, PSoundChannel::Player);
71
devices_array = audio_devices.ToCharArray ();
73
for (PINDEX j = 0; devices_array[j] != NULL; j++) {
75
device.name = devices_array[j];
76
devices.push_back(device);
84
bool GMAudioOutputManager_ptlib::set_device (Ekiga::AudioOutputPS ps, const Ekiga::AudioOutputDevice & device)
86
if ( device.type == DEVICE_TYPE ) {
88
PTRACE(4, "GMAudioOutputManager_ptlib\tSetting Device[" << ps << "] " << device);
89
current_state[ps].device = device;
96
bool GMAudioOutputManager_ptlib::open (Ekiga::AudioOutputPS ps, unsigned channels, unsigned samplerate, unsigned bits_per_sample)
98
PTRACE(4, "GMAudioOutputManager_ptlib\tOpening Device " << current_state[ps].device);
99
PTRACE(4, "GMAudioOutputManager_ptlib\tOpening Device with " << channels << "-" << samplerate << "/" << bits_per_sample);
101
current_state[ps].channels = channels;
102
current_state[ps].samplerate = samplerate;
103
current_state[ps].bits_per_sample = bits_per_sample;
105
output_device[ps] = PSoundChannel::CreateOpenedChannel (current_state[ps].device.source,
106
current_state[ps].device.name,
107
PSoundChannel::Player,
112
Ekiga::AudioOutputErrorCodes error_code = Ekiga::AO_ERROR_NONE;
113
if (!output_device[ps])
114
error_code = Ekiga::AO_ERROR_DEVICE;
116
if (error_code != Ekiga::AO_ERROR_NONE) {
117
PTRACE(1, "GMAudioOutputManager_ptlib\tEncountered error " << error_code << " while opening device[" << ps << "]");
118
runtime.run_in_main (sigc::bind (device_error.make_slot (), ps, current_state[ps].device, error_code));
123
output_device[ps]->GetVolume (volume);
124
current_state[ps].opened = true;
126
Ekiga::AudioOutputSettings settings;
127
settings.volume = volume;
128
settings.modifyable = true;
129
runtime.run_in_main (sigc::bind (device_opened.make_slot (), ps, current_state[ps].device, settings));
134
void GMAudioOutputManager_ptlib::close(Ekiga::AudioOutputPS ps)
136
PTRACE(4, "GMAudioOutputManager_ptlib\tClosing device[" << ps << "] " << current_state[ps].device);
137
if (output_device[ps]) {
138
delete output_device[ps];
139
output_device[ps] = NULL;
141
current_state[ps].opened = false;
142
runtime.run_in_main (sigc::bind (device_closed.make_slot (), ps, current_state[ps].device));
145
void GMAudioOutputManager_ptlib::set_buffer_size (Ekiga::AudioOutputPS ps, unsigned buffer_size, unsigned num_buffers)
147
PTRACE(4, "GMAudioOutputManager_ptlib\tSetting buffer size of device[" << ps << "] " << buffer_size << "/" << num_buffers);
149
if (output_device[ps])
150
output_device[ps]->SetBuffers (buffer_size, num_buffers);
154
bool GMAudioOutputManager_ptlib::set_frame_data (Ekiga::AudioOutputPS ps,
157
unsigned & bytes_written)
162
if (!current_state[ps].opened) {
163
PTRACE(1, "GMAudioOutputManager_ptlib\tTrying to get frame from closed device[" << ps << "]");
167
if (output_device[ps]) {
168
ret = output_device[ps]->Write ((void*)data, size);
170
bytes_written = output_device[ps]->GetLastWriteCount();
173
PTRACE(1, "GMAudioOutputManager_ptlib\tEncountered error while trying to write data");
174
runtime.run_in_main (sigc::bind (device_error.make_slot (), ps, current_state[ps].device, Ekiga::AO_ERROR_WRITE));
181
void GMAudioOutputManager_ptlib::set_volume (Ekiga::AudioOutputPS ps, unsigned volume )
183
PTRACE(4, "GMAudioOutputManager_ptlib\tSetting volume of device [" << ps << "] to " << volume);
184
if (output_device[ps])
185
output_device[ps]->SetVolume(volume);
188
bool GMAudioOutputManager_ptlib::has_device(const std::string & sink, const std::string & device_name, Ekiga::AudioOutputDevice & device)
190
if (sink == "alsa") {
191
device.type = DEVICE_TYPE;
192
device.source = "ALSA";
193
device.name = device_name;
196
/* if (source == "oss") {
197
device.type = DEVICE_TYPE;
198
device.source = "OSS";
199
device.device = device_name;