From 130cf8075295ce8871b668067d50e5916ebafd53 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marc-Andr=C3=A9=20Lureau?= Date: Wed, 3 Feb 2010 13:41:27 +0100 Subject: [PATCH] mpegtsmux: fix PAT/PMT insertion frequency The current code is comparing timestamps with different clock. Let's use only the clock for PTS values. Also rename frequency to interval, to avoid confusion. And remove documentation about value 0, which won't work like documented. https://bugzilla.gnome.org/show_bug.cgi?id=608896 --- gst/mpegtsmux/tsmux/tsmux.c | 62 ++++++++++++++++++++++----------------------- gst/mpegtsmux/tsmux/tsmux.h | 12 ++++----- 2 files changed, 36 insertions(+), 38 deletions(-) diff --git a/gst/mpegtsmux/tsmux/tsmux.c b/gst/mpegtsmux/tsmux/tsmux.c index 70ad3dc..538f3b2 100644 --- a/gst/mpegtsmux/tsmux/tsmux.c +++ b/gst/mpegtsmux/tsmux/tsmux.c @@ -110,10 +110,10 @@ /* Times per second to write PCR */ #define TSMUX_DEFAULT_PCR_FREQ (25) -/* PAT frequency (1/10th sec) */ -#define TSMUX_DEFAULT_PAT_FREQ (TSMUX_CLOCK_FREQ / 10) -/* PMT frequency (1/10th sec) */ -#define TSMUX_DEFAULT_PMT_FREQ (TSMUX_CLOCK_FREQ / 10) +/* PAT interval (1/10th sec) */ +#define TSMUX_DEFAULT_PAT_INTERVAL (TSMUX_CLOCK_FREQ / 10) +/* PMT interval (1/10th sec) */ +#define TSMUX_DEFAULT_PMT_INTERVAL (TSMUX_CLOCK_FREQ / 10) static gboolean tsmux_write_pat (TsMux * mux); static gboolean tsmux_write_pmt (TsMux * mux, TsMuxProgram * program); @@ -140,7 +140,7 @@ tsmux_new () mux->pat_changed = TRUE; mux->last_pat_ts = -1; - mux->pat_frequency = TSMUX_DEFAULT_PAT_FREQ; + mux->pat_interval = TSMUX_DEFAULT_PAT_INTERVAL; return mux; } @@ -164,39 +164,38 @@ tsmux_set_write_func (TsMux * mux, TsMuxWriteFunc func, void *user_data) } /** - * tsmux_set_pat_frequency: + * tsmux_set_pat_interval: * @mux: a #TsMux - * @freq: a new PAT frequency + * @freq: a new PAT interval * - * Set the frequency (against the 90Hz clock) for writing out the PAT table. - * A frequency of 0 will only write the PAT table when it changes. + * Set the interval (in cycles of the 90kHz clock) for writing out the PAT table. * * Many transport stream clients might have problems if the PAT table is not * inserted in the stream at regular intervals, especially when initially trying * to figure out the contents of the stream. */ void -tsmux_set_pat_frequency (TsMux * mux, guint freq) +tsmux_set_pat_interval (TsMux * mux, guint freq) { g_return_if_fail (mux != NULL); - mux->pat_frequency = freq; + mux->pat_interval = freq; } /** - * tsmux_get_pat_frequency: + * tsmux_get_pat_interval: * @mux: a #TsMux * - * Get the configured PAT frequency. See also tsmux_set_pat_frequency(). + * Get the configured PAT interval. See also tsmux_set_pat_interval(). * - * Returns: the configured PAT frequency + * Returns: the configured PAT interval */ guint -tsmux_get_pat_frequency (TsMux * mux) +tsmux_get_pat_interval (TsMux * mux) { g_return_val_if_fail (mux != NULL, 0); - return mux->pat_frequency; + return mux->pat_interval; } /** @@ -256,7 +255,7 @@ tsmux_program_new (TsMux * mux) program->pmt_changed = TRUE; program->last_pmt_ts = -1; - program->pmt_frequency = TSMUX_DEFAULT_PMT_FREQ; + program->pmt_interval = TSMUX_DEFAULT_PMT_INTERVAL; program->pgm_number = mux->next_pgm_no++; program->pmt_pid = mux->next_pmt_pid++; @@ -273,39 +272,38 @@ tsmux_program_new (TsMux * mux) } /** - * tsmux_set_pmt_frequency: + * tsmux_set_pmt_interval: * @program: a #TsMuxProgram - * @freq: a new PMT frequency + * @freq: a new PMT interval * - * Set the frequency (against the 90Hz clock) for writing out the PMT table. - * A frequency of 0 will only write the PMT table when it changes. + * Set the interval (in cycles of the 90kHz clock) for writing out the PMT table. * * Many transport stream clients might have problems if the PMT table is not * inserted in the stream at regular intervals, especially when initially trying * to figure out the contents of the stream. */ void -tsmux_set_pmt_frequency (TsMuxProgram * program, guint freq) +tsmux_set_pmt_interval (TsMuxProgram * program, guint freq) { g_return_if_fail (program != NULL); - program->pmt_frequency = freq; + program->pmt_interval = freq; } /** - * tsmux_get_pmt_frequency: + * tsmux_get_pmt_interval: * @program: a #TsMuxProgram * - * Get the configured PMT frequency. See also tsmux_set_pmt_frequency(). + * Get the configured PMT interval. See also tsmux_set_pmt_interval(). * - * Returns: the configured PMT frequency + * Returns: the configured PMT interval */ guint -tsmux_get_pmt_frequency (TsMuxProgram * program) +tsmux_get_pmt_interval (TsMuxProgram * program) { g_return_val_if_fail (program != NULL, 0); - return program->pmt_frequency; + return program->pmt_interval; } /** @@ -746,13 +744,13 @@ tsmux_write_stream_packet (TsMux * mux, TsMuxStream * stream) /* check if we need to rewrite pat */ if (mux->last_pat_ts == -1 || mux->pat_changed) write_pat = TRUE; - else if (cur_pcr >= mux->last_pat_ts + mux->pat_frequency) + else if (cur_pts >= mux->last_pat_ts + mux->pat_interval) write_pat = TRUE; else write_pat = FALSE; if (write_pat) { - mux->last_pat_ts = cur_pcr; + mux->last_pat_ts = cur_pts; if (!tsmux_write_pat (mux)) return FALSE; } @@ -765,13 +763,13 @@ tsmux_write_stream_packet (TsMux * mux, TsMuxStream * stream) if (program->last_pmt_ts == -1 || program->pmt_changed) write_pmt = TRUE; - else if (cur_pcr >= program->last_pmt_ts + program->pmt_frequency) + else if (cur_pts >= program->last_pmt_ts + program->pmt_interval) write_pmt = TRUE; else write_pmt = FALSE; if (write_pmt) { - program->last_pmt_ts = cur_pcr; + program->last_pmt_ts = cur_pts; if (!tsmux_write_pmt (mux, program)) return FALSE; } diff --git a/gst/mpegtsmux/tsmux/tsmux.h b/gst/mpegtsmux/tsmux/tsmux.h index 4e7e063..ab764d6 100644 --- a/gst/mpegtsmux/tsmux/tsmux.h +++ b/gst/mpegtsmux/tsmux/tsmux.h @@ -110,7 +110,7 @@ struct TsMuxProgram { guint8 pmt_version; gboolean pmt_changed; - guint pmt_frequency; + guint pmt_interval; gint64 last_pmt_ts; guint16 pgm_number; /* program ID for the PAT */ @@ -140,7 +140,7 @@ struct TsMux { guint8 pat_version; gboolean pat_changed; - guint pat_frequency; + guint pat_interval; gint64 last_pat_ts; guint8 packet_buf[TSMUX_PACKET_LENGTH]; @@ -158,15 +158,15 @@ void tsmux_free (TsMux *mux); /* Setting muxing session properties */ void tsmux_set_write_func (TsMux *mux, TsMuxWriteFunc func, void *user_data); -void tsmux_set_pat_frequency (TsMux *mux, guint freq); -guint tsmux_get_pat_frequency (TsMux *mux); +void tsmux_set_pat_interval (TsMux *mux, guint interval); +guint tsmux_get_pat_interval (TsMux *mux); guint16 tsmux_get_new_pid (TsMux *mux); /* pid/program management */ TsMuxProgram * tsmux_program_new (TsMux *mux); void tsmux_program_free (TsMuxProgram *program); -void tsmux_set_pmt_frequency (TsMuxProgram *program, guint freq); -guint tsmux_get_pmt_frequency (TsMuxProgram *program); +void tsmux_set_pmt_interval (TsMuxProgram *program, guint interval); +guint tsmux_get_pmt_interval (TsMuxProgram *program); /* stream management */ TsMuxStream * tsmux_create_stream (TsMux *mux, TsMuxStreamType stream_type, guint16 pid); -- 2.7.4