-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathAudioRecorder.h
58 lines (41 loc) · 1.07 KB
/
AudioRecorder.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
#ifndef AUDIORECORDER_AUDIORECORDER_H
#define AUDIORECORDER_AUDIORECORDER_H
#ifdef WINDOWS
#include "ListAVDevices.h"
#endif
#include "ffmpeg.h"
#include <string>
#include <cstdint>
#ifdef __linux__
#include <atomic>
#include <thread>
#endif
using std::string;
class AudioRecorder {
private:
string outfile;
string deviceName;
string failReason;
AVFormatContext *audioInFormatCtx;
AVStream *audioInStream;
AVCodecContext *audioInCodecCtx;
SwrContext *audioConverter;
AVAudioFifo *audioFifo;
AVFormatContext *audioOutFormatCtx;
AVStream *audioOutStream;
AVCodecContext *audioOutCodecCtx;
std::atomic_bool isRun;
std::thread *audioThread;
void StartEncode();
public:
AudioRecorder(string filepath, string device)
:outfile(filepath),deviceName(device),failReason(""),isRun(false){}
void Open();
void Start();
void Stop();
~AudioRecorder() {
Stop();
}
std::string GetLastError() { return failReason; }
};
#endif //AUDIORECORDER_AUDIORECORDER_H