-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAACDecoder.cpp
More file actions
33 lines (29 loc) · 850 Bytes
/
AACDecoder.cpp
File metadata and controls
33 lines (29 loc) · 850 Bytes
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
#include "AACDecoder.h"
AACDecoder::AACDecoder()
: FFmpeg_Decoder(AV_CODEC_ID_AAC)
, pcmCallBack(nullptr) {
buf = new BYTE [MAX_BUF_SIZE];
}
AACDecoder::~AACDecoder() {
if(buf) {
delete [] buf;
buf = nullptr;
}
}
void AACDecoder::setPCMCallBack(PCMCallBack callback) {
this->pcmCallBack = callback;
}
void AACDecoder::handleOneFrame(AVFrame* frame) {
UINT32 data_size = av_get_bytes_per_sample(codec_ctx->sample_fmt);
if(data_size < 0) {
debug("failed to calculate data size");
return;
}
UINT32 len = 0;
for(int i=0; i < frame->nb_samples; ++i)
for(int ch=0; ch < codec_ctx->channels; ++ch) {
memcpy(buf + len, frame->data[ch] + data_size * i, data_size);
len += data_size;
}
pcmCallBack(buf, len);
}