~ubuntu-branches/ubuntu/wily/sflphone/wily

« back to all changes in this revision

Viewing changes to daemon/src/audio/audiolayer.cpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (1.1.11)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: package-import@ubuntu.com-20140128182336-3xenud1kbnwmf3mz
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *  Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
 
2
 *  Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
3
3
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
4
4
 *  Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
5
5
 *
33
33
#include "audiolayer.h"
34
34
#include "audio/dcblocker.h"
35
35
#include "manager.h"
36
 
#include "scoped_lock.h"
37
 
 
38
 
unsigned int AudioLayer::captureGain_ = 100;
39
 
unsigned int AudioLayer::playbackGain_ = 100;
40
 
 
41
 
AudioLayer::AudioLayer()
42
 
    : isStarted_(false)
43
 
    , playbackMode_(NONE)
 
36
 
 
37
AudioLayer::AudioLayer(const AudioPreference &pref)
 
38
    : isCaptureMuted_(pref.getCaptureMuted())
 
39
    , isPlaybackMuted_(pref.getPlaybackMuted())
 
40
    , captureGain_(pref.getVolumemic())
 
41
    , playbackGain_(pref.getVolumespkr())
 
42
    , isStarted_(false)
44
43
    , urgentRingBuffer_(SIZEBUF, MainBuffer::DEFAULT_ID)
45
44
    , sampleRate_(Manager::instance().getMainBuffer().getInternalSamplingRate())
46
45
    , mutex_()
48
47
    , converter_(sampleRate_)
49
48
    , lastNotificationTime_(0)
50
49
{
51
 
    pthread_mutex_init(&mutex_, NULL);
52
50
    urgentRingBuffer_.createReadPointer(MainBuffer::DEFAULT_ID);
53
51
}
54
52
 
55
53
AudioLayer::~AudioLayer()
56
 
{
57
 
    pthread_mutex_destroy(&mutex_);
58
 
}
 
54
{}
59
55
 
60
56
void AudioLayer::flushMain()
61
57
{
62
 
    sfl::ScopedLock guard(mutex_);
 
58
    std::lock_guard<std::mutex> lock(mutex_);
63
59
    // should pass call id
64
60
    Manager::instance().getMainBuffer().flushAllBuffers();
65
61
}
66
62
 
67
63
void AudioLayer::flushUrgent()
68
64
{
69
 
    sfl::ScopedLock guard(mutex_);
 
65
    std::lock_guard<std::mutex> lock(mutex_);
70
66
    urgentRingBuffer_.flushAll();
71
67
}
72
68
 
73
 
void AudioLayer::putUrgent(void* buffer, int toCopy)
74
 
{
75
 
    sfl::ScopedLock guard(mutex_);
76
 
    urgentRingBuffer_.put(buffer, toCopy);
77
 
}
78
 
 
79
 
void AudioLayer::applyGain(SFLDataFormat *src , int samples, int gain)
80
 
{
81
 
    if (gain != 100)
82
 
        for (int i = 0 ; i < samples; i++)
83
 
            src[i] = src[i] * gain* 0.01;
 
69
void AudioLayer::putUrgent(AudioBuffer& buffer)
 
70
{
 
71
    std::lock_guard<std::mutex> lock(mutex_);
 
72
    urgentRingBuffer_.put(buffer);
84
73
}
85
74
 
86
75
// Notify (with a beep) an incoming call when there is already a call in progress
87
76
void AudioLayer::notifyIncomingCall()
88
77
{
89
 
    if (!Manager::instance().incomingCallWaiting())
 
78
    if (!Manager::instance().incomingCallsWaiting())
90
79
        return;
91
80
 
92
81
    time_t now = time(NULL);
103
92
 
104
93
    Tone tone("440/160", getSampleRate());
105
94
    unsigned int nbSample = tone.getSize();
106
 
    SFLDataFormat buf[nbSample];
107
 
    tone.getNext(buf, nbSample);
 
95
    AudioBuffer buf(nbSample, 1, 8000);
 
96
    tone.getNext(buf, 1.0);
108
97
 
109
98
    /* Put the data in the urgent ring buffer */
110
99
    flushUrgent();
111
 
    putUrgent(buf, sizeof buf);
 
100
    putUrgent(buf);
112
101
}
113