-
Notifications
You must be signed in to change notification settings - Fork 53
/
Audio.h
60 lines (54 loc) · 1.61 KB
/
Audio.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
#pragma once
#include "PacketQueue.h"
extern "C" {
#include <libavformat/avformat.h>
}
class Audio
{
public:
Audio();
~Audio();
const uint32_t BUFFERSIZE = 192000;// 缓冲区的大小
bool audioPlay();//音频播放
bool audioClose();//音频关闭
double getCurrentAudioClock();//获取当前音频时钟
int getStreamIndex();
void setStreamIndex(const int streamIndex);
int getAudioQueueSize();
void enqueuePacket(const AVPacket pkt);
AVPacket dequeuePacket();
uint8_t* getAudioBuff();
void setAudioBuff(uint8_t*& audioBuff);
uint32_t getAudioBuffSize();
void setAudioBuffSize(uint32_t audioBuffSize);
uint32_t getAudioBuffIndex();
void setAudioBuffIndex(uint32_t audioBuffIndex);
double getAudioClock();
void setAudioClock(const double &audioClock);
AVStream *getStream();
void setStream(AVStream *&stream);
AVCodecContext *getAVCodecContext();//获取音频解码器上下文
void setAVCodecContext(AVCodecContext *audioContext);
bool getIsPlaying();
void setPlaying(bool isPlaying);
void clearPacket();
void setVolume(int volume);
private:
AVCodecContext *audioContext;//音频解码器上下文
AVStream *stream; //音频流
double audioClock; // audio clock
PacketQueue audiaPackets;
uint8_t *audioBuff; // 解码后数据的缓冲空间
uint32_t audioBuffSize; // buffer中的字节数
uint32_t audioBuffIndex; // buffer中未发送数据的index
int streamIndex = -1;
bool isPlay = false;
};
/**
* 向设备发送audio数据的回调函数
*/
void audioCallback(void* userdata, Uint8 *stream, int len);
/**
* 解码Avpacket中的数据填充到缓冲空间
*/
int audioDecodeFrame(Audio*audio, uint8_t *audioBuffer, int bufferSize);