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

« back to all changes in this revision

Viewing changes to daemon/src/audio/mainbuffer.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2015-01-07 14:51:16 UTC
  • mfrom: (4.3.5 sid)
  • Revision ID: package-import@ubuntu.com-20150107145116-yxnafinf4lrdvrmx
Tags: 1.4.1-0.1ubuntu1
* Merge with Debian, remaining changes:
 - Drop soprano, nepomuk build-dep
* Drop ubuntu patches, now upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *  Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
 
2
 *  Copyright (C) 2004-2014 Savoir-Faire Linux Inc.
3
3
 *  Author : Alexandre Savard <alexandre.savard@savoirfairelinux.com>
4
4
 *
5
5
 *  This program is free software; you can redistribute it and/or modify
31
31
#ifndef MAIN_BUFFER_H_
32
32
#define MAIN_BUFFER_H_
33
33
 
 
34
#include "audiobuffer.h"
 
35
#include "noncopyable.h"
 
36
 
34
37
#include <map>
35
38
#include <set>
36
39
#include <string>
37
40
#include <mutex>
38
 
 
39
 
#include "audiobuffer.h"
40
 
#include "mainbuffer.h"
41
 
#include "noncopyable.h"
 
41
#include <memory>
42
42
 
43
43
class RingBuffer;
44
44
 
53
53
 
54
54
        ~MainBuffer();
55
55
 
56
 
        void setInternalSamplingRate(int sr);
57
 
 
58
56
        int getInternalSamplingRate() const {
59
 
            return internalSamplingRate_;
60
 
        }
 
57
            return internalAudioFormat_.sample_rate;
 
58
        }
 
59
 
 
60
        AudioFormat getInternalAudioFormat() const {
 
61
            return internalAudioFormat_;
 
62
        }
 
63
 
 
64
        void setInternalSamplingRate(unsigned sr);
 
65
 
 
66
        void setInternalAudioFormat(AudioFormat format);
61
67
 
62
68
        /**
63
69
         * Bind together two audio streams so taht a client will be able
64
70
         * to put and get data specifying its callid only.
65
71
         */
66
 
        void bindCallID(const std::string &call_id1, const std::string &call_id2);
 
72
        void bindCallID(const std::string& call_id1, const std::string& call_id2);
67
73
 
68
74
        /**
69
75
         * Add a new call_id to unidirectional outgoing stream
70
76
         * \param call_id New call id to be added for this stream
71
77
         * \param process_id Process that require this stream
72
78
         */
73
 
        void bindHalfDuplexOut(const std::string &process_id, const std::string &call_id);
 
79
        void bindHalfDuplexOut(const std::string& process_id, const std::string& call_id);
74
80
 
75
81
        /**
76
82
         * Unbind two calls
77
83
         */
78
 
        void unBindCallID(const std::string &call_id1, const std::string &call_id2);
 
84
        void unBindCallID(const std::string& call_id1, const std::string& call_id2);
79
85
 
80
86
        /**
81
87
         * Unbind a unidirectional stream
82
88
         */
83
 
        void unBindHalfDuplexOut(const std::string &process_id, const std::string &call_id);
84
 
 
85
 
        void unBindAll(const std::string &call_id);
86
 
 
87
 
        void putData(AudioBuffer& buffer, const std::string &call_id);
88
 
 
89
 
        size_t getData(AudioBuffer& buffer, const std::string &call_id);
90
 
 
91
 
        size_t availableForGet(const std::string &call_id);
92
 
 
93
 
        size_t discard(size_t toDiscard, const std::string &call_id);
94
 
 
95
 
        void flush(const std::string &call_id);
 
89
        void unBindHalfDuplexOut(const std::string& process_id, const std::string& call_id);
 
90
 
 
91
        void unBindAll(const std::string& call_id);
 
92
 
 
93
        void putData(AudioBuffer& buffer, const std::string& call_id);
 
94
 
 
95
        bool waitForDataAvailable(const std::string& call_id, size_t min_data_length, const std::chrono::microseconds& max_wait) const;
 
96
 
 
97
        size_t getData(AudioBuffer& buffer, const std::string& call_id);
 
98
        size_t getAvailableData(AudioBuffer& buffer, const std::string& call_id);
 
99
 
 
100
        size_t availableForGet(const std::string& call_id) const;
 
101
 
 
102
        size_t discard(size_t toDiscard, const std::string& call_id);
 
103
 
 
104
        void flush(const std::string& call_id);
96
105
 
97
106
        void flushAllBuffers();
98
107
 
99
108
    private:
100
109
        NON_COPYABLE(MainBuffer);
101
110
 
102
 
        CallIDSet* getCallIDSet(const std::string &call_id);
103
 
 
104
 
        void createCallIDSet(const std::string &set_id);
105
 
 
106
 
        void removeCallIDSet(const std::string &set_id);
 
111
        bool hasCallIDSet(const std::string& call_id);
 
112
        std::shared_ptr<CallIDSet> getCallIDSet(const std::string& call_id);
 
113
        std::shared_ptr<CallIDSet> getCallIDSet(const std::string& call_id) const;
 
114
 
 
115
        void createCallIDSet(const std::string& set_id);
 
116
 
 
117
        void removeCallIDSet(const std::string& set_id);
107
118
 
108
119
        /**
109
120
         * Add a new call id to this set
110
121
         */
111
 
        void addCallIDtoSet(const std::string &set_id, const std::string &call_id);
 
122
        void addCallIDtoSet(const std::string& set_id, const std::string& call_id);
112
123
 
113
 
        void removeCallIDfromSet(const std::string &set_id, const std::string &call_id);
 
124
        void removeCallIDfromSet(const std::string& set_id, const std::string& call_id);
114
125
 
115
126
        /**
116
 
         * Create a new ringbuffer with default readpointer
 
127
         * Create a new ringbuffer with default readoffset
117
128
         */
118
 
        void createRingBuffer(const std::string &call_id);
119
 
 
120
 
        void removeRingBuffer(const std::string &call_id);
121
 
 
122
 
        RingBuffer* getRingBuffer(const std::string &call_id);
123
 
        const RingBuffer* getRingBuffer(const std::string & call_id) const;
124
 
 
125
 
        size_t getDataByID(AudioBuffer& buffer, const std::string &call_id, const std::string &reader_id);
126
 
 
127
 
        size_t availableForGetByID(const std::string &call_id, const std::string &reader_id) const;
128
 
 
129
 
        void discardByID(size_t toDiscard, const std::string &call_id, const std::string &reader_id);
130
 
 
131
 
        void flushByID(const std::string &call_id, const std::string &reader_id);
132
 
 
133
 
        typedef std::map<std::string, RingBuffer*> RingBufferMap;
134
 
        RingBufferMap ringBufferMap_;
135
 
 
136
 
        typedef std::map<std::string, CallIDSet*> CallIDMap;
137
 
        CallIDMap callIDMap_;
138
 
 
139
 
        std::mutex mutex_;
140
 
 
141
 
        int internalSamplingRate_;
142
 
 
143
 
        friend class MainBufferTest;
 
129
        void createRingBuffer(const std::string& call_id);
 
130
 
 
131
        void removeRingBuffer(const std::string& call_id);
 
132
 
 
133
        bool hasRingBuffer(const std::string& call_id);
 
134
        std::shared_ptr<RingBuffer> getRingBuffer(const std::string& call_id);
 
135
        std::shared_ptr<RingBuffer> getRingBuffer(const std::string& call_id) const;
 
136
 
 
137
        void removeReadOffsetFromRingBuffer(const std::string& call_id1,
 
138
                                             const std::string& call_id2);
 
139
 
 
140
        size_t getDataByID(AudioBuffer& buffer, const std::string& call_id, const std::string& reader_id);
 
141
 
 
142
        size_t availableForGetByID(const std::string& call_id, const std::string& reader_id) const;
 
143
 
 
144
        void discardByID(size_t toDiscard, const std::string& call_id, const std::string& reader_id);
 
145
 
 
146
        void flushByID(const std::string& call_id, const std::string& reader_id);
 
147
 
 
148
        typedef std::map<std::string, std::shared_ptr<RingBuffer> > RingBufferMap;
 
149
        RingBufferMap ringBufferMap_ = RingBufferMap{};
 
150
 
 
151
        typedef std::map<std::string, std::shared_ptr<CallIDSet> > CallIDMap;
 
152
        CallIDMap callIDMap_ = CallIDMap{};
 
153
 
 
154
        mutable std::recursive_mutex stateLock_ = {};
 
155
 
 
156
        AudioFormat internalAudioFormat_ = AudioFormat::MONO;
144
157
};
145
158
 
146
159
#endif  // MainBuffer