mainbuffer.h 4.13 KB
Newer Older
1
/*
2
 *  Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc.
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 *  Author : Alexandre Savard <alexandre.savard@savoirfairelinux.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 3 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., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20
21
22
23
24
25
26
27
28
29
 *
 *  Additional permission under GNU GPL version 3 section 7:
 *
 *  If you modify this program, or any covered work, by linking or
 *  combining it with the OpenSSL project's OpenSSL library (or a
 *  modified version of that library), containing parts covered by the
 *  terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
 *  grants you additional permission to convey the resulting work.
 *  Corresponding Source for a non-source form of such a combination
 *  shall include the source code for the parts of OpenSSL used as well
 *  as that of the covered work.
30
31
32
33
34
35
 */

#ifndef __MAIN_BUFFER__
#define __MAIN_BUFFER__

#include <map>
36
#include <set>
37
#include <cc++/thread.h> // for ost::Mutex
38
#include <string>
39
40
41
42
43

#include "../global.h"
#include "../call.h"
#include "ringbuffer.h"

44
45


46
47
typedef std::map<CallID, RingBuffer*> RingBufferMap;

48
49
50
typedef std::set<CallID> CallIDSet;

typedef std::map<CallID, CallIDSet*> CallIDMap;
51

52
53
class MainBuffer {

54
 public:
55
56
57
58
59

        MainBuffer();

        ~MainBuffer();

60
61
62
63
	void setInternalSamplingRate(int sr);

	int getInternalSamplingRate() {return _internalSamplingRate;}

64
65
66
67
68
69
	CallIDSet* getCallIDSet(CallID call_id);

	bool createCallIDSet(CallID set_id);

	bool removeCallIDSet(CallID set_id);

70
71
72
	/**
	 * Add a new call id to this set
	 */
73
74
75
76
	void addCallIDtoSet(CallID set_id, CallID call_id);

	void removeCallIDfromSet(CallID set_id, CallID call_id);

77
78
79
	/**
	 * Create a new ringbuffer with default readpointer
	 */
80
81
82
83
	RingBuffer* createRingBuffer(CallID call_id);

	bool removeRingBuffer(CallID call_id);

84
85
	void bindCallID(CallID call_id1, CallID call_id2 = default_id);

86
87
88
89
90
91
92
93
94
95
	/**
	 * Add a new call_id to unidirectional outgoing stream
	 * \param call_id New call id to be added for this stream
	 * \param process_id Process that require this stream
	 */
	void bindHalfDuplexOut(CallID process_id, CallID call_id = default_id);

	/**
	 * Unbind two calls
	 */
96
97
	void unBindCallID(CallID call_id1, CallID call_id2 = default_id);

98
99
	void unBindHalfDuplexOut(CallID process_id, CallID call_id = default_id);

100
101
	void unBindAll(CallID call_id);

102
103
	void unBindAllHalfDuplexOut(CallID process_id);

104
105
106
107
	int putData(void *buffer, int toCopy, unsigned short volume = 100, CallID call_id = default_id);

	int getData(void *buffer, int toCopy, unsigned short volume = 100, CallID call_id = default_id);

108
109
	int availForPut(CallID call_id = default_id);

110
	int availForGet(CallID call_id = default_id);
111

112
	int discard(int toDiscard, CallID call_id = default_id);
113

114
	void flush(CallID call_id = default_id);
115

116
117
	void flushAllBuffers();

118
	void flushDefault();
119

120
121
	void stateInfo();

122
    private:
123

124
125
	RingBuffer* getRingBuffer(CallID call_id);

126
	int getDataByID(void *buffer, int toCopy, unsigned short volume, CallID call_id, CallID reader_id);
127

128
	int availForGetByID(CallID call_id, CallID reader_id);
129

130
	int discardByID(int toDiscard, CallID call_id, CallID reader_id);
131

132
	void flushByID(CallID call_id, CallID reader_id);
133

134
135
	RingBufferMap _ringBufferMap;

136
137
	CallIDMap _callIDMap;

138
139
	SFLDataFormat* mixBuffer;

Alexandre Savard's avatar
Alexandre Savard committed
140
	// ost::Mutex _mutex;
141

142
143
	int _internalSamplingRate;

144
145
146
147
148
149
    public:

	friend class MainBufferTest;
};

#endif