mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-29 22:00:58 +02:00
avcodec/options: factorize avcodec_copy_context() cleanup code
Reviewed-by: Aaron Levinson <alevinsn@aracnet.com> Tested-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: James Almer <jamrial@gmail.com> (cherry picked from commit 54a4c9b4e9a1524b1ac5d2be97c8042272402d0a)
This commit is contained in:
parent
4117f19f2f
commit
4122e5fcb3
@ -179,6 +179,18 @@ void avcodec_free_context(AVCodecContext **pavctx)
|
|||||||
av_freep(pavctx);
|
av_freep(pavctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void copy_context_reset(AVCodecContext *avctx)
|
||||||
|
{
|
||||||
|
av_opt_free(avctx);
|
||||||
|
av_freep(&avctx->rc_override);
|
||||||
|
av_freep(&avctx->intra_matrix);
|
||||||
|
av_freep(&avctx->inter_matrix);
|
||||||
|
av_freep(&avctx->extradata);
|
||||||
|
av_freep(&avctx->subtitle_header);
|
||||||
|
avctx->subtitle_header_size = 0;
|
||||||
|
avctx->extradata_size = 0;
|
||||||
|
}
|
||||||
|
|
||||||
int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)
|
int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)
|
||||||
{
|
{
|
||||||
const AVCodec *orig_codec = dest->codec;
|
const AVCodec *orig_codec = dest->codec;
|
||||||
@ -191,12 +203,7 @@ int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)
|
|||||||
return AVERROR(EINVAL);
|
return AVERROR(EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
av_opt_free(dest);
|
copy_context_reset(dest);
|
||||||
av_freep(&dest->rc_override);
|
|
||||||
av_freep(&dest->intra_matrix);
|
|
||||||
av_freep(&dest->inter_matrix);
|
|
||||||
av_freep(&dest->extradata);
|
|
||||||
av_freep(&dest->subtitle_header);
|
|
||||||
|
|
||||||
memcpy(dest, src, sizeof(*dest));
|
memcpy(dest, src, sizeof(*dest));
|
||||||
av_opt_copy(dest, src);
|
av_opt_copy(dest, src);
|
||||||
@ -248,14 +255,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
av_freep(&dest->rc_override);
|
copy_context_reset(dest);
|
||||||
av_freep(&dest->intra_matrix);
|
|
||||||
av_freep(&dest->inter_matrix);
|
|
||||||
av_freep(&dest->extradata);
|
|
||||||
av_freep(&dest->subtitle_header);
|
|
||||||
dest->subtitle_header_size = 0;
|
|
||||||
dest->extradata_size = 0;
|
|
||||||
av_opt_free(dest);
|
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user