pull filtered audio from the filter graph

dev
xufuji456 4 years ago
parent 4f77ad512d
commit 9ceed1d4af
  1. 17
      app/src/main/cpp/audio_player.cpp

@ -28,7 +28,7 @@ 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=6:8b=6"; const char *filter_descr = "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) {
@ -276,7 +276,7 @@ AUDIO_PLAYER_FUNC(void, play, jstring input_jstr) {
// in_ch_layout, in_sample_fmt, in_sample_rate); // in_ch_layout, in_sample_fmt, in_sample_rate);
ret = init_equalizer_filter(codecCtx, &audioFilterGraph, &audioSrcContext, &audioSinkContext); ret = init_equalizer_filter(codecCtx, &audioFilterGraph, &audioSrcContext, &audioSinkContext);
if (ret < 0) { if (ret < 0) {
LOGE(TAG, "Unable to init filter graph:%d", stderr); LOGE(TAG, "Unable to init filter graph:%d", ret);
goto end; goto end;
} }
@ -290,19 +290,17 @@ AUDIO_PLAYER_FUNC(void, play, jstring input_jstr) {
if (got_frame > 0) { if (got_frame > 0) {
ret = av_buffersrc_add_frame(audioSrcContext, frame); ret = av_buffersrc_add_frame(audioSrcContext, frame);
if (ret < 0) { if (ret < 0) {
LOGE(TAG, "Error add the frame to the filter graph:%d", stderr); LOGE(TAG, "Error add the frame to the filter graph:%d", ret);
} }
/* Get all the filtered output that is available. */ /* Get all the filtered output that is available. */
while (1) {
ret = av_buffersink_get_frame(audioSinkContext, filter_frame); ret = av_buffersink_get_frame(audioSinkContext, filter_frame);
if (ret == AVERROR(EAGAIN)) { if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
LOGE(TAG, "get filter frame again..."); break;
continue;
}
if (ret < 0) { if (ret < 0) {
LOGE(TAG, "Error get the frame from the filter graph:%d", stderr); LOGE(TAG, "Error get the frame from the filter graph:%d", ret);
goto end; goto end;
} }
//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);
@ -321,6 +319,7 @@ AUDIO_PLAYER_FUNC(void, play, jstring input_jstr) {
usleep(SLEEP_TIME); usleep(SLEEP_TIME);
} }
} }
}
av_packet_unref(packet); av_packet_unref(packet);
} }
end: end:

Loading…
Cancel
Save