From e4a0c4d5092639e01fa8c9db4f8225b27c1d5c2e Mon Sep 17 00:00:00 2001 From: Jesper Larsen Date: Sun, 10 Mar 2013 17:02:18 +0100 Subject: [PATCH] mpegtsmux: Set the program number from prog-map The prog-map property of mpegtsmux only allows you to group pids together in a program. The program number set in the PAT/PMT tables cannot be set explicitly. This patch will set the program number according to the prog-map. If a program id of 0 is given, the first vacant program number starting from 1 will be used. https://bugzilla.gnome.org/show_bug.cgi?id=697239 --- gst/mpegtsmux/mpegtsmux.c | 2 +- gst/mpegtsmux/tsmux/tsmux.c | 25 ++++++++++++++++++++++--- gst/mpegtsmux/tsmux/tsmux.h | 2 +- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/gst/mpegtsmux/mpegtsmux.c b/gst/mpegtsmux/mpegtsmux.c index a31157fc7b..aebe23a50a 100644 --- a/gst/mpegtsmux/mpegtsmux.c +++ b/gst/mpegtsmux/mpegtsmux.c @@ -738,7 +738,7 @@ mpegtsmux_create_streams (MpegTsMux * mux) ts_data->prog = mux->programs[ts_data->prog_id]; if (ts_data->prog == NULL) { - ts_data->prog = tsmux_program_new (mux->tsmux); + ts_data->prog = tsmux_program_new (mux->tsmux, ts_data->prog_id); if (ts_data->prog == NULL) goto no_program; tsmux_set_pmt_interval (ts_data->prog, mux->pmt_interval); diff --git a/gst/mpegtsmux/tsmux/tsmux.c b/gst/mpegtsmux/tsmux/tsmux.c index 7698266b25..e7edf57f54 100644 --- a/gst/mpegtsmux/tsmux/tsmux.c +++ b/gst/mpegtsmux/tsmux/tsmux.c @@ -247,17 +247,23 @@ tsmux_free (TsMux * mux) g_slice_free (TsMux, mux); } +static gint +tsmux_program_compare (TsMuxProgram * program, gint * needle) +{ + return (program->pgm_number - *needle); +} + /** * tsmux_program_new: * @mux: a #TsMux * * Create a new program in the mising session @mux. - * + * * Returns: a new #TsMuxProgram or %NULL when the maximum number of programs has * been reached. */ TsMuxProgram * -tsmux_program_new (TsMux * mux) +tsmux_program_new (TsMux * mux, gint prog_id) { TsMuxProgram *program; @@ -273,7 +279,20 @@ tsmux_program_new (TsMux * mux) program->last_pmt_ts = -1; program->pmt_interval = TSMUX_DEFAULT_PMT_INTERVAL; - program->pgm_number = mux->next_pgm_no++; + if (prog_id == 0) { + program->pgm_number = mux->next_pgm_no++; + while (g_list_find_custom (mux->programs, &program->pgm_number, + (GCompareFunc) tsmux_program_compare) != NULL) { + program->pgm_number = mux->next_pgm_no++; + } + } else { + program->pgm_number = prog_id; + while (g_list_find_custom (mux->programs, &program->pgm_number, + (GCompareFunc) tsmux_program_compare) != NULL) { + program->pgm_number++; + } + } + program->pmt_pid = mux->next_pmt_pid++; program->pcr_stream = NULL; diff --git a/gst/mpegtsmux/tsmux/tsmux.h b/gst/mpegtsmux/tsmux/tsmux.h index 2936271fd9..160b6bde45 100644 --- a/gst/mpegtsmux/tsmux/tsmux.h +++ b/gst/mpegtsmux/tsmux/tsmux.h @@ -183,7 +183,7 @@ guint tsmux_get_pat_interval (TsMux *mux); guint16 tsmux_get_new_pid (TsMux *mux); /* pid/program management */ -TsMuxProgram * tsmux_program_new (TsMux *mux); +TsMuxProgram * tsmux_program_new (TsMux *mux, gint prog_id); void tsmux_program_free (TsMuxProgram *program); void tsmux_set_pmt_interval (TsMuxProgram *program, guint interval); guint tsmux_get_pmt_interval (TsMuxProgram *program);