On 17/03/16 14:11, Mark Thompson wrote: > On 17/03/16 13:57, Michael Niedermayer wrote: >> On Thu, Mar 17, 2016 at 01:48:37PM +0000, Mark Thompson wrote: >>> hevc_parse.c | 10 ++++++++-- >>> 1 file changed, 8 insertions(+), 2 deletions(-) >>> daf73b16f8185221a1e8112ab1928157a855fe76 >>> 0001-lavc-hevc-Allow-arbitrary-garbage-in-bytestream-as-l.patch >>> From 725fb99402fa468e5f11f94e0ec09b2e0c91e6b2 Mon Sep 17 00:00:00 2001 >>> From: Mark Thompson <m...@jkqxz.net> >>> Date: Thu, 17 Mar 2016 13:41:02 +0000 >>> Subject: [PATCH] lavc/hevc: Allow arbitrary garbage in bytestream as long as >>> at least one NAL unit is found. >>> >>> --- >>> libavcodec/hevc_parse.c | 10 ++++++++-- >>> 1 file changed, 8 insertions(+), 2 deletions(-) >>> >>> diff --git a/libavcodec/hevc_parse.c b/libavcodec/hevc_parse.c >>> index 63ed84a..d557cc7 100644 >>> --- a/libavcodec/hevc_parse.c >>> +++ b/libavcodec/hevc_parse.c >>> @@ -232,8 +232,14 @@ int ff_hevc_split_packet(HEVCContext *s, HEVCPacket >>> *pkt, const uint8_t *buf, in >>> ++buf; >>> --length; >>> if (length < 4) { >>> - av_log(avctx, AV_LOG_ERROR, "No start code is >>> found.\n"); >>> - return AVERROR_INVALIDDATA; >>> + if (pkt->nb_nals > 0) { >>> + // No more start codes: we discarded some >>> irrelevant >>> + // bytes at the end of the packet. >>> + return 0; >> >> does the case of garbage still print something at some level? >> if not, it should. It could be usefull for debuging to know if theres >> something funky going on with NAL parsing > > It already doesn't print anything for the garbage it accepts between NAL units > in a packet; this change just makes it consistent by silently accepting > garbage > at the end as well. If we want to log something for all of these cases then > it > would have to look more like the first version of the patch to skip zeroes and > then log a warning if the second search does not find a start code > immediately.
Something like this, perhaps (not thoroughly tested).
>From 439408a7f25b1dc5146a580fec487ad0b2c0163a Mon Sep 17 00:00:00 2001 From: Mark Thompson <m...@jkqxz.net> Date: Thu, 17 Mar 2016 13:41:02 +0000 Subject: [PATCH] lavc/hevc: Log warnings for garbage found when parsing bytestream. --- libavcodec/hevc_parse.c | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/libavcodec/hevc_parse.c b/libavcodec/hevc_parse.c index 63ed84a..a153747 100644 --- a/libavcodec/hevc_parse.c +++ b/libavcodec/hevc_parse.c @@ -227,13 +227,48 @@ int ff_hevc_split_packet(HEVCContext *s, HEVCPacket *pkt, const uint8_t *buf, in return AVERROR_INVALIDDATA; } } else { - /* search start code */ - while (buf[0] != 0 || buf[1] != 0 || buf[2] != 1) { + int i; + // Skip leading zeroes before the start code in the bytestream (or, + // equivalently, trailing zeroes of the previous NAL unit). + while (buf[0] == 0 && buf[1] == 0 && buf[2] == 0) { ++buf; --length; - if (length < 4) { - av_log(avctx, AV_LOG_ERROR, "No start code is found.\n"); + if (length < 4) + break; + } + if (length < 4) { + if (pkt->nb_nals == 0) { + av_log(avctx, AV_LOG_ERROR, "No start code found: packet " + "contains only zero bytes.\n"); return AVERROR_INVALIDDATA; + } else { + // There was a NAL unit with trailing zeroes which we + // are ignoring. + break; + } + } + // We should find a start code immediately, if we don't then there + // is something funny going on in the packet. + for (i = 0; buf[0] != 0 || buf[1] != 0 || buf[2] != 1; i++) { + ++buf; + --length; + if (length < 4) + break; + } + if (i > 0) { + if (length < 4) { + if (pkt->nb_nals > 0) { + av_log(avctx, AV_LOG_WARNING, "Skipped %d bytes of " + "garbage at end of packet.\n", i); + break; + } else { + av_log(avctx, AV_LOG_ERROR, "No start code found: " + "packet contains garbage.\n"); + return AVERROR_INVALIDDATA; + } + } else { + av_log(avctx, AV_LOG_WARNING, "Skipped %d bytes of " + "garbage before finding a start code.\n", i); } } -- 2.7.0
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel