From 6015d75c4c01cc69424bff82031aa84f2d504d93 Mon Sep 17 00:00:00 2001 From: xufuji456 <839789740@qq.com> Date: Sun, 21 Feb 2021 11:04:49 +0800 Subject: [PATCH] change openSL_audio_player.c to cpp --- app/CMakeLists.txt | 2 +- ...audio_player.c => openSL_audio_player.cpp} | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) rename app/src/main/cpp/{openSL_audio_player.c => openSL_audio_player.cpp} (97%) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 1d04fdf..3802ec9 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -26,7 +26,7 @@ add_library( # Sets the name of the library. src/main/cpp/ffmpeg/ffprobe.c src/main/cpp/ffmpeg/ffmpeg_hw.c src/main/cpp/audio_player.cpp - src/main/cpp/openSL_audio_player.c + src/main/cpp/openSL_audio_player.cpp src/main/cpp/video_player.cpp src/main/cpp/ffmpeg_pusher.cpp src/main/cpp/packet_queue.cpp diff --git a/app/src/main/cpp/openSL_audio_player.c b/app/src/main/cpp/openSL_audio_player.cpp similarity index 97% rename from app/src/main/cpp/openSL_audio_player.c rename to app/src/main/cpp/openSL_audio_player.cpp index 82412c4..cf97784 100644 --- a/app/src/main/cpp/openSL_audio_player.c +++ b/app/src/main/cpp/openSL_audio_player.cpp @@ -4,16 +4,23 @@ #include #include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif #include "libavcodec/avcodec.h" #include "libavformat/avformat.h" #include "libswscale/swscale.h" #include "libswresample/swresample.h" #include "libavutil/samplefmt.h" -#include -#include -#include -#include +#include "libavutil/opt.h" #include "ffmpeg_jni_define.h" +#ifdef __cplusplus +} +#endif #define TAG "OpenSLPlayer" @@ -162,7 +169,7 @@ int createAudioPlayer(int *rate, int *channel, const char *file_name) { int i; audioStream = -1; for (i = 0; i < aFormatCtx->nb_streams; i++) { - if (aFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO && + if (aFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && audioStream < 0) { audioStream = i; } @@ -242,7 +249,7 @@ int releaseAudioPlayer() { AUDIO_PLAYER_FUNC(void, playAudio, jstring filePath) { int rate, channel; - const char *file_name = (*env)->GetStringUTFChars(env, filePath, NULL); + const char *file_name = env->GetStringUTFChars(filePath, NULL); LOGI(TAG, "file_name=%s", file_name); createAudioPlayer(&rate, &channel, file_name);