/
amb_capture.h
70 lines (52 loc) · 1.29 KB
/
amb_capture.h
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
#pragma once
#include <condition_variable>
#include <functional>
#include <mutex>
#include <queue>
#include <thread>
#include <pulse/simple.h>
#include "amb_buffers.h"
namespace amb {
using ::std::condition_variable;
using ::std::function;
using ::std::mutex;
using ::std::queue;
using ::std::thread;
class Capture
{
public:
typedef function<void(const int error)> ErrorHandlerType;
typedef function<void(const Buffer& buffer)> BufferHandlerType;
Capture(const ErrorHandlerType& error_handler,
const BufferHandlerType& full_buffer_handler);
~Capture();
int Open(const Metadata& metadata);
void Close();
int Start();
void Stop();
int ReturnBuffer(const Buffer& buffer);
private:
enum class MessageType {
kStop,
kBuffer,
};
struct Message {
MessageType type;
Buffer buffer;
};
static void StaticThreadEntry(Capture* capture);
void ThreadCapture();
ErrorHandlerType error_handler_;
BufferHandlerType full_buffer_handler_;
pa_simple* pulseaudio_handle_;
Buffers buffers_;
thread* thread_;
mutex message_lock_;
queue<Message> messages_;
condition_variable signal_;
Capture(const Capture&) = delete;
Capture(Capture&&) = delete;
Capture& operator=(const Capture&) = delete;
Capture& operator=(const Capture&&) = delete;
};
};