Skip to content

Commit

Permalink
Use swr_alloc_set_opts2 function to set SwrContext options
Browse files Browse the repository at this point in the history
  • Loading branch information
equeim committed Oct 11, 2023
1 parent fb63e64 commit fa0c457
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions libraries/decoder_ffmpeg/src/main/jni/ffmpeg_jni.cc
Original file line number Diff line number Diff line change
Expand Up @@ -301,19 +301,24 @@ int decodePacket(AVCodecContext *context, AVPacket *packet,
int sampleCount = frame->nb_samples;
int dataSize = av_samples_get_buffer_size(NULL, channelCount, sampleCount,
sampleFormat, 1);
SwrContext *resampleContext;
if (context->opaque) {
resampleContext = (SwrContext *)context->opaque;
} else {
resampleContext = swr_alloc();
av_opt_set_chlayout(resampleContext, "in_chlayout", &context->ch_layout, 0);
av_opt_set_chlayout(resampleContext, "out_chlayout", &context->ch_layout, 0);
av_opt_set_int(resampleContext, "in_sample_rate", sampleRate, 0);
av_opt_set_int(resampleContext, "out_sample_rate", sampleRate, 0);
av_opt_set_int(resampleContext, "in_sample_fmt", sampleFormat, 0);
// The output format is always the requested format.
av_opt_set_int(resampleContext, "out_sample_fmt",
context->request_sample_fmt, 0);
SwrContext *resampleContext = static_cast<SwrContext *>(context->opaque);
if (!resampleContext) {
result = swr_alloc_set_opts2(
&resampleContext, // ps
&context->ch_layout, // out_ch_layout
context->request_sample_fmt, // out_sample_fmt
sampleRate, // out_sample_rate
&context->ch_layout, // in_ch_layout
sampleFormat, // in_sample_fmt
sampleRate, // in_sample_rate
0, // log_offset
NULL // log_ctx
);
if (result < 0) {
logError("swr_alloc_set_opts2", result);
av_frame_free(&frame);
return transformError(result);
}
result = swr_init(resampleContext);
if (result < 0) {
logError("swr_init", result);
Expand Down

0 comments on commit fa0c457

Please sign in to comment.