mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-17 04:45:47 +00:00
mpegtspacketizer: Make next_packet() return an enum.
This avoids calling an extra gst_adapter_available() in a tight loop.
This commit is contained in:
parent
bdc513b31e
commit
8b981fba5c
3 changed files with 16 additions and 12 deletions
|
@ -1971,15 +1971,15 @@ mpegts_packetizer_has_packets (MpegTSPacketizer * packetizer)
|
||||||
return gst_adapter_available (packetizer->adapter) >= 188;
|
return gst_adapter_available (packetizer->adapter) >= 188;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
MpegTSPacketizerPacketReturn
|
||||||
mpegts_packetizer_next_packet (MpegTSPacketizer * packetizer,
|
mpegts_packetizer_next_packet (MpegTSPacketizer * packetizer,
|
||||||
MpegTSPacketizerPacket * packet)
|
MpegTSPacketizerPacket * packet)
|
||||||
{
|
{
|
||||||
guint8 sync_byte;
|
guint8 sync_byte;
|
||||||
gboolean ret = FALSE;
|
guint avail;
|
||||||
|
|
||||||
packet->buffer = NULL;
|
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);
|
sync_byte = *gst_adapter_peek (packetizer->adapter, 1);
|
||||||
if (G_UNLIKELY (sync_byte != 0x47)) {
|
if (G_UNLIKELY (sync_byte != 0x47)) {
|
||||||
GST_DEBUG ("lost sync %02x", sync_byte);
|
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_start = GST_BUFFER_DATA (packet->buffer);
|
||||||
packet->data_end =
|
packet->data_end =
|
||||||
GST_BUFFER_DATA (packet->buffer) + GST_BUFFER_SIZE (packet->buffer);
|
GST_BUFFER_DATA (packet->buffer) + GST_BUFFER_SIZE (packet->buffer);
|
||||||
ret = mpegts_packetizer_parse_packet (packetizer, packet);
|
return mpegts_packetizer_parse_packet (packetizer, packet);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return PACKET_NEED_MORE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -104,6 +104,11 @@ typedef struct
|
||||||
GSList *subtables;
|
GSList *subtables;
|
||||||
} MpegTSPacketizerStream;
|
} MpegTSPacketizerStream;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
PACKET_BAD = FALSE,
|
||||||
|
PACKET_OK = TRUE,
|
||||||
|
PACKET_NEED_MORE
|
||||||
|
} MpegTSPacketizerPacketReturn;
|
||||||
|
|
||||||
GType gst_mpegts_packetizer_get_type(void);
|
GType gst_mpegts_packetizer_get_type(void);
|
||||||
|
|
||||||
|
@ -111,7 +116,7 @@ MpegTSPacketizer *mpegts_packetizer_new ();
|
||||||
void mpegts_packetizer_clear (MpegTSPacketizer *packetizer);
|
void mpegts_packetizer_clear (MpegTSPacketizer *packetizer);
|
||||||
void mpegts_packetizer_push (MpegTSPacketizer *packetizer, GstBuffer *buffer);
|
void mpegts_packetizer_push (MpegTSPacketizer *packetizer, GstBuffer *buffer);
|
||||||
gboolean mpegts_packetizer_has_packets (MpegTSPacketizer *packetizer);
|
gboolean mpegts_packetizer_has_packets (MpegTSPacketizer *packetizer);
|
||||||
gboolean mpegts_packetizer_next_packet (MpegTSPacketizer *packetizer,
|
MpegTSPacketizerPacketReturn mpegts_packetizer_next_packet (MpegTSPacketizer *packetizer,
|
||||||
MpegTSPacketizerPacket *packet);
|
MpegTSPacketizerPacket *packet);
|
||||||
void mpegts_packetizer_clear_packet (MpegTSPacketizer *packetizer,
|
void mpegts_packetizer_clear_packet (MpegTSPacketizer *packetizer,
|
||||||
MpegTSPacketizerPacket *packet);
|
MpegTSPacketizerPacket *packet);
|
||||||
|
|
|
@ -1214,6 +1214,7 @@ mpegts_parse_chain (GstPad * pad, GstBuffer * buf)
|
||||||
GstFlowReturn res = GST_FLOW_OK;
|
GstFlowReturn res = GST_FLOW_OK;
|
||||||
MpegTSParse *parse;
|
MpegTSParse *parse;
|
||||||
gboolean parsed;
|
gboolean parsed;
|
||||||
|
MpegTSPacketizerPacketReturn pret;
|
||||||
MpegTSPacketizer *packetizer;
|
MpegTSPacketizer *packetizer;
|
||||||
MpegTSPacketizerPacket packet;
|
MpegTSPacketizerPacket packet;
|
||||||
|
|
||||||
|
@ -1221,11 +1222,10 @@ mpegts_parse_chain (GstPad * pad, GstBuffer * buf)
|
||||||
packetizer = parse->packetizer;
|
packetizer = parse->packetizer;
|
||||||
|
|
||||||
mpegts_packetizer_push (parse->packetizer, buf);
|
mpegts_packetizer_push (parse->packetizer, buf);
|
||||||
while (mpegts_packetizer_has_packets (parse->packetizer) &&
|
while (((pret =
|
||||||
!GST_FLOW_IS_FATAL (res)) {
|
mpegts_packetizer_next_packet (parse->packetizer,
|
||||||
/* get the next packet */
|
&packet)) != PACKET_NEED_MORE) && !GST_FLOW_IS_FATAL (res)) {
|
||||||
parsed = mpegts_packetizer_next_packet (packetizer, &packet);
|
if (G_UNLIKELY (pret == PACKET_BAD))
|
||||||
if (G_UNLIKELY (!parsed))
|
|
||||||
/* bad header, skip the packet */
|
/* bad header, skip the packet */
|
||||||
goto next;
|
goto next;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue