basetsmux: expose pcr-interval property

Instead of using a static hardcoded PCR interval, allow the user
to configure it.

Also revert back the default to a 40 ms interval, that was changed
in recent patches for no good reason.
This commit is contained in:
Mathieu Duponchelle 2019-07-30 21:18:59 +02:00
parent dae6e7964c
commit 73f92371b8
5 changed files with 42 additions and 6 deletions

View file

@ -194,6 +194,7 @@ enum
PROP_ALIGNMENT,
PROP_SI_INTERVAL,
PROP_BITRATE,
PROP_PCR_INTERVAL,
};
#define BASETSMUX_DEFAULT_ALIGNMENT -1
@ -1704,6 +1705,11 @@ gst_base_ts_mux_set_property (GObject * object, guint prop_id,
if (mux->tsmux)
tsmux_set_bitrate (mux->tsmux, mux->bitrate);
break;
case PROP_PCR_INTERVAL:
mux->pcr_interval = g_value_get_uint (value);
if (mux->tsmux)
tsmux_set_pcr_interval (mux->tsmux, mux->pcr_interval);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -1735,6 +1741,9 @@ gst_base_ts_mux_get_property (GObject * object, guint prop_id,
case PROP_BITRATE:
g_value_set_uint64 (value, mux->bitrate);
break;
case PROP_PCR_INTERVAL:
g_value_set_uint (value, mux->pcr_interval);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -1863,6 +1872,12 @@ gst_base_ts_mux_class_init (GstBaseTsMuxClass * klass)
0, G_MAXUINT64, TSMUX_DEFAULT_BITRATE,
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_PCR_INTERVAL,
g_param_spec_uint ("pcr-interval", "PCR interval",
"Set the interval (in ticks of the 90kHz clock) for writing PCR",
1, G_MAXUINT, TSMUX_DEFAULT_PCR_INTERVAL,
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
gst_element_class_add_static_pad_template_with_gtype (gstelement_class,
&gst_base_ts_mux_src_factory, GST_TYPE_AGGREGATOR_PAD);
}
@ -1876,6 +1891,7 @@ gst_base_ts_mux_init (GstBaseTsMux * mux)
mux->pat_interval = TSMUX_DEFAULT_PAT_INTERVAL;
mux->pmt_interval = TSMUX_DEFAULT_PMT_INTERVAL;
mux->si_interval = TSMUX_DEFAULT_SI_INTERVAL;
mux->pcr_interval = TSMUX_DEFAULT_PCR_INTERVAL;
mux->prog_map = NULL;
mux->alignment = BASETSMUX_DEFAULT_ALIGNMENT;
mux->bitrate = TSMUX_DEFAULT_BITRATE;

View file

@ -173,6 +173,7 @@ struct GstBaseTsMux {
gint alignment;
guint si_interval;
guint64 bitrate;
guint pcr_interval;
/* state */
gboolean first;

View file

@ -106,9 +106,6 @@
* 1/8 second atm */
#define TSMUX_PCR_OFFSET (TSMUX_CLOCK_FREQ / 8)
/* Times per second to write PCR */
#define TSMUX_DEFAULT_PCR_FREQ (50)
/* Base for all written PCR and DTS/PTS,
* so we have some slack to go backwards */
#define CLOCK_BASE (TSMUX_CLOCK_FREQ * 10 * 360)
@ -149,6 +146,8 @@ tsmux_new (void)
mux->si_changed = TRUE;
mux->si_interval = TSMUX_DEFAULT_SI_INTERVAL;
mux->pcr_interval = TSMUX_DEFAULT_PCR_INTERVAL;
mux->next_si_pcr = -1;
mux->si_sections = g_hash_table_new_full (g_direct_hash, g_direct_equal,
@ -236,6 +235,21 @@ tsmux_set_pat_interval (TsMux * mux, guint freq)
mux->pat_interval = freq;
}
/**
* tsmux_set_pcr_interval:
* @mux: a #TsMux
* @freq: a new PCR interval
*
* Set the interval (in cycles of the 90kHz clock) for writing the PCR.
*/
void
tsmux_set_pcr_interval (TsMux * mux, guint freq)
{
g_return_if_fail (mux != NULL);
mux->pcr_interval = freq;
}
/**
* tsmux_get_pat_interval:
* @mux: a #TsMux
@ -1086,10 +1100,9 @@ write_new_pcr (TsMux * mux, TsMuxStream * stream, gint64 cur_pcr)
stream->pi.pcr = cur_pcr;
if (stream->next_pcr == -1)
stream->next_pcr =
cur_pcr + TSMUX_SYS_CLOCK_FREQ / TSMUX_DEFAULT_PCR_FREQ;
stream->next_pcr = cur_pcr + mux->pcr_interval * 300;
else
stream->next_pcr += TSMUX_SYS_CLOCK_FREQ / TSMUX_DEFAULT_PCR_FREQ;
stream->next_pcr += mux->pcr_interval * 300;
} else {
cur_pcr = -1;
}

View file

@ -164,6 +164,9 @@ struct TsMux {
/* Next PAT position, 27 MHz */
gint64 next_pat_pcr;
/* interval between PCR in MPEG PTS clock time */
guint pcr_interval;
/* trigger writing Service Information Tables */
gboolean si_changed;
/* interval between SIT in MPEG PTS clock time */
@ -224,6 +227,7 @@ TsMuxStream * tsmux_find_stream (TsMux *mux, guint16 pid);
void tsmux_program_add_stream (TsMuxProgram *program, TsMuxStream *stream);
void tsmux_program_set_pcr_stream (TsMuxProgram *program, TsMuxStream *stream);
void tsmux_set_pcr_interval (TsMux * mux, guint freq);
/* writing stuff */
gboolean tsmux_write_stream_packet (TsMux *mux, TsMuxStream *stream);

View file

@ -121,6 +121,8 @@ G_BEGIN_DECLS
#define TSMUX_DEFAULT_PMT_INTERVAL (TSMUX_CLOCK_FREQ / 10)
/* SI interval (1/10th sec) */
#define TSMUX_DEFAULT_SI_INTERVAL (TSMUX_CLOCK_FREQ / 10)
/* PCR interval (1/25th sec) */
#define TSMUX_DEFAULT_PCR_INTERVAL (TSMUX_CLOCK_FREQ / 25)
/* Bitrate (bits per second) */
#define TSMUX_DEFAULT_BITRATE 0