From 5b0b69a85812378bb7deedce0bb3c0e27e0316b5 Mon Sep 17 00:00:00 2001 From: Lin YANG Date: Sat, 11 Jul 2009 19:29:53 +0800 Subject: [PATCH] mpegtsmux: mpegtsmux_collected(): calculate PCR for programs --- gst/mpegtsmux/mpegtsmux.c | 37 +++++++++++++++++++++++-------------- gst/mpegtsmux/mpegtsmux.h | 1 - 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/gst/mpegtsmux/mpegtsmux.c b/gst/mpegtsmux/mpegtsmux.c index ad50a9ba6b..07744a2bf2 100644 --- a/gst/mpegtsmux/mpegtsmux.c +++ b/gst/mpegtsmux/mpegtsmux.c @@ -610,18 +610,6 @@ mpegtsmux_collected (GstCollectPads * pads, MpegTsMux * mux) best = mpegtsmux_choose_best_stream (mux); - if (mux->pcr_stream == NULL) { - if (best) { - /* Take the first data stream for the PCR */ - GST_DEBUG_OBJECT (COLLECT_DATA_PAD (best), "Use stream as PCR"); - mux->pcr_stream = best->stream; - } - } - - /* Set the chosen PCR stream */ - g_return_val_if_fail (mux->pcr_stream != NULL, GST_FLOW_ERROR); - tsmux_program_set_pcr_stream (mux->program, mux->pcr_stream); - if (!mpegtsdemux_prepare_srcpad (mux)) { GST_DEBUG_OBJECT (mux, "Failed to send new segment"); goto new_seg_fail; @@ -633,9 +621,29 @@ mpegtsmux_collected (GstCollectPads * pads, MpegTsMux * mux) } if (best != NULL) { + TsMuxProgram *prog = best->prog; GstBuffer *buf = best->queued_buf; gint64 pts = -1; + if (prog == NULL) { + GST_ELEMENT_ERROR (mux, STREAM, MUX, ("Stream is not associated with " + "any program"), (NULL)); + return GST_FLOW_ERROR; + } + + if (G_UNLIKELY (prog->pcr_stream == NULL)) { + if (best) { + MpegTsPadData *ts_data = (MpegTsPadData *) best; + /* Take the first data stream for the PCR */ + GST_DEBUG_OBJECT (COLLECT_DATA_PAD (best), + "Use stream (pid=%d) from pad as PCR for program (prog_id = %d)", + ts_data->pid, ts_data->prog_id); + + /* Set the chosen PCR stream */ + tsmux_program_set_pcr_stream (prog, best->stream); + } + } + g_return_val_if_fail (buf != NULL, GST_FLOW_ERROR); GST_DEBUG_OBJECT (COLLECT_DATA_PAD (best), @@ -657,8 +665,9 @@ mpegtsmux_collected (GstCollectPads * pads, MpegTsMux * mux) goto write_fail; } } - if (mux->pcr_stream == best->stream) { - mux->last_ts = best->last_ts; + if (prog->pcr_stream == best->stream) { + /* FIXME: is this correct? */ + mux->last_ts = best->last_ts; // how? } } else { /* FIXME: Drain all remaining streams */ diff --git a/gst/mpegtsmux/mpegtsmux.h b/gst/mpegtsmux/mpegtsmux.h index a5193936b2..7e158553c9 100644 --- a/gst/mpegtsmux/mpegtsmux.h +++ b/gst/mpegtsmux/mpegtsmux.h @@ -113,7 +113,6 @@ struct MpegTsMux { GstStructure *prog_map; gboolean first; - TsMuxStream *pcr_stream; GstFlowReturn last_flow_ret; GstAdapter *adapter; gint64 previous_pcr;