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
* audioinput-manager-ptlib.cpp - description
29
* ------------------------------------------
30
* begin : written in 2008 by Matthias Schneider
31
* copyright : (c) 2008 by Matthias Schneider
32
* description : declaration of a PTLIB audio input manager
37
#include "audioinput-manager-ptlib.h"
38
#include "ptbuildopts.h"
41
#define DEVICE_TYPE "PTLIB"
44
GMAudioInputManager_ptlib::GMAudioInputManager_ptlib (Ekiga::ServiceCore & _core)
46
runtime (*(dynamic_cast<Ekiga::Runtime *> (_core.get ("runtime"))))
48
current_state.opened = false;
50
expectedFrameSize = 0;
53
void GMAudioInputManager_ptlib::get_devices(std::vector <Ekiga::AudioInputDevice> & devices)
55
PStringArray audio_sources;
56
PStringArray audio_devices;
60
Ekiga::AudioInputDevice 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::Recorder);
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 GMAudioInputManager_ptlib::set_device (const Ekiga::AudioInputDevice & device)
86
if ( device.type == DEVICE_TYPE ) {
88
PTRACE(4, "GMAudioInputManager_ptlib\tSetting Device " << device);
89
current_state.device = device;
96
bool GMAudioInputManager_ptlib::open (unsigned channels, unsigned samplerate, unsigned bits_per_sample)
98
PTRACE(4, "GMAudioInputManager_ptlib\tOpening Device " << current_state.device);
99
PTRACE(4, "GMAudioInputManager_ptlib\tOpening Device with " << channels << "-" << samplerate << "/" << bits_per_sample);
101
current_state.channels = channels;
102
current_state.samplerate = samplerate;
103
current_state.bits_per_sample = bits_per_sample;
105
input_device = PSoundChannel::CreateOpenedChannel (current_state.device.source,
106
current_state.device.name,
107
PSoundChannel::Recorder,
112
Ekiga::AudioInputErrorCodes error_code = Ekiga::AI_ERROR_NONE;
114
error_code = Ekiga::AI_ERROR_DEVICE;
116
if (error_code != Ekiga::AI_ERROR_NONE) {
117
PTRACE(1, "GMAudioInputManager_ptlib\tEncountered error " << error_code << " while opening device ");
118
runtime.run_in_main (sigc::bind (device_error.make_slot (), current_state.device, error_code));
123
input_device->GetVolume (volume);
124
current_state.opened = true;
126
Ekiga::AudioInputSettings settings;
127
settings.volume = volume;
128
settings.modifyable = true;
129
runtime.run_in_main (sigc::bind (device_opened.make_slot (), current_state.device, settings));
134
void GMAudioInputManager_ptlib::close()
136
PTRACE(4, "GMAudioInputManager_ptlib\tClosing device " << current_state.device);
141
current_state.opened = false;
142
runtime.run_in_main (sigc::bind (device_closed.make_slot (), current_state.device));
145
void GMAudioInputManager_ptlib::set_buffer_size (unsigned buffer_size, unsigned num_buffers)
147
PTRACE(4, "GMAudioInputManager_ptlib\tSetting buffer size to " << buffer_size << "/" << num_buffers);
150
input_device->SetBuffers (buffer_size, num_buffers);
154
bool GMAudioInputManager_ptlib::get_frame_data (char *data,
156
unsigned & bytes_read)
161
if (!current_state.opened) {
162
PTRACE(1, "GMAudioInputManager_ptlib\tTrying to get frame from closed device");
167
ret = input_device->Read ((void*)data, size);
169
bytes_read = input_device->GetLastReadCount();
172
PTRACE(1, "GMAudioInputManager_ptlib\tEncountered error while trying to read data");
173
runtime.run_in_main (sigc::bind (device_error.make_slot (), current_state.device, Ekiga::AI_ERROR_READ));
179
void GMAudioInputManager_ptlib::set_volume (unsigned volume)
181
PTRACE(4, "GMAudioInputManager_ptlib\tSetting volume to " << volume);
183
input_device->SetVolume(volume);
186
bool GMAudioInputManager_ptlib::has_device(const std::string & source, const std::string & device_name, Ekiga::AudioInputDevice & device)
188
if (source == "alsa") {
189
device.type = DEVICE_TYPE;
190
device.source = "ALSA";
191
device.name = device_name;
194
/* if (source == "oss") {
195
device.type = DEVICE_TYPE;
196
device.source = "OSS";
197
device.device = device;