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>
+
* gst/typefind/gsttypefindfunctions.c:
(DATA_SCAN_CTX_CHUNK_SIZE), (DataScanCtx), (data_scan_ctx_advance),
(data_scan_ctx_ensure_data), (GST_MPEGVID_TYPEFIND_TRY_SYNC),
"systemstream = (boolean) true, mpegversion = (int) [ 1, 2 ]");
#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))[2] == 0x01))
+ (((guint8 *)(data))[2] == 0x01)))
#define IS_MPEG_PACK_CODE(b) ((b) == 0xBA)
#define IS_MPEG_SYS_CODE(b) ((b) == 0xBB)
static void
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
* by NALs
*/
- guint8 *data = NULL;
- int offset = 0;
int stat_slice = 0;
int stat_dpa = 0;
int stat_dpb = 0;
int stat_pps = 0;
int nut, ref;
- while (offset < H264_MAX_PROBE_LENGTH) {
- data = gst_type_find_peek (tf, offset, 4);
- if (data == NULL)
- goto done;
+ while (c.offset < H264_MAX_PROBE_LENGTH) {
+ if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 4)))
+ break;
- if (data && IS_MPEG_HEADER (data)) {
- nut = data[3] & 0x9f; /* forbiden_zero_bit | nal_unit_type */
- ref = data[3] & 0x60; /* nal_ref_idc */
+ if (IS_MPEG_HEADER (c.data)) {
+ nut = c.data[3] & 0x9f; /* forbiden_zero_bit | nal_unit_type */
+ ref = c.data[3] & 0x60; /* nal_ref_idc */
/* if forbiden bit is different to 0 won't be h264 */
if (nut > 0x1f)
- goto done;
+ break;
/* collect statistics about the NAL types */
if (nut == 1)
else if ((nut == 8) && (ref != 0))
stat_pps++;
- offset += 4;
- }
- offset += 1;
+ if ((stat_slice > 4 || (stat_dpa > 4 && stat_dpb > 4 && stat_dpc > 4)) &&
+ stat_idr >= 1 && stat_sps >= 1 && stat_pps >= 1) {
+ GstCaps *caps = gst_caps_copy (H264_VIDEO_CAPS);
- if ((stat_slice > 4 || (stat_dpa > 4 && stat_dpb > 4 && stat_dpc > 4)) &&
- stat_idr >= 1 && stat_sps >= 1 && stat_pps >= 1) {
- GstCaps *caps = gst_caps_copy (H264_VIDEO_CAPS);
-
- gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM - 1, caps);
- gst_caps_unref (caps);
+ gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM - 1, caps);
+ gst_caps_unref (caps);
+ return;
+ }
- goto done;
+ data_scan_ctx_advance (tf, &c, 4);
}
+ data_scan_ctx_advance (tf, &c, 1);
}
-
-done:
- return;
}
/*** video/mpeg video stream ***/