It's not a decoding exclusive function anymore.
Unified · Split
| @@ -1961,47 +1961,3 @@ int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int flags) · 1960 unmodified lines | |||
| 1961 | av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); | 1961 | av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); |
| 1962 | return ret; | 1962 | return ret; |
| 1963 | } | 1963 | } |
| 1964 | |||
| 1965 | void avcodec_flush_buffers(AVCodecContext *avctx) | ||
| 1966 | { | ||
| 1967 | AVCodecInternal *avci = avctx->internal; | ||
| 1968 | |||
| 1969 | if (av_codec_is_encoder(avctx->codec)) { | ||
| 1970 | int caps = avctx->codec->capabilities; | ||
| 1971 | |||
| 1972 | if (!(caps & AV_CODEC_CAP_ENCODER_FLUSH)) { | ||
| 1973 | // Only encoders that explicitly declare support for it can be | ||
| 1974 | // flushed. Otherwise, this is a no-op. | ||
| 1975 | av_log(avctx, AV_LOG_WARNING, "Ignoring attempt to flush encoder " | ||
| 1976 | "that doesn't support it\n"); | ||
| 1977 | return; | ||
| 1978 | } | ||
| 1979 | |||
| 1980 | // We haven't implemented flushing for frame-threaded encoders. | ||
| 1981 | av_assert0(!(caps & AV_CODEC_CAP_FRAME_THREADS)); | ||
| 1982 | } | ||
| 1983 | |||
| 1984 | avci->draining = 0; | ||
| 1985 | avci->draining_done = 0; | ||
| 1986 | avci->nb_draining_errors = 0; | ||
| 1987 | av_frame_unref(avci->buffer_frame); | ||
| 1988 | av_frame_unref(avci->compat_decode_frame); | ||
| 1989 | av_packet_unref(avci->buffer_pkt); | ||
| 1990 | avci->buffer_pkt_valid = 0; | ||
| 1991 | |||
| 1992 | av_packet_unref(avci->ds.in_pkt); | ||
| 1993 | |||
| 1994 | if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) | ||
| 1995 | ff_thread_flush(avctx); | ||
| 1996 | else if (avctx->codec->flush) | ||
| 1997 | avctx->codec->flush(avctx); | ||
| 1998 | |||
| 1999 | avctx->pts_correction_last_pts = | ||
| 2000 | avctx->pts_correction_last_dts = INT64_MIN; | ||
| 2001 | |||
| 2002 | if (av_codec_is_decoder(avctx->codec)) | ||
| 2003 | av_bsf_flush(avci->bsf); | ||
| 2004 | |||
| 2005 | if (!avctx->refcounted_frames) | ||
| 2006 | av_frame_unref(avci->to_free); | ||
| 2007 | } | ||
| @@ -1055,6 +1055,50 @@ FF_ENABLE_DEPRECATION_WARNINGS · 1054 unmodified lines | |||
| 1055 | goto end; | 1055 | goto end; |
| 1056 | } | 1056 | } |
| 1057 | 1057 | ||
| 1058 | void avcodec_flush_buffers(AVCodecContext *avctx) | ||
| 1059 | { | ||
| 1060 | AVCodecInternal *avci = avctx->internal; | ||
| 1061 | |||
| 1062 | if (av_codec_is_encoder(avctx->codec)) { | ||
| 1063 | int caps = avctx->codec->capabilities; | ||
| 1064 | |||
| 1065 | if (!(caps & AV_CODEC_CAP_ENCODER_FLUSH)) { | ||
| 1066 | // Only encoders that explicitly declare support for it can be | ||
| 1067 | // flushed. Otherwise, this is a no-op. | ||
| 1068 | av_log(avctx, AV_LOG_WARNING, "Ignoring attempt to flush encoder " | ||
| 1069 | "that doesn't support it\n"); | ||
| 1070 | return; | ||
| 1071 | } | ||
| 1072 | |||
| 1073 | // We haven't implemented flushing for frame-threaded encoders. | ||
| 1074 | av_assert0(!(caps & AV_CODEC_CAP_FRAME_THREADS)); | ||
| 1075 | } | ||
| 1076 | |||
| 1077 | avci->draining = 0; | ||
| 1078 | avci->draining_done = 0; | ||
| 1079 | avci->nb_draining_errors = 0; | ||
| 1080 | av_frame_unref(avci->buffer_frame); | ||
| 1081 | av_frame_unref(avci->compat_decode_frame); | ||
| 1082 | av_packet_unref(avci->buffer_pkt); | ||
| 1083 | avci->buffer_pkt_valid = 0; | ||
| 1084 | |||
| 1085 | av_packet_unref(avci->ds.in_pkt); | ||
| 1086 | |||
| 1087 | if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) | ||
| 1088 | ff_thread_flush(avctx); | ||
| 1089 | else if (avctx->codec->flush) | ||
| 1090 | avctx->codec->flush(avctx); | ||
| 1091 | |||
| 1092 | avctx->pts_correction_last_pts = | ||
| 1093 | avctx->pts_correction_last_dts = INT64_MIN; | ||
| 1094 | |||
| 1095 | if (av_codec_is_decoder(avctx->codec)) | ||
| 1096 | av_bsf_flush(avci->bsf); | ||
| 1097 | |||
| 1098 | if (!avctx->refcounted_frames) | ||
| 1099 | av_frame_unref(avci->to_free); | ||
| 1100 | } | ||
| 1101 | |||
| 1058 | void avsubtitle_free(AVSubtitle *sub) | 1102 | void avsubtitle_free(AVSubtitle *sub) |
| 1059 | { | 1103 | { |
| 1060 | int i; | 1104 | int i; |