Use swr_alloc_set_opts2 function to set SwrContext options
This commit is contained in:
parent
815d93cfa2
commit
6332693ce4
@ -342,19 +342,24 @@ int decodePacket(AVCodecContext *context, AVPacket *packet,
|
|||||||
int sampleCount = frame->nb_samples;
|
int sampleCount = frame->nb_samples;
|
||||||
int dataSize = av_samples_get_buffer_size(NULL, channelCount, sampleCount,
|
int dataSize = av_samples_get_buffer_size(NULL, channelCount, sampleCount,
|
||||||
sampleFormat, 1);
|
sampleFormat, 1);
|
||||||
SwrContext *resampleContext;
|
SwrContext *resampleContext = static_cast<SwrContext *>(context->opaque);
|
||||||
if (context->opaque) {
|
if (!resampleContext) {
|
||||||
resampleContext = (SwrContext *)context->opaque;
|
result = swr_alloc_set_opts2(
|
||||||
} else {
|
&resampleContext, // ps
|
||||||
resampleContext = swr_alloc();
|
&context->ch_layout, // out_ch_layout
|
||||||
av_opt_set_chlayout(resampleContext, "in_chlayout", &context->ch_layout, 0);
|
context->request_sample_fmt, // out_sample_fmt
|
||||||
av_opt_set_chlayout(resampleContext, "out_chlayout", &context->ch_layout, 0);
|
sampleRate, // out_sample_rate
|
||||||
av_opt_set_int(resampleContext, "in_sample_rate", sampleRate, 0);
|
&context->ch_layout, // in_ch_layout
|
||||||
av_opt_set_int(resampleContext, "out_sample_rate", sampleRate, 0);
|
sampleFormat, // in_sample_fmt
|
||||||
av_opt_set_int(resampleContext, "in_sample_fmt", sampleFormat, 0);
|
sampleRate, // in_sample_rate
|
||||||
// The output format is always the requested format.
|
0, // log_offset
|
||||||
av_opt_set_int(resampleContext, "out_sample_fmt",
|
NULL // log_ctx
|
||||||
context->request_sample_fmt, 0);
|
);
|
||||||
|
if (result < 0) {
|
||||||
|
logError("swr_alloc_set_opts2", result);
|
||||||
|
av_frame_free(&frame);
|
||||||
|
return transformError(result);
|
||||||
|
}
|
||||||
result = swr_init(resampleContext);
|
result = swr_init(resampleContext);
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
logError("swr_init", result);
|
logError("swr_init", result);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user