From a3118c47585d98891454731f66e62d79fff153d9 Mon Sep 17 00:00:00 2001
From: Song Bing <b06498@freescale.com>
Date: Wed, 22 Apr 2015 18:06:35 +0800
Subject: [PATCH] mpegtsmux: Need get pid when create streams.

when camerabin use mpegtsmux as muxer, start video recording and then
stop video recording and then start video recording, mpegtsmux get wrong
pid.

https://bugzilla.gnome.org/show_bug.cgi?id=748288

UpStream Status: Pending

Signed-off-by: Lyon Wang <lyon.wang@freescale.com>
---
 gst/mpegtsmux/mpegtsmux.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/gst/mpegtsmux/mpegtsmux.c b/gst/mpegtsmux/mpegtsmux.c
index 4c68e3e95f96..d93374520e36 100644
--- a/gst/mpegtsmux/mpegtsmux.c
+++ b/gst/mpegtsmux/mpegtsmux.c
@@ -833,6 +833,21 @@ mpegtsmux_create_streams (MpegTsMux * mux)
       } else {
         ts_data->prog_id = DEFAULT_PROG_ID;
       }
+
+      if (!ts_data->pid) {
+        gint pid = -1;
+
+        name = GST_PAD_NAME (c_data->pad);
+        if (name != NULL && sscanf (name, "sink_%d", &pid) == 1) {
+          if (tsmux_find_stream (mux->tsmux, pid)) {
+            GST_WARNING_OBJECT (mux, "Duplicate PID");
+          }
+        } else {
+          pid = tsmux_get_new_pid (mux->tsmux);
+        }
+
+        ts_data->pid = pid;
+      }
     }
 
     ts_data->prog =
