mpegtspacketizer: Speedup packet parsing
authorEdward Hervey <edward@collabora.com>
Sun, 23 Jun 2013 13:26:14 +0000 (15:26 +0200)
committerEdward Hervey <edward@collabora.com>
Mon, 24 Jun 2013 05:49:34 +0000 (07:49 +0200)
Avoid using bitshifting where not needed.

Speeds up packet parsing by 3% (this is *the* hotspot of mpeg-ts elements).

gst/mpegtsdemux/mpegtspacketizer.c
gst/mpegtsdemux/mpegtspacketizer.h
gst/mpegtsdemux/tsdemux.c

index 11d6e82..85e1cda 100644 (file)
@@ -508,7 +508,7 @@ mpegts_packetizer_parse_adaptation_field_control (MpegTSPacketizer2 *
     return TRUE;
   }
 
-  if (packet->adaptation_field_control == 0x02) {
+  if (packet->adaptation_field_control == 0x20) {
     /* no payload, adaptation field of 183 bytes */
     if (length != 183) {
       GST_DEBUG ("PID %d afc == 0x%x and length %d != 183",
@@ -567,40 +567,43 @@ mpegts_packetizer_parse_packet (MpegTSPacketizer2 * packetizer,
     MpegTSPacketizerPacket * packet)
 {
   guint8 *data;
+  guint8 tmp;
 
   data = packet->data_start;
-  data++;
+  data += 1;
+  tmp = *data;
 
   /* transport_error_indicator 1 */
-  if (G_UNLIKELY (*data >> 7))
+  if (G_UNLIKELY (tmp & 0x80))
     return PACKET_BAD;
 
   /* payload_unit_start_indicator 1 */
-  packet->payload_unit_start_indicator = (*data >> 6) & 0x01;
+  packet->payload_unit_start_indicator = tmp & 0x40;
 
   /* transport_priority 1 */
   /* PID 13 */
   packet->pid = GST_READ_UINT16_BE (data) & 0x1FFF;
   data += 2;
 
+  tmp = *data;
   /* transport_scrambling_control 2 */
-  if (G_UNLIKELY (*data >> 6))
+  if (G_UNLIKELY (tmp & 0xc0))
     return PACKET_BAD;
 
   /* adaptation_field_control 2 */
-  packet->adaptation_field_control = (*data >> 4) & 0x03;
+  packet->adaptation_field_control = tmp & 0x30;
 
   /* continuity_counter 4 */
-  packet->continuity_counter = *data & 0x0F;
+  packet->continuity_counter = tmp & 0x0F;
   data += 1;
 
   packet->data = data;
 
-  if (packet->adaptation_field_control & 0x02)
+  if (packet->adaptation_field_control & 0x20)
     if (!mpegts_packetizer_parse_adaptation_field_control (packetizer, packet))
       return FALSE;
 
-  if (packet->adaptation_field_control & 0x01)
+  if (packet->adaptation_field_control & 0x10)
     packet->payload = packet->data;
   else
     packet->payload = NULL;
@@ -2789,7 +2792,7 @@ mpegts_packetizer_push_section (MpegTSPacketizer2 * packetizer,
   data = packet->data;
   section->pid = packet->pid;
 
-  if (packet->payload_unit_start_indicator == 1) {
+  if (packet->payload_unit_start_indicator) {
     pointer = *data++;
     if (data + pointer > packet->data_end) {
       GST_WARNING ("PID 0x%04x PSI section pointer points past the end "
index b6e1aaf..bdc6073 100644 (file)
@@ -153,7 +153,7 @@ typedef struct
    * section when the section_syntax_indicator is set to a value of "1". If 
    * section_syntax_indicator is 0, sub_table_extension will be set to 0 */
   guint16 subtable_extension;
-  guint8 version_number;
+  guint8  version_number;
   GList * crc;
 } MpegTSPacketizerStreamSubtable;
 
index 509e612..7b1f6db 100644 (file)
@@ -1559,7 +1559,7 @@ gst_ts_demux_handle_packet (GstTSDemux * demux, TSDemuxStream * stream,
   }
 
   if (G_UNLIKELY (packet->payload_unit_start_indicator) &&
-      packet->adaptation_field_control & 0x1)
+      packet->adaptation_field_control & 0x10)
     /* Flush previous data */
     res = gst_ts_demux_push_pending_data (demux, stream);