After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 744090 - mpegtsmux: add support for adding/removing streams at runtime
mpegtsmux: add support for adding/removing streams at runtime
Status: RESOLVED OBSOLETE
Product: GStreamer
Classification: Platform
Component: gst-plugins-bad
git master
Other All
: Normal enhancement
: git master
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2015-02-06 11:47 UTC by Andreas Schuler
Modified: 2018-11-03 13:30 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch (1.49 KB, patch)
2015-02-11 15:27 UTC, Andreas Schuler
none Details | Review
updated patch (5.78 KB, patch)
2015-02-26 13:40 UTC, Andreas Schuler
reviewed Details | Review

Description Andreas Schuler 2015-02-06 11:47:08 UTC
When mpegtsmux is in PLAYING oder PAUSED state, I can add sink-pads, but when I activate it and put data in, I get the Error:

Stream on pad sink_xxx is not associated with any program.

With this patch, a new pad is added to the default, when it is not associated with any program. So it's possible to simply add streams during state PLAYING and PAUSED.


diff --git a/gst/mpegtsmux/mpegtsmux.c b/gst/mpegtsmux/mpegtsmux.c
index 975c926..6df698d 100644
--- a/gst/mpegtsmux/mpegtsmux.c
+++ b/gst/mpegtsmux/mpegtsmux.c
@@ -1117,6 +1117,25 @@ mpegtsmux_collected_buffer (GstCollectPads * pads, GstCollectData * data,
     return GST_FLOW_OK;
   }

+  if((best->prog) == NULL) {
+    GST_WARNING_OBJECT (mux, "Stream on pad %"
+      GST_PTR_FORMAT " was not associated with any program, adding to default program",
+      COLLECT_DATA_PAD (best));
+
+    best->prog_id = DEFAULT_PROG_ID;
+    best->prog = mux->programs[best->prog_id];
+
+    if(best->stream == NULL) {
+      ret = mpegtsmux_create_stream (mux, best);
+      if (ret != GST_FLOW_OK) {
+          GST_ELEMENT_ERROR (mux, STREAM, MUX, ("Stream on pad %"
+            GST_PTR_FORMAT " is not associated with any program",
+            COLLECT_DATA_PAD (best)),(NULL));
+          return GST_FLOW_ERROR;
+      }
+    }
+  }
+
   prog = best->prog;
   if (prog == NULL)
     goto no_program;
Comment 1 Tim-Philipp Müller 2015-02-06 11:58:50 UTC
Thanks for the patch. Could you please create a patch in "git format-patch" format with you as author and a proper commit message (containing a description and this bug url), and then attach it to this bug report?
Comment 2 Andreas Schuler 2015-02-11 15:27:19 UTC
Created attachment 296609 [details] [review]
patch
Comment 3 Thiago Sousa Santos 2015-02-11 22:11:04 UTC
Review of attachment 296609 [details] [review]:

::: gst/mpegtsmux/mpegtsmux.c
@@ +1131,3 @@
+
+    best->prog_id = DEFAULT_PROG_ID;
+    best->prog = mux->programs[best->prog_id];

Why not check the stream to program map that is used for streams created since the beginning? You can likely refactor the code used in create_streams() for that, if the program isn't present you assume the default.
Comment 4 Andreas Schuler 2015-02-12 09:37:14 UTC
You're right. Thats the better solution. Do you have example code how to use the prog-map parameter ?
Comment 5 Thiago Sousa Santos 2015-02-12 13:51:42 UTC
You can refactor the part that uses it in create_streams to a new function and use the same to decide the program_id for a stream in create_streams or when a new pad is requested.
Comment 6 Andreas Schuler 2015-02-12 15:03:27 UTC
Yes, but at the moment I have problems to build a test code that creates more than one program. 

I tried it with some lines from this:
https://github.com/kanongil/gst-plugins-bad/blob/master/tests/examples/mpegtsmux/mpts_test2.c

and endet up with a TS with one program and 3 video streams. (and without the "was not associated" warning).

So if you have any code with them I can test if the program handling is working, please give me a link. I want to test it before and after I refactored the code. At the moment I can't say if this feature is anyway working.
Comment 7 Thiago Sousa Santos 2015-02-12 16:03:36 UTC
Unfortunatelly I don't have, did you try running with GST_DEBUG enabled for mpegts to check what happened?
Comment 8 Andreas Schuler 2015-02-12 16:20:24 UTC
Yes, I working on it. looks like the muxer didn't found the pads in prog-map. I don't know why...beeing searching...
Comment 9 Andreas Schuler 2015-02-12 16:59:10 UTC
okay its working now
Comment 10 Thiago Sousa Santos 2015-02-12 17:39:30 UTC
Do you have an updated patch?
Comment 11 Andreas Schuler 2015-02-26 13:40:39 UTC
Created attachment 297977 [details] [review]
updated patch
Comment 12 Andreas Schuler 2015-02-26 13:41:08 UTC
yes I added the new patch.
Comment 13 Thiago Sousa Santos 2015-02-27 22:37:46 UTC
Review of attachment 297977 [details] [review]:

Thanks for the update, your patch looks good, just some minor stuff to update.

First, could you please commit the code and provide patches by using 'git format-patch'. It makes easier to merge to our local trees and then push.
Committing the code will make sure that you've gone through our indentation hook that makes sure your code follows the expected coding guidelines.

Also please use a meaningful commit message, check the git log to see other commits and try to follow the pattern.

Thanks again for taking time to update your patch.

::: gst/mpegtsmux/mpegtsmux.c
@@ +748,3 @@
+            if (!ret)
+            {
+                GST_ELEMENT_ERROR (mux, STREAM, MUX, ("Reading program map failed. Assuming default"), (NULL));

While we are at this, GST_ELEMENT_ERROR will cause an error message to be posted and the program will stop, I don't think this should lead to an error. So I think we should just use GST_ELEMENT_WARNING (that posts a warning message to the application) or just a GST_WARNING_OBJECT that will only print at the stderr a warning (the application won't get a message).

@@ +1263,2 @@
   {
+      GST_ELEMENT_ERROR (mux, STREAM, MUX, ("Can't init stream on pad %" GST_PTR_FORMAT , COLLECT_DATA_PAD (best)), (NULL));

Any reason to change the message here? I think the init_stream_settings should already have mentioned the reason why it failed to init the stream program. I think the original message here made more sense.
Comment 14 Andreas Schuler 2015-03-01 00:09:53 UTC
Okay, first of all, there must went anything wrong. I used git format-patch. Looks like I uploaded the wrong file....sorry.

::: gst/mpegtsmux/mpegtsmux.c
@@ +748,3 @@
+            if (!ret)
+            {
+                GST_ELEMENT_ERROR (mux, STREAM, MUX, ("Reading program map failed. Assuming default"), (NULL));


Hmm....I copied it from the old functions. But it's a good time to think about this part of code. In my opinion, when the developer adds a program map, he want to generate more than one program. If this doesn't works, all video and audio streams are added to one program. Normally this stream is not usable as intendet and we should stop with a error because the user doesn't suppose to get a stream like this. 

But when we do this, maybee we don't need the following line in code:
idx = DEFAULT_PROG_ID;


@@ +1263,2 @@
   {
+      GST_ELEMENT_ERROR (mux, STREAM, MUX, ("Can't init stream on pad %" GST_PTR_FORMAT , COLLECT_DATA_PAD (best)), (NULL));

Hmm...yes, the old message is better.
Comment 15 Thiago Sousa Santos 2015-03-02 17:16:53 UTC
(In reply to Andreas Schuler from comment #14)
> Okay, first of all, there must went anything wrong. I used git format-patch.
> Looks like I uploaded the wrong file....sorry.
> 
> ::: gst/mpegtsmux/mpegtsmux.c
> @@ +748,3 @@
> +            if (!ret)
> +            {
> +                GST_ELEMENT_ERROR (mux, STREAM, MUX, ("Reading program map
> failed. Assuming default"), (NULL));
> 
> 
> Hmm....I copied it from the old functions. But it's a good time to think
> about this part of code. In my opinion, when the developer adds a program
> map, he want to generate more than one program. If this doesn't works, all
> video and audio streams are added to one program. Normally this stream is
> not usable as intendet and we should stop with a error because the user
> doesn't suppose to get a stream like this. 
> 
> But when we do this, maybee we don't need the following line in code:
> idx = DEFAULT_PROG_ID;

Imagine you are using this to record a live event, so erroring out because of a human error (the program map wasn't properly set) would cause you to lose the recording, while just posting a warning gives the choice for the application to continue or abort. I believe being more resilient is usually better, the 'broken' mpegts can be fixed with remuxing into the desired format while erroring out could make the content lost forever.

Anyway this is not part of the intent of your patch, so if you desire it to remain posting an error I will make no objection on merging your work. The discussion for error/warning here can be done as a separate issue.
Comment 16 GStreamer system administrator 2018-11-03 13:30:32 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/issues/208.