• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  *
3  * tsmux-prog-map.c: sample application to show how to construct the
4  * mpegtsmux prog-map property.
5  *
6  * MIT License
7  *
8  * Copyright (C) 2021 Jan Schmidt <jan@centricular.com>
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining a copy
11  * of this software and associated documentation files (the "Software"), to deal
12  * in the Software without restriction, including without limitation the rights
13  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14  * copies of the Software, and to permit persons to whom the Software is
15  * furnished to do so, subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be included in all
18  * copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26  * SOFTWARE.*
27  *
28  */
29 
30 #ifdef HAVE_CONFIG_H
31 #include "config.h"
32 #endif
33 
34 #include <gst/gst.h>
35 
36 /* Test pipeline with h264video on PID 101 and AAC audio on PID 102
37  * The streams will be assigned to Program #2, with PMT on PID 100, and
38  * the PCR on the video stream */
39 #define TEST_PIPELINE "videotestsrc num-buffers=90 ! video/x-raw,framerate=30/1 ! x264enc ! queue ! .sink_101 mpegtsmux name=mux ! fakesink audiotestsrc samplesperbuffer=4800 num-buffers=30 ! audio/x-raw,rate=48000 ! fdkaacenc ! aacparse ! mux.sink_102"
40 
41 static void
_on_bus_message(GstBus * bus,GstMessage * message,GMainLoop * mainloop)42 _on_bus_message (GstBus * bus, GstMessage * message, GMainLoop * mainloop)
43 {
44   switch (GST_MESSAGE_TYPE (message)) {
45     case GST_MESSAGE_ERROR:
46     case GST_MESSAGE_EOS:
47       g_main_loop_quit (mainloop);
48       break;
49     default:
50       break;
51   }
52 }
53 
54 int
main(int argc,char ** argv)55 main (int argc, char **argv)
56 {
57   GstElement *pipeline = NULL;
58   GError *error = NULL;
59   GstBus *bus;
60   GMainLoop *mainloop;
61   GstElement *muxer;
62   GstStructure *prog_map;
63 
64   gst_init (&argc, &argv);
65 
66   pipeline = gst_parse_launch (TEST_PIPELINE, &error);
67   if (error) {
68     g_print ("Error constructing pipeline: %s\n", error->message);
69     g_clear_error (&error);
70     return 1;
71   }
72 
73   mainloop = g_main_loop_new (NULL, FALSE);
74 
75   bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
76   gst_bus_add_signal_watch (bus);
77   g_signal_connect (bus, "message", (GCallback) _on_bus_message, mainloop);
78 
79   /* Configure the program map here. The elementary streams get their PIDs from the pad name.
80    * Assign them to program # 2, with PMT on PID 100 */
81 
82   muxer = gst_bin_get_by_name (GST_BIN (pipeline), "mux");
83 
84   prog_map = gst_structure_new ("x-prog-map",
85       "sink_101", G_TYPE_INT, 2, "sink_102", G_TYPE_INT, 2,
86       "PMT_2", G_TYPE_UINT, 100, "PCR_2", G_TYPE_STRING, "sink_101", NULL);
87   g_object_set (muxer, "prog-map", prog_map, NULL);
88 
89   gst_element_set_state (pipeline, GST_STATE_PLAYING);
90 
91   g_main_loop_run (mainloop);
92 
93   gst_element_set_state (pipeline, GST_STATE_NULL);
94 
95   gst_object_unref (pipeline);
96   gst_object_unref (bus);
97 
98   return 0;
99 }
100