+int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame)
+{
+ av_buffer_unref(&ifilter->hw_frames_ctx);
+
+ ifilter->format = frame->format;
+
+ ifilter->width = frame->width;
+ ifilter->height = frame->height;
+ ifilter->sample_aspect_ratio = frame->sample_aspect_ratio;
+
+ ifilter->sample_rate = frame->sample_rate;
+ ifilter->channels = av_frame_get_channels(frame);
+ ifilter->channel_layout = frame->channel_layout;
+
+ if (frame->hw_frames_ctx) {
+ ifilter->hw_frames_ctx = av_buffer_ref(frame->hw_frames_ctx);
+ if (!ifilter->hw_frames_ctx)
+ return AVERROR(ENOMEM);
+ }
+
+ return 0;
+}
+
+int ifilter_parameters_from_decoder(InputFilter *ifilter, const AVCodecContext *avctx)
+{
+ av_buffer_unref(&ifilter->hw_frames_ctx);
+
+ if (avctx->codec_type == AVMEDIA_TYPE_VIDEO)
+ ifilter->format = avctx->pix_fmt;
+ else
+ ifilter->format = avctx->sample_fmt;
+
+ ifilter->width = avctx->width;
+ ifilter->height = avctx->height;
+ if (ifilter->ist && ifilter->ist->st && ifilter->ist->st->sample_aspect_ratio.num)
+ ifilter->sample_aspect_ratio = ifilter->ist->st->sample_aspect_ratio;
+ else
+ ifilter->sample_aspect_ratio = avctx->sample_aspect_ratio;
+
+ ifilter->sample_rate = avctx->sample_rate;
+ ifilter->channels = avctx->channels;
+ ifilter->channel_layout = avctx->channel_layout;
+
+ if (ifilter->ist && ifilter->ist->hw_frames_ctx) {
+ ifilter->format = ifilter->ist->resample_pix_fmt;
+ ifilter->hw_frames_ctx = av_buffer_ref(ifilter->ist->hw_frames_ctx);
+ if (!ifilter->hw_frames_ctx)
+ return AVERROR(ENOMEM);
+ }
+
+ return 0;
+}
+