[FFmpeg-cvslog] avcodec/h264_parser: Factor get_avc_nalsize() out
Michael Niedermayer
git at videolan.org
Sat Aug 20 01:59:37 EEST 2016
ffmpeg | branch: master | Michael Niedermayer <michael at niedermayer.cc> | Sat Aug 20 00:36:38 2016 +0200| [f10ea03df3dd1c15e3a957ca0aba528251438a79] | committer: Michael Niedermayer
avcodec/h264_parser: Factor get_avc_nalsize() out
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f10ea03df3dd1c15e3a957ca0aba528251438a79
---
libavcodec/h2645_parse.h | 20 ++++++++++++++++++++
libavcodec/h264_parser.c | 22 +---------------------
2 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/libavcodec/h2645_parse.h b/libavcodec/h2645_parse.h
index 6302359..3a60f3f 100644
--- a/libavcodec/h2645_parse.h
+++ b/libavcodec/h2645_parse.h
@@ -90,4 +90,24 @@ int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length,
*/
void ff_h2645_packet_uninit(H2645Packet *pkt);
+static inline int get_nalsize(int nal_length_size, const uint8_t *buf,
+ int buf_size, int *buf_index, void *logctx)
+{
+ int i, nalsize = 0;
+
+ if (*buf_index >= buf_size - nal_length_size) {
+ // the end of the buffer is reached, refill it
+ return AVERROR(EAGAIN);
+ }
+
+ for (i = 0; i < nal_length_size; i++)
+ nalsize = ((unsigned)nalsize << 8) | buf[(*buf_index)++];
+ if (nalsize <= 0 || nalsize > buf_size - *buf_index) {
+ av_log(logctx, AV_LOG_ERROR,
+ "Invalid nal size %d\n", nalsize);
+ return AVERROR_INVALIDDATA;
+ }
+ return nalsize;
+}
+
#endif /* AVCODEC_H2645_PARSE_H */
diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
index 8abe05d..615884f 100644
--- a/libavcodec/h264_parser.c
+++ b/libavcodec/h264_parser.c
@@ -228,26 +228,6 @@ static int scan_mmco_reset(AVCodecParserContext *s, GetBitContext *gb,
return 0;
}
-static inline int get_avc_nalsize(H264ParseContext *p, const uint8_t *buf,
- int buf_size, int *buf_index, void *logctx)
-{
- int i, nalsize = 0;
-
- if (*buf_index >= buf_size - p->nal_length_size) {
- // the end of the buffer is reached, refill it
- return AVERROR(EAGAIN);
- }
-
- for (i = 0; i < p->nal_length_size; i++)
- nalsize = ((unsigned)nalsize << 8) | buf[(*buf_index)++];
- if (nalsize <= 0 || nalsize > buf_size - *buf_index) {
- av_log(logctx, AV_LOG_ERROR,
- "AVC: nal size %d\n", nalsize);
- return AVERROR_INVALIDDATA;
- }
- return nalsize;
-}
-
/**
* Parse NAL units of found picture and decode some basic information.
*
@@ -288,7 +268,7 @@ static inline int parse_nal_units(AVCodecParserContext *s,
int src_length, consumed, nalsize = 0;
if (buf_index >= next_avc) {
- nalsize = get_avc_nalsize(p, buf, buf_size, &buf_index, avctx);
+ nalsize = get_nalsize(p->nal_length_size, buf, buf_size, &buf_index, avctx);
if (nalsize < 0)
break;
next_avc = buf_index + nalsize;
More information about the ffmpeg-cvslog
mailing list