File: MediaStreamItf.h

package info (click to toggle)
libtgvoip 2.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 9,004 kB
  • sloc: cpp: 61,331; ansic: 24,725; sh: 4,150; makefile: 749; asm: 242
file content (88 lines) | stat: -rw-r--r-- 2,126 bytes parent folder | download | duplicates (3)
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
//
// libtgvoip is free and unencumbered public domain software.
// For more information, see http://unlicense.org or the UNLICENSE file
// you should have received with this source code distribution.
//

#ifndef LIBTGVOIP_MEDIASTREAMINPUT_H
#define LIBTGVOIP_MEDIASTREAMINPUT_H

#include <string.h>
#include <vector>
#include <memory>
#include <stdint.h>
#include "threading.h"
#include "BlockingQueue.h"
#include "Buffers.h"

namespace tgvoip{

	class EchoCanceller;

class MediaStreamItf{
public:
	virtual void Start()=0;
	virtual void Stop()=0;
	void SetCallback(size_t (*f)(unsigned char*, size_t, void*), void* param);

//protected:
	size_t InvokeCallback(unsigned char* data, size_t length);

private:
	size_t (*callback)(unsigned char*, size_t, void*)=NULL;
	void* callbackParam;
};

	class AudioMixer : public MediaStreamItf{
	public:
		AudioMixer();
		virtual ~AudioMixer();
		void SetOutput(MediaStreamItf* output);
		virtual void Start();
		virtual void Stop();
		void AddInput(std::shared_ptr<MediaStreamItf> input);
		void RemoveInput(std::shared_ptr<MediaStreamItf> input);
		void SetInputVolume(std::shared_ptr<MediaStreamItf> input, float volumeDB);
		void SetEchoCanceller(EchoCanceller* aec);
	private:
		void RunThread();
		struct MixerInput{
			std::shared_ptr<MediaStreamItf> source;
			float multiplier;
		};
		Mutex inputsMutex;
		void DoCallback(unsigned char* data, size_t length);
		static size_t OutputCallback(unsigned char* data, size_t length, void* arg);
		std::vector<MixerInput> inputs;
		Thread* thread;
		BufferPool bufferPool;
		BlockingQueue<unsigned char*> processedQueue;
		Semaphore semaphore;
		EchoCanceller* echoCanceller;
		bool running;
	};

	class CallbackWrapper : public MediaStreamItf{
	public:
		CallbackWrapper(){};
		virtual ~CallbackWrapper(){};
		virtual void Start(){};
		virtual void Stop(){};

	};

	class AudioLevelMeter{
	public:
		AudioLevelMeter();
		float GetLevel();
		void Update(int16_t* samples, size_t count);
	private:
		int16_t absMax;
		int16_t count;
		int8_t currentLevel;
		int16_t currentLevelFullRange;
	};
};


#endif //LIBTGVOIP_MEDIASTREAMINPUT_H