gst-scte-section: implement partial parsing

In cases where either the SIT is encrypted, or an unknown
command is encountered, we still want to send an event downstream.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/913>
This commit is contained in:
Mathieu Duponchelle 2021-04-13 20:44:54 +02:00 committed by GStreamer Marge Bot
parent d17c7f25e6
commit 61fecce193
2 changed files with 31 additions and 9 deletions

View file

@ -184,6 +184,8 @@ _parse_sit (GstMpegtsSection * section)
sit = g_slice_new0 (GstMpegtsSCTESIT);
sit->fully_parsed = FALSE;
data = section->data;
end = data + section->section_length;
@ -220,16 +222,22 @@ _parse_sit (GstMpegtsSection * section)
if (sit->splice_command_length == 0xfff)
sit->splice_command_length = 0;
GST_LOG ("command length %d", sit->splice_command_length);
sit->splice_command_type = *data;
data += 1;
if (sit->encrypted_packet) {
GST_LOG ("Encrypted SIT, parsed partially");
goto done;
}
if (sit->splice_command_length
&& (data + sit->splice_command_length > end - 4)) {
&& (data + sit->splice_command_length > end - 5)) {
GST_WARNING ("PID %d invalid SCTE SIT splice command length %d",
section->pid, sit->splice_command_length);
goto error;
}
sit->splice_command_type = *data;
data += 1;
sit->splices = g_ptr_array_new_with_free_func ((GDestroyNotify)
_gst_mpegts_scte_splice_event_free);
switch (sit->splice_command_type) {
@ -264,9 +272,9 @@ _parse_sit (GstMpegtsSection * section)
}
break;
default:
GST_ERROR ("Unknown SCTE splice command type (0x%02x) !",
GST_WARNING ("Unknown SCTE splice command type (0x%02x) !",
sit->splice_command_type);
goto error;
goto done;
}
/* descriptors */
@ -280,7 +288,6 @@ _parse_sit (GstMpegtsSection * section)
}
data += tmp;
GST_DEBUG ("%p - %p", data, end);
if (data != end - 4) {
GST_WARNING ("PID %d invalid SIT parsed %d length %d",
@ -288,13 +295,18 @@ _parse_sit (GstMpegtsSection * section)
goto error;
}
sit->fully_parsed = TRUE;
done:
return sit;
error:
if (sit)
if (sit) {
_gst_mpegts_scte_sit_free (sit);
sit = NULL;
}
return NULL;
goto done;
}
/**
@ -337,6 +349,7 @@ gst_mpegts_scte_sit_new (void)
/* Set all default values (which aren't already 0/NULL) */
sit->tier = 0xfff;
sit->fully_parsed = TRUE;
sit->splices = g_ptr_array_new_with_free_func ((GDestroyNotify)
_gst_mpegts_scte_splice_event_free);
@ -492,6 +505,11 @@ _packetize_sit (GstMpegtsSection * section)
if (sit == NULL)
return FALSE;
if (sit->fully_parsed == FALSE) {
GST_WARNING ("Attempted to packetize an incompletely parsed SIT");
return FALSE;
}
/* Skip cases we don't handle for now */
if (sit->encrypted_packet) {
GST_WARNING ("SCTE encrypted packet is not supported");

View file

@ -159,7 +159,6 @@ typedef struct _GstMpegtsSCTESIT GstMpegtsSCTESIT;
struct _GstMpegtsSCTESIT
{
/* Encryption not supported for now */
gboolean encrypted_packet;
guint8 encryption_algorithm;
@ -168,6 +167,11 @@ struct _GstMpegtsSCTESIT
guint16 tier;
guint16 splice_command_length;
/* When encrypted, or when encountering an unknown command type,
* we may still want to pass the sit through */
gboolean fully_parsed;
GstMpegtsSCTESpliceCommandType splice_command_type;
/* For time_signal commands */