[FFmpeg-devel] [PATCH] Replace all the uses of the deprecated sws_getContext() function.
Stefano Sabatini
stefano.sabatini-lala
Wed Sep 29 18:00:39 CEST 2010
---
ffmpeg.c | 54 +++++++++++++++++++++++++++--------------------
ffplay.c | 21 +++++++++++++-----
libavfilter/vf_scale.c | 22 ++++++++++++++++---
3 files changed, 64 insertions(+), 33 deletions(-)
diff --git a/ffmpeg.c b/ffmpeg.c
index 056bd37..bdaea27 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -1239,19 +1239,23 @@ static void do_video_out(AVFormatContext *s,
/* initialize a new scaler context */
sws_freeContext(ost->img_resample_ctx);
- sws_flags = av_get_int(sws_opts, "sws_flags", NULL);
- ost->img_resample_ctx = sws_getContext(
- ist->st->codec->width - (ost->leftBand + ost->rightBand),
- ist->st->codec->height - (ost->topBand + ost->bottomBand),
- ist->st->codec->pix_fmt,
- ost->st->codec->width,
- ost->st->codec->height,
- ost->st->codec->pix_fmt,
- sws_flags, NULL, NULL, NULL);
- if (ost->img_resample_ctx == NULL) {
- fprintf(stderr, "Cannot get resampling context\n");
+ if (!(ost->img_resample_ctx = sws_alloc_context())) {
+ fprintf(stderr, "Cannot allocate resampling context\n");
ffmpeg_exit(1);
}
+ av_set_int(ost->img_resample_ctx, "srcw", ist->st->codec->width - (ost->leftBand + ost->rightBand));
+ av_set_int(ost->img_resample_ctx, "srch", ist->st->codec->height - (ost->topBand + ost->bottomBand));
+ av_set_int(ost->img_resample_ctx, "src_format", ist->st->codec->pix_fmt);
+ av_set_int(ost->img_resample_ctx, "dstw", ost->st->codec->width);
+ av_set_int(ost->img_resample_ctx, "dsth", ost->st->codec->height);
+ av_set_int(ost->img_resample_ctx, "dst_format", ost->st->codec->pix_fmt);
+ av_set_int(ost->img_resample_ctx, "sws_flags", av_get_int(sws_opts, "sws_flags", NULL));
+ if (sws_init_context(ost->img_resample_ctx, NULL, NULL) < 0) {
+ fprintf(stderr, "Cannot initialize resampling context\n");
+ sws_freeContext(ost->img_resample_ctx);
+ ffmpeg_exit(1);
+ }
+
}
sws_scale(ost->img_resample_ctx, formatted_picture->data, formatted_picture->linesize,
0, ost->resample_height, resampling_dst->data, resampling_dst->linesize);
@@ -2245,17 +2249,20 @@ static int transcode(AVFormatContext **output_files,
fprintf(stderr, "Cannot allocate temp picture, check pix fmt\n");
ffmpeg_exit(1);
}
- sws_flags = av_get_int(sws_opts, "sws_flags", NULL);
- ost->img_resample_ctx = sws_getContext(
- icodec->width - (frame_leftBand + frame_rightBand),
- icodec->height - (frame_topBand + frame_bottomBand),
- icodec->pix_fmt,
- codec->width,
- codec->height,
- codec->pix_fmt,
- sws_flags, NULL, NULL, NULL);
- if (ost->img_resample_ctx == NULL) {
- fprintf(stderr, "Cannot get resampling context\n");
+ if (!(ost->img_resample_ctx = sws_alloc_context())) {
+ fprintf(stderr, "Cannot allocate resampling context\n");
+ ffmpeg_exit(1);
+ }
+ av_set_int(ost->img_resample_ctx, "srcw", icodec->width - (frame_leftBand + frame_rightBand));
+ av_set_int(ost->img_resample_ctx, "srch", icodec->height - (frame_topBand + frame_bottomBand));
+ av_set_int(ost->img_resample_ctx, "src_format", icodec->pix_fmt);
+ av_set_int(ost->img_resample_ctx, "dstw", codec->width);
+ av_set_int(ost->img_resample_ctx, "dsth", codec->height);
+ av_set_int(ost->img_resample_ctx, "dst_format", codec->pix_fmt);
+ av_set_int(ost->img_resample_ctx, "sws_flags", av_get_int(sws_opts, "sws_flags", NULL));
+ if (sws_init_context(ost->img_resample_ctx, NULL, NULL) < 0) {
+ fprintf(stderr, "Cannot initialize resampling context\n");
+ sws_freeContext(ost->img_resample_ctx);
ffmpeg_exit(1);
}
@@ -4313,7 +4320,8 @@ int main(int argc, char **argv)
avcodec_opts[i]= avcodec_alloc_context2(i);
}
avformat_opts = avformat_alloc_context();
- sws_opts = sws_getContext(16,16,0, 16,16,0, sws_flags, NULL,NULL,NULL);
+ sws_opts = sws_alloc_context();
+ av_set_int(sws_opts, "sws_flags", sws_flags);
show_banner();
diff --git a/ffplay.c b/ffplay.c
index 99932c5..d803fea 100644
--- a/ffplay.c
+++ b/ffplay.c
@@ -1482,12 +1482,20 @@ static int queue_picture(VideoState *is, AVFrame *src_frame, double pts, int64_t
av_picture_copy(&pict, &pict_src,
vp->pix_fmt, vp->width, vp->height);
#else
- sws_flags = av_get_int(sws_opts, "sws_flags", NULL);
- is->img_convert_ctx = sws_getCachedContext(is->img_convert_ctx,
- vp->width, vp->height, vp->pix_fmt, vp->width, vp->height,
- dst_pix_fmt, sws_flags, NULL, NULL, NULL);
- if (is->img_convert_ctx == NULL) {
+ if (!(is->img_convert_ctx = sws_alloc_context())) {
+ fprintf(stderr, "Cannot allocate the conversion context\n");
+ exit(1);
+ }
+ av_set_int(is->img_convert_ctx, "srcw", vp->width);
+ av_set_int(is->img_convert_ctx, "srch", vp->height);
+ av_set_int(is->img_convert_ctx, "src_format", vp->pix_fmt);
+ av_set_int(is->img_convert_ctx, "dstw", vp->width);
+ av_set_int(is->img_convert_ctx, "dsth", vp->height);
+ av_set_int(is->img_convert_ctx, "dst_format", dst_pix_fmt);
+ av_set_int(is->img_convert_ctx, "sws_flags", av_get_int(sws_opts, "sws_flags", NULL));
+ if (sws_init_context(is->img_convert_ctx, NULL, NULL) < 0) {
fprintf(stderr, "Cannot initialize the conversion context\n");
+ sws_freeContext(is->img_convert_ctx);
exit(1);
}
sws_scale(is->img_convert_ctx, src_frame->data, src_frame->linesize,
@@ -3159,7 +3167,8 @@ int main(int argc, char **argv)
}
avformat_opts = avformat_alloc_context();
#if !CONFIG_AVFILTER
- sws_opts = sws_getContext(16,16,0, 16,16,0, sws_flags, NULL,NULL,NULL);
+ sws_opts = sws_alloc_context();
+ av_set_int(sws_opts, "sws_flags", sws_flags);
#endif
show_banner();
diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
index d99e0c1..44501fa 100644
--- a/libavfilter/vf_scale.c
+++ b/libavfilter/vf_scale.c
@@ -24,6 +24,7 @@
*/
#include "avfilter.h"
+#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libswscale/swscale.h"
@@ -108,6 +109,7 @@ static int config_props(AVFilterLink *outlink)
AVFilterContext *ctx = outlink->src;
AVFilterLink *inlink = outlink->src->inputs[0];
ScaleContext *scale = ctx->priv;
+ int ret;
int64_t w, h;
if (!(w = scale->w))
@@ -135,11 +137,23 @@ static int config_props(AVFilterLink *outlink)
scale->input_is_pal = av_pix_fmt_descriptors[inlink->format].flags & PIX_FMT_PAL;
- scale->sws = sws_getContext(inlink ->w, inlink ->h, inlink ->format,
- outlink->w, outlink->h, outlink->format,
- scale->flags, NULL, NULL, NULL);
+ if (!(scale->sws = sws_alloc_context()))
+ return AVERROR(ENOMEM);
+
+ av_set_int(scale->sws, "srcw", inlink->w);
+ av_set_int(scale->sws, "srch", inlink->h);
+ av_set_int(scale->sws, "src_format", inlink->format);
+ av_set_int(scale->sws, "dstw", outlink->w);
+ av_set_int(scale->sws, "dsth", outlink->h);
+ av_set_int(scale->sws, "dst_format", outlink->format);
+ av_set_int(scale->sws, "sws_flags", scale->flags);
+ if ((ret = sws_init_context(scale->sws, NULL, NULL)) < 0) {
+ sws_freeContext(scale->sws);
+ scale->sws = NULL;
+ return ret;
+ }
- return !scale->sws;
+ return 0;
}
static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
--
1.7.1
More information about the ffmpeg-devel
mailing list