ZegoAudioRoom
audio_in_output.h
Go to the documentation of this file.
1//
2// ZegoAudioInOutput.h
3// zegoavkit
4//
5// Copyright © 2017 Zego. All rights reserved.
6//
7#ifndef ZEGOAudioInOutput_h
8#define ZEGOAudioInOutput_h
9
10namespace AVE
11{
13 {
14 TYPE_PCM = 0x1001, //PCM
15 TYPE_PCM_TS_10MS = 0x1002, //PCM with ts and every frame is 10ms pcm data.
16 TYPE_PCM_10MS = 0x1003, //PCM without ts and every frame is 10ms pcm data.//engine inner use
17 TYPE_AAC_STREAM = 0x100A, //AAC encode data
18 TYPE_OPUS_STREAM = 0x100B, //opus encode data
19 };
20
21 /*
22 TYPE_PCM: Buffer data only contail pcm data.
23
24 |-----------------------------------------buffer data(bufLen)-----------------------------------|
25 |-----------------------------------------pcm data(pcmLen)--------------------------------------|
26
27 configLen = 0.
28 pcmLen = bufLen = 2 * samples * channels. (only need correct fill samples and channels, inner will calculate bufLen).
29
30
31 TYPE_AAC_STREAM: Buffer data is made up of specail config and encode data.
32
33 |-----------------------------------------buffer data(bufLen)-----------------------------------|
34 |----special config(configLen)------|-----------------encode data(encodeLen)--------------------|
35
36 encodeLen = bufLen - configLen.
37 if configLen == 0: indicate this frame only contain aac encode data.
38 if configLen == bufLen: indicate this frame only contain aac special config(encodeLen = bufLen - configLen = 0).
39 if (config != 0) && (configLen < bufLen): indicate this frame contain special config and encode data.
40 */
42 {
44 {
45 frameType = 0;
46 samples = 0;
48 channels = 0;
49 sampleRate = 0;
50 timeStamp = 0.0;
51 configLen = 0;
52 bufLen = 0;
53 buffer = 0;
54 }
55
56 int frameType; //refer to enum FrameType
57 int samples; //PCM:capture pcm samples at this input. AAC:aac encode one frame need samples
58 int bytesPerSample; //bytes per sample = 2 * channels, current bit depth only support 16bit(2 bytes).
59 int channels; //channels, 1 or 2.
60 int sampleRate; //PCM: capture sample rate; AAC: encode sample rate. supported [16k/32k/44.1k/48k]
61 double timeStamp; //time stamp, PCM: 0; AAC: 0 or encode timeStamp, if buffer data only contain special config fill 0.
62 //pre process callback: capture timestamp(ms);
63 //post process callback: signle stream: play timestamp(ms), mutil stream: ignore this value
64 int configLen; //aac special config Len, PCM: 0; AAC: range [0-64]. 0 indicate this frame not contain spcial config.
65 int bufLen; /*buffer Length, PCM bufLen = 2 * samples * channels(only need correct fill samples and channels,
66 not use filed bufLen). AAC encode data len = bufLen - configLen.*/
67 unsigned char* buffer; //data buffer, the caller is responsible for bufer allocate and release
68 };
69
71 {
72 public:
73 virtual void startCapture() = 0;
74 virtual void stopCapture() = 0;
75 virtual void startRender() = 0;
76 virtual void stopRender() = 0;
77 virtual bool onRecordAudioFrame(const AudioFrame& audioFrame) = 0;
78 virtual bool onPlaybackAudioFrame(AudioFrame& audioFrame) = 0;
79 virtual void onRefFrame(const AudioFrame& audioFrame) = 0;
80 };
81
82
84 {
85 bool bEncode; /*
86 bEncode == false, external prep output PCM data.
87 bEncode == true, external prep output AAC encode data(only support aac encode)
88 */
89 int nSampleRate; //pcm capture or encode sample rate, if 0 use sdk inner sample rate..
90 int nChannel; //pcm capture or encode channels. if 0 use sdk inner channels.
91 int nSamples; /*
92 bEncode == false, if nSamples == 0. use sdk inner samples, push 10ms audio data to external prep module once.
93 else push nSamples(nSamples >= 160 AND nSamples <= 2048) audio data to external prep module once,
94 some audio processing algorithm may need length not 10ms.
95
96 bEncode == true, AAC encode one frame need samples(480/512/1024/1960/2048).
97 */
99 {
100 bEncode = false;
101 nSampleRate = 0;
102 nChannel = 0;
103 nSamples = 0;
104 }
105
106 };
107
108 const int MAX_SAMPLES_IN_FRAME = 3200;
109 typedef void(*OnAudioProcCallback)(const AudioFrame& inFrame, AudioFrame& outFrame);
110 /*
111 const AudioFrame& inFrame:
112 caller fill the input data to handle,refer to struct AudioFrame:
113 AudioFrame.frameType = TYPE_PCM;
114 AudioFrame.timeStamp = 0;
115 AudioFrame.configLen = 0;
116 AudioFrame.bufLen = AudioFrame.samples * AudioFrame.channels * 2(bitDepthInByte);
117
118 AudioFrame& outFrame:
119 outFrame is used for receiving data after called handle.
120 caller(zego sdk)will allocate the outFrame.buffer and tell the outFrame.bufLen(allocated buffer length that store output data max length),
121 after the called handle. called will alert outFrame.configLen/outFrame.bufLen and write handled data in outFrame.buffer, needn't fill timeStamp.
122
123 if AACEncodeSet.bEncode = true, data after handling must be TYPE_AAC_STREAM:
124 outFrame.frameType = TYPE_AAC_STREAM;
125 outFrame.timeStamp = 0;
126
127 if AACEncodeSet.bEncode = false, data after handling must be TYPE_PCM:
128 outFrame.frameType = TYPE_PCM;
129 AudioFrame.timeStamp = 0;
130 AudioFrame.configLen = 0;
131 AudioFrame.bufLen = AudioFrame.samples * AudioFrame.channels * 2(bitDepthInByte);
132
133 PS:
134 Even without any treatment, you need copy data from inFrame to outFrame,else the outFrame.buffer is empty data(all zeros/000000....0000);
135 */
136
137 //SetExternalAudioPreProcCallback
138 /* for audio prep-process */
141
142 //SetExternalAudioPostProcCallback
143 /* for audio post-process only support now:
144 ExtPostpSet.bEncode = false; */
146 typedef void(*OnPostpCallback)(const char* streamId, const AudioFrame& inFrame, AudioFrame& outFrame);
147
148 //SetExternalAudioProcCallbackAfterLoopback
149 /* for audio process after loopback in encdoer module only support now:
150 ExtPostpSet.bEncode = false; */
151
153 {
154 public:
155 virtual int Process(const unsigned char *in, int inLen, int inSampleRate, int inChannels,
156 unsigned char *out, int *outLen, int outSampleRate, int outChannels) = 0;
157 };
158}
159
160#endif
Definition: audio_in_output.h:153
virtual int Process(const unsigned char *in, int inLen, int inSampleRate, int inChannels, unsigned char *out, int *outLen, int outSampleRate, int outChannels)=0
Definition: audio_in_output.h:71
virtual void startCapture()=0
virtual bool onRecordAudioFrame(const AudioFrame &audioFrame)=0
virtual void startRender()=0
virtual void onRefFrame(const AudioFrame &audioFrame)=0
virtual void stopCapture()=0
virtual void stopRender()=0
virtual bool onPlaybackAudioFrame(AudioFrame &audioFrame)=0
Definition: audio_capture.h:4
OnAudioProcCallback OnPrepCallback
Definition: audio_in_output.h:140
FrameType
Definition: audio_in_output.h:13
@ TYPE_AAC_STREAM
Definition: audio_in_output.h:17
@ TYPE_OPUS_STREAM
Definition: audio_in_output.h:18
@ TYPE_PCM_10MS
Definition: audio_in_output.h:16
@ TYPE_PCM_TS_10MS
Definition: audio_in_output.h:15
@ TYPE_PCM
Definition: audio_in_output.h:14
void(* OnPostpCallback)(const char *streamId, const AudioFrame &inFrame, AudioFrame &outFrame)
Definition: audio_in_output.h:146
void(* OnAudioProcCallback)(const AudioFrame &inFrame, AudioFrame &outFrame)
Definition: audio_in_output.h:109
const int MAX_SAMPLES_IN_FRAME
Definition: audio_in_output.h:108
Definition: audio_in_output.h:42
int frameType
Definition: audio_in_output.h:56
int bufLen
Definition: audio_in_output.h:65
int bytesPerSample
Definition: audio_in_output.h:58
int sampleRate
Definition: audio_in_output.h:60
unsigned char * buffer
Definition: audio_in_output.h:67
int configLen
Definition: audio_in_output.h:64
double timeStamp
Definition: audio_in_output.h:61
int channels
Definition: audio_in_output.h:59
AudioFrame()
Definition: audio_in_output.h:43
int samples
Definition: audio_in_output.h:57
Definition: audio_in_output.h:84
ExtAudioProcSet()
Definition: audio_in_output.h:98
int nChannel
Definition: audio_in_output.h:90
int nSamples
Definition: audio_in_output.h:91
int nSampleRate
Definition: audio_in_output.h:89
bool bEncode
Definition: audio_in_output.h:85