-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAlsaPlay.h
61 lines (57 loc) · 1.28 KB
/
AlsaPlay.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
#ifndef _Alsa_Play_H__
#define _Alsa_Play_H__
#include <alsa/asoundlib.h>
#include <pthread.h>
#include "RecvAudioJitterBuffer.h"
#include "UtilsPoisx.h"
static const int kMaxPlayDeviceNameSize = 128;
class AlsaPlay
{
public:
AlsaPlay(const char* pDevName, unsigned int iRate);
virtual ~AlsaPlay();
public:
void Start();
void Stop();
public:
void InputVoiceData(unsigned char *szData, unsigned int nSize);
private:
void Init();
bool InitJitterBufferMutex();
private:
bool TryOpenDev();
bool OpenDev();
void Close();
bool SetParams();
void StartReOpenDev();
void StopReOpenDev();
private:
static void* PlayAudioLoopThread(void *pParam);
static void* ReOpenDevThread(void *pParam);
void RunPlayAudioLoop();
void RunReOpenDev();
int LockJitterBufferMutex();
int UnLockJitterBufferMutex();
private:
snd_pcm_t *handle;
snd_pcm_format_t format;
snd_pcm_uframes_t period_size;
private:
unsigned int channels;
unsigned int rate;
unsigned int sample_size;
//uint8_t *buffer;
char *buffer;
//char *pBuffer;
RecvAudioJitterBuffer* m_pJitterBuffer;
volatile bool active;
char devName[kMaxPlayDeviceNameSize];
private:
EventStru *abort_event;
pthread_mutex_t bufMutex;
pthread_t playThread;
pthread_t reOpenThread;
AtomicBoolStruct *bPlay;
AtomicBoolStruct *bReOpen;
};
#endif