mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 04:56:14 +00:00
tsmux: Use DTS over PTS
This commit is contained in:
parent
33c0c7c33d
commit
dc2b28d456
3 changed files with 42 additions and 18 deletions
|
@ -1042,22 +1042,27 @@ tsmux_write_stream_packet (TsMux * mux, TsMuxStream * stream)
|
||||||
g_return_val_if_fail (stream != NULL, FALSE);
|
g_return_val_if_fail (stream != NULL, FALSE);
|
||||||
|
|
||||||
if (tsmux_stream_is_pcr (stream)) {
|
if (tsmux_stream_is_pcr (stream)) {
|
||||||
gint64 cur_pts = tsmux_stream_get_pts (stream);
|
gint64 cur_ts;
|
||||||
gboolean write_pat;
|
gboolean write_pat;
|
||||||
gboolean write_si;
|
gboolean write_si;
|
||||||
GList *cur;
|
GList *cur;
|
||||||
|
|
||||||
|
if (tsmux_stream_get_dts (stream) != G_MININT64)
|
||||||
|
cur_ts = tsmux_stream_get_dts (stream);
|
||||||
|
else
|
||||||
|
cur_ts = tsmux_stream_get_pts (stream);
|
||||||
|
|
||||||
cur_pcr = 0;
|
cur_pcr = 0;
|
||||||
if (cur_pts != G_MININT64) {
|
if (cur_ts != G_MININT64) {
|
||||||
TS_DEBUG ("TS for PCR stream is %" G_GINT64_FORMAT, cur_pts);
|
TS_DEBUG ("TS for PCR stream is %" G_GINT64_FORMAT, cur_ts);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME: The current PCR needs more careful calculation than just
|
/* FIXME: The current PCR needs more careful calculation than just
|
||||||
* writing a fixed offset */
|
* writing a fixed offset */
|
||||||
if (cur_pts != G_MININT64) {
|
if (cur_ts != G_MININT64) {
|
||||||
/* CLOCK_BASE >= TSMUX_PCR_OFFSET */
|
/* CLOCK_BASE >= TSMUX_PCR_OFFSET */
|
||||||
cur_pts += CLOCK_BASE;
|
cur_ts += CLOCK_BASE;
|
||||||
cur_pcr = (cur_pts - TSMUX_PCR_OFFSET) *
|
cur_pcr = (cur_ts - TSMUX_PCR_OFFSET) *
|
||||||
(TSMUX_SYS_CLOCK_FREQ / TSMUX_CLOCK_FREQ);
|
(TSMUX_SYS_CLOCK_FREQ / TSMUX_CLOCK_FREQ);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1077,13 +1082,13 @@ tsmux_write_stream_packet (TsMux * mux, TsMuxStream * stream)
|
||||||
/* check if we need to rewrite pat */
|
/* check if we need to rewrite pat */
|
||||||
if (mux->last_pat_ts == G_MININT64 || mux->pat_changed)
|
if (mux->last_pat_ts == G_MININT64 || mux->pat_changed)
|
||||||
write_pat = TRUE;
|
write_pat = TRUE;
|
||||||
else if (cur_pts >= mux->last_pat_ts + mux->pat_interval)
|
else if (cur_ts >= mux->last_pat_ts + mux->pat_interval)
|
||||||
write_pat = TRUE;
|
write_pat = TRUE;
|
||||||
else
|
else
|
||||||
write_pat = FALSE;
|
write_pat = FALSE;
|
||||||
|
|
||||||
if (write_pat) {
|
if (write_pat) {
|
||||||
mux->last_pat_ts = cur_pts;
|
mux->last_pat_ts = cur_ts;
|
||||||
if (!tsmux_write_pat (mux))
|
if (!tsmux_write_pat (mux))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -1091,13 +1096,13 @@ tsmux_write_stream_packet (TsMux * mux, TsMuxStream * stream)
|
||||||
/* check if we need to rewrite sit */
|
/* check if we need to rewrite sit */
|
||||||
if (mux->last_si_ts == G_MININT64 || mux->si_changed)
|
if (mux->last_si_ts == G_MININT64 || mux->si_changed)
|
||||||
write_si = TRUE;
|
write_si = TRUE;
|
||||||
else if (cur_pts >= mux->last_si_ts + mux->si_interval)
|
else if (cur_ts >= mux->last_si_ts + mux->si_interval)
|
||||||
write_si = TRUE;
|
write_si = TRUE;
|
||||||
else
|
else
|
||||||
write_si = FALSE;
|
write_si = FALSE;
|
||||||
|
|
||||||
if (write_si) {
|
if (write_si) {
|
||||||
mux->last_si_ts = cur_pts;
|
mux->last_si_ts = cur_ts;
|
||||||
if (!tsmux_write_si (mux))
|
if (!tsmux_write_si (mux))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -1109,13 +1114,13 @@ tsmux_write_stream_packet (TsMux * mux, TsMuxStream * stream)
|
||||||
|
|
||||||
if (program->last_pmt_ts == G_MININT64 || program->pmt_changed)
|
if (program->last_pmt_ts == G_MININT64 || program->pmt_changed)
|
||||||
write_pmt = TRUE;
|
write_pmt = TRUE;
|
||||||
else if (cur_pts >= program->last_pmt_ts + program->pmt_interval)
|
else if (cur_ts >= program->last_pmt_ts + program->pmt_interval)
|
||||||
write_pmt = TRUE;
|
write_pmt = TRUE;
|
||||||
else
|
else
|
||||||
write_pmt = FALSE;
|
write_pmt = FALSE;
|
||||||
|
|
||||||
if (write_pmt) {
|
if (write_pmt) {
|
||||||
program->last_pmt_ts = cur_pts;
|
program->last_pmt_ts = cur_ts;
|
||||||
if (!tsmux_write_pmt (mux, program))
|
if (!tsmux_write_pmt (mux, program))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -307,10 +307,9 @@ tsmux_stream_consume (TsMuxStream * stream, guint len)
|
||||||
if (stream->cur_buffer_consumed == 0 && stream->cur_buffer->size != 0)
|
if (stream->cur_buffer_consumed == 0 && stream->cur_buffer->size != 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (GST_CLOCK_STIME_IS_VALID (stream->cur_buffer->pts)) {
|
if (GST_CLOCK_STIME_IS_VALID (stream->cur_buffer->pts))
|
||||||
stream->last_pts = stream->cur_buffer->pts;
|
stream->last_pts = stream->cur_buffer->pts;
|
||||||
stream->last_dts = stream->cur_buffer->dts;
|
if (GST_CLOCK_STIME_IS_VALID (stream->cur_buffer->dts))
|
||||||
} else if (GST_CLOCK_STIME_IS_VALID (stream->cur_buffer->dts))
|
|
||||||
stream->last_dts = stream->cur_buffer->dts;
|
stream->last_dts = stream->cur_buffer->dts;
|
||||||
|
|
||||||
if (stream->cur_buffer_consumed == stream->cur_buffer->size) {
|
if (stream->cur_buffer_consumed == stream->cur_buffer->size) {
|
||||||
|
@ -716,8 +715,10 @@ tsmux_stream_add_data (TsMuxStream * stream, guint8 * data, guint len,
|
||||||
packet->pts = pts;
|
packet->pts = pts;
|
||||||
packet->dts = dts;
|
packet->dts = dts;
|
||||||
|
|
||||||
if (stream->bytes_avail == 0)
|
if (stream->bytes_avail == 0) {
|
||||||
stream->last_pts = pts;
|
stream->last_pts = pts;
|
||||||
|
stream->last_dts = dts;
|
||||||
|
}
|
||||||
|
|
||||||
stream->bytes_avail += len;
|
stream->bytes_avail += len;
|
||||||
stream->buffers = g_list_append (stream->buffers, packet);
|
stream->buffers = g_list_append (stream->buffers, packet);
|
||||||
|
@ -1087,10 +1088,27 @@ tsmux_stream_is_pcr (TsMuxStream * stream)
|
||||||
*
|
*
|
||||||
* Returns: the PTS of the last buffer in @stream.
|
* Returns: the PTS of the last buffer in @stream.
|
||||||
*/
|
*/
|
||||||
guint64
|
gint64
|
||||||
tsmux_stream_get_pts (TsMuxStream * stream)
|
tsmux_stream_get_pts (TsMuxStream * stream)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (stream != NULL, GST_CLOCK_STIME_NONE);
|
g_return_val_if_fail (stream != NULL, GST_CLOCK_STIME_NONE);
|
||||||
|
|
||||||
return stream->last_pts;
|
return stream->last_pts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tsmux_stream_get_dts:
|
||||||
|
* @stream: a #TsMuxStream
|
||||||
|
*
|
||||||
|
* Return the DTS of the last buffer that has had bytes written and
|
||||||
|
* which _had_ a DTS in @stream.
|
||||||
|
*
|
||||||
|
* Returns: the DTS of the last buffer in @stream.
|
||||||
|
*/
|
||||||
|
gint64
|
||||||
|
tsmux_stream_get_dts (TsMuxStream * stream)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (stream != NULL, GST_CLOCK_STIME_NONE);
|
||||||
|
|
||||||
|
return stream->last_dts;
|
||||||
|
}
|
||||||
|
|
|
@ -256,7 +256,8 @@ gint tsmux_stream_bytes_avail (TsMuxStream *stream);
|
||||||
gboolean tsmux_stream_initialize_pes_packet (TsMuxStream *stream);
|
gboolean tsmux_stream_initialize_pes_packet (TsMuxStream *stream);
|
||||||
gboolean tsmux_stream_get_data (TsMuxStream *stream, guint8 *buf, guint len);
|
gboolean tsmux_stream_get_data (TsMuxStream *stream, guint8 *buf, guint len);
|
||||||
|
|
||||||
guint64 tsmux_stream_get_pts (TsMuxStream *stream);
|
gint64 tsmux_stream_get_pts (TsMuxStream *stream);
|
||||||
|
gint64 tsmux_stream_get_dts (TsMuxStream *stream);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue