~ubuntu-branches/ubuntu/saucy/sflphone/saucy

« back to all changes in this revision

Viewing changes to sflphone-common/src/audio/ringbuffer.h

  • Committer: Bazaar Package Importer
  • Author(s): Francois Marier
  • Date: 2010-12-24 16:33:55 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20101224163355-tkvvikqxbrbav6up
Tags: 0.9.11-1
* New upstream release
* Add new build dependencies on libwebkit-dev and libyaml-dev

* Bump Standards-Version up to 3.9.1
* Bump debhelper compatibility to 8
* Patch another typo in the upstream code (lintian notice)

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
 
34
34
static CallID default_id = "audiolayer_id";
35
35
 
36
 
class RingBuffer {
37
 
  public:
38
 
    /**
39
 
     * Constructor
40
 
     * @param size  Size of the buffer to create
41
 
     */
42
 
    RingBuffer(int size, CallID call_id);
43
 
 
44
 
    /**
45
 
     * Destructor
46
 
     */
47
 
    ~RingBuffer();
48
 
 
49
 
    CallID getBufferId(){ return buffer_id; }
50
 
 
51
 
    /**
52
 
     * Reset the counters to 0
53
 
     */
54
 
    void flush (CallID call_id = default_id);
55
 
 
56
 
    void flushAll();
57
 
 
58
 
    int getReadPointer(CallID call_id = default_id);
59
 
 
60
 
    ReadPointer* getReadPointerList() { return &_readpointer; }
61
 
 
62
 
    int getSmallestReadPointer();
63
 
 
64
 
    void storeReadPointer(int pointer_value, CallID call_id = default_id);
65
 
 
66
 
    void createReadPointer(CallID call_id = default_id);
67
 
 
68
 
    void removeReadPointer(CallID call_id = default_id);
69
 
 
70
 
    bool hasThisReadPointer(CallID call_id);
71
 
 
72
 
    int getNbReadPointer();
73
 
 
74
 
    /**
75
 
     * To get how much space is available in the buffer to write in
76
 
     * @return int The available size
77
 
     */
78
 
    int AvailForPut (void);
79
 
 
80
 
    /**
81
 
     * Write data in the ring buffer
82
 
     * @param buffer Data to copied
83
 
     * @param toCopy Number of bytes to copy
84
 
     * @param volume The volume
85
 
     * @return int Number of bytes copied
86
 
     */
87
 
    int Put (void* buffer, int toCopy, unsigned short volume = 100);
88
 
 
89
 
    /**
90
 
     * To get how much space is available in the buffer to read in
91
 
     * @return int The available size
92
 
     */
93
 
    int AvailForGet (CallID call_id = default_id);
94
 
 
95
 
    /**
96
 
     * Get data in the ring buffer
97
 
     * @param buffer Data to copied
98
 
     * @param toCopy Number of bytes to copy
99
 
     * @param volume The volume
100
 
     * @return int Number of bytes copied
101
 
     */
102
 
    int Get (void* buffer, int toCopy, unsigned short volume = 100, CallID call_id = default_id);
103
 
 
104
 
    /**
105
 
     * Discard data from the buffer
106
 
     * @param toDiscard Number of bytes to discard
107
 
     * @return int Number of bytes discarded 
108
 
     */
109
 
    int Discard(int toDiscard, CallID call_id = default_id);
110
 
 
111
 
    /**
112
 
     * Total length of the ring buffer
113
 
     * @return int  
114
 
     */
115
 
    int putLen();
116
 
 
117
 
    int getLen(CallID call_id = default_id);
118
 
    
119
 
    /**
120
 
     * Debug function print mEnd, mStart, mBufferSize
121
 
     */
122
 
    void debug();
123
 
 
124
 
  private:
125
 
    // Copy Constructor
126
 
    RingBuffer(const RingBuffer& rh);
127
 
 
128
 
    // Assignment operator
129
 
    RingBuffer& operator=(const RingBuffer& rh);
130
 
 
131
 
    /** Pointer on the first data */
132
 
    // int           mStart;
133
 
    /** Pointer on the last data */
134
 
    int           mEnd;
135
 
    /** Buffer size */
136
 
    int           mBufferSize;
137
 
    /** Data */
138
 
    samplePtr     mBuffer;
139
 
 
140
 
    ReadPointer   _readpointer;
141
 
 
142
 
    CallID buffer_id;
143
 
 
144
 
  public:
145
 
 
146
 
    friend class MainBufferTest;
147
 
 
148
 
    std::fstream *buffer_input_rec;
149
 
    std::fstream *buffer_output_rec;
150
 
 
151
 
    static int count_rb;
152
 
    
 
36
class RingBuffer
 
37
{
 
38
    public:
 
39
        /**
 
40
         * Constructor
 
41
         * @param size  Size of the buffer to create
 
42
         */
 
43
        RingBuffer (int size, CallID call_id = default_id);
 
44
 
 
45
        /**
 
46
         * Destructor
 
47
         */
 
48
        ~RingBuffer();
 
49
 
 
50
        CallID getBufferId() {
 
51
            return buffer_id;
 
52
        }
 
53
 
 
54
        /**
 
55
         * Reset the counters to 0 for this read pointer
 
56
         */
 
57
        void flush (CallID call_id = default_id);
 
58
 
 
59
        void flushAll();
 
60
 
 
61
        /**
 
62
         * Get read pointer coresponding to this call
 
63
         */
 
64
        int getReadPointer (CallID call_id = default_id);
 
65
 
 
66
        /**
 
67
         * Get the whole readpointer list for this ringbuffer
 
68
         */
 
69
        ReadPointer* getReadPointerList() {
 
70
            return &_readpointer;
 
71
        }
 
72
 
 
73
        /**
 
74
         * Return the smalest readpointer. Usefull to evaluate if ringbuffer is full
 
75
         */
 
76
        int getSmallestReadPointer();
 
77
 
 
78
        /**
 
79
         * Move readpointer forward by pointer_value
 
80
         */
 
81
        void storeReadPointer (int pointer_value, CallID call_id = default_id);
 
82
 
 
83
        /**
 
84
         * Add a new readpointer for this ringbuffer
 
85
         */
 
86
        void createReadPointer (CallID call_id = default_id);
 
87
 
 
88
        /**
 
89
         * Remove a readpointer for this ringbuffer
 
90
         */
 
91
        void removeReadPointer (CallID call_id = default_id);
 
92
 
 
93
        /**
 
94
         * Test if readpointer coresponding to this call is still active
 
95
         */
 
96
        bool hasThisReadPointer (CallID call_id);
 
97
 
 
98
        int getNbReadPointer();
 
99
 
 
100
        /**
 
101
         * To get how much space is available in the buffer to write in
 
102
         * @return int The available size
 
103
         */
 
104
        int AvailForPut (void);
 
105
 
 
106
        /**
 
107
         * Write data in the ring buffer
 
108
         * @param buffer Data to copied
 
109
         * @param toCopy Number of bytes to copy
 
110
         * @param volume The volume
 
111
         * @return int Number of bytes copied
 
112
         */
 
113
        int Put (void* buffer, int toCopy, unsigned short volume = 100);
 
114
 
 
115
        /**
 
116
         * To get how much space is available in the buffer to read in
 
117
         * @return int The available size
 
118
         */
 
119
        int AvailForGet (CallID call_id = default_id);
 
120
 
 
121
        /**
 
122
         * Get data in the ring buffer
 
123
         * @param buffer Data to copied
 
124
         * @param toCopy Number of bytes to copy
 
125
         * @param volume The volume
 
126
         * @return int Number of bytes copied
 
127
         */
 
128
        int Get (void* buffer, int toCopy, unsigned short volume = 100, CallID call_id = default_id);
 
129
 
 
130
        /**
 
131
         * Discard data from the buffer
 
132
         * @param toDiscard Number of bytes to discard
 
133
         * @return int Number of bytes discarded
 
134
         */
 
135
        int Discard (int toDiscard, CallID call_id = default_id);
 
136
 
 
137
        /**
 
138
         * Total length of the ring buffer
 
139
         * @return int
 
140
         */
 
141
        int putLen();
 
142
 
 
143
        int getLen (CallID call_id = default_id);
 
144
 
 
145
        /**
 
146
         * Debug function print mEnd, mStart, mBufferSize
 
147
         */
 
148
        void debug();
 
149
 
 
150
    private:
 
151
        // Copy Constructor
 
152
        RingBuffer (const RingBuffer& rh);
 
153
 
 
154
        // Assignment operator
 
155
        RingBuffer& operator= (const RingBuffer& rh);
 
156
 
 
157
        /** Pointer on the first data */
 
158
        // int           mStart;
 
159
        /** Pointer on the last data */
 
160
        int           mEnd;
 
161
        /** Buffer size */
 
162
        int           mBufferSize;
 
163
        /** Data */
 
164
        samplePtr     mBuffer;
 
165
 
 
166
        ReadPointer   _readpointer;
 
167
 
 
168
        CallID buffer_id;
 
169
 
 
170
    public:
 
171
 
 
172
        friend class MainBufferTest;
 
173
 
 
174
        std::fstream *buffer_input_rec;
 
175
        std::fstream *buffer_output_rec;
 
176
 
 
177
        static int count_rb;
 
178
 
153
179
};
154
180
 
155
181