aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Penquerc'h2012-10-19 09:47:29 -0500
committerNikhil Devshatwar2013-05-15 08:18:35 -0500
commit931f75a10306dc710f0ee4661d472faf173cf9d1 (patch)
tree9fcc41ba54828db77e008e52d8fb052aa2d0b5aa
parente10c6c9cb7b71cda2b13912630a93004661250e8 (diff)
downloadgst-plugins-bad0-10-931f75a10306dc710f0ee4661d472faf173cf9d1.tar.gz
gst-plugins-bad0-10-931f75a10306dc710f0ee4661d472faf173cf9d1.tar.xz
gst-plugins-bad0-10-931f75a10306dc710f0ee4661d472faf173cf9d1.zip
mpeg4parser: speed up scan for start codes
While some may be suspicious of the call to memchr, GCC is expected to have an intrinsic definition for it, which should see it turned into a set of asm opcodes tailored for the task.
-rw-r--r--gst-libs/gst/codecparsers/gstmpeg4parser.c32
1 files changed, 28 insertions, 4 deletions
diff --git a/gst-libs/gst/codecparsers/gstmpeg4parser.c b/gst-libs/gst/codecparsers/gstmpeg4parser.c
index 0923c103c..0827e9f0e 100644
--- a/gst-libs/gst/codecparsers/gstmpeg4parser.c
+++ b/gst-libs/gst/codecparsers/gstmpeg4parser.c
@@ -407,6 +407,32 @@ gst_mpeg4_next_resync (GstMpeg4Packet * packet,
407 407
408/********** API **********/ 408/********** API **********/
409 409
410static guint
411find_start_code (const guint8 * data, guint offset, guint size)
412{
413 const guint8 *start = data;
414
415 g_return_val_if_fail (size > 0, -1);
416
417 /* we can't find the pattern with less than 4 bytes */
418 if (G_UNLIKELY (size < 4))
419 return -1;
420
421 data += offset;
422 size -= 3;
423 while (size > 0) {
424 const guint8 *ptr = memchr (data, 0, size);
425 if (G_UNLIKELY (ptr == NULL))
426 return -1;
427 if (ptr[2] == 1 && ptr[1] == 0)
428 return ptr - start;
429 size -= (ptr - data) + 1;
430 data = ptr + 1;
431 }
432
433 return -1;
434}
435
410/** 436/**
411 * gst_mpeg4_parse: 437 * gst_mpeg4_parse:
412 * @packet: The #GstMpeg4Packet to fill 438 * @packet: The #GstMpeg4Packet to fill
@@ -461,8 +487,7 @@ gst_mpeg4_parse (GstMpeg4Packet * packet, gboolean skip_user_data,
461 first_resync_marker = TRUE; 487 first_resync_marker = TRUE;
462 } 488 }
463 489
464 off1 = gst_byte_reader_masked_scan_uint32 (&br, 0xffffff00, 0x00000100, 490 off1 = find_start_code (br.data + br.byte, offset, size - offset);
465 offset, size - offset);
466 491
467 if (off1 == -1) { 492 if (off1 == -1) {
468 GST_DEBUG ("No start code prefix in this buffer"); 493 GST_DEBUG ("No start code prefix in this buffer");
@@ -480,8 +505,7 @@ gst_mpeg4_parse (GstMpeg4Packet * packet, gboolean skip_user_data,
480 packet->type = (GstMpeg4StartCode) (data[off1 + 3]); 505 packet->type = (GstMpeg4StartCode) (data[off1 + 3]);
481 506
482find_end: 507find_end:
483 off2 = gst_byte_reader_masked_scan_uint32 (&br, 0xffffff00, 0x00000100, 508 off2 = find_start_code (br.data + br.byte, off1 + 4, size - off1 - 4);
484 off1 + 4, size - off1 - 4);
485 509
486 if (off2 == -1) { 510 if (off2 == -1) {
487 GST_DEBUG ("Packet start %d, No end found", off1 + 4); 511 GST_DEBUG ("Packet start %d, No end found", off1 + 4);