File: audioinput-manager-null.cpp

package info (click to toggle)
ekiga 4.0.1-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 31,612 kB
  • ctags: 14,511
  • sloc: cpp: 72,155; sh: 11,298; xml: 8,904; ansic: 8,572; makefile: 1,738; asm: 453; awk: 16
file content (152 lines) | stat: -rw-r--r-- 4,502 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
 * Ekiga -- A VoIP and Video-Conferencing application
 * Copyright (C) 2000-2009 Damien Sandras <dsandras@seconix.com>

 * This program is free software; you can  redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version. This program is distributed in the hope
 * that it will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * Ekiga is licensed under the GPL license and as a special exception, you
 * have permission to link or otherwise combine this program with the
 * programs OPAL, OpenH323 and PWLIB, and distribute the combination, without
 * applying the requirements of the GNU GPL to the OPAL, OpenH323 and PWLIB
 * programs, as long as you do follow the requirements of the GNU GPL for all
 * the rest of the software thus combined.
 */


/*
 *                         audioinput-manager-null.cpp  -  description
 *                         ------------------------------------------
 *   begin                : written in 2008 by Matthias Schneider
 *   copyright            : (c) 2008 by Matthias Schneider
 *   description          : declaration of a NULL audio input manager
 *
 */

#include "audioinput-manager-null.h"

#define DEVICE_TYPE   "Ekiga"
#define DEVICE_SOURCE "Ekiga"
#define DEVICE_NAME   "SILENT"

#if DEBUG
#define DEBUG_ARG(a) a
#else
#define DEBUG_ARG(a)
#endif

GMAudioInputManager_null::GMAudioInputManager_null (Ekiga::ServiceCore & _core)
:    core (_core)
{
  current_state.opened = false;
}

GMAudioInputManager_null::~GMAudioInputManager_null ()
{
}

void
GMAudioInputManager_null::get_devices(std::vector <Ekiga::AudioInputDevice> & DEBUG_ARG(devices))
{
#if DEBUG
  Ekiga::AudioInputDevice device;
  device.type   = DEVICE_TYPE;
  device.source = DEVICE_SOURCE;
  device.name   = DEVICE_NAME;
  devices.push_back(device);
#endif
}

bool
GMAudioInputManager_null::set_device (const Ekiga::AudioInputDevice & device)
{
  if ( ( device.type   == DEVICE_TYPE ) &&
       ( device.source == DEVICE_SOURCE) &&
       ( device.name   == DEVICE_NAME) ) {

    PTRACE(4, "GMAudioInputManager_null\tSetting Device " << device);
    current_state.device = device;
    return true;
  }
  return false;
}

bool
GMAudioInputManager_null::open (unsigned channels,
				unsigned samplerate,
				unsigned bits_per_sample)
{
  PTRACE(4, "GMAudioInputManager_null\tOpening Device " << current_state.device);
  PTRACE(4, "GMAudioInputManager_null\tOpening Device with " << channels << "-" << samplerate << "/" << bits_per_sample);

  current_state.channels        = channels;
  current_state.samplerate      = samplerate;
  current_state.bits_per_sample = bits_per_sample;
  current_state.opened = true;

  adaptive_delay.Restart();

  Ekiga::AudioInputSettings settings;
  settings.volume = 0;
  settings.modifyable = false;
  Ekiga::Runtime::run_in_main (boost::bind (&GMAudioInputManager_null::device_opened_in_main, this, current_state.device, settings));

  return true;
}

void
GMAudioInputManager_null::close()
{
  current_state.opened = false;
  Ekiga::Runtime::run_in_main (boost::bind (&GMAudioInputManager_null::device_closed_in_main, this, current_state.device));
}


bool
GMAudioInputManager_null::get_frame_data (char *data, 
					  unsigned size,
					  unsigned & bytes_read)
{
  if (!current_state.opened) {
    PTRACE(1, "GMAudioInputManager_null\tTrying to get frame from closed device");
    return true;
  }

  memset (data, 0, size);

  bytes_read = size;

  adaptive_delay.Delay(size * 8 / current_state.bits_per_sample * 1000 / current_state.samplerate);

  return true;
}

bool
GMAudioInputManager_null::has_device(const std::string & /*source*/,
				     const std::string & /*device_name*/,
				     Ekiga::AudioInputDevice & /*device*/)
{
  return false;
}

void
GMAudioInputManager_null::device_opened_in_main (Ekiga::AudioInputDevice device,
						 Ekiga::AudioInputSettings settings)
{
  device_opened (device, settings);
}

void
GMAudioInputManager_null::device_closed_in_main (Ekiga::AudioInputDevice device)
{
  device_closed (device);
}