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.h - description
29
* ------------------------------------------
30
* begin : written in 2008 by Matthias Schneider
31
* copyright : (c) 2008 by Matthias Schneider
32
* description : Declaration of the interface of an audioinput manager
33
* implementation backend.
38
#ifndef __AUDIOINPUT_MANAGER_H__
39
#define __AUDIOINPUT_MANAGER_H__
41
#include "audioinput-core.h"
47
* @addtogroup audioinput
51
/** Generic implementation for the Ekiga::AudioInputManager class.
53
* Each AudioInputManager will represent a specific backend able to record audio.
54
* Each AudioInputManager will manage one or more devices.
55
* The AudioInputCore will control the different managers and their devices.
57
class AudioInputManager
64
AudioInputManager () {}
68
virtual ~AudioInputManager () {}
71
/*** API for audio input ***/
73
/** Get a list of all devices supported by the manager.
74
* Add it to the list of devices already collected by the core.
75
* @param devices a vector of device names to be filled by the manager.
77
virtual void get_devices (std::vector <AudioInputDevice> & devices) = 0;
79
/** Set the current device.
80
* Must be called before opening the device.
81
* In case a different device of the same manager was opened before, it must be
82
* closed before setting the new device.
83
* @param device the device to be used.
85
virtual bool set_device (const AudioInputDevice & device) = 0;
88
* The device must be opened before calling get_frame_data(), set_buffer_size() and set_volume().
89
* Requires the set_device() to be called before.
90
* Returns false if the device cannot be opened. Also sends a GUI callback to the main thread in that case.
91
* @param channels number of channels (1=mono, 2=stereo).
92
* @param samplerate the samplerate.
93
* @param bits_per_sample the number bits per sample.
94
* @return true if the opening succeeded. False if the device cannot be opened.
96
virtual bool open (unsigned channels, unsigned samplerate, unsigned bits_per_sample) = 0;
100
virtual void close() {};
102
/** Set the buffer size.
103
* The buffer size must be set before calling get_frame_data().
104
* Requires the device to be opened.
105
* @param buffer_size the size of each buffer in bytes.
106
* @param num_buffers the number of buffers.
108
virtual void set_buffer_size (unsigned /*buffer_size*/, unsigned /*num_buffers*/) {};
110
/** Get one audio buffer.
111
* This function will block until the buffer is completely filled.
112
* Requires the device to be opened and the buffer size to be set.
113
* Returns false if reading the device fails. Also sends a GUI callback to the main thread in that case.
114
* @param data a pointer to the buffer that is to be filled. The memory has to be allocated already.
115
* @param size the size of the buffer to be filled.
116
* @param bytes_read returns the number of bytes actually read into the buffer. Should be equal to size.
117
* @return false if the reading failed.
119
virtual bool get_frame_data (char *data,
121
unsigned & bytes_read) = 0;
123
/** Set the volume level for the current device.
124
* Requires the device to be opened.
125
* @param volume the new volume (0..255).
127
virtual void set_volume (unsigned /*volume*/) {};
129
/** Returns true if a specific device is supported by the manager.
130
* If the device specified by source and device_name is supported by the manager, true
131
* is returned and an AudioOutputDevice structure filled with the respective details.
132
* This function is used by the core to map added or removed devices to managers and AudioOutputDevices.
133
* @param source the source type of the device (e.g. alsa, oss, etc.).
134
* @param device_name the name of the device.
135
* @param device in case the device is supported by the manager, this structure will be filled with the device details.
136
* @return true if the device is supported by the manager.
138
virtual bool has_device (const std::string & source, const std::string & device_name, AudioInputDevice & device) = 0;
141
/*** API to act on AudioInputDevice events ***/
143
/** This signal is emitted when an audio input device is opened.
144
* @param device the audio input device that was opened.
145
* @param config the current audio input device configuration (current volume, etc.).
147
sigc::signal<void, AudioInputDevice, AudioInputSettings> device_opened;
149
/** This signal is emitted when an audio input device is closed.
150
* @param device the audio input device that was closed.
152
sigc::signal<void, AudioInputDevice> device_closed;
154
/** This signal is emitted when an error occurs when opening a audio input device.
155
* @param device the audio input device that caused the error.
156
* @param error_code the audio input device error code.
158
sigc::signal<void, AudioInputDevice, AudioInputErrorCodes> device_error;
162
typedef struct ManagerState {
166
unsigned bits_per_sample;
167
AudioInputDevice device;
170
ManagerState current_state;