[FFmpeg-devel] [PATCH 2/4] lavc+lavf: split AV_PKG_FLAG_CORRUPT into more specific flags
Rodger Combs
rodger.combs at gmail.com
Wed Dec 13 13:44:51 EET 2017
This maintains AV_PKG_FLAG_CORRUPT as a mask of the 3 new flags.
Requires a major bump in both libraries.
---
libavcodec/avcodec.h | 29 ++++++++++++++++++++++++++++-
libavcodec/trace_headers_bsf.c | 10 ++++++++--
libavcodec/version.h | 3 +++
libavformat/aiffdec.c | 2 +-
libavformat/apc.c | 2 +-
libavformat/iv8.c | 2 +-
libavformat/jvdec.c | 2 +-
libavformat/mp3dec.c | 2 +-
libavformat/mpegts.c | 6 +++---
libavformat/oggparseopus.c | 2 +-
libavformat/oggparsevorbis.c | 4 ++--
libavformat/omadec.c | 4 ++--
libavformat/pcm.c | 2 +-
libavformat/sdsdec.c | 2 +-
libavformat/sol.c | 2 +-
libavformat/utils.c | 2 +-
16 files changed, 56 insertions(+), 20 deletions(-)
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 5db6a81320..b00e851ccb 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1430,7 +1430,11 @@ typedef struct AVPacket {
#endif
} AVPacket;
#define AV_PKT_FLAG_KEY 0x0001 ///< The packet contains a keyframe
-#define AV_PKT_FLAG_CORRUPT 0x0002 ///< The packet content is corrupted
+/**
+ * The packet's data is corrupted (as opposed to the headers being corrupted,
+ * or the data being truncated).
+ */
+#define AV_PKT_FLAG_DATA_CORRUPT 0x0002
/**
* Flag is used to discard packets which are required to maintain valid
* decoder state but are not required for output and should be dropped
@@ -1449,6 +1453,29 @@ typedef struct AVPacket {
* be discarded by the decoder. I.e. Non-reference frames.
*/
#define AV_PKT_FLAG_DISPOSABLE 0x0010
+#if !FF_API_SINGLE_CORRUPT_FLAG
+/**
+ * The packet's contents are truncated.
+ */
+#define AV_PKT_FLAG_DATA_TRUNCATED 0x0020
+/**
+ * The packet's headers (most notably including the timestamps) are corrupted.
+ */
+#define AV_PKT_FLAG_HEADER_CORRUPT 0x0040
+
+/**
+ * The packet's data or headers are corrupted or truncated.
+ * Bit-combination of AV_PKT_FLAG_DATA_CORRUPT, AV_PKT_FLAG_DATA_TRUNCATED, and
+ * AV_PKT_FLAG_HEADER_CORRUPT.
+ * Can be set to indicate corruption that may affect data or headers, or cause truncation.
+ * Can be masked against to check for any kind of corruption.
+ */
+#define AV_PKT_FLAG_CORRUPT (AV_PKT_FLAG_DATA_CORRUPT|AV_PKT_FLAG_DATA_TRUNCATED|AV_PKT_FLAG_HEADER_CORRUPT)
+#else
+#define AV_PKT_FLAG_CORRUPT AV_PKT_FLAG_DATA_CORRUPT
+#define AV_PKT_FLAG_DATA_TRUNCATED AV_PKT_FLAG_DATA_CORRUPT
+#define AV_PKT_FLAG_HEADER_CORRUPT AV_PKT_FLAG_DATA_CORRUPT
+#endif
enum AVSideDataParamChangeFlags {
diff --git a/libavcodec/trace_headers_bsf.c b/libavcodec/trace_headers_bsf.c
index 93d04cb509..cbea9cdf1c 100644
--- a/libavcodec/trace_headers_bsf.c
+++ b/libavcodec/trace_headers_bsf.c
@@ -81,8 +81,14 @@ static int trace_headers(AVBSFContext *bsf, AVPacket *out)
if (in->flags & AV_PKT_FLAG_KEY)
av_strlcat(tmp, ", key frame", sizeof(tmp));
- if (in->flags & AV_PKT_FLAG_CORRUPT)
- av_strlcat(tmp, ", corrupt", sizeof(tmp));
+ if (in->flags & AV_PKT_FLAG_DATA_CORRUPT)
+ av_strlcat(tmp, ", data corrupt", sizeof(tmp));
+#if !FF_API_SINGLE_CORRUPT_FLAG
+ if (in->flags & AV_PKT_FLAG_DATA_TRUNCATED)
+ av_strlcat(tmp, ", truncated", sizeof(tmp));
+ if (in->flags & AV_PKT_FLAG_HEADER_CORRUPT)
+ av_strlcat(tmp, ", header corrupt", sizeof(tmp));
+#endif
if (in->pts != AV_NOPTS_VALUE)
av_strlcatf(tmp, sizeof(tmp), ", pts %"PRId64, in->pts);
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 3b5c3000be..2673d8528c 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -126,6 +126,9 @@
#ifndef FF_API_USER_VISIBLE_AVHWACCEL
#define FF_API_USER_VISIBLE_AVHWACCEL (LIBAVCODEC_VERSION_MAJOR < 59)
#endif
+#ifndef FF_API_SINGLE_CORRUPT_FLAG
+#define FF_API_SINGLE_CORRUPT_FLAG (LIBAVCODEC_VERSION_MAJOR < 59)
+#endif
#endif /* AVCODEC_VERSION_H */
diff --git a/libavformat/aiffdec.c b/libavformat/aiffdec.c
index 99e05c78ec..efe6ce3c42 100644
--- a/libavformat/aiffdec.c
+++ b/libavformat/aiffdec.c
@@ -396,7 +396,7 @@ static int aiff_read_packet(AVFormatContext *s,
return res;
if (size >= st->codecpar->block_align)
- pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
+ pkt->flags &= ~AV_PKT_FLAG_DATA_TRUNCATED;
/* Only one stream in an AIFF file */
pkt->stream_index = 0;
pkt->duration = (res / st->codecpar->block_align) * aiff->block_duration;
diff --git a/libavformat/apc.c b/libavformat/apc.c
index b180a50c9b..63a96666c9 100644
--- a/libavformat/apc.c
+++ b/libavformat/apc.c
@@ -78,7 +78,7 @@ static int apc_read_packet(AVFormatContext *s, AVPacket *pkt)
{
if (av_get_packet(s->pb, pkt, MAX_READ_SIZE) <= 0)
return AVERROR(EIO);
- pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
+ pkt->flags &= ~AV_PKT_FLAG_DATA_TRUNCATED;
pkt->stream_index = 0;
return 0;
}
diff --git a/libavformat/iv8.c b/libavformat/iv8.c
index 077d905b4b..74059c976f 100644
--- a/libavformat/iv8.c
+++ b/libavformat/iv8.c
@@ -99,7 +99,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
if (ret < size) {
av_log(s, AV_LOG_ERROR, "Truncated packet! Read %d of %d bytes\n",
ret, size);
- pkt->flags |= AV_PKT_FLAG_CORRUPT;
+ pkt->flags |= AV_PKT_FLAG_DATA_TRUNCATED;
break;
}
}
diff --git a/libavformat/jvdec.c b/libavformat/jvdec.c
index b2c067fb99..d752969e22 100644
--- a/libavformat/jvdec.c
+++ b/libavformat/jvdec.c
@@ -197,7 +197,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
if (ret < size) {
memset(pkt->data + JV_PREAMBLE_SIZE + ret, 0,
AV_INPUT_BUFFER_PADDING_SIZE);
- pkt->flags |= AV_PKT_FLAG_CORRUPT;
+ pkt->flags |= AV_PKT_FLAG_DATA_TRUNCATED;
}
pkt->size = ret + JV_PREAMBLE_SIZE;
pkt->stream_index = 1;
diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c
index a76fe32e59..3dfce2de66 100644
--- a/libavformat/mp3dec.c
+++ b/libavformat/mp3dec.c
@@ -442,7 +442,7 @@ static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt)
return AVERROR_EOF;
}
- pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
+ pkt->flags &= ~AV_PKT_FLAG_DATA_TRUNCATED;
pkt->stream_index = 0;
return ret;
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 0a3ad05726..e068653a7b 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -899,7 +899,7 @@ static int new_pes_packet(PESContext *pes, AVPacket *pkt)
pes->pes_header_size + pes->data_index != pes->total_size +
PES_START_SIZE) {
av_log(pes->stream, AV_LOG_WARNING, "PES packet size mismatch\n");
- pes->flags |= AV_PKT_FLAG_CORRUPT;
+ pes->flags |= AV_PKT_FLAG_DATA_CORRUPT | AV_PKT_FLAG_DATA_TRUNCATED;
}
memset(pkt->data + pkt->size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
@@ -2292,7 +2292,7 @@ static int handle_packet(MpegTSContext *ts, const uint8_t *packet)
pid, expected_cc, cc);
if (tss->type == MPEGTS_PES) {
PESContext *pc = tss->u.pes_filter.opaque;
- pc->flags |= AV_PKT_FLAG_CORRUPT;
+ pc->flags |= AV_PKT_FLAG_DATA_CORRUPT | AV_PKT_FLAG_DATA_TRUNCATED;
}
}
@@ -2300,7 +2300,7 @@ static int handle_packet(MpegTSContext *ts, const uint8_t *packet)
av_log(ts->stream, AV_LOG_DEBUG, "Packet had TEI flag set; marking as corrupt\n");
if (tss->type == MPEGTS_PES) {
PESContext *pc = tss->u.pes_filter.opaque;
- pc->flags |= AV_PKT_FLAG_CORRUPT;
+ pc->flags |= AV_PKT_FLAG_HEADER_CORRUPT | AV_PKT_FLAG_DATA_CORRUPT;
}
}
diff --git a/libavformat/oggparseopus.c b/libavformat/oggparseopus.c
index cd34cf23ba..51e7d0b118 100644
--- a/libavformat/oggparseopus.c
+++ b/libavformat/oggparseopus.c
@@ -133,7 +133,7 @@ static int opus_packet(AVFormatContext *avf, int idx)
seg = os->segp;
d = opus_duration(last_pkt, os->psize);
if (d < 0) {
- os->pflags |= AV_PKT_FLAG_CORRUPT;
+ os->pflags |= AV_PKT_FLAG_HEADER_CORRUPT;
return 0;
}
duration += d;
diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c
index 29b1ab514e..8c33d35998 100644
--- a/libavformat/oggparsevorbis.c
+++ b/libavformat/oggparsevorbis.c
@@ -425,7 +425,7 @@ static int vorbis_packet(AVFormatContext *s, int idx)
seg = os->segp;
d = av_vorbis_parse_frame_flags(priv->vp, last_pkt, 1, &flags);
if (d < 0) {
- os->pflags |= AV_PKT_FLAG_CORRUPT;
+ os->pflags |= AV_PKT_FLAG_HEADER_CORRUPT;
return 0;
} else if (flags & VORBIS_FLAG_COMMENT) {
vorbis_update_metadata(s, idx);
@@ -467,7 +467,7 @@ static int vorbis_packet(AVFormatContext *s, int idx)
if (os->psize > 0) {
duration = av_vorbis_parse_frame_flags(priv->vp, os->buf + os->pstart, 1, &flags);
if (duration < 0) {
- os->pflags |= AV_PKT_FLAG_CORRUPT;
+ os->pflags |= AV_PKT_FLAG_HEADER_CORRUPT;
return 0;
} else if (flags & VORBIS_FLAG_COMMENT) {
vorbis_update_metadata(s, idx);
diff --git a/libavformat/omadec.c b/libavformat/omadec.c
index 423d52b3aa..6868884968 100644
--- a/libavformat/omadec.c
+++ b/libavformat/omadec.c
@@ -314,7 +314,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
int ret = av_get_packet(s->pb, pkt, packet_size);
if (ret < packet_size)
- pkt->flags |= AV_PKT_FLAG_CORRUPT;
+ pkt->flags |= AV_PKT_FLAG_DATA_TRUNCATED;
if (ret < 0)
return ret;
@@ -365,7 +365,7 @@ static int aal_read_packet(AVFormatContext *s, AVPacket *pkt)
avio_skip(s->pb, 12);
ret = av_get_packet(s->pb, pkt, packet_size);
if (ret < packet_size)
- pkt->flags |= AV_PKT_FLAG_CORRUPT;
+ pkt->flags |= AV_PKT_FLAG_DATA_TRUNCATED;
if (ret < 0)
return ret;
diff --git a/libavformat/pcm.c b/libavformat/pcm.c
index 806f91b6b1..bd381cc52f 100644
--- a/libavformat/pcm.c
+++ b/libavformat/pcm.c
@@ -36,7 +36,7 @@ int ff_pcm_read_packet(AVFormatContext *s, AVPacket *pkt)
ret= av_get_packet(s->pb, pkt, size);
- pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
+ pkt->flags &= ~AV_PKT_FLAG_DATA_TRUNCATED;
pkt->stream_index = 0;
return ret;
diff --git a/libavformat/sdsdec.c b/libavformat/sdsdec.c
index 081bb4ca2d..5e482d7efa 100644
--- a/libavformat/sdsdec.c
+++ b/libavformat/sdsdec.c
@@ -146,7 +146,7 @@ static int sds_read_packet(AVFormatContext *ctx, AVPacket *pkt)
if (avio_r8(pb) != 0xF7)
return AVERROR_INVALIDDATA;
- pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
+ pkt->flags &= ~AV_PKT_FLAG_DATA_TRUNCATED;
pkt->stream_index = 0;
pkt->pos = pos;
diff --git a/libavformat/sol.c b/libavformat/sol.c
index 5796f8d234..1c01e2d015 100644
--- a/libavformat/sol.c
+++ b/libavformat/sol.c
@@ -133,7 +133,7 @@ static int sol_read_packet(AVFormatContext *s,
ret= av_get_packet(s->pb, pkt, MAX_SIZE);
if (ret < 0)
return ret;
- pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
+ pkt->flags &= ~AV_PKT_FLAG_DATA_TRUNCATED;
pkt->stream_index = 0;
return 0;
}
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 84e49208b8..8d49348d9e 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -282,7 +282,7 @@ static int append_packet_chunked(AVIOContext *s, AVPacket *pkt, int size)
size -= read_size;
} while (size > 0);
if (size > 0)
- pkt->flags |= AV_PKT_FLAG_CORRUPT;
+ pkt->flags |= AV_PKT_FLAG_DATA_TRUNCATED;
pkt->pos = orig_pos;
if (!pkt->size)
--
2.15.1
More information about the ffmpeg-devel
mailing list