|
|
@ -28,7 +28,8 @@ extern "C" { |
|
|
|
#define SLEEP_TIME 1000 * 16 |
|
|
|
#define SLEEP_TIME 1000 * 16 |
|
|
|
#define MAX_AUDIO_FRAME_SIZE 48000 * 4 |
|
|
|
#define MAX_AUDIO_FRAME_SIZE 48000 * 4 |
|
|
|
|
|
|
|
|
|
|
|
//const char *filter_descr = "superequalizer=6b=4:8b=5:10b=5";
|
|
|
|
int filter_again = 0; |
|
|
|
|
|
|
|
const char *filter_desc = "superequalizer=6b=4:8b=5:10b=5"; |
|
|
|
|
|
|
|
|
|
|
|
int init_volume_filter(AVFilterGraph **graph, AVFilterContext **src, AVFilterContext **sink, |
|
|
|
int init_volume_filter(AVFilterGraph **graph, AVFilterContext **src, AVFilterContext **sink, |
|
|
|
uint64_t channel_layout, AVSampleFormat inputFormat, int sample_rate) { |
|
|
|
uint64_t channel_layout, AVSampleFormat inputFormat, int sample_rate) { |
|
|
@ -204,7 +205,7 @@ AUDIO_PLAYER_FUNC(void, play, jstring input_jstr, jstring filter_jstr) { |
|
|
|
|
|
|
|
|
|
|
|
const char *input_cstr = env->GetStringUTFChars(input_jstr, NULL); |
|
|
|
const char *input_cstr = env->GetStringUTFChars(input_jstr, NULL); |
|
|
|
LOGI(TAG, "input url=%s", input_cstr); |
|
|
|
LOGI(TAG, "input url=%s", input_cstr); |
|
|
|
const char *filter_desc = env->GetStringUTFChars(filter_jstr, NULL); |
|
|
|
filter_desc = env->GetStringUTFChars(filter_jstr, NULL); |
|
|
|
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(); |
|
|
@ -280,7 +281,19 @@ AUDIO_PLAYER_FUNC(void, play, jstring input_jstr, jstring filter_jstr) { |
|
|
|
|
|
|
|
|
|
|
|
//read audio frame
|
|
|
|
//read audio frame
|
|
|
|
while (av_read_frame(pFormatCtx, packet) >= 0) { |
|
|
|
while (av_read_frame(pFormatCtx, packet) >= 0) { |
|
|
|
if (packet->stream_index == audio_stream_idx) { |
|
|
|
if (packet->stream_index != audio_stream_idx) { |
|
|
|
|
|
|
|
av_packet_unref(packet); |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (filter_again) { |
|
|
|
|
|
|
|
filter_again = 0; |
|
|
|
|
|
|
|
avfilter_graph_free(&audioFilterGraph); |
|
|
|
|
|
|
|
if (init_equalizer_filter(filter_desc, codecCtx, &audioFilterGraph, &audioSrcContext, &audioSinkContext) < 0) { |
|
|
|
|
|
|
|
LOGE(TAG, "init_filter error, ret=%d\n", ret); |
|
|
|
|
|
|
|
goto end; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
LOGE(TAG, "play again,filter_descr=_=%s", filter_desc); |
|
|
|
|
|
|
|
} |
|
|
|
ret = avcodec_decode_audio4(codecCtx, frame, &got_frame, packet); |
|
|
|
ret = avcodec_decode_audio4(codecCtx, frame, &got_frame, packet); |
|
|
|
if (ret < 0) { |
|
|
|
if (ret < 0) { |
|
|
|
break; |
|
|
|
break; |
|
|
@ -317,7 +330,6 @@ AUDIO_PLAYER_FUNC(void, play, jstring input_jstr, jstring filter_jstr) { |
|
|
|
usleep(SLEEP_TIME); |
|
|
|
usleep(SLEEP_TIME); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
av_packet_unref(packet); |
|
|
|
av_packet_unref(packet); |
|
|
|
} |
|
|
|
} |
|
|
|
end: |
|
|
|
end: |
|
|
@ -332,3 +344,9 @@ end: |
|
|
|
env->ReleaseStringUTFChars(input_jstr, input_cstr); |
|
|
|
env->ReleaseStringUTFChars(input_jstr, input_cstr); |
|
|
|
env->ReleaseStringUTFChars(filter_jstr, filter_desc); |
|
|
|
env->ReleaseStringUTFChars(filter_jstr, filter_desc); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AUDIO_PLAYER_FUNC(void, again, jstring filter_jstr) { |
|
|
|
|
|
|
|
if (!filter_jstr) return; |
|
|
|
|
|
|
|
filter_again = 1; |
|
|
|
|
|
|
|
filter_desc = env->GetStringUTFChars(filter_jstr, NULL); |
|
|
|
|
|
|
|
} |