From 66533ea77dc6eb23d231a49dc7d070f3c1ecbbed Mon Sep 17 00:00:00 2001 From: Mathieu Duponchelle Date: Tue, 13 Apr 2021 20:51:09 +0200 Subject: [PATCH] scte-section: add support for SCHEDULE commands Part-of: --- .../gst-libs/gst/mpegts/gst-scte-section.c | 33 +++++++++++++++++-- .../gst-libs/gst/mpegts/gst-scte-section.h | 8 +++-- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/mpegts/gst-scte-section.c b/subprojects/gst-plugins-bad/gst-libs/gst/mpegts/gst-scte-section.c index d52fe665db..88e99aac13 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/mpegts/gst-scte-section.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/mpegts/gst-scte-section.c @@ -83,11 +83,17 @@ _parse_splice_event (guint8 ** orig_data, guint8 * end, gboolean insert_event) event->out_of_network_indicator = *data >> 7; event->program_splice_flag = (*data >> 6) & 0x01; event->duration_flag = (*data >> 5) & 0x01; - event->splice_immediate_flag = (*data >> 4) & 0x01; + + if (insert_event) + event->splice_immediate_flag = (*data >> 4) & 0x01; + GST_LOG ("out_of_network_indicator:%d", event->out_of_network_indicator); GST_LOG ("program_splice_flag:%d", event->program_splice_flag); GST_LOG ("duration_flag:%d", event->duration_flag); - GST_LOG ("splice_immediate_flag:%d", event->splice_immediate_flag); + + if (insert_event) + GST_LOG ("splice_immediate_flag:%d", event->splice_immediate_flag); + data += 1; if (event->program_splice_flag == 0) { @@ -95,7 +101,7 @@ _parse_splice_event (guint8 ** orig_data, guint8 * end, gboolean insert_event) goto error; } - if (event->splice_immediate_flag == 0) { + if (insert_event && event->splice_immediate_flag == 0) { event->program_splice_time_specified = *data >> 7; if (event->program_splice_time_specified) { event->program_splice_time = ((guint64) (*data & 0x01)) << 32; @@ -107,6 +113,10 @@ _parse_splice_event (guint8 ** orig_data, guint8 * end, gboolean insert_event) GST_TIME_ARGS (MPEGTIME_TO_GSTTIME (event->program_splice_time))); } else data += 1; + } else if (!insert_event) { + event->utc_splice_time = GST_READ_UINT32_BE (data); + GST_LOG ("utc_splice_time %u", event->utc_splice_time); + data += 4; } if (event->duration_flag) { @@ -257,6 +267,21 @@ _parse_sit (GstMpegtsSection * section) data += 1; } break; + case GST_MTS_SCTE_SPLICE_COMMAND_SCHEDULE: + { + guint i; + guint splice_count = *data; + data += 1; + + for (i = 0; i < splice_count; i++) { + GstMpegtsSCTESpliceEvent *event = + _parse_splice_event (&data, end, FALSE); + if (event == NULL) + goto error; + g_ptr_array_add (sit->splices, event); + } + } + break; case GST_MTS_SCTE_SPLICE_COMMAND_INSERT: { GstMpegtsSCTESpliceEvent *event = _parse_splice_event (&data, end, TRUE); @@ -419,6 +444,7 @@ gst_mpegts_scte_splice_in_new (guint32 event_id, GstClockTime splice_time) sit->splice_command_type = GST_MTS_SCTE_SPLICE_COMMAND_INSERT; event->splice_event_id = event_id; + event->insert_event = TRUE; if (splice_time == G_MAXUINT64) { event->splice_immediate_flag = TRUE; } else { @@ -457,6 +483,7 @@ gst_mpegts_scte_splice_out_new (guint32 event_id, GstClockTime splice_time, sit->splice_command_type = GST_MTS_SCTE_SPLICE_COMMAND_INSERT; event->splice_event_id = event_id; event->out_of_network_indicator = TRUE; + event->insert_event = TRUE; if (splice_time == G_MAXUINT64) { event->splice_immediate_flag = TRUE; } else { diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/mpegts/gst-scte-section.h b/subprojects/gst-plugins-bad/gst-libs/gst/mpegts/gst-scte-section.h index e77a19d57f..26946263ff 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/mpegts/gst-scte-section.h +++ b/subprojects/gst-plugins-bad/gst-libs/gst/mpegts/gst-scte-section.h @@ -118,10 +118,12 @@ struct _GstMpegtsSCTESpliceEvent { gboolean out_of_network_indicator; gboolean program_splice_flag; /* NOTE: Only program splice are supported */ gboolean duration_flag; - gboolean splice_immediate_flag; /* Only valid for insert_event */ - gboolean program_splice_time_specified; - guint64 program_splice_time; + gboolean splice_immediate_flag; /* Only valid for insert_event */ + gboolean program_splice_time_specified; /* Only valid for insert_event */ + guint64 program_splice_time; /* Only valid for insert_event */ + + guint32 utc_splice_time; /* Only valid for !insert_event (schedule) */ gboolean break_duration_auto_return; guint64 break_duration;