|
|
|
@ -41,7 +41,7 @@ int init_volume_filter(AVFilterGraph **graph, AVFilterContext **src, AVFilterCon |
|
|
|
|
const AVFilter *volume; |
|
|
|
|
AVFilterContext *buffersink_ctx; |
|
|
|
|
const AVFilter *buffersink; |
|
|
|
|
AVDictionary *options_dict = NULL; |
|
|
|
|
AVDictionary *options_dict = nullptr; |
|
|
|
|
uint8_t ch_layout[64]; |
|
|
|
|
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_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); |
|
|
|
|
ret = avfilter_init_str(buffer_ctx, NULL); |
|
|
|
|
ret = avfilter_init_str(buffer_ctx, nullptr); |
|
|
|
|
if (ret < 0) { |
|
|
|
|
LOGE(TAG, "Could not initialize the buffer filter:%d", ret); |
|
|
|
|
return ret; |
|
|
|
@ -105,7 +105,7 @@ int init_volume_filter(AVFilterGraph **graph, AVFilterContext **src, AVFilterCon |
|
|
|
|
LOGE(TAG, "Could not allocate the abuffersink instance..."); |
|
|
|
|
return AVERROR(ENOMEM); |
|
|
|
|
} |
|
|
|
|
ret = avfilter_init_str(buffersink_ctx, NULL); |
|
|
|
|
ret = avfilter_init_str(buffersink_ctx, nullptr); |
|
|
|
|
if (ret < 0) { |
|
|
|
|
LOGE(TAG, "Could not initialize the abuffersink instance:%d", ret); |
|
|
|
|
return ret; |
|
|
|
@ -119,7 +119,7 @@ int init_volume_filter(AVFilterGraph **graph, AVFilterContext **src, AVFilterCon |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
/* Configure the graph. */ |
|
|
|
|
ret = avfilter_graph_config(filter_graph, NULL); |
|
|
|
|
ret = avfilter_graph_config(filter_graph, nullptr); |
|
|
|
|
if (ret < 0) { |
|
|
|
|
LOGE(TAG, "Error configuring the filter graph:%d", 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); |
|
|
|
|
|
|
|
|
|
ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in", |
|
|
|
|
args, NULL, filter_graph); |
|
|
|
|
args, nullptr, filter_graph); |
|
|
|
|
if (ret < 0) { |
|
|
|
|
LOGE(TAG, "Cannot create buffer source:%d", ret); |
|
|
|
|
goto end; |
|
|
|
|
} |
|
|
|
|
/* buffer audio sink: to terminate the filter chain. */ |
|
|
|
|
ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out", |
|
|
|
|
NULL, NULL, filter_graph); |
|
|
|
|
nullptr, nullptr, filter_graph); |
|
|
|
|
if (ret < 0) { |
|
|
|
|
LOGE(TAG, "Cannot create buffer sink:%d", ret); |
|
|
|
|
goto end; |
|
|
|
@ -174,18 +174,18 @@ int init_equalizer_filter(const char *filter_desc, AVCodecContext *codecCtx, AVF |
|
|
|
|
outputs->name = av_strdup("in"); |
|
|
|
|
outputs->filter_ctx = buffersrc_ctx; |
|
|
|
|
outputs->pad_idx = 0; |
|
|
|
|
outputs->next = NULL; |
|
|
|
|
outputs->next = nullptr; |
|
|
|
|
inputs->name = av_strdup("out"); |
|
|
|
|
inputs->filter_ctx = buffersink_ctx; |
|
|
|
|
inputs->pad_idx = 0; |
|
|
|
|
inputs->next = NULL; |
|
|
|
|
inputs->next = nullptr; |
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
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); |
|
|
|
|
goto end; |
|
|
|
|
} |
|
|
|
@ -204,17 +204,17 @@ AUDIO_PLAYER_FUNC(void, play, jstring input_jstr, jstring filter_jstr) { |
|
|
|
|
AVFilterContext *audioSrcContext; |
|
|
|
|
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); |
|
|
|
|
filter_desc = env->GetStringUTFChars(filter_jstr, NULL); |
|
|
|
|
filter_desc = env->GetStringUTFChars(filter_jstr, nullptr); |
|
|
|
|
LOGE(TAG, "filter_desc=%s", filter_desc); |
|
|
|
|
av_register_all(); |
|
|
|
|
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!"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (avformat_find_stream_info(pFormatCtx, NULL) < 0) { |
|
|
|
|
if (avformat_find_stream_info(pFormatCtx, nullptr) < 0) { |
|
|
|
|
LOGE(TAG, "Couldn't find stream info!"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
@ -231,7 +231,7 @@ AUDIO_PLAYER_FUNC(void, play, jstring input_jstr, jstring filter_jstr) { |
|
|
|
|
LOGE(TAG, "Couldn't find audio decoder!"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (avcodec_open2(codecCtx, codec, NULL) < 0) { |
|
|
|
|
if (avcodec_open2(codecCtx, codec, nullptr) < 0) { |
|
|
|
|
LOGE(TAG, "Couldn't open audio decoder"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
@ -247,8 +247,7 @@ AUDIO_PLAYER_FUNC(void, play, jstring input_jstr, jstring filter_jstr) { |
|
|
|
|
|
|
|
|
|
swr_alloc_set_opts(swrCtx, |
|
|
|
|
out_ch_layout, out_sample_fmt, out_sample_rate, |
|
|
|
|
in_ch_layout, in_sample_fmt, in_sample_rate, |
|
|
|
|
0, NULL); |
|
|
|
|
in_ch_layout, in_sample_fmt, in_sample_rate, 0, nullptr); |
|
|
|
|
swr_init(swrCtx); |
|
|
|
|
int out_channel = av_get_channel_layout_nb_channels(out_ch_layout); |
|
|
|
|
jclass player_class = env->GetObjectClass(thiz); |
|
|
|
@ -316,11 +315,11 @@ AUDIO_PLAYER_FUNC(void, play, jstring input_jstr, jstring filter_jstr) { |
|
|
|
|
//convert audio format
|
|
|
|
|
swr_convert(swrCtx, &out_buffer, MAX_AUDIO_FRAME_SIZE, |
|
|
|
|
(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); |
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
env->ReleaseByteArrayElements(audio_sample_array, sample_byte_array, 0); |
|
|
|
|
//call write method to play
|
|
|
|
@ -353,7 +352,7 @@ end: |
|
|
|
|
AUDIO_PLAYER_FUNC(void, again, jstring filter_jstr) { |
|
|
|
|
if (!filter_jstr) return; |
|
|
|
|
filter_again = 1; |
|
|
|
|
filter_desc = env->GetStringUTFChars(filter_jstr, NULL); |
|
|
|
|
filter_desc = env->GetStringUTFChars(filter_jstr, nullptr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
AUDIO_PLAYER_FUNC(void, release) { |
|
|
|
|