mpegtspacketizer: Make next_packet() return an enum.

This avoids calling an extra gst_adapter_available() in a tight loop.
This commit is contained in:
Edward Hervey 2009-09-15 23:12:33 +02:00
parent bdc513b31e
commit 8b981fba5c
3 changed files with 16 additions and 12 deletions

View file

@ -1971,15 +1971,15 @@ mpegts_packetizer_has_packets (MpegTSPacketizer * packetizer)
return gst_adapter_available (packetizer->adapter) >= 188;
}
gboolean
MpegTSPacketizerPacketReturn
mpegts_packetizer_next_packet (MpegTSPacketizer * packetizer,
MpegTSPacketizerPacket * packet)
{
guint8 sync_byte;
gboolean ret = FALSE;
guint avail;
packet->buffer = NULL;
while (gst_adapter_available (packetizer->adapter) >= 188) {
while ((avail = gst_adapter_available (packetizer->adapter)) >= 188) {
sync_byte = *gst_adapter_peek (packetizer->adapter, 1);
if (G_UNLIKELY (sync_byte != 0x47)) {
GST_DEBUG ("lost sync %02x", sync_byte);
@ -1991,11 +1991,10 @@ mpegts_packetizer_next_packet (MpegTSPacketizer * packetizer,
packet->data_start = GST_BUFFER_DATA (packet->buffer);
packet->data_end =
GST_BUFFER_DATA (packet->buffer) + GST_BUFFER_SIZE (packet->buffer);
ret = mpegts_packetizer_parse_packet (packetizer, packet);
break;
return mpegts_packetizer_parse_packet (packetizer, packet);
}
return ret;
return PACKET_NEED_MORE;
}
void

View file

@ -104,6 +104,11 @@ typedef struct
GSList *subtables;
} MpegTSPacketizerStream;
typedef enum {
PACKET_BAD = FALSE,
PACKET_OK = TRUE,
PACKET_NEED_MORE
} MpegTSPacketizerPacketReturn;
GType gst_mpegts_packetizer_get_type(void);
@ -111,7 +116,7 @@ MpegTSPacketizer *mpegts_packetizer_new ();
void mpegts_packetizer_clear (MpegTSPacketizer *packetizer);
void mpegts_packetizer_push (MpegTSPacketizer *packetizer, GstBuffer *buffer);
gboolean mpegts_packetizer_has_packets (MpegTSPacketizer *packetizer);
gboolean mpegts_packetizer_next_packet (MpegTSPacketizer *packetizer,
MpegTSPacketizerPacketReturn mpegts_packetizer_next_packet (MpegTSPacketizer *packetizer,
MpegTSPacketizerPacket *packet);
void mpegts_packetizer_clear_packet (MpegTSPacketizer *packetizer,
MpegTSPacketizerPacket *packet);

View file

@ -1214,6 +1214,7 @@ mpegts_parse_chain (GstPad * pad, GstBuffer * buf)
GstFlowReturn res = GST_FLOW_OK;
MpegTSParse *parse;
gboolean parsed;
MpegTSPacketizerPacketReturn pret;
MpegTSPacketizer *packetizer;
MpegTSPacketizerPacket packet;
@ -1221,11 +1222,10 @@ mpegts_parse_chain (GstPad * pad, GstBuffer * buf)
packetizer = parse->packetizer;
mpegts_packetizer_push (parse->packetizer, buf);
while (mpegts_packetizer_has_packets (parse->packetizer) &&
!GST_FLOW_IS_FATAL (res)) {
/* get the next packet */
parsed = mpegts_packetizer_next_packet (packetizer, &packet);
if (G_UNLIKELY (!parsed))
while (((pret =
mpegts_packetizer_next_packet (parse->packetizer,
&packet)) != PACKET_NEED_MORE) && !GST_FLOW_IS_FATAL (res)) {
if (G_UNLIKELY (pret == PACKET_BAD))
/* bad header, skip the packet */
goto next;