diff options
author | Jan Schmidt <jan@centricular.com> | 2021-02-26 02:53:33 +1100 |
---|---|---|
committer | GStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org> | 2021-03-18 15:07:53 +0000 |
commit | 18a095ca630148e5af0503da2d554c804bc1f55d (patch) | |
tree | 160f0fc0ccc898c0bbb83c644c5c3680196645f8 | |
parent | 5e4a11bf36b6646021b653855a0a2152be338428 (diff) | |
download | gstreamer-plugins-bad-18a095ca630148e5af0503da2d554c804bc1f55d.tar.gz |
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>
-rw-r--r-- | gst/mpegtsmux/gstbasetsmux.c | 38 | ||||
-rw-r--r-- | gst/mpegtsmux/tsmux/tsmux.c | 11 | ||||
-rw-r--r-- | gst/mpegtsmux/tsmux/tsmux.h | 1 |
3 files changed, 45 insertions, 5 deletions
diff --git a/gst/mpegtsmux/gstbasetsmux.c b/gst/mpegtsmux/gstbasetsmux.c index 6439832f0..8f024be4e 100644 --- a/gst/mpegtsmux/gstbasetsmux.c +++ b/gst/mpegtsmux/gstbasetsmux.c @@ -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; diff --git a/gst/mpegtsmux/tsmux/tsmux.c b/gst/mpegtsmux/tsmux/tsmux.c index 3c04c4295..566111bf8 100644 --- a/gst/mpegtsmux/tsmux/tsmux.c +++ b/gst/mpegtsmux/tsmux/tsmux.c @@ -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) { diff --git a/gst/mpegtsmux/tsmux/tsmux.h b/gst/mpegtsmux/tsmux/tsmux.h index df2a4676a..ddb5a662b 100644 --- a/gst/mpegtsmux/tsmux/tsmux.h +++ b/gst/mpegtsmux/tsmux/tsmux.h @@ -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); |