mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-03-29 12:25:37 +00:00
tsmux: tsmux_packet_out should always consume its buffer
Consuming the buffer only when successful is an antipattern and easily leads to leaks. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5516>
This commit is contained in:
parent
6198c4b8a1
commit
c205086f2b
1 changed files with 14 additions and 16 deletions
|
@ -834,9 +834,10 @@ tsmux_get_buffer (TsMux * mux, GstBuffer ** buf)
|
|||
static gboolean
|
||||
tsmux_packet_out (TsMux * mux, GstBuffer * buf, gint64 pcr)
|
||||
{
|
||||
g_return_val_if_fail (buf, FALSE);
|
||||
|
||||
if (G_UNLIKELY (mux->write_func == NULL)) {
|
||||
if (buf)
|
||||
gst_buffer_unref (buf);
|
||||
gst_buffer_unref (buf);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -863,19 +864,19 @@ tsmux_packet_out (TsMux * mux, GstBuffer * buf, gint64 pcr)
|
|||
new_pcr = write_new_pcr (mux, stream, cur_pcr, next_pcr);
|
||||
|
||||
if (new_pcr != -1) {
|
||||
GstBuffer *buf = NULL;
|
||||
GstBuffer *pcr_buf = NULL;
|
||||
GstMapInfo map;
|
||||
|
||||
if (!tsmux_get_buffer (mux, &buf)) {
|
||||
if (!tsmux_get_buffer (mux, &pcr_buf)) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
gst_buffer_map (buf, &map, GST_MAP_WRITE);
|
||||
gst_buffer_map (pcr_buf, &map, GST_MAP_WRITE);
|
||||
tsmux_write_ts_header (mux, map.data, &stream->pi, 0, NULL, NULL);
|
||||
gst_buffer_unmap (buf, &map);
|
||||
gst_buffer_unmap (pcr_buf, &map);
|
||||
|
||||
stream->pi.flags &= TSMUX_PACKET_FLAG_PES_FULL_HEADER;
|
||||
if (!tsmux_packet_out (mux, buf, new_pcr))
|
||||
if (!tsmux_packet_out (mux, pcr_buf, new_pcr))
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
@ -887,6 +888,7 @@ tsmux_packet_out (TsMux * mux, GstBuffer * buf, gint64 pcr)
|
|||
return mux->write_func (buf, mux->write_func_data, pcr);
|
||||
|
||||
error:
|
||||
gst_buffer_unref (buf);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -1523,6 +1525,7 @@ pad_stream (TsMux * mux, TsMuxStream * stream, gint64 cur_ts)
|
|||
if (diff == 0)
|
||||
goto done;
|
||||
|
||||
ret = FALSE;
|
||||
start_n_bytes = mux->n_bytes;
|
||||
do {
|
||||
GST_LOG ("Transport stream bitrate: %" G_GUINT64_FORMAT " over %"
|
||||
|
@ -1538,14 +1541,11 @@ pad_stream (TsMux * mux, TsMuxStream * stream, gint64 cur_ts)
|
|||
if (bitrate <= mux->bitrate) {
|
||||
gint64 new_pcr;
|
||||
|
||||
if (!tsmux_get_buffer (mux, &buf)) {
|
||||
ret = FALSE;
|
||||
if (!tsmux_get_buffer (mux, &buf))
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (!gst_buffer_map (buf, &map, GST_MAP_WRITE)) {
|
||||
gst_buffer_unref (buf);
|
||||
ret = FALSE;
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
@ -1559,7 +1559,6 @@ pad_stream (TsMux * mux, TsMuxStream * stream, gint64 cur_ts)
|
|||
if (!rewrite_si (mux, cur_ts)) {
|
||||
gst_buffer_unmap (buf, &map);
|
||||
gst_buffer_unref (buf);
|
||||
ret = FALSE;
|
||||
goto done;
|
||||
}
|
||||
tsmux_write_null_ts_header (map.data);
|
||||
|
@ -1569,11 +1568,8 @@ pad_stream (TsMux * mux, TsMuxStream * stream, gint64 cur_ts)
|
|||
gst_buffer_unmap (buf, &map);
|
||||
|
||||
stream->pi.flags &= TSMUX_PACKET_FLAG_PES_FULL_HEADER;
|
||||
ret = tsmux_packet_out (mux, buf, new_pcr);
|
||||
if (!ret) {
|
||||
gst_buffer_unref (buf);
|
||||
if (!tsmux_packet_out (mux, buf, new_pcr))
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
} while (bitrate < mux->bitrate);
|
||||
|
||||
|
@ -1581,6 +1577,8 @@ pad_stream (TsMux * mux, TsMuxStream * stream, gint64 cur_ts)
|
|||
GST_LOG ("Finished padding the mux");
|
||||
}
|
||||
|
||||
ret = TRUE;
|
||||
|
||||
done:
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue