~ubuntu-branches/ubuntu/maverick/ekiga/maverick

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Eugen Dedu, Eugen Dedu, Loic Minier
  • Date: 2008-09-27 10:00:00 UTC
  • mfrom: (1.1.8 upstream)
  • mto: (1.4.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 38.
  • Revision ID: james.westby@ubuntu.com-20080927100000-l5k5werb6czr5b3h
Tags: 3.0.1-1
[ Eugen Dedu ]
* New version.  (Closes: #500089).
* Add our own changelog file in /usr/share/doc.
* Remove gnomemeeting transitional package.
* Discover new interfaces.  (Closes: #488199).
* Compile with dbus support.  (Closes: #467212).
* Numeric keypad inserts digits at correct position.  (Closes: #440159).
* Use libnotify upon call.  (Closes: #412604).
* Symlink identical GNOME help files, to reduce size.  (Closes: #505536).
* Explicitely build-depends on a few dev packages, even if they were
  pulled out anyway by the other dependencies.

[ Loic Minier ]
* Use clean:: instead of clean: in rules.
* Don't disable Uploaders: generation for control.in -> control generation
  in rules.
* Fix some tabs which were size 4 anyway.
* Generate a PO template during build by calling intltool-update -p in
  install; thanks Ubuntu and Martin Pitt; closes: #505535.
* Also let the -dbg depend on ${misc:Depends}.
* Cleanup rules; in particular, use dpkg-parsechangelog and honor
  distclean/clean failures, remove old clean rules, commented out stuff,
  gtk-only stuff.
* Pass -s to dh_* in binary-arch.
* Use debian/*.links and debian/*.manpages instead of symlink manually or
  passing files to dh_installman.
* Use ftp.gnome.org in copyright.
* Switch to quilt and fix target deps in the process; build-dep on quilt
  instead of dpatch; rename news.dpatch to 00_news.patch and refresh;
  replace 00list with series.
* Install autotools-dev config.guess and .sub after patching.

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
 *                         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.
 
34
 *
 
35
 */
 
36
 
 
37
#include "audiooutput-manager-ptlib.h"
 
38
#include "ptbuildopts.h"
 
39
#include "ptlib.h"
 
40
 
 
41
#define DEVICE_TYPE "PTLIB"
 
42
 
 
43
GMAudioOutputManager_ptlib::GMAudioOutputManager_ptlib (Ekiga::ServiceCore & _core)
 
44
: core (_core),
 
45
  runtime (*(dynamic_cast<Ekiga::Runtime *> (_core.get ("runtime"))))
 
46
{
 
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;
 
51
}
 
52
 
 
53
void GMAudioOutputManager_ptlib::get_devices(std::vector <Ekiga::AudioOutputDevice> & devices)
 
54
{
 
55
  PStringArray audio_sources;
 
56
  PStringArray audio_devices;
 
57
  char **sources_array;
 
58
  char **devices_array;
 
59
 
 
60
  Ekiga::AudioOutputDevice 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::Player);
 
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 GMAudioOutputManager_ptlib::set_device (Ekiga::AudioOutputPS ps, const Ekiga::AudioOutputDevice & device)
 
85
{
 
86
  if ( device.type == DEVICE_TYPE ) {
 
87
 
 
88
    PTRACE(4, "GMAudioOutputManager_ptlib\tSetting Device[" << ps << "] " << device);
 
89
    current_state[ps].device = device;  
 
90
    return true;
 
91
  }
 
92
 
 
93
  return false;
 
94
}
 
95
 
 
96
bool GMAudioOutputManager_ptlib::open (Ekiga::AudioOutputPS ps, unsigned channels, unsigned samplerate, unsigned bits_per_sample)
 
97
{
 
98
  PTRACE(4, "GMAudioOutputManager_ptlib\tOpening Device " << current_state[ps].device);
 
99
  PTRACE(4, "GMAudioOutputManager_ptlib\tOpening Device with " << channels << "-" << samplerate << "/" << bits_per_sample);
 
100
 
 
101
  current_state[ps].channels        = channels;
 
102
  current_state[ps].samplerate      = samplerate;
 
103
  current_state[ps].bits_per_sample = bits_per_sample;
 
104
 
 
105
  output_device[ps] = PSoundChannel::CreateOpenedChannel (current_state[ps].device.source, 
 
106
                                                                        current_state[ps].device.name,
 
107
                                                                        PSoundChannel::Player,
 
108
                                                                        channels,
 
109
                                                                        samplerate,
 
110
                                                                        bits_per_sample);
 
111
 
 
112
  Ekiga::AudioOutputErrorCodes error_code = Ekiga::AO_ERROR_NONE;
 
113
  if (!output_device[ps])
 
114
    error_code = Ekiga::AO_ERROR_DEVICE;
 
115
 
 
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));
 
119
    return false;
 
120
  }
 
121
 
 
122
  unsigned volume;
 
123
  output_device[ps]->GetVolume (volume);
 
124
  current_state[ps].opened = true;
 
125
 
 
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));
 
130
 
 
131
  return true;
 
132
}
 
133
 
 
134
void GMAudioOutputManager_ptlib::close(Ekiga::AudioOutputPS ps)
 
135
{
 
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;
 
140
  }
 
141
  current_state[ps].opened = false;
 
142
  runtime.run_in_main (sigc::bind (device_closed.make_slot (), ps, current_state[ps].device));
 
143
}
 
144
 
 
145
void GMAudioOutputManager_ptlib::set_buffer_size (Ekiga::AudioOutputPS ps, unsigned buffer_size, unsigned num_buffers)
 
146
{
 
147
  PTRACE(4, "GMAudioOutputManager_ptlib\tSetting buffer size of device[" << ps << "] " << buffer_size << "/" <<  num_buffers);
 
148
 
 
149
  if (output_device[ps])
 
150
    output_device[ps]->SetBuffers (buffer_size, num_buffers);
 
151
}
 
152
 
 
153
 
 
154
bool GMAudioOutputManager_ptlib::set_frame_data (Ekiga::AudioOutputPS ps, 
 
155
                                   const char *data, 
 
156
                                   unsigned size,
 
157
                                   unsigned & bytes_written)
 
158
{
 
159
  bool ret = false;
 
160
  bytes_written = 0;
 
161
 
 
162
  if (!current_state[ps].opened) {
 
163
    PTRACE(1, "GMAudioOutputManager_ptlib\tTrying to get frame from closed device[" << ps << "]");
 
164
    return false;
 
165
  }
 
166
 
 
167
  if (output_device[ps]) {
 
168
    ret = output_device[ps]->Write ((void*)data, size);
 
169
    if (ret) {
 
170
      bytes_written = output_device[ps]->GetLastWriteCount();
 
171
    }
 
172
    else {
 
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));
 
175
 
 
176
    }
 
177
  }
 
178
  return ret;
 
179
}
 
180
 
 
181
void GMAudioOutputManager_ptlib::set_volume (Ekiga::AudioOutputPS ps, unsigned volume )
 
182
{
 
183
  PTRACE(4, "GMAudioOutputManager_ptlib\tSetting volume of device [" << ps << "] to " << volume);
 
184
  if (output_device[ps])
 
185
    output_device[ps]->SetVolume(volume);
 
186
}
 
187
 
 
188
bool GMAudioOutputManager_ptlib::has_device(const std::string & sink, const std::string & device_name, Ekiga::AudioOutputDevice & device)
 
189
{
 
190
  if (sink == "alsa") {
 
191
    device.type = DEVICE_TYPE;
 
192
    device.source = "ALSA";
 
193
    device.name = device_name;
 
194
    return true;
 
195
  }
 
196
/*  if (source == "oss") {
 
197
    device.type = DEVICE_TYPE;
 
198
    device.source = "OSS";
 
199
    device.device = device_name;
 
200
    return true;
 
201
  }*/
 
202
  return false;
 
203
}