~ubuntu-branches/ubuntu/vivid/ekiga/vivid-proposed

« back to all changes in this revision

Viewing changes to lib/engine/audioinput/ptlib/audioinput-manager-ptlib.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kilian Krause
  • Date: 2011-07-17 00:24:50 UTC
  • mfrom: (5.1.5 upstream) (7.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20110717002450-ytg3wsrc1ptd3153
Tags: 3.3.1-1
* New upstream release.
 - Required libpt-dev 2.10 and libopal-dev 3.10
* Fix debian/watch to catch new version
* Remove libnotify0.7.patch - included upstream
* Add libboost-dev and libboost-signals-dev to Build-Depends
* debian/rules: Don't install *.la files for new internal shared libs
* Fix Vcs URIs to point to correct desktop/experimental/ekiga tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
/*
3
 
 * Ekiga -- A VoIP and Video-Conferencing application
4
 
 * Copyright (C) 2000-2008 Damien Sandras
5
 
 
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.
13
 
 *
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.
17
 
 *
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.
24
 
 */
25
 
 
26
 
 
27
 
/*
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
33
 
 
34
 
 *
35
 
 */
36
 
 
37
 
#include "audioinput-manager-ptlib.h"
38
 
#include "ptbuildopts.h"
39
 
#include "ptlib.h"
40
 
 
41
 
#define DEVICE_TYPE "PTLIB"
42
 
 
43
 
 
44
 
GMAudioInputManager_ptlib::GMAudioInputManager_ptlib (Ekiga::ServiceCore & _core)
45
 
: core (_core), 
46
 
  runtime (*(dynamic_cast<Ekiga::Runtime *> (_core.get ("runtime"))))
47
 
{
48
 
  current_state.opened = false;
49
 
  input_device = NULL;
50
 
  expectedFrameSize = 0;
51
 
}
52
 
 
53
 
void GMAudioInputManager_ptlib::get_devices(std::vector <Ekiga::AudioInputDevice> & devices)
54
 
{
55
 
  PStringArray audio_sources;
56
 
  PStringArray audio_devices;
57
 
  char **sources_array;
58
 
  char **devices_array;
59
 
 
60
 
  Ekiga::AudioInputDevice device;
61
 
  device.type   = DEVICE_TYPE;
62
 
 
63
 
  audio_sources = PSoundChannel::GetDriverNames ();
64
 
  sources_array = audio_sources.ToCharArray ();
65
 
  for (PINDEX i = 0; sources_array[i] != NULL; i++) {
66
 
 
67
 
    device.source = sources_array[i];
68
 
 
69
 
    if (device.source != "EKIGA") {
70
 
      audio_devices = PSoundChannel::GetDeviceNames (device.source, PSoundChannel::Recorder);
71
 
      devices_array = audio_devices.ToCharArray ();
72
 
 
73
 
      for (PINDEX j = 0; devices_array[j] != NULL; j++) {
74
 
 
75
 
        device.name = devices_array[j];
76
 
        devices.push_back(device);
77
 
      }
78
 
      free (devices_array);
79
 
    }
80
 
  }
81
 
  free (sources_array);
82
 
}
83
 
 
84
 
bool GMAudioInputManager_ptlib::set_device (const Ekiga::AudioInputDevice & device)
85
 
{
86
 
  if ( device.type == DEVICE_TYPE ) {
87
 
 
88
 
    PTRACE(4, "GMAudioInputManager_ptlib\tSetting Device " << device);
89
 
    current_state.device = device;
90
 
    return true;
91
 
  }
92
 
 
93
 
  return false;
94
 
}
95
 
 
96
 
bool GMAudioInputManager_ptlib::open (unsigned channels, unsigned samplerate, unsigned bits_per_sample)
97
 
{
98
 
  PTRACE(4, "GMAudioInputManager_ptlib\tOpening Device " << current_state.device);
99
 
  PTRACE(4, "GMAudioInputManager_ptlib\tOpening Device with " << channels << "-" << samplerate << "/" << bits_per_sample);
100
 
 
101
 
  current_state.channels        = channels;
102
 
  current_state.samplerate      = samplerate;
103
 
  current_state.bits_per_sample = bits_per_sample;
104
 
 
105
 
  input_device = PSoundChannel::CreateOpenedChannel (current_state.device.source, 
106
 
                                                     current_state.device.name,
107
 
                                                     PSoundChannel::Recorder,
108
 
                                                     channels,
109
 
                                                     samplerate,
110
 
                                                     bits_per_sample);
111
 
 
112
 
  Ekiga::AudioInputErrorCodes error_code = Ekiga::AI_ERROR_NONE;
113
 
  if (!input_device)
114
 
    error_code = Ekiga::AI_ERROR_DEVICE;
115
 
 
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));
119
 
    return false;
120
 
  }
121
 
 
122
 
  unsigned volume;
123
 
  input_device->GetVolume (volume);
124
 
  current_state.opened = true;
125
 
 
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));
130
 
 
131
 
  return true;
132
 
}
133
 
 
134
 
void GMAudioInputManager_ptlib::close()
135
 
{
136
 
  PTRACE(4, "GMAudioInputManager_ptlib\tClosing device " << current_state.device);
137
 
  if (input_device) {
138
 
     delete input_device;
139
 
     input_device = NULL;
140
 
  }
141
 
  current_state.opened = false;
142
 
  runtime.run_in_main (sigc::bind (device_closed.make_slot (), current_state.device));
143
 
}
144
 
 
145
 
void GMAudioInputManager_ptlib::set_buffer_size (unsigned buffer_size, unsigned num_buffers)
146
 
{
147
 
  PTRACE(4, "GMAudioInputManager_ptlib\tSetting buffer size to " << buffer_size << "/" <<  num_buffers);
148
 
 
149
 
  if (input_device)
150
 
    input_device->SetBuffers (buffer_size, num_buffers);
151
 
}
152
 
 
153
 
 
154
 
bool GMAudioInputManager_ptlib::get_frame_data (char *data, 
155
 
                                                unsigned size,
156
 
                                                unsigned & bytes_read)
157
 
{
158
 
  bool ret = false;
159
 
  bytes_read = 0;
160
 
 
161
 
  if (!current_state.opened) {
162
 
    PTRACE(1, "GMAudioInputManager_ptlib\tTrying to get frame from closed device");
163
 
    return false;
164
 
  }
165
 
 
166
 
  if (input_device) {
167
 
    ret = input_device->Read ((void*)data, size);
168
 
    if (ret) {
169
 
      bytes_read = input_device->GetLastReadCount();
170
 
    }
171
 
    else {
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));
174
 
    }
175
 
  }
176
 
  return ret;
177
 
}
178
 
 
179
 
void GMAudioInputManager_ptlib::set_volume (unsigned volume)
180
 
{
181
 
  PTRACE(4, "GMAudioInputManager_ptlib\tSetting volume to " << volume);
182
 
  if (input_device)
183
 
    input_device->SetVolume(volume);
184
 
}
185
 
 
186
 
bool GMAudioInputManager_ptlib::has_device(const std::string & source, const std::string & device_name, Ekiga::AudioInputDevice & device)
187
 
{
188
 
  if (source == "alsa") {
189
 
    device.type = DEVICE_TYPE;
190
 
    device.source = "ALSA";
191
 
    device.name = device_name;
192
 
    return true;
193
 
  }
194
 
/*  if (source == "oss") {
195
 
    device.type = DEVICE_TYPE;
196
 
    device.source = "OSS";
197
 
    device.device = device;
198
 
    return true;
199
 
  }*/
200
 
  return false;
201
 
}