• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <gst/gst.h>
2 #include <gst/mpegts/mpegts.h>
3 
4 #define PIPELINE_STR "videotestsrc num-buffers=100 ! x264enc ! queue ! mpegtsmux name=mux ! fakesink"
5 
6 static void
_on_bus_message(GstBus * bus,GstMessage * message,GMainLoop * mainloop)7 _on_bus_message (GstBus * bus, GstMessage * message, GMainLoop * mainloop)
8 {
9   switch (GST_MESSAGE_TYPE (message)) {
10     case GST_MESSAGE_ERROR:
11     case GST_MESSAGE_EOS:
12       g_main_loop_quit (mainloop);
13       break;
14     default:
15       break;
16   }
17 }
18 
19 static void
advertise_service(GstElement * mux)20 advertise_service (GstElement * mux)
21 {
22   GstMpegtsSDTService *service;
23   GstMpegtsSDT *sdt;
24   GstMpegtsDescriptor *desc;
25   GstMpegtsSection *section;
26 
27   sdt = gst_mpegts_sdt_new ();
28 
29   sdt->actual_ts = TRUE;
30   sdt->transport_stream_id = 42;
31 
32   service = gst_mpegts_sdt_service_new ();
33   service->service_id = 42;
34   service->running_status =
35       GST_MPEGTS_RUNNING_STATUS_RUNNING + service->service_id;
36   service->EIT_schedule_flag = FALSE;
37   service->EIT_present_following_flag = FALSE;
38   service->free_CA_mode = FALSE;
39 
40   desc = gst_mpegts_descriptor_from_dvb_service
41       (GST_DVB_SERVICE_DIGITAL_TELEVISION, "some-service", NULL);
42 
43   g_ptr_array_add (service->descriptors, desc);
44   g_ptr_array_add (sdt->services, service);
45 
46   section = gst_mpegts_section_from_sdt (sdt);
47   gst_mpegts_section_send_event (section, mux);
48   gst_mpegts_section_unref (section);
49 }
50 
51 int
main(int argc,char ** argv)52 main (int argc, char **argv)
53 {
54   GstElement *pipeline = NULL;
55   GError *error = NULL;
56   GstBus *bus;
57   GMainLoop *mainloop;
58   GstElement *mux;
59 
60   gst_init (&argc, &argv);
61 
62   pipeline = gst_parse_launch (PIPELINE_STR, &error);
63   if (error) {
64     g_print ("pipeline could not be constructed: %s\n", error->message);
65     g_clear_error (&error);
66     return 1;
67   }
68 
69   mainloop = g_main_loop_new (NULL, FALSE);
70 
71   mux = gst_bin_get_by_name (GST_BIN (pipeline), "mux");
72   advertise_service (mux);
73   gst_object_unref (mux);
74 
75   /* Put a bus handler */
76   bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
77   gst_bus_add_signal_watch (bus);
78   g_signal_connect (bus, "message", (GCallback) _on_bus_message, mainloop);
79 
80   /* Start pipeline */
81   gst_element_set_state (pipeline, GST_STATE_PLAYING);
82   g_main_loop_run (mainloop);
83 
84   gst_element_set_state (pipeline, GST_STATE_NULL);
85 
86   gst_object_unref (pipeline);
87   gst_object_unref (bus);
88 
89   return 0;
90 }
91