From 37087f129fe8ab81f9a4fda3d1d50c92e6fbc789 Mon Sep 17 00:00:00 2001 From: Aniket Hande Date: Wed, 16 Oct 2024 15:56:40 +0900 Subject: [PATCH] tsparse: Extract and fill m2ts header for each packet Part-of: --- .../gst/mpegtsdemux/mpegtspacketizer.c | 9 +++++++++ .../gst/mpegtsdemux/mpegtspacketizer.h | 1 + .../gst/mpegtsdemux/mpegtsparse.c | 17 +++++++++++++---- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/subprojects/gst-plugins-bad/gst/mpegtsdemux/mpegtspacketizer.c b/subprojects/gst-plugins-bad/gst/mpegtsdemux/mpegtspacketizer.c index c50dec31e0..04ec1729fb 100644 --- a/subprojects/gst-plugins-bad/gst/mpegtsdemux/mpegtspacketizer.c +++ b/subprojects/gst-plugins-bad/gst/mpegtsdemux/mpegtspacketizer.c @@ -871,6 +871,15 @@ mpegts_packetizer_next_packet (MpegTSPacketizer2 * packetizer, if (!mpegts_packetizer_map (packetizer, packet_size)) return PACKET_NEED_MORE; + /* Get M2TS header start */ + if (packet_size == MPEGTS_M2TS_PACKETSIZE) { + guint8 *m2ts_header_start = &packetizer->map_data[packetizer->map_offset]; + packet->m2ts_header_start = m2ts_header_start; + GST_MEMDUMP ("M2TS header start", packet->m2ts_header_start, 4); + } else + packet->m2ts_header_start = NULL; + + /* Get TS packet data start */ packet_data = &packetizer->map_data[packetizer->map_offset + sync_offset]; /* Check sync byte */ diff --git a/subprojects/gst-plugins-bad/gst/mpegtsdemux/mpegtspacketizer.h b/subprojects/gst-plugins-bad/gst/mpegtsdemux/mpegtspacketizer.h index c857950629..3a3038b1df 100644 --- a/subprojects/gst-plugins-bad/gst/mpegtsdemux/mpegtspacketizer.h +++ b/subprojects/gst-plugins-bad/gst/mpegtsdemux/mpegtspacketizer.h @@ -309,6 +309,7 @@ typedef struct guint8 scram_afc_cc; guint8 *payload; + guint8 *m2ts_header_start; guint8 *data_start; guint8 *data_end; guint8 *data; diff --git a/subprojects/gst-plugins-bad/gst/mpegtsdemux/mpegtsparse.c b/subprojects/gst-plugins-bad/gst/mpegtsdemux/mpegtsparse.c index 47ea96bc8d..f4d8161aac 100644 --- a/subprojects/gst-plugins-bad/gst/mpegtsdemux/mpegtsparse.c +++ b/subprojects/gst-plugins-bad/gst/mpegtsdemux/mpegtsparse.c @@ -610,10 +610,19 @@ mpegts_parse_request_new_pad (GstElement * element, GstPadTemplate * template, static GstBuffer * mpegts_packet_to_buffer (MpegTSPacketizerPacket * packet) { - GstBuffer *buf = - gst_buffer_new_and_alloc (packet->data_end - packet->data_start); - gst_buffer_fill (buf, 0, packet->data_start, - packet->data_end - packet->data_start); + GstBuffer *buf; + if (packet->m2ts_header_start != NULL) { + /* Fill the buffer with all 192 bytes */ + buf = + gst_buffer_new_and_alloc (packet->data_end - packet->m2ts_header_start); + gst_buffer_fill (buf, 0, packet->m2ts_header_start, + packet->data_end - packet->m2ts_header_start); + } else { + buf = gst_buffer_new_and_alloc (packet->data_end - packet->data_start); + gst_buffer_fill (buf, 0, packet->data_start, + packet->data_end - packet->data_start); + } + return buf; }