mpegts: add support for KLV metadata in PES packets

Co-authored-by: Andoni Morales Alastruey <ylatuya@gmail.com>
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1312>
This commit is contained in:
Brad Hards 2023-03-30 20:09:59 +11:00 committed by GStreamer Marge Bot
parent 4e14bac1ff
commit 6f2eb752c5

View file

@ -1728,6 +1728,28 @@ create_pad_for_stream (MpegTSBase * base, MpegTSBaseStream * bstream,
"mpegversion", G_TYPE_INT, 4,
"systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
break;
case GST_MPEGTS_STREAM_TYPE_METADATA_PES_PACKETS:
desc = mpegts_get_descriptor_from_stream (bstream, GST_MTS_DESC_METADATA);
if (desc) {
GstMpegtsMetadataDescriptor *metadataDescriptor;
if (gst_mpegts_descriptor_parse_metadata (desc, &metadataDescriptor)) {
if ((metadataDescriptor->metadata_format ==
GST_MPEGTS_METADATA_FORMAT_IDENTIFIER_FIELD)
&& (metadataDescriptor->metadata_format_identifier ==
DRF_ID_KLVA)) {
sparse = TRUE;
is_private = TRUE;
/* registration_id is not correctly set or parsed for some streams */
bstream->registration_id = DRF_ID_KLVA;
caps = gst_caps_new_simple ("meta/x-klv",
"parsed", G_TYPE_BOOLEAN, TRUE,
"stream-type", G_TYPE_INT, bstream->stream_type, NULL);
}
g_free (metadataDescriptor);
}
}
break;
case GST_MPEGTS_STREAM_TYPE_VIDEO_H264:
is_video = TRUE;
caps = gst_caps_new_simple ("video/x-h264",
@ -3431,18 +3453,19 @@ gst_ts_demux_push_pending_data (GstTSDemux * demux, TSDemuxStream * stream,
res = GST_FLOW_ERROR;
goto beach;
}
if (gst_buffer_list_length (buffer_list) == 1) {
buffer = gst_buffer_ref (gst_buffer_list_get (buffer_list, 0));
gst_buffer_list_unref (buffer_list);
buffer_list = NULL;
}
} else if (bs->stream_type == GST_MPEGTS_STREAM_TYPE_VIDEO_JP2K) {
buffer = parse_jp2k_access_unit (stream);
if (!buffer) {
res = GST_FLOW_ERROR;
goto beach;
}
} else if (bs->stream_type == GST_MPEGTS_STREAM_TYPE_METADATA_PES_PACKETS
&& bs->registration_id == DRF_ID_KLVA) {
buffer_list = parse_pes_metadata_frame (stream);
if (!buffer_list) {
res = GST_FLOW_ERROR;
goto beach;
}
} else {
buffer = gst_buffer_new_wrapped (stream->data, stream->current_size);
}
@ -3485,12 +3508,6 @@ gst_ts_demux_push_pending_data (GstTSDemux * demux, TSDemuxStream * stream,
res = GST_FLOW_ERROR;
goto beach;
}
if (gst_buffer_list_length (buffer_list) == 1) {
buffer = gst_buffer_ref (gst_buffer_list_get (buffer_list, 0));
gst_buffer_list_unref (buffer_list);
buffer_list = NULL;
}
} else if (bs->stream_type == GST_MPEGTS_STREAM_TYPE_VIDEO_JP2K) {
buffer = parse_jp2k_access_unit (stream);
if (!buffer) {
@ -3503,6 +3520,13 @@ gst_ts_demux_push_pending_data (GstTSDemux * demux, TSDemuxStream * stream,
res = GST_FLOW_ERROR;
goto beach;
}
} else if (bs->stream_type == GST_MPEGTS_STREAM_TYPE_METADATA_PES_PACKETS
&& bs->registration_id == DRF_ID_KLVA) {
buffer_list = parse_pes_metadata_frame (stream);
if (!buffer_list) {
res = GST_FLOW_ERROR;
goto beach;
}
} else {
buffer = gst_buffer_new_wrapped (stream->data, stream->current_size);
}
@ -3535,6 +3559,13 @@ gst_ts_demux_push_pending_data (GstTSDemux * demux, TSDemuxStream * stream,
}
}
if (buffer_list != NULL && gst_buffer_list_length (buffer_list) == 1) {
buffer = gst_buffer_ref (gst_buffer_list_get (buffer_list, 0));
gst_buffer_list_unref (buffer_list);
buffer_list = NULL;
}
if (G_UNLIKELY (stream->need_newsegment))
calculate_and_push_newsegment (demux, stream, target_program);