gst/typefind/gsttypefindfunctions.c: Don't do lots of 4-byte peeks, but use the 'new' data scan helper for this inste...
Original commit message from CVS: * gst/typefind/gsttypefindfunctions.c: (h264_video_type_find): Don't do lots of 4-byte peeks, but use the 'new' data scan helper for this instead; don't check if we've found enough markers after each and every step, it's enough to do that only if we've actually found a new marker. Embed a G_UNLIKELY into the IS_MPEG_HEADER macro.
This commit is contained in:
parent
104fed4d66
commit
fed34307db
@ -1,3 +1,12 @@
|
|||||||
|
2008-05-10 Tim-Philipp Müller <tim.muller at collabora co uk>
|
||||||
|
|
||||||
|
* gst/typefind/gsttypefindfunctions.c: (h264_video_type_find):
|
||||||
|
Don't do lots of 4-byte peeks, but use the 'new' data scan helper
|
||||||
|
for this instead; don't check if we've found enough markers after
|
||||||
|
each and every step, it's enough to do that only if we've actually
|
||||||
|
found a new marker.
|
||||||
|
Embed a G_UNLIKELY into the IS_MPEG_HEADER macro.
|
||||||
|
|
||||||
2008-05-10 Tim-Philipp Müller <tim.muller at collabora co uk>
|
2008-05-10 Tim-Philipp Müller <tim.muller at collabora co uk>
|
||||||
|
|
||||||
* gst/typefind/gsttypefindfunctions.c:
|
* gst/typefind/gsttypefindfunctions.c:
|
||||||
|
@ -1220,9 +1220,9 @@ static GstStaticCaps mpeg_sys_caps = GST_STATIC_CAPS ("video/mpeg, "
|
|||||||
"systemstream = (boolean) true, mpegversion = (int) [ 1, 2 ]");
|
"systemstream = (boolean) true, mpegversion = (int) [ 1, 2 ]");
|
||||||
|
|
||||||
#define MPEG_SYS_CAPS gst_static_caps_get(&mpeg_sys_caps)
|
#define MPEG_SYS_CAPS gst_static_caps_get(&mpeg_sys_caps)
|
||||||
#define IS_MPEG_HEADER(data) ((((guint8 *)(data))[0] == 0x00) && \
|
#define IS_MPEG_HEADER(data) (G_UNLIKELY((((guint8 *)(data))[0] == 0x00) && \
|
||||||
(((guint8 *)(data))[1] == 0x00) && \
|
(((guint8 *)(data))[1] == 0x00) && \
|
||||||
(((guint8 *)(data))[2] == 0x01))
|
(((guint8 *)(data))[2] == 0x01)))
|
||||||
|
|
||||||
#define IS_MPEG_PACK_CODE(b) ((b) == 0xBA)
|
#define IS_MPEG_PACK_CODE(b) ((b) == 0xBA)
|
||||||
#define IS_MPEG_SYS_CODE(b) ((b) == 0xBB)
|
#define IS_MPEG_SYS_CODE(b) ((b) == 0xBB)
|
||||||
@ -1630,11 +1630,11 @@ static GstStaticCaps h264_video_caps = GST_STATIC_CAPS ("video/x-h264");
|
|||||||
static void
|
static void
|
||||||
h264_video_type_find (GstTypeFind * tf, gpointer unused)
|
h264_video_type_find (GstTypeFind * tf, gpointer unused)
|
||||||
{
|
{
|
||||||
|
DataScanCtx c = { 0, NULL, 0 };
|
||||||
|
|
||||||
/* Stream consists of: a series of sync codes (00 00 00 01) followed
|
/* Stream consists of: a series of sync codes (00 00 00 01) followed
|
||||||
* by NALs
|
* by NALs
|
||||||
*/
|
*/
|
||||||
guint8 *data = NULL;
|
|
||||||
int offset = 0;
|
|
||||||
int stat_slice = 0;
|
int stat_slice = 0;
|
||||||
int stat_dpa = 0;
|
int stat_dpa = 0;
|
||||||
int stat_dpb = 0;
|
int stat_dpb = 0;
|
||||||
@ -1644,18 +1644,17 @@ h264_video_type_find (GstTypeFind * tf, gpointer unused)
|
|||||||
int stat_pps = 0;
|
int stat_pps = 0;
|
||||||
int nut, ref;
|
int nut, ref;
|
||||||
|
|
||||||
while (offset < H264_MAX_PROBE_LENGTH) {
|
while (c.offset < H264_MAX_PROBE_LENGTH) {
|
||||||
data = gst_type_find_peek (tf, offset, 4);
|
if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 4)))
|
||||||
if (data == NULL)
|
break;
|
||||||
goto done;
|
|
||||||
|
|
||||||
if (data && IS_MPEG_HEADER (data)) {
|
if (IS_MPEG_HEADER (c.data)) {
|
||||||
nut = data[3] & 0x9f; /* forbiden_zero_bit | nal_unit_type */
|
nut = c.data[3] & 0x9f; /* forbiden_zero_bit | nal_unit_type */
|
||||||
ref = data[3] & 0x60; /* nal_ref_idc */
|
ref = c.data[3] & 0x60; /* nal_ref_idc */
|
||||||
|
|
||||||
/* if forbiden bit is different to 0 won't be h264 */
|
/* if forbiden bit is different to 0 won't be h264 */
|
||||||
if (nut > 0x1f)
|
if (nut > 0x1f)
|
||||||
goto done;
|
break;
|
||||||
|
|
||||||
/* collect statistics about the NAL types */
|
/* collect statistics about the NAL types */
|
||||||
if (nut == 1)
|
if (nut == 1)
|
||||||
@ -1673,23 +1672,19 @@ h264_video_type_find (GstTypeFind * tf, gpointer unused)
|
|||||||
else if ((nut == 8) && (ref != 0))
|
else if ((nut == 8) && (ref != 0))
|
||||||
stat_pps++;
|
stat_pps++;
|
||||||
|
|
||||||
offset += 4;
|
if ((stat_slice > 4 || (stat_dpa > 4 && stat_dpb > 4 && stat_dpc > 4)) &&
|
||||||
}
|
stat_idr >= 1 && stat_sps >= 1 && stat_pps >= 1) {
|
||||||
offset += 1;
|
GstCaps *caps = gst_caps_copy (H264_VIDEO_CAPS);
|
||||||
|
|
||||||
if ((stat_slice > 4 || (stat_dpa > 4 && stat_dpb > 4 && stat_dpc > 4)) &&
|
gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM - 1, caps);
|
||||||
stat_idr >= 1 && stat_sps >= 1 && stat_pps >= 1) {
|
gst_caps_unref (caps);
|
||||||
GstCaps *caps = gst_caps_copy (H264_VIDEO_CAPS);
|
return;
|
||||||
|
}
|
||||||
gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM - 1, caps);
|
|
||||||
gst_caps_unref (caps);
|
data_scan_ctx_advance (tf, &c, 4);
|
||||||
|
|
||||||
goto done;
|
|
||||||
}
|
}
|
||||||
|
data_scan_ctx_advance (tf, &c, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** video/mpeg video stream ***/
|
/*** video/mpeg video stream ***/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user