rename variable field

pull/209/head
xufuji456 3 years ago
parent d8529a6b24
commit 3f7fba0a0b
  1. 71
      app/src/main/cpp/opensl_audio_player.cpp

@ -25,47 +25,48 @@ extern "C" {
//object of engine //object of engine
SLObjectItf engineObject = nullptr; SLObjectItf engineObject = nullptr;
SLEngineItf engineEngine; SLEngineItf engineEngine = nullptr;
//object of mixer //object of mixer
SLObjectItf outputMixObject = nullptr; SLObjectItf outputMixObject = nullptr;
SLEnvironmentalReverbItf outputMixEnvironmentalReverb = nullptr; SLEnvironmentalReverbItf outputMixEnvironmentalReverb = nullptr;
//object of buffer //object of buffer
SLObjectItf bqPlayerObject = nullptr; SLPlayItf mPlayerPlay = nullptr;
SLPlayItf bqPlayerPlay; SLVolumeItf mPlayerVolume = nullptr;
SLAndroidSimpleBufferQueueItf bqPlayerBufferQueue; SLObjectItf mPlayerObject = nullptr;
SLEffectSendItf bqPlayerEffectSend; SLEffectSendItf mPlayerEffectSend = nullptr;
SLVolumeItf bqPlayerVolume; SLAndroidSimpleBufferQueueItf mPlayerBufferQueue = nullptr;
//audio effect //audio effect
const SLEnvironmentalReverbSettings reverbSettings = SL_I3DL2_ENVIRONMENT_PRESET_STONECORRIDOR;
void *openBuffer; void *openBuffer;
size_t bufferSize; size_t bufferSize;
uint8_t *outputBuffer; uint8_t *outputBuffer;
size_t outputBufferSize; size_t outputBufferSize;
const SLEnvironmentalReverbSettings reverbSettings = SL_I3DL2_ENVIRONMENT_PRESET_STONECORRIDOR;
AVPacket packet; AVPacket packet;
int audioStream; int audioStream;
AVFrame *aFrame; AVFrame *aFrame;
SwrContext *swr; SwrContext *swr;
int frame_count = 0;
AVFormatContext *aFormatCtx; AVFormatContext *aFormatCtx;
AVCodecContext *aCodecCtx; AVCodecContext *aCodecCtx;
int frame_count = 0;
int createAudioPlayer(int *rate, int *channel, const char *file_name);
int releaseAudioPlayer(); int releaseAudioPlayer();
int getPCM(void **pcm, size_t *pcmSize); int getPCMData(void **pcm, size_t *pcmSize);
int createAudioPlayer(int *rate, int *channel, const char *file_name);
//callback by player void audioCallback(SLAndroidSimpleBufferQueueItf bufferQueueItf, void *context) {
void bqPlayerCallback(SLAndroidSimpleBufferQueueItf bufferQueueItf, void *context) {
bufferSize = 0; bufferSize = 0;
getPCM(&openBuffer, &bufferSize); getPCMData(&openBuffer, &bufferSize);
if (nullptr != openBuffer && 0 != bufferSize) { if (nullptr != openBuffer && 0 != bufferSize) {
SLresult result; SLresult result;
result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, openBuffer, bufferSize); result = (*mPlayerBufferQueue)->Enqueue(mPlayerBufferQueue, openBuffer, bufferSize);
if (result < 0) { if (result < 0) {
LOGE(TAG, "Enqueue error..."); LOGE(TAG, "Enqueue error...");
} else { } else {
@ -93,7 +94,7 @@ int createEngine() {
LOGE(TAG, "engineObject->GetInterface error=%d", result); LOGE(TAG, "engineObject->GetInterface error=%d", result);
return result; return result;
} }
result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, 0, 0, 0); result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, 0, nullptr, nullptr);
if (result != SL_RESULT_SUCCESS) { if (result != SL_RESULT_SUCCESS) {
LOGE(TAG, "engineEngine->CreateOutputMix error=%d", result); LOGE(TAG, "engineEngine->CreateOutputMix error=%d", result);
return result; return result;
@ -139,27 +140,27 @@ int createBufferQueueAudioPlayer(int rate, int channel, int bitsPerSample) {
const SLInterfaceID ids[3] = {SL_IID_BUFFERQUEUE, SL_IID_EFFECTSEND, SL_IID_VOLUME}; const SLInterfaceID ids[3] = {SL_IID_BUFFERQUEUE, SL_IID_EFFECTSEND, SL_IID_VOLUME};
const SLboolean req[3] = {SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE}; const SLboolean req[3] = {SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE};
result = (*engineEngine)->CreateAudioPlayer(engineEngine, &bqPlayerObject, &audioSrc, &audioSnk, result = (*engineEngine)->CreateAudioPlayer(engineEngine, &mPlayerObject, &audioSrc, &audioSnk,
3, ids, req); 3, ids, req);
if (result != SL_RESULT_SUCCESS) { if (result != SL_RESULT_SUCCESS) {
LOGE(TAG, "outputMixObject->GetInterface error=%d", result); LOGE(TAG, "outputMixObject->GetInterface error=%d", result);
return result; return result;
} }
result = (*bqPlayerObject)->Realize(bqPlayerObject, SL_BOOLEAN_FALSE); result = (*mPlayerObject)->Realize(mPlayerObject, SL_BOOLEAN_FALSE);
if (result != SL_RESULT_SUCCESS) { if (result != SL_RESULT_SUCCESS) {
LOGE(TAG, "bqPlayerObject->Realize error=%d", result); LOGE(TAG, "mPlayerObject->Realize error=%d", result);
return result; return result;
} }
(*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_PLAY, &bqPlayerPlay); (*mPlayerObject)->GetInterface(mPlayerObject, SL_IID_PLAY, &mPlayerPlay);
(*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_BUFFERQUEUE, &bqPlayerBufferQueue); (*mPlayerObject)->GetInterface(mPlayerObject, SL_IID_BUFFERQUEUE, &mPlayerBufferQueue);
result = (*bqPlayerBufferQueue)->RegisterCallback(bqPlayerBufferQueue, bqPlayerCallback, nullptr); result = (*mPlayerBufferQueue)->RegisterCallback(mPlayerBufferQueue, audioCallback, nullptr);
if (result != SL_RESULT_SUCCESS) { if (result != SL_RESULT_SUCCESS) {
LOGE(TAG, "bqPlayerBufferQueue->RegisterCallback error=%d", result); LOGE(TAG, "mPlayerBufferQueue->RegisterCallback error=%d", result);
return result; return result;
} }
(*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_EFFECTSEND, &bqPlayerEffectSend); (*mPlayerObject)->GetInterface(mPlayerObject, SL_IID_EFFECTSEND, &mPlayerEffectSend);
(*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_VOLUME, &bqPlayerVolume); (*mPlayerObject)->GetInterface(mPlayerObject, SL_IID_VOLUME, &mPlayerVolume);
result = (*bqPlayerPlay)->SetPlayState(bqPlayerPlay, SL_PLAYSTATE_PLAYING); result = (*mPlayerPlay)->SetPlayState(mPlayerPlay, SL_PLAYSTATE_PLAYING);
return result; return result;
} }
@ -218,7 +219,7 @@ int createAudioPlayer(int *rate, int *channel, const char *file_name) {
return 0; return 0;
} }
int getPCM(void **pcm, size_t *pcmSize) { int getPCMData(void **pcm, size_t *pcmSize) {
while (av_read_frame(aFormatCtx, &packet) >= 0) { while (av_read_frame(aFormatCtx, &packet) >= 0) {
int frameFinished = 0; int frameFinished = 0;
//is audio stream //is audio stream
@ -272,17 +273,17 @@ AUDIO_PLAYER_FUNC(void, playAudio, jstring filePath) {
ret = createBufferQueueAudioPlayer(rate, channel, SL_PCMSAMPLEFORMAT_FIXED_16); ret = createBufferQueueAudioPlayer(rate, channel, SL_PCMSAMPLEFORMAT_FIXED_16);
if (ret < 0) if (ret < 0)
return; return;
bqPlayerCallback(bqPlayerBufferQueue, nullptr); bqPlayerCallback(mPlayerBufferQueue, nullptr);
} }
AUDIO_PLAYER_FUNC(void, stop) { AUDIO_PLAYER_FUNC(void, stop) {
if (bqPlayerObject != nullptr) { if (mPlayerObject != nullptr) {
(*bqPlayerObject)->Destroy(bqPlayerObject); (*mPlayerObject)->Destroy(mPlayerObject);
bqPlayerObject = nullptr; mPlayerObject = nullptr;
bqPlayerPlay = nullptr; mPlayerPlay = nullptr;
bqPlayerBufferQueue = nullptr; mPlayerBufferQueue = nullptr;
bqPlayerEffectSend = nullptr; mPlayerEffectSend = nullptr;
bqPlayerVolume = nullptr; mPlayerVolume = nullptr;
} }
if (outputMixObject != nullptr) { if (outputMixObject != nullptr) {

Loading…
Cancel
Save