[FFmpeg-devel] [PATCH] avformat/mpeg: use avpriv_find_start_code in mpegps_probe()
zhaoxiu.zeng
zhaoxiu.zeng at gmail.com
Sun Mar 15 10:05:46 CET 2015
>From 520c5898f2c0372188f17f98e10a40174dde4aac Mon Sep 17 00:00:00 2001
From: Zeng Zhaoxiu <zhaoxiu.zeng at gmail.com>
Date: Sun, 15 Mar 2015 12:01:51 +0800
Subject: [PATCH 5/7] avformat/mpeg: use avpriv_find_start_code in
mpegps_probe()
Signed-off-by: Zeng Zhaoxiu <zhaoxiu.zeng at gmail.com>
---
libavformat/mpeg.c | 51 ++++++++++++++++++++++++---------------------------
1 file changed, 24 insertions(+), 27 deletions(-)
diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c
index a0b5738..ffba786 100644
--- a/libavformat/mpeg.c
+++ b/libavformat/mpeg.c
@@ -29,6 +29,7 @@
#endif
#include "libavutil/avassert.h"
+#include "libavcodec/internal.h"
/*********************************************/
/* demux code */
@@ -38,12 +39,12 @@
static int check_pes(const uint8_t *p, const uint8_t *end)
{
int pes1;
- int pes2 = (p[3] & 0xC0) == 0x80 &&
- (p[4] & 0xC0) != 0x40 &&
- ((p[4] & 0xC0) == 0x00 ||
- (p[4] & 0xC0) >> 2 == (p[6] & 0xF0));
+ int pes2 = (p[2] & 0xC0) == 0x80 &&
+ (p[3] & 0xC0) != 0x40 &&
+ ((p[3] & 0xC0) == 0x00 ||
+ (p[3] & 0xC0) >> 2 == (p[5] & 0xF0));
- for (p += 3; p < end && *p == 0xFF; p++) ;
+ for (p += 2; p < end && *p == 0xFF; p++) ;
if ((*p & 0xC0) == 0x40)
p += 2;
@@ -59,41 +60,37 @@ static int check_pes(const uint8_t *p, const uint8_t *end)
static int check_pack_header(const uint8_t *buf)
{
- return (buf[1] & 0xC0) == 0x40 || (buf[1] & 0xF0) == 0x20;
+ return (buf[0] & 0xC0) == 0x40 || (buf[0] & 0xF0) == 0x20;
}
static int mpegps_probe(AVProbeData *p)
{
uint32_t code = -1;
- int i;
int sys = 0, pspack = 0, priv1 = 0, vid = 0;
int audio = 0, invalid = 0, score = 0;
- int endpes = 0;
+ const uint8_t *ptr = p->buf, *end = ptr + p->buf_size;
+ const uint8_t *endpes = ptr;
- for (i = 0; i < p->buf_size; i++) {
- code = (code << 8) + p->buf[i];
+ while (ptr < end) {
+ ptr = avpriv_find_start_code(ptr, end, &code);
if ((code & 0xffffff00) == 0x100) {
- int len = p->buf[i + 1] << 8 | p->buf[i + 2];
- int pes = endpes <= i && check_pes(p->buf + i, p->buf + p->buf_size);
- int pack = check_pack_header(p->buf + i);
-
if (code == SYSTEM_HEADER_START_CODE)
sys++;
- else if (code == PACK_START_CODE && pack)
+ else if (code == PACK_START_CODE && check_pack_header(ptr))
pspack++;
- else if ((code & 0xf0) == VIDEO_ID && pes) {
- endpes = i + len;
- vid++;
+ else if (endpes < ptr && check_pes(ptr, end)) {
+ int len = AV_RB16(ptr);
+ if ((code & 0xf0) == VIDEO_ID) { vid++; endpes = ptr + len; }
+ // skip pes payload to avoid start code emulation for private
+ // and audio streams
+ else if ((code & 0xe0) == AUDIO_ID) { audio++; ptr += len; code = -1; }
+ else if (code == PRIVATE_STREAM_1 ) { priv1++; ptr += len; code = -1; }
+ else if (code == 0x1fd ) vid++; //VC1
+ } else {
+ if ((code & 0xf0) == VIDEO_ID) invalid++;
+ else if ((code & 0xe0) == AUDIO_ID) invalid++;
+ else if (code == PRIVATE_STREAM_1 ) invalid++;
}
- // skip pes payload to avoid start code emulation for private
- // and audio streams
- else if ((code & 0xe0) == AUDIO_ID && pes) {audio++; i+=len;}
- else if (code == PRIVATE_STREAM_1 && pes) {priv1++; i+=len;}
- else if (code == 0x1fd && pes) vid++; //VC1
-
- else if ((code & 0xf0) == VIDEO_ID && !pes) invalid++;
- else if ((code & 0xe0) == AUDIO_ID && !pes) invalid++;
- else if (code == PRIVATE_STREAM_1 && !pes) invalid++;
}
}
--
2.1.0
More information about the ffmpeg-devel
mailing list