change NULL to nullptr

dev
xufuji456 4 years ago
parent 74dca79a8f
commit 6480ebadde
  1. 39
      app/src/main/cpp/audio_player.cpp
  2. 10
      app/src/main/cpp/ffmpeg_pusher.cpp
  3. 50
      app/src/main/cpp/media_player.cpp
  4. 50
      app/src/main/cpp/openSL_audio_player.cpp
  5. 18
      app/src/main/cpp/video_player.cpp

@ -41,7 +41,7 @@ int init_volume_filter(AVFilterGraph **graph, AVFilterContext **src, AVFilterCon
const AVFilter *volume; const AVFilter *volume;
AVFilterContext *buffersink_ctx; AVFilterContext *buffersink_ctx;
const AVFilter *buffersink; const AVFilter *buffersink;
AVDictionary *options_dict = NULL; AVDictionary *options_dict = nullptr;
uint8_t ch_layout[64]; uint8_t ch_layout[64];
int ret; int ret;
@ -68,7 +68,7 @@ int init_volume_filter(AVFilterGraph **graph, AVFilterContext **src, AVFilterCon
av_opt_set (buffer_ctx, "sample_fmt", av_get_sample_fmt_name(inputFormat), AV_OPT_SEARCH_CHILDREN); av_opt_set (buffer_ctx, "sample_fmt", av_get_sample_fmt_name(inputFormat), AV_OPT_SEARCH_CHILDREN);
av_opt_set_q (buffer_ctx, "time_base", (AVRational){ 1, sample_rate }, AV_OPT_SEARCH_CHILDREN); av_opt_set_q (buffer_ctx, "time_base", (AVRational){ 1, sample_rate }, AV_OPT_SEARCH_CHILDREN);
av_opt_set_int(buffer_ctx, "sample_rate", sample_rate, AV_OPT_SEARCH_CHILDREN); av_opt_set_int(buffer_ctx, "sample_rate", sample_rate, AV_OPT_SEARCH_CHILDREN);
ret = avfilter_init_str(buffer_ctx, NULL); ret = avfilter_init_str(buffer_ctx, nullptr);
if (ret < 0) { if (ret < 0) {
LOGE(TAG, "Could not initialize the buffer filter:%d", ret); LOGE(TAG, "Could not initialize the buffer filter:%d", ret);
return ret; return ret;
@ -105,7 +105,7 @@ int init_volume_filter(AVFilterGraph **graph, AVFilterContext **src, AVFilterCon
LOGE(TAG, "Could not allocate the abuffersink instance..."); LOGE(TAG, "Could not allocate the abuffersink instance...");
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
ret = avfilter_init_str(buffersink_ctx, NULL); ret = avfilter_init_str(buffersink_ctx, nullptr);
if (ret < 0) { if (ret < 0) {
LOGE(TAG, "Could not initialize the abuffersink instance:%d", ret); LOGE(TAG, "Could not initialize the abuffersink instance:%d", ret);
return ret; return ret;
@ -119,7 +119,7 @@ int init_volume_filter(AVFilterGraph **graph, AVFilterContext **src, AVFilterCon
return ret; return ret;
} }
/* Configure the graph. */ /* Configure the graph. */
ret = avfilter_graph_config(filter_graph, NULL); ret = avfilter_graph_config(filter_graph, nullptr);
if (ret < 0) { if (ret < 0) {
LOGE(TAG, "Error configuring the filter graph:%d", ret); LOGE(TAG, "Error configuring the filter graph:%d", ret);
return ret; return ret;
@ -158,14 +158,14 @@ int init_equalizer_filter(const char *filter_desc, AVCodecContext *codecCtx, AVF
av_get_sample_fmt_name(codecCtx->sample_fmt), codecCtx->channel_layout); av_get_sample_fmt_name(codecCtx->sample_fmt), codecCtx->channel_layout);
ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in", ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in",
args, NULL, filter_graph); args, nullptr, filter_graph);
if (ret < 0) { if (ret < 0) {
LOGE(TAG, "Cannot create buffer source:%d", ret); LOGE(TAG, "Cannot create buffer source:%d", ret);
goto end; goto end;
} }
/* buffer audio sink: to terminate the filter chain. */ /* buffer audio sink: to terminate the filter chain. */
ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out", ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out",
NULL, NULL, filter_graph); nullptr, nullptr, filter_graph);
if (ret < 0) { if (ret < 0) {
LOGE(TAG, "Cannot create buffer sink:%d", ret); LOGE(TAG, "Cannot create buffer sink:%d", ret);
goto end; goto end;
@ -174,18 +174,18 @@ int init_equalizer_filter(const char *filter_desc, AVCodecContext *codecCtx, AVF
outputs->name = av_strdup("in"); outputs->name = av_strdup("in");
outputs->filter_ctx = buffersrc_ctx; outputs->filter_ctx = buffersrc_ctx;
outputs->pad_idx = 0; outputs->pad_idx = 0;
outputs->next = NULL; outputs->next = nullptr;
inputs->name = av_strdup("out"); inputs->name = av_strdup("out");
inputs->filter_ctx = buffersink_ctx; inputs->filter_ctx = buffersink_ctx;
inputs->pad_idx = 0; inputs->pad_idx = 0;
inputs->next = NULL; inputs->next = nullptr;
if ((ret = avfilter_graph_parse_ptr(filter_graph, filter_desc, if ((ret = avfilter_graph_parse_ptr(filter_graph, filter_desc,
&inputs, &outputs, NULL)) < 0) { &inputs, &outputs, nullptr)) < 0) {
LOGE(TAG, "avfilter_graph_parse_ptr error:%d", ret); LOGE(TAG, "avfilter_graph_parse_ptr error:%d", ret);
goto end; goto end;
} }
if ((ret = avfilter_graph_config(filter_graph, NULL)) < 0) { if ((ret = avfilter_graph_config(filter_graph, nullptr)) < 0) {
LOGE(TAG, "avfilter_graph_config error:%d", ret); LOGE(TAG, "avfilter_graph_config error:%d", ret);
goto end; goto end;
} }
@ -204,17 +204,17 @@ AUDIO_PLAYER_FUNC(void, play, jstring input_jstr, jstring filter_jstr) {
AVFilterContext *audioSrcContext; AVFilterContext *audioSrcContext;
AVFilterContext *audioSinkContext; AVFilterContext *audioSinkContext;
const char *input_cstr = env->GetStringUTFChars(input_jstr, NULL); const char *input_cstr = env->GetStringUTFChars(input_jstr, nullptr);
LOGI(TAG, "input url=%s", input_cstr); LOGI(TAG, "input url=%s", input_cstr);
filter_desc = env->GetStringUTFChars(filter_jstr, NULL); filter_desc = env->GetStringUTFChars(filter_jstr, nullptr);
LOGE(TAG, "filter_desc=%s", filter_desc); LOGE(TAG, "filter_desc=%s", filter_desc);
av_register_all(); av_register_all();
AVFormatContext *pFormatCtx = avformat_alloc_context(); AVFormatContext *pFormatCtx = avformat_alloc_context();
if (avformat_open_input(&pFormatCtx, input_cstr, NULL, NULL) != 0) { if (avformat_open_input(&pFormatCtx, input_cstr, nullptr, nullptr) != 0) {
LOGE(TAG, "Couldn't open the audio file!"); LOGE(TAG, "Couldn't open the audio file!");
return; return;
} }
if (avformat_find_stream_info(pFormatCtx, NULL) < 0) { if (avformat_find_stream_info(pFormatCtx, nullptr) < 0) {
LOGE(TAG, "Couldn't find stream info!"); LOGE(TAG, "Couldn't find stream info!");
return; return;
} }
@ -231,7 +231,7 @@ AUDIO_PLAYER_FUNC(void, play, jstring input_jstr, jstring filter_jstr) {
LOGE(TAG, "Couldn't find audio decoder!"); LOGE(TAG, "Couldn't find audio decoder!");
return; return;
} }
if (avcodec_open2(codecCtx, codec, NULL) < 0) { if (avcodec_open2(codecCtx, codec, nullptr) < 0) {
LOGE(TAG, "Couldn't open audio decoder"); LOGE(TAG, "Couldn't open audio decoder");
return; return;
} }
@ -247,8 +247,7 @@ AUDIO_PLAYER_FUNC(void, play, jstring input_jstr, jstring filter_jstr) {
swr_alloc_set_opts(swrCtx, swr_alloc_set_opts(swrCtx,
out_ch_layout, out_sample_fmt, out_sample_rate, out_ch_layout, out_sample_fmt, out_sample_rate,
in_ch_layout, in_sample_fmt, in_sample_rate, in_ch_layout, in_sample_fmt, in_sample_rate, 0, nullptr);
0, NULL);
swr_init(swrCtx); swr_init(swrCtx);
int out_channel = av_get_channel_layout_nb_channels(out_ch_layout); int out_channel = av_get_channel_layout_nb_channels(out_ch_layout);
jclass player_class = env->GetObjectClass(thiz); jclass player_class = env->GetObjectClass(thiz);
@ -316,11 +315,11 @@ AUDIO_PLAYER_FUNC(void, play, jstring input_jstr, jstring filter_jstr) {
//convert audio format //convert audio format
swr_convert(swrCtx, &out_buffer, MAX_AUDIO_FRAME_SIZE, swr_convert(swrCtx, &out_buffer, MAX_AUDIO_FRAME_SIZE,
(const uint8_t **) /*frame*/filter_frame->data, /*frame*/filter_frame->nb_samples); (const uint8_t **) /*frame*/filter_frame->data, /*frame*/filter_frame->nb_samples);
int out_buffer_size = av_samples_get_buffer_size(NULL, out_channel, int out_buffer_size = av_samples_get_buffer_size(nullptr, out_channel,
/*frame*/filter_frame->nb_samples, out_sample_fmt, 1); /*frame*/filter_frame->nb_samples, out_sample_fmt, 1);
jbyteArray audio_sample_array = env->NewByteArray(out_buffer_size); jbyteArray audio_sample_array = env->NewByteArray(out_buffer_size);
jbyte *sample_byte_array = env->GetByteArrayElements(audio_sample_array, NULL); jbyte *sample_byte_array = env->GetByteArrayElements(audio_sample_array, nullptr);
memcpy(sample_byte_array, out_buffer, (size_t) out_buffer_size); memcpy(sample_byte_array, out_buffer, (size_t) out_buffer_size);
env->ReleaseByteArrayElements(audio_sample_array, sample_byte_array, 0); env->ReleaseByteArrayElements(audio_sample_array, sample_byte_array, 0);
//call write method to play //call write method to play
@ -353,7 +352,7 @@ end:
AUDIO_PLAYER_FUNC(void, again, jstring filter_jstr) { AUDIO_PLAYER_FUNC(void, again, jstring filter_jstr) {
if (!filter_jstr) return; if (!filter_jstr) return;
filter_again = 1; filter_again = 1;
filter_desc = env->GetStringUTFChars(filter_jstr, NULL); filter_desc = env->GetStringUTFChars(filter_jstr, nullptr);
} }
AUDIO_PLAYER_FUNC(void, release) { AUDIO_PLAYER_FUNC(void, release) {

@ -18,7 +18,7 @@ extern "C" {
PUSHER_FUNC(jint, pushStream, jstring filePath, jstring liveUrl) { PUSHER_FUNC(jint, pushStream, jstring filePath, jstring liveUrl) {
AVFormatContext *in_format = NULL, *out_format = NULL; AVFormatContext *in_format = nullptr, *out_format = nullptr;
AVPacket packet; AVPacket packet;
const char *file_path, *live_url; const char *file_path, *live_url;
int video_index = -1; int video_index = -1;
@ -26,8 +26,8 @@ PUSHER_FUNC(jint, pushStream, jstring filePath, jstring liveUrl) {
int frame_index = 0; int frame_index = 0;
int64_t start_time = 0; int64_t start_time = 0;
file_path = env->GetStringUTFChars(filePath, NULL); file_path = env->GetStringUTFChars(filePath, nullptr);
live_url = env->GetStringUTFChars(liveUrl, NULL); live_url = env->GetStringUTFChars(liveUrl, nullptr);
LOGE(TAG, "file_path=%s", file_path); LOGE(TAG, "file_path=%s", file_path);
LOGE(TAG, "live_url=%s", live_url); LOGE(TAG, "live_url=%s", live_url);
@ -49,7 +49,7 @@ PUSHER_FUNC(jint, pushStream, jstring filePath, jstring liveUrl) {
} }
} }
av_dump_format(in_format, 0, file_path, 0); av_dump_format(in_format, 0, file_path, 0);
avformat_alloc_output_context2(&out_format, NULL, "flv", live_url); avformat_alloc_output_context2(&out_format, nullptr, "flv", live_url);
if (!out_format) { if (!out_format) {
LOGE(TAG, "could not alloc output context..."); LOGE(TAG, "could not alloc output context...");
ret = AVERROR_UNKNOWN; ret = AVERROR_UNKNOWN;
@ -84,7 +84,7 @@ PUSHER_FUNC(jint, pushStream, jstring filePath, jstring liveUrl) {
} }
} }
//Write header //Write header
ret = avformat_write_header(out_format, NULL); ret = avformat_write_header(out_format, nullptr);
if (ret < 0) { if (ret < 0) {
LOGE(TAG, "could not write header..."); LOGE(TAG, "could not write header...");
goto end; goto end;

@ -85,12 +85,12 @@ int init_input_format_context(MediaPlayer* player, const char* file_name){
//alloc format context //alloc format context
player->format_context = avformat_alloc_context(); player->format_context = avformat_alloc_context();
//open the input file //open the input file
if(avformat_open_input(&player->format_context, file_name, NULL, NULL)!=0) { if(avformat_open_input(&player->format_context, file_name, nullptr, nullptr)!=0) {
LOGE(TAG, "Couldn't open file:%s\n", file_name); LOGE(TAG, "Couldn't open file:%s\n", file_name);
return -1; return -1;
} }
//find the info of all streams //find the info of all streams
if(avformat_find_stream_info(player->format_context, NULL)<0) { if(avformat_find_stream_info(player->format_context, nullptr)<0) {
LOGE(TAG, "Couldn't find stream information."); LOGE(TAG, "Couldn't find stream information.");
return -1; return -1;
} }
@ -126,21 +126,21 @@ int init_codec_context(MediaPlayer* player){
player->video_codec_context = player->format_context->streams[player->video_stream_index]->codec; player->video_codec_context = player->format_context->streams[player->video_stream_index]->codec;
//find audio and video decoder //find audio and video decoder
player->video_codec = avcodec_find_decoder(player->video_codec_context->codec_id); player->video_codec = avcodec_find_decoder(player->video_codec_context->codec_id);
if(player->video_codec == NULL) { if(player->video_codec == nullptr) {
LOGE(TAG, "couldn't find video Codec."); LOGE(TAG, "couldn't find video Codec.");
return -1; return -1;
} }
if(avcodec_open2(player->video_codec_context, player->video_codec, NULL) < 0) { if(avcodec_open2(player->video_codec_context, player->video_codec, nullptr) < 0) {
LOGE(TAG, "Couldn't open video codec."); LOGE(TAG, "Couldn't open video codec.");
return -1; return -1;
} }
player->audio_codec_context = player->format_context->streams[player->audio_stream_index]->codec; player->audio_codec_context = player->format_context->streams[player->audio_stream_index]->codec;
player->audio_codec = avcodec_find_decoder(player->audio_codec_context->codec_id); player->audio_codec = avcodec_find_decoder(player->audio_codec_context->codec_id);
if( player->audio_codec == NULL) { if( player->audio_codec == nullptr) {
LOGE(TAG, "couldn't find audio Codec."); LOGE(TAG, "couldn't find audio Codec.");
return -1; return -1;
} }
if(avcodec_open2(player->audio_codec_context, player->audio_codec, NULL) < 0) { if(avcodec_open2(player->audio_codec_context, player->audio_codec, nullptr) < 0) {
LOGE(TAG, "Couldn't open audio codec."); LOGE(TAG, "Couldn't open audio codec.");
return -1; return -1;
} }
@ -188,7 +188,7 @@ void player_wait_for_frame(MediaPlayer *player, int64_t stream_time) {
//TODO: waiting util time out //TODO: waiting util time out
// pthread_cond_timeout_np(&player->cond, &player->mutex, // pthread_cond_timeout_np(&player->cond, &player->mutex,
// (unsigned int) (sleep_time / 1000ll)); // (unsigned int) (sleep_time / 1000ll));
gettimeofday(&now, NULL); gettimeofday(&now, nullptr);
timeout.tv_sec = now.tv_sec; timeout.tv_sec = now.tv_sec;
timeout.tv_nsec = static_cast<long>((now.tv_usec + sleep_time) * 1000); timeout.tv_nsec = static_cast<long>((now.tv_usec + sleep_time) * 1000);
pthread_cond_timedwait(&player->cond, &player->mutex, &timeout); pthread_cond_timedwait(&player->cond, &player->mutex, &timeout);
@ -204,7 +204,7 @@ int decode_video(MediaPlayer* player, AVPacket* packet){
ANativeWindow_Buffer windowBuffer; ANativeWindow_Buffer windowBuffer;
player->yuv_frame = av_frame_alloc(); player->yuv_frame = av_frame_alloc();
player->rgba_frame = av_frame_alloc(); player->rgba_frame = av_frame_alloc();
if(player->rgba_frame == NULL || player->yuv_frame == NULL) { if(player->rgba_frame == nullptr || player->yuv_frame == nullptr) {
LOGE(TAG, "Couldn't allocate video frame."); LOGE(TAG, "Couldn't allocate video frame.");
return -1; return -1;
} }
@ -224,9 +224,9 @@ int decode_video(MediaPlayer* player, AVPacket* packet){
player->video_height, player->video_height,
AV_PIX_FMT_RGBA, AV_PIX_FMT_RGBA,
SWS_BILINEAR, SWS_BILINEAR,
NULL, nullptr,
NULL, nullptr,
NULL); nullptr);
int frameFinished; int frameFinished;
//decode video frame //decode video frame
@ -285,7 +285,7 @@ void audio_decoder_prepare(MediaPlayer* player) {
swr_alloc_set_opts(player->swrContext, swr_alloc_set_opts(player->swrContext,
out_ch_layout, player->out_sample_fmt, player->out_sample_rate, out_ch_layout, player->out_sample_fmt, player->out_sample_rate,
in_ch_layout, in_sample_fmt, in_sample_rate, in_ch_layout, in_sample_fmt, in_sample_rate,
0, NULL); 0, nullptr);
swr_init(player->swrContext); swr_init(player->swrContext);
player->out_channel_nb = av_get_channel_layout_nb_channels(out_ch_layout); player->out_channel_nb = av_get_channel_layout_nb_channels(out_ch_layout);
} }
@ -332,7 +332,7 @@ int decode_audio(MediaPlayer* player, AVPacket* packet){
MAX_AUDIO_FRAME_SIZE, MAX_AUDIO_FRAME_SIZE,
(const uint8_t **)player->audio_frame->data, (const uint8_t **)player->audio_frame->data,
player->audio_frame->nb_samples); player->audio_frame->nb_samples);
int out_buffer_size = av_samples_get_buffer_size(NULL, int out_buffer_size = av_samples_get_buffer_size(nullptr,
player->out_channel_nb, player->out_channel_nb,
player->audio_frame->nb_samples, player->audio_frame->nb_samples,
player->out_sample_fmt, player->out_sample_fmt,
@ -346,11 +346,11 @@ int decode_audio(MediaPlayer* player, AVPacket* packet){
player_wait_for_frame(player, player->audio_clock + AUDIO_TIME_ADJUST_US); player_wait_for_frame(player, player->audio_clock + AUDIO_TIME_ADJUST_US);
} }
if(javaVM != NULL){ if(javaVM != nullptr){
JNIEnv * env; JNIEnv * env;
javaVM->AttachCurrentThread(&env, NULL); javaVM->AttachCurrentThread(&env, nullptr);
jbyteArray audio_sample_array = env->NewByteArray(out_buffer_size); jbyteArray audio_sample_array = env->NewByteArray(out_buffer_size);
jbyte* sample_byte_array = env->GetByteArrayElements(audio_sample_array,NULL); jbyte* sample_byte_array = env->GetByteArrayElements(audio_sample_array, nullptr);
memcpy(sample_byte_array, player->audio_buffer, (size_t) out_buffer_size); memcpy(sample_byte_array, player->audio_buffer, (size_t) out_buffer_size);
env->ReleaseByteArrayElements(audio_sample_array,sample_byte_array,0); env->ReleaseByteArrayElements(audio_sample_array,sample_byte_array,0);
//call write method of AudioTrack to play //call write method of AudioTrack to play
@ -432,7 +432,7 @@ MEDIA_PLAYER_FUNC(jint, setup, jstring filePath, jobject surface){
const char *file_name = env->GetStringUTFChars(filePath, JNI_FALSE); const char *file_name = env->GetStringUTFChars(filePath, JNI_FALSE);
int ret; int ret;
player = static_cast<MediaPlayer *>(malloc(sizeof(MediaPlayer))); player = static_cast<MediaPlayer *>(malloc(sizeof(MediaPlayer)));
if(player == NULL){ if(player == nullptr){
return -1; return -1;
} }
ret = init_input_format_context(player, file_name); ret = init_input_format_context(player, file_name);
@ -456,23 +456,23 @@ MEDIA_PLAYER_FUNC(jint, setup, jstring filePath, jobject surface){
} }
MEDIA_PLAYER_FUNC(jint, play){ MEDIA_PLAYER_FUNC(jint, play){
pthread_mutex_init(&player->mutex, NULL); pthread_mutex_init(&player->mutex, nullptr);
pthread_cond_init(&player->cond, NULL); pthread_cond_init(&player->cond, nullptr);
pthread_create(&player->write_thread, NULL, write_packet_to_queue, (void*)player); pthread_create(&player->write_thread, nullptr, write_packet_to_queue, (void*)player);
sleep(1); sleep(1);
player->start_time = 0; player->start_time = 0;
Decoder data1 = {player, player->video_stream_index}, *decoder_data1 = &data1; Decoder data1 = {player, player->video_stream_index}, *decoder_data1 = &data1;
pthread_create(&player->video_thread, NULL, decode_func, (void*)decoder_data1); pthread_create(&player->video_thread, nullptr, decode_func, (void*)decoder_data1);
Decoder data2 = {player, player->audio_stream_index}, *decoder_data2 = &data2; Decoder data2 = {player, player->audio_stream_index}, *decoder_data2 = &data2;
pthread_create(&player->audio_thread,NULL,decode_func,(void*)decoder_data2); pthread_create(&player->audio_thread, nullptr, decode_func, (void*)decoder_data2);
pthread_join(player->write_thread, NULL); pthread_join(player->write_thread, nullptr);
pthread_join(player->video_thread, NULL); pthread_join(player->video_thread, nullptr);
pthread_join(player->audio_thread, NULL); pthread_join(player->audio_thread, nullptr);
return 0; return 0;
} }

@ -24,15 +24,15 @@ extern "C" {
#define TAG "OpenSLPlayer" #define TAG "OpenSLPlayer"
//object of engine //object of engine
SLObjectItf engineObject = NULL; SLObjectItf engineObject = nullptr;
SLEngineItf engineEngine; SLEngineItf engineEngine;
//object of mixer //object of mixer
SLObjectItf outputMixObject = NULL; SLObjectItf outputMixObject = nullptr;
SLEnvironmentalReverbItf outputMixEnvironmentalReverb = NULL; SLEnvironmentalReverbItf outputMixEnvironmentalReverb = nullptr;
//object of buffer //object of buffer
SLObjectItf bqPlayerObject = NULL; SLObjectItf bqPlayerObject = nullptr;
SLPlayItf bqPlayerPlay; SLPlayItf bqPlayerPlay;
SLAndroidSimpleBufferQueueItf bqPlayerBufferQueue; SLAndroidSimpleBufferQueueItf bqPlayerBufferQueue;
SLEffectSendItf bqPlayerEffectSend; SLEffectSendItf bqPlayerEffectSend;
@ -63,7 +63,7 @@ int getPCM(void **pcm, size_t *pcmSize);
void bqPlayerCallback(SLAndroidSimpleBufferQueueItf bufferQueueItf, void *context) { void bqPlayerCallback(SLAndroidSimpleBufferQueueItf bufferQueueItf, void *context) {
bufferSize = 0; bufferSize = 0;
getPCM(&openBuffer, &bufferSize); getPCM(&openBuffer, &bufferSize);
if (NULL != openBuffer && 0 != bufferSize) { if (nullptr != openBuffer && 0 != bufferSize) {
SLresult result; SLresult result;
result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, openBuffer, bufferSize); result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, openBuffer, bufferSize);
if (result < 0) { if (result < 0) {
@ -77,7 +77,7 @@ void bqPlayerCallback(SLAndroidSimpleBufferQueueItf bufferQueueItf, void *contex
//create the engine of OpenSLES //create the engine of OpenSLES
void createEngine() { void createEngine() {
SLresult result; SLresult result;
result = slCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL); result = slCreateEngine(&engineObject, 0, nullptr, 0, nullptr, nullptr);
LOGI(TAG, "slCreateEngine=%d", result); LOGI(TAG, "slCreateEngine=%d", result);
result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE); result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE);
LOGI(TAG, "engineObject->Realize=%d", result); LOGI(TAG, "engineObject->Realize=%d", result);
@ -118,7 +118,7 @@ void createBufferQueueAudioPlayer(int rate, int channel, int bitsPerSample) {
SLDataSource audioSrc = {&buffer_queue, &format_pcm}; SLDataSource audioSrc = {&buffer_queue, &format_pcm};
SLDataLocator_OutputMix loc_outmix = {SL_DATALOCATOR_OUTPUTMIX, outputMixObject}; SLDataLocator_OutputMix loc_outmix = {SL_DATALOCATOR_OUTPUTMIX, outputMixObject};
SLDataSink audioSnk = {&loc_outmix, NULL}; SLDataSink audioSnk = {&loc_outmix, nullptr};
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};
@ -136,7 +136,7 @@ void createBufferQueueAudioPlayer(int rate, int channel, int bitsPerSample) {
&bqPlayerBufferQueue); &bqPlayerBufferQueue);
LOGI(TAG, "GetInterface bqPlayerBufferQueue=%d", result); LOGI(TAG, "GetInterface bqPlayerBufferQueue=%d", result);
result = (*bqPlayerBufferQueue)->RegisterCallback(bqPlayerBufferQueue, bqPlayerCallback, NULL); result = (*bqPlayerBufferQueue)->RegisterCallback(bqPlayerBufferQueue, bqPlayerCallback, nullptr);
LOGI(TAG, "RegisterCallback=%d", result); LOGI(TAG, "RegisterCallback=%d", result);
result = (*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_EFFECTSEND, result = (*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_EFFECTSEND,
@ -155,12 +155,12 @@ int createAudioPlayer(int *rate, int *channel, const char *file_name) {
av_register_all(); av_register_all();
aFormatCtx = avformat_alloc_context(); aFormatCtx = avformat_alloc_context();
if (avformat_open_input(&aFormatCtx, file_name, NULL, NULL) != 0) { if (avformat_open_input(&aFormatCtx, file_name, nullptr, nullptr) != 0) {
LOGE(TAG, "Couldn't open file:%s\n", file_name); LOGE(TAG, "Couldn't open file:%s\n", file_name);
return -1; return -1;
} }
if (avformat_find_stream_info(aFormatCtx, NULL) < 0) { if (avformat_find_stream_info(aFormatCtx, nullptr) < 0) {
LOGE(TAG, "Couldn't find stream information."); LOGE(TAG, "Couldn't find stream information.");
return -1; return -1;
} }
@ -184,7 +184,7 @@ int createAudioPlayer(int *rate, int *channel, const char *file_name) {
fprintf(stderr, "Unsupported codec!\n"); fprintf(stderr, "Unsupported codec!\n");
return -1; return -1;
} }
if (avcodec_open2(aCodecCtx, aCodec, NULL) < 0) { if (avcodec_open2(aCodecCtx, aCodec, nullptr) < 0) {
LOGE(TAG, "Could not open codec."); LOGE(TAG, "Could not open codec.");
return -1; return -1;
} }
@ -248,35 +248,35 @@ int releaseAudioPlayer() {
AUDIO_PLAYER_FUNC(void, playAudio, jstring filePath) { AUDIO_PLAYER_FUNC(void, playAudio, jstring filePath) {
int rate, channel; int rate, channel;
const char *file_name = env->GetStringUTFChars(filePath, NULL); const char *file_name = env->GetStringUTFChars(filePath, nullptr);
LOGI(TAG, "file_name=%s", file_name); LOGI(TAG, "file_name=%s", file_name);
createAudioPlayer(&rate, &channel, file_name); createAudioPlayer(&rate, &channel, file_name);
createEngine(); createEngine();
createBufferQueueAudioPlayer(rate, channel, SL_PCMSAMPLEFORMAT_FIXED_16); createBufferQueueAudioPlayer(rate, channel, SL_PCMSAMPLEFORMAT_FIXED_16);
bqPlayerCallback(bqPlayerBufferQueue, NULL); bqPlayerCallback(bqPlayerBufferQueue, nullptr);
} }
AUDIO_PLAYER_FUNC(void, stop) { AUDIO_PLAYER_FUNC(void, stop) {
if (bqPlayerObject != NULL) { if (bqPlayerObject != nullptr) {
(*bqPlayerObject)->Destroy(bqPlayerObject); (*bqPlayerObject)->Destroy(bqPlayerObject);
bqPlayerObject = NULL; bqPlayerObject = nullptr;
bqPlayerPlay = NULL; bqPlayerPlay = nullptr;
bqPlayerBufferQueue = NULL; bqPlayerBufferQueue = nullptr;
bqPlayerEffectSend = NULL; bqPlayerEffectSend = nullptr;
bqPlayerVolume = NULL; bqPlayerVolume = nullptr;
} }
if (outputMixObject != NULL) { if (outputMixObject != nullptr) {
(*outputMixObject)->Destroy(outputMixObject); (*outputMixObject)->Destroy(outputMixObject);
outputMixObject = NULL; outputMixObject = nullptr;
outputMixEnvironmentalReverb = NULL; outputMixEnvironmentalReverb = nullptr;
} }
if (engineObject != NULL) { if (engineObject != nullptr) {
(*engineObject)->Destroy(engineObject); (*engineObject)->Destroy(engineObject);
engineObject = NULL; engineObject = nullptr;
engineEngine = NULL; engineEngine = nullptr;
} }
releaseAudioPlayer(); releaseAudioPlayer();

@ -29,11 +29,11 @@ VIDEO_PLAYER_FUNC(jint, play, jstring filePath, jobject surface) {
LOGE(TAG, "open file:%s\n", file_name); LOGE(TAG, "open file:%s\n", file_name);
av_register_all(); av_register_all();
AVFormatContext *pFormatCtx = avformat_alloc_context(); AVFormatContext *pFormatCtx = avformat_alloc_context();
if (avformat_open_input(&pFormatCtx, file_name, NULL, NULL) != 0) { if (avformat_open_input(&pFormatCtx, file_name, nullptr, nullptr) != 0) {
LOGE(TAG, "Couldn't open file:%s\n", file_name); LOGE(TAG, "Couldn't open file:%s\n", file_name);
return -1; return -1;
} }
if (avformat_find_stream_info(pFormatCtx, NULL) < 0) { if (avformat_find_stream_info(pFormatCtx, nullptr) < 0) {
LOGE(TAG, "Couldn't find stream information."); LOGE(TAG, "Couldn't find stream information.");
return -1; return -1;
} }
@ -57,11 +57,11 @@ VIDEO_PLAYER_FUNC(jint, play, jstring filePath, jobject surface) {
AVCodecContext *pCodecCtx = pFormatCtx->streams[videoStream]->codec; AVCodecContext *pCodecCtx = pFormatCtx->streams[videoStream]->codec;
AVCodec *pCodec = avcodec_find_decoder(pCodecCtx->codec_id); AVCodec *pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
if (pCodec == NULL) { if (pCodec == nullptr) {
LOGE(TAG, "couldn't find Codec."); LOGE(TAG, "couldn't find Codec.");
return -1; return -1;
} }
if (avcodec_open2(pCodecCtx, pCodec, NULL) < 0) { if (avcodec_open2(pCodecCtx, pCodec, nullptr) < 0) {
LOGE(TAG, "Couldn't open codec."); LOGE(TAG, "Couldn't open codec.");
return -1; return -1;
} }
@ -72,13 +72,13 @@ VIDEO_PLAYER_FUNC(jint, play, jstring filePath, jobject surface) {
ANativeWindow_setBuffersGeometry(nativeWindow, videoWidth, videoHeight, ANativeWindow_setBuffersGeometry(nativeWindow, videoWidth, videoHeight,
WINDOW_FORMAT_RGBA_8888); WINDOW_FORMAT_RGBA_8888);
ANativeWindow_Buffer windowBuffer; ANativeWindow_Buffer windowBuffer;
if (avcodec_open2(pCodecCtx, pCodec, NULL) < 0) { if (avcodec_open2(pCodecCtx, pCodec, nullptr) < 0) {
LOGE(TAG, "Couldn't open codec."); LOGE(TAG, "Couldn't open codec.");
return -1; return -1;
} }
AVFrame *pFrame = av_frame_alloc(); AVFrame *pFrame = av_frame_alloc();
AVFrame *pFrameRGBA = av_frame_alloc(); AVFrame *pFrameRGBA = av_frame_alloc();
if (pFrameRGBA == NULL || pFrame == NULL) { if (pFrameRGBA == nullptr || pFrame == nullptr) {
LOGE(TAG, "Couldn't allocate video frame."); LOGE(TAG, "Couldn't allocate video frame.");
return -1; return -1;
} }
@ -96,9 +96,9 @@ VIDEO_PLAYER_FUNC(jint, play, jstring filePath, jobject surface) {
pCodecCtx->height, pCodecCtx->height,
AV_PIX_FMT_RGBA, AV_PIX_FMT_RGBA,
SWS_BILINEAR, SWS_BILINEAR,
NULL, nullptr,
NULL, nullptr,
NULL); nullptr);
int frameFinished; int frameFinished;
AVPacket packet; AVPacket packet;

Loading…
Cancel
Save