-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudio_receiver.hpp
More file actions
48 lines (33 loc) · 1.06 KB
/
audio_receiver.hpp
File metadata and controls
48 lines (33 loc) · 1.06 KB
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
//
// Created by pengx on 2026/2/10.
//
#ifndef GB28181CONSOLE_AUDIO_RECEIVER_HPP
#define GB28181CONSOLE_AUDIO_RECEIVER_HPP
#include <atomic>
#include <functional>
#include <string>
#include <thread>
#include "ring_buffer.hpp"
class AudioReceiver {
public:
~AudioReceiver();
using AudioDataCallback = std::function<void(uint8_t* buffer, size_t len)>;
int initialize();
bool connectPlatform(const std::string& server_ip, uint16_t server_port) const;
void start(AudioDataCallback callback);
void stop();
private:
int _receive_socket_fd = -1;
std::atomic<bool> _is_thread_running{false};
std::thread _receive_thread;
AudioDataCallback _audio_callback;
// 环形缓冲区(256KB,可存储约1.6秒的PCMA数据@128kbps)
RingBuffer _ring_buffer{256 * 1024};
// G.711帧处理缓冲区(每帧160字节,20ms)
std::vector<uint8_t> _frame_buffer;
std::atomic<int> _frame_count{0};
void data_receive_loop();
// 处理音频帧
void handle_audio_frames();
};
#endif //GB28181CONSOLE_AUDIO_RECEIVER_HPP