lavc: deprecate AV_CODEC_(FLAG|CAP)_TRUNCATED

It is supported only by a few decoders (h263, h263p, mpeg(1|2|)video
and mpeg4) and is entirely redundant with parsers. Furthermore, using
it leads to missing frames, as flushing the decoder at the end does not
work properly.

Co-authored-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
pull/369/head
Anton Khirnov 4 years ago committed by Andreas Rheinhardt
parent 9c489a0f3a
commit dd846bc4a9
  1. 4
      doc/APIchanges
  2. 4
      libavcodec/avcodec.h
  3. 5
      libavcodec/codec.h
  4. 4
      libavcodec/decode.c
  5. 18
      libavcodec/h263dec.c
  6. 28
      libavcodec/mpeg12dec.c
  7. 6
      libavcodec/mpeg4videodec.c
  8. 6
      libavcodec/mpegvideo.c
  9. 2
      libavcodec/mpegvideo.h
  10. 4
      libavcodec/options_table.h
  11. 2
      libavcodec/pthread.c
  12. 7
      libavcodec/version.h

@ -14,6 +14,10 @@ libavutil: 2021-04-27
API changes, most recent first:
2021-09-20 - xxxxxxxxxx - lavc 59.8.100 - avcodec.h codec.h
Deprecate AV_CODEC_FLAG_TRUNCATED and AV_CODEC_CAP_TRUNCATED,
as they are redundant with parsers.
2021-09-17 - xxxxxxxxxx - lavu 57.5.101 - buffer.h
Constified the input parameters in av_buffer_replace(), av_buffer_ref(),
and av_buffer_pool_buffer_get_opaque().

@ -245,11 +245,15 @@ typedef struct RcOverride{
* error[?] variables will be set during encoding.
*/
#define AV_CODEC_FLAG_PSNR (1 << 15)
#if FF_API_FLAG_TRUNCATED
/**
* Input bitstream might be truncated at a random location
* instead of only at frame boundaries.
*
* @deprecated use codec parsers for packetizing input
*/
#define AV_CODEC_FLAG_TRUNCATED (1 << 16)
#endif
/**
* Use interlaced DCT.
*/

@ -50,7 +50,12 @@
* avcodec_default_get_buffer2 or avcodec_default_get_encode_buffer.
*/
#define AV_CODEC_CAP_DR1 (1 << 1)
#if FF_API_FLAG_TRUNCATED
/**
* @deprecated Use parsers to always send proper frames.
*/
#define AV_CODEC_CAP_TRUNCATED (1 << 3)
#endif
/**
* Encoder or decoder requires flushing with NULL input at the end in order to
* give the complete and correct output.

@ -455,7 +455,11 @@ static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame,
if (!got_frame)
av_frame_unref(frame);
#if FF_API_FLAG_TRUNCATED
if (ret >= 0 && avctx->codec->type == AVMEDIA_TYPE_VIDEO && !(avctx->flags & AV_CODEC_FLAG_TRUNCATED))
#else
if (ret >= 0 && avctx->codec->type == AVMEDIA_TYPE_VIDEO)
#endif
ret = pkt->size;
#if FF_API_AVCTX_TIMEBASE

@ -33,12 +33,16 @@
#include "error_resilience.h"
#include "flv.h"
#include "h263.h"
#if FF_API_FLAG_TRUNCATED
#include "h263_parser.h"
#endif
#include "hwconfig.h"
#include "internal.h"
#include "mpeg_er.h"
#include "mpeg4video.h"
#if FF_API_FLAG_TRUNCATED
#include "mpeg4video_parser.h"
#endif
#include "mpegutils.h"
#include "mpegvideo.h"
#include "msmpeg4.h"
@ -170,12 +174,14 @@ static int get_consumed_bytes(MpegEncContext *s, int buf_size)
/* We would have to scan through the whole buf to handle the weird
* reordering ... */
return buf_size;
#if FF_API_FLAG_TRUNCATED
} else if (s->avctx->flags & AV_CODEC_FLAG_TRUNCATED) {
pos -= s->parse_context.last_index;
// padding is not really read so this might be -1
if (pos < 0)
pos = 0;
return pos;
#endif
} else {
// avoid infinite loops (maybe not needed...)
if (pos == 0)
@ -441,6 +447,7 @@ int ff_h263_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
return 0;
}
#if FF_API_FLAG_TRUNCATED
if (s->avctx->flags & AV_CODEC_FLAG_TRUNCATED) {
int next;
@ -460,6 +467,7 @@ int ff_h263_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
&buf_size) < 0)
return buf_size;
}
#endif
retry:
if (s->divx_packed && s->bitstream_buffer_size) {
@ -768,7 +776,10 @@ const AVCodec ff_h263_decoder = {
.close = ff_h263_decode_end,
.decode = ff_h263_decode_frame,
.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 |
AV_CODEC_CAP_TRUNCATED | AV_CODEC_CAP_DELAY,
#if FF_API_FLAG_TRUNCATED
AV_CODEC_CAP_TRUNCATED |
#endif
AV_CODEC_CAP_DELAY,
.caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
.flush = ff_mpeg_flush,
.max_lowres = 3,
@ -786,7 +797,10 @@ const AVCodec ff_h263p_decoder = {
.close = ff_h263_decode_end,
.decode = ff_h263_decode_frame,
.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 |
AV_CODEC_CAP_TRUNCATED | AV_CODEC_CAP_DELAY,
#if FF_API_FLAG_TRUNCATED
AV_CODEC_CAP_TRUNCATED |
#endif
AV_CODEC_CAP_DELAY,
.caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
.flush = ff_mpeg_flush,
.max_lowres = 3,

@ -1265,10 +1265,14 @@ static int mpeg_decode_postinit(AVCodecContext *avctx)
(s1->save_progressive_seq != s->progressive_sequence && FFALIGN(s->height, 16) != FFALIGN(s->height, 32)) ||
0) {
if (s1->mpeg_enc_ctx_allocated) {
#if FF_API_FLAG_TRUNCATED
ParseContext pc = s->parse_context;
s->parse_context.buffer = 0;
ff_mpv_common_end(s);
s->parse_context = pc;
#else
ff_mpv_common_end(s);
#endif
s1->mpeg_enc_ctx_allocated = 0;
}
@ -2504,7 +2508,11 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame *picture,
if (avctx->err_recognition & AV_EF_EXPLODE && s2->er.error_count)
return AVERROR_INVALIDDATA;
#if FF_API_FLAG_TRUNCATED
return FFMAX(0, buf_ptr - buf - s2->parse_context.last_index);
#else
return FFMAX(0, buf_ptr - buf);
#endif
}
input_size = buf_end - buf_ptr;
@ -2812,6 +2820,7 @@ static int mpeg_decode_frame(AVCodecContext *avctx, void *data,
return buf_size;
}
#if FF_API_FLAG_TRUNCATED
if (s2->avctx->flags & AV_CODEC_FLAG_TRUNCATED) {
int next = ff_mpeg1_find_frame_end(&s2->parse_context, buf,
buf_size, NULL);
@ -2820,6 +2829,7 @@ static int mpeg_decode_frame(AVCodecContext *avctx, void *data,
(const uint8_t **) &buf, &buf_size) < 0)
return buf_size;
}
#endif
s2->codec_tag = avpriv_toupper4(avctx->codec_tag);
if (s->mpeg_enc_ctx_allocated == 0 && ( s2->codec_tag == AV_RL32("VCR2")
@ -2896,8 +2906,10 @@ const AVCodec ff_mpeg1video_decoder = {
.close = mpeg_decode_end,
.decode = mpeg_decode_frame,
.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 |
AV_CODEC_CAP_TRUNCATED | AV_CODEC_CAP_DELAY |
AV_CODEC_CAP_SLICE_THREADS,
#if FF_API_FLAG_TRUNCATED
AV_CODEC_CAP_TRUNCATED |
#endif
AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS,
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE |
FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
.flush = flush,
@ -2930,8 +2942,10 @@ const AVCodec ff_mpeg2video_decoder = {
.close = mpeg_decode_end,
.decode = mpeg_decode_frame,
.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 |
AV_CODEC_CAP_TRUNCATED | AV_CODEC_CAP_DELAY |
AV_CODEC_CAP_SLICE_THREADS,
#if FF_API_FLAG_TRUNCATED
AV_CODEC_CAP_TRUNCATED |
#endif
AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS,
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE |
FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
.flush = flush,
@ -2976,7 +2990,11 @@ const AVCodec ff_mpegvideo_decoder = {
.init = mpeg_decode_init,
.close = mpeg_decode_end,
.decode = mpeg_decode_frame,
.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 | AV_CODEC_CAP_TRUNCATED | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS,
.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 |
#if FF_API_FLAG_TRUNCATED
AV_CODEC_CAP_TRUNCATED |
#endif
AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS,
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE |
FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
.flush = flush,

@ -3590,8 +3590,10 @@ const AVCodec ff_mpeg4_decoder = {
.close = ff_h263_decode_end,
.decode = ff_h263_decode_frame,
.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 |
AV_CODEC_CAP_TRUNCATED | AV_CODEC_CAP_DELAY |
AV_CODEC_CAP_FRAME_THREADS,
#if FF_API_FLAG_TRUNCATED
AV_CODEC_CAP_TRUNCATED |
#endif
AV_CODEC_CAP_DELAY | AV_CODEC_CAP_FRAME_THREADS,
.caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM |
FF_CODEC_CAP_ALLOCATE_PROGRESS,
.flush = ff_mpeg_flush,

@ -974,7 +974,9 @@ av_cold int ff_mpv_common_init(MpegEncContext *s)
if ((ret = init_context_frame(s)))
goto fail;
#if FF_API_FLAG_TRUNCATED
s->parse_context.state = -1;
#endif
s->context_initialized = 1;
memset(s->thread_context, 0, sizeof(s->thread_context));
@ -1119,8 +1121,10 @@ void ff_mpv_common_end(MpegEncContext *s)
if (s->slice_context_count > 1)
s->slice_context_count = 1;
#if FF_API_FLAG_TRUNCATED
av_freep(&s->parse_context.buffer);
s->parse_context.buffer_size = 0;
#endif
av_freep(&s->bitstream_buffer);
s->allocated_bitstream_buffer_size = 0;
@ -2315,12 +2319,14 @@ void ff_mpeg_flush(AVCodecContext *avctx){
s->mb_x= s->mb_y= 0;
s->closed_gop= 0;
#if FF_API_FLAG_TRUNCATED
s->parse_context.state= -1;
s->parse_context.frame_start_found= 0;
s->parse_context.overread= 0;
s->parse_context.overread_index= 0;
s->parse_context.index= 0;
s->parse_context.last_index= 0;
#endif
s->bitstream_buffer_size=0;
s->pp_time=0;
}

@ -347,7 +347,9 @@ typedef struct MpegEncContext {
int mb_num_left; ///< number of MBs left in this video packet (for partitioned Slices only)
int next_p_frame_damaged; ///< set if the next p frame is damaged, to avoid showing trashed B-frames
#if FF_API_FLAG_TRUNCATED
ParseContext parse_context;
#endif
/* H.263 specific */
int gob_index;

@ -59,7 +59,9 @@ static const AVOption avcodec_options[] = {
{"pass2", "use internal 2-pass ratecontrol in second pass mode", 0, AV_OPT_TYPE_CONST, {.i64 = AV_CODEC_FLAG_PASS2 }, INT_MIN, INT_MAX, 0, "flags"},
{"gray", "only decode/encode grayscale", 0, AV_OPT_TYPE_CONST, {.i64 = AV_CODEC_FLAG_GRAY }, INT_MIN, INT_MAX, V|E|D, "flags"},
{"psnr", "error[?] variables will be set during encoding", 0, AV_OPT_TYPE_CONST, {.i64 = AV_CODEC_FLAG_PSNR }, INT_MIN, INT_MAX, V|E, "flags"},
{"truncated", "Input bitstream might be randomly truncated", 0, AV_OPT_TYPE_CONST, {.i64 = AV_CODEC_FLAG_TRUNCATED }, INT_MIN, INT_MAX, V|D, "flags"},
#if FF_API_FLAG_TRUNCATED
{"truncated", "(Deprecated, use parsers instead.) Input bitstream might be randomly truncated", 0, AV_OPT_TYPE_CONST, {.i64 = AV_CODEC_FLAG_TRUNCATED }, INT_MIN, INT_MAX, V|D | AV_OPT_FLAG_DEPRECATED, "flags"},
#endif
{"ildct", "use interlaced DCT", 0, AV_OPT_TYPE_CONST, {.i64 = AV_CODEC_FLAG_INTERLACED_DCT }, INT_MIN, INT_MAX, V|E, "flags"},
{"low_delay", "force low delay", 0, AV_OPT_TYPE_CONST, {.i64 = AV_CODEC_FLAG_LOW_DELAY }, INT_MIN, INT_MAX, V|D|E, "flags"},
{"global_header", "place global headers in extradata instead of every keyframe", 0, AV_OPT_TYPE_CONST, {.i64 = AV_CODEC_FLAG_GLOBAL_HEADER }, INT_MIN, INT_MAX, V|A|E, "flags"},

@ -48,7 +48,9 @@
static void validate_thread_parameters(AVCodecContext *avctx)
{
int frame_threading_supported = (avctx->codec->capabilities & AV_CODEC_CAP_FRAME_THREADS)
#if FF_API_FLAG_TRUNCATED
&& !(avctx->flags & AV_CODEC_FLAG_TRUNCATED)
#endif
&& !(avctx->flags & AV_CODEC_FLAG_LOW_DELAY)
&& !(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS);
if (avctx->thread_count == 1) {

@ -28,8 +28,8 @@
#include "libavutil/version.h"
#define LIBAVCODEC_VERSION_MAJOR 59
#define LIBAVCODEC_VERSION_MINOR 7
#define LIBAVCODEC_VERSION_MICRO 103
#define LIBAVCODEC_VERSION_MINOR 8
#define LIBAVCODEC_VERSION_MICRO 100
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \
@ -81,5 +81,8 @@
#ifndef FF_API_MPEGVIDEO_OPTS
#define FF_API_MPEGVIDEO_OPTS (LIBAVCODEC_VERSION_MAJOR < 60)
#endif
#ifndef FF_API_FLAG_TRUNCATED
#define FF_API_FLAG_TRUNCATED (LIBAVCODEC_VERSION_MAJOR < 60)
#endif
#endif /* AVCODEC_VERSION_H */

Loading…
Cancel
Save