mpegtsmux: Add PMT_%d support to prog-map.

Support a PMT_%d field in the prog-map, that's optionally used
to set the PMT for each program in the mux.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2039>
This commit is contained in:
Jan Schmidt 2021-02-26 02:53:33 +11:00 committed by GStreamer Marge Bot
parent 5e4a11bf36
commit 18a095ca63
3 changed files with 45 additions and 5 deletions

View file

@ -729,12 +729,20 @@ not_negotiated:
}
}
static gboolean
is_valid_pmt_pid (guint16 pmt_pid)
{
if (pmt_pid < 0x0010 || pmt_pid > 0x1ffe)
return FALSE;
return TRUE;
}
static GstFlowReturn
gst_base_ts_mux_create_pad_stream (GstBaseTsMux * mux, GstPad * pad)
{
GstBaseTsMuxPad *ts_pad = GST_BASE_TS_MUX_PAD (pad);
gchar *name = NULL;
gchar *pcr_name;
gchar *prop_name;
GstFlowReturn ret = GST_FLOW_OK;
if (ts_pad->prog_id == -1) {
@ -771,6 +779,25 @@ gst_base_ts_mux_create_pad_stream (GstBaseTsMux * mux, GstPad * pad)
tsmux_program_set_scte35_interval (ts_pad->prog, mux->scte35_null_interval);
g_hash_table_insert (mux->programs, GINT_TO_POINTER (ts_pad->prog_id),
ts_pad->prog);
/* Check for user-specified PMT PID */
prop_name = g_strdup_printf ("PMT_%d", ts_pad->prog->pgm_number);
if (mux->prog_map && gst_structure_has_field (mux->prog_map, prop_name)) {
guint pmt_pid;
if (gst_structure_get_uint (mux->prog_map, prop_name, &pmt_pid)) {
if (is_valid_pmt_pid (pmt_pid)) {
GST_DEBUG_OBJECT (mux, "User specified pid=%u as PMT for "
"program (prog_id = %d)", pmt_pid, ts_pad->prog->pgm_number);
tsmux_program_set_pmt_pid (ts_pad->prog, pmt_pid);
} else {
GST_ELEMENT_WARNING (mux, LIBRARY, SETTINGS,
("User specified PMT pid %u for program %d is not valid.",
pmt_pid, ts_pad->prog->pgm_number), (NULL));
}
}
}
g_free (prop_name);
}
if (ts_pad->stream == NULL) {
@ -789,9 +816,10 @@ gst_base_ts_mux_create_pad_stream (GstBaseTsMux * mux, GstPad * pad)
}
/* Check for user-specified PCR PID */
pcr_name = g_strdup_printf ("PCR_%d", ts_pad->prog->pgm_number);
if (mux->prog_map && gst_structure_has_field (mux->prog_map, pcr_name)) {
const gchar *sink_name = gst_structure_get_string (mux->prog_map, pcr_name);
prop_name = g_strdup_printf ("PCR_%d", ts_pad->prog->pgm_number);
if (mux->prog_map && gst_structure_has_field (mux->prog_map, prop_name)) {
const gchar *sink_name =
gst_structure_get_string (mux->prog_map, prop_name);
if (!g_strcmp0 (name, sink_name)) {
GST_DEBUG_OBJECT (mux, "User specified stream (pid=%d) as PCR for "
@ -799,7 +827,7 @@ gst_base_ts_mux_create_pad_stream (GstBaseTsMux * mux, GstPad * pad)
tsmux_program_set_pcr_stream (ts_pad->prog, ts_pad->stream);
}
}
g_free (pcr_name);
g_free (prop_name);
return ret;

View file

@ -1652,6 +1652,17 @@ tsmux_program_free (TsMuxProgram * program)
g_slice_free (TsMuxProgram, program);
}
/**
* tsmux_program_set_pmt_pid:
* @program: A #TsmuxProgram
* @pmt_pid: PID to write PMT for this program
*/
void
tsmux_program_set_pmt_pid (TsMuxProgram * program, guint16 pmt_pid)
{
program->pmt_pid = pmt_pid;
}
static gboolean
tsmux_write_pat (TsMux * mux)
{

View file

@ -224,6 +224,7 @@ void tsmux_set_bitrate (TsMux *mux, guint64 bitrate);
/* pid/program management */
TsMuxProgram * tsmux_program_new (TsMux *mux, gint prog_id);
void tsmux_program_free (TsMuxProgram *program);
void tsmux_program_set_pmt_pid (TsMuxProgram *program, guint16 pmt_pid);
void tsmux_set_pmt_interval (TsMuxProgram *program, guint interval);
guint tsmux_get_pmt_interval (TsMuxProgram *program);
void tsmux_resend_pmt (TsMuxProgram *program);