From: Edward Hervey Date: Thu, 13 Oct 2011 14:55:54 +0000 (+0200) Subject: mpegtsbase: Refactor scan loop X-Git-Tag: 1.19.3~507^2~16002 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=db0633918ab0dce08f9a9a20961ca543ed6a467c;p=platform%2Fupstream%2Fgstreamer.git mpegtsbase: Refactor scan loop Avoids ending up leaking packets when we got one and res was different from GST_FLOW_OK. It also looks more comprehensible --- diff --git a/gst/mpegtsdemux/mpegtsbase.c b/gst/mpegtsdemux/mpegtsbase.c index c1e96a9..9972172 100644 --- a/gst/mpegtsdemux/mpegtsbase.c +++ b/gst/mpegtsdemux/mpegtsbase.c @@ -1262,11 +1262,16 @@ mpegts_base_chain (GstPad * pad, GstBuffer * buf) } mpegts_packetizer_push (base->packetizer, buf); - while (((pret = - mpegts_packetizer_next_packet (base->packetizer, - &packet)) != PACKET_NEED_MORE) && res == GST_FLOW_OK) { + + while (res == GST_FLOW_OK) { + pret = mpegts_packetizer_next_packet (base->packetizer, &packet); + + /* If we don't have enough data, return */ + if (G_UNLIKELY (pret == PACKET_NEED_MORE)) + break; + + /* bad header, skip the packet */ if (G_UNLIKELY (pret == PACKET_BAD)) - /* bad header, skip the packet */ goto next; GST_DEBUG ("Got packet (buffer:%p)", packet.buffer); @@ -1292,13 +1297,15 @@ mpegts_base_chain (GstPad * pad, GstBuffer * buf) /* bad PSI table */ goto next; } + /* we need to push section packet downstream */ res = mpegts_base_push (base, &packet, §ion); } else if (MPEGTS_BIT_IS_SET (base->is_pes, packet.pid)) { /* push the packet downstream */ res = mpegts_base_push (base, &packet, NULL); - } else + } else { gst_buffer_unref (packet.buffer); + } next: mpegts_packetizer_clear_packet (base->packetizer, &packet);