mpegtsmux: Cleanup TsMuxStream fields

Instead of using plenty of case-specific booleans:
* Store type as GstStreamType
* Store unique stream type

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7476>
This commit is contained in:
Edward Hervey 2024-08-29 12:16:16 +02:00 committed by GStreamer Marge Bot
parent 595983df9f
commit 2024287a39
5 changed files with 31 additions and 35 deletions

View file

@ -299,10 +299,11 @@ gst_atsc_mux_create_new_stream (guint16 new_pid, TsMuxStreamType stream_type,
if (stream_type == ATSCMUX_ST_PS_AUDIO_EAC3) {
ret->id = 0xBD;
ret->pi.flags |= TSMUX_PACKET_FLAG_PES_FULL_HEADER;
ret->is_audio = TRUE;
ret->gst_stream_type = GST_STREAM_TYPE_AUDIO;
} else if (stream_type == TSMUX_ST_PS_AUDIO_AC3) {
ret->id = 0xBD;
ret->id_extended = 0;
ret->gst_stream_type = GST_STREAM_TYPE_AUDIO;
}
tsmux_stream_set_get_es_descriptors_func (ret,

View file

@ -1413,7 +1413,8 @@ gst_base_ts_mux_aggregate_buffer (GstBaseTsMux * mux,
buf = tmp;
}
if (mux->force_key_unit_event != NULL && best->stream->is_video_stream) {
if (mux->force_key_unit_event != NULL
&& best->stream->gst_stream_type == GST_STREAM_TYPE_VIDEO) {
GstEvent *event;
g_mutex_unlock (&mux->lock);
@ -1494,12 +1495,13 @@ gst_base_ts_mux_aggregate_buffer (GstBaseTsMux * mux,
pts = dts;
}
if (best->stream->is_video_stream) {
if (best->stream->gst_stream_type == GST_STREAM_TYPE_VIDEO) {
delta = GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT);
header = GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_HEADER);
}
if (best->stream->is_meta && gst_buffer_get_size (buf) > (G_MAXUINT16 - 3)) {
if (best->stream->internal_stream_type == TSMUX_ST_PS_KLV &&
gst_buffer_get_size (buf) > (G_MAXUINT16 - 3)) {
GST_WARNING_OBJECT (mux, "KLV meta unit too big, splitting not supported");
gst_buffer_unref (buf);

View file

@ -1859,7 +1859,7 @@ tsmux_write_pmt (TsMux * mux, TsMuxProgram * program)
for (i = 0; i < program->streams->len; i++) {
TsMuxStream *stream = g_ptr_array_index (program->streams, i);
if (stream->is_id3_metadata == TRUE) {
if (stream->internal_stream_type == TSMUX_ST_PS_ID3) {
GstMpegtsMetadataPointerDescriptor metadata_pointer_descriptor;
metadata_pointer_descriptor.metadata_application_format =
GST_MPEGTS_METADATA_APPLICATION_FORMAT_IDENTIFIER_FIELD;

View file

@ -124,6 +124,7 @@ tsmux_stream_new (guint16 pid, guint stream_type, guint stream_number)
stream->state = TSMUX_STREAM_STATE_HEADER;
stream->pi.pid = pid;
stream->stream_type = stream_type;
stream->internal_stream_type = stream_type;
stream->pes_payload_size = 0;
stream->cur_pes_payload_size = 0;
@ -144,13 +145,13 @@ tsmux_stream_new (guint16 pid, guint stream_type, guint stream_number)
}
stream->id = 0xE0 | stream_number;
stream->pi.flags |= TSMUX_PACKET_FLAG_PES_FULL_HEADER;
stream->is_video_stream = TRUE;
stream->gst_stream_type = GST_STREAM_TYPE_VIDEO;
supports_user_specified_stream_number = TRUE;
break;
case TSMUX_ST_VIDEO_JP2K:
stream->id = 0xBD;
stream->pi.flags |= TSMUX_PACKET_FLAG_PES_FULL_HEADER;
stream->is_video_stream = TRUE;
stream->gst_stream_type = GST_STREAM_TYPE_VIDEO;
break;
case TSMUX_ST_AUDIO_AAC:
case TSMUX_ST_AUDIO_MPEG1:
@ -161,7 +162,7 @@ tsmux_stream_new (guint16 pid, guint stream_type, guint stream_number)
stream_number);
stream_number = 0;
}
stream->is_audio = TRUE;
stream->gst_stream_type = GST_STREAM_TYPE_AUDIO;
stream->id = 0xC0 | stream_number;
stream->pi.flags |= TSMUX_PACKET_FLAG_PES_FULL_HEADER;
supports_user_specified_stream_number = TRUE;
@ -175,18 +176,18 @@ tsmux_stream_new (guint16 pid, guint stream_type, guint stream_number)
switch (stream_type) {
case TSMUX_ST_VIDEO_DIRAC:
stream->id_extended = 0x60;
stream->is_video_stream = TRUE;
stream->gst_stream_type = GST_STREAM_TYPE_VIDEO;
break;
case TSMUX_ST_PS_AUDIO_LPCM:
stream->is_audio = TRUE;
stream->gst_stream_type = GST_STREAM_TYPE_AUDIO;
stream->id_extended = 0x80;
break;
case TSMUX_ST_PS_AUDIO_AC3:
stream->is_audio = TRUE;
stream->gst_stream_type = GST_STREAM_TYPE_AUDIO;
stream->id_extended = 0x71;
break;
case TSMUX_ST_PS_AUDIO_DTS:
stream->is_audio = TRUE;
stream->gst_stream_type = GST_STREAM_TYPE_AUDIO;
stream->id_extended = 0x82;
break;
default:
@ -214,7 +215,6 @@ tsmux_stream_new (guint16 pid, guint stream_type, guint stream_number)
/* FIXME: assign sequential extended IDs? */
stream->id = 0xBD;
stream->stream_type = TSMUX_ST_PRIVATE_DATA;
stream->is_meta = TRUE;
stream->pi.flags |=
TSMUX_PACKET_FLAG_PES_FULL_HEADER |
TSMUX_PACKET_FLAG_PES_DATA_ALIGNMENT;
@ -222,17 +222,14 @@ tsmux_stream_new (guint16 pid, guint stream_type, guint stream_number)
case TSMUX_ST_PS_ID3:
stream->id = 0xBD; // private stream
stream->stream_type = TSMUX_ST_PES_METADATA;
stream->is_meta = TRUE;
stream->is_id3_metadata = TRUE;
stream->pi.flags |= TSMUX_PACKET_FLAG_PES_FULL_HEADER |
TSMUX_PACKET_FLAG_PES_DATA_ALIGNMENT;
break;
case TSMUX_ST_PS_OPUS:
/* FIXME: assign sequential extended IDs? */
stream->id = 0xBD;
stream->is_audio = TRUE;
stream->gst_stream_type = GST_STREAM_TYPE_AUDIO;
stream->stream_type = TSMUX_ST_PRIVATE_DATA;
stream->is_opus = TRUE;
stream->pi.flags |= TSMUX_PACKET_FLAG_PES_FULL_HEADER;
break;
default:
@ -494,7 +491,7 @@ tsmux_stream_initialize_pes_packet (TsMuxStream * stream)
}
}
if (stream->is_video_stream) {
if (stream->gst_stream_type == GST_STREAM_TYPE_VIDEO) {
guint8 hdr_len;
hdr_len = tsmux_stream_pes_header_length (stream);
@ -504,10 +501,8 @@ tsmux_stream_initialize_pes_packet (TsMuxStream * stream)
stream->cur_pes_payload_size = 0;
}
// stream_type specific flags
switch (stream->stream_type) {
case TSMUX_ST_PES_METADATA:
stream->pi.flags |= TSMUX_PACKET_FLAG_PES_DATA_ALIGNMENT;
break;
if (stream->stream_type == TSMUX_ST_PES_METADATA) {
stream->pi.flags |= TSMUX_PACKET_FLAG_PES_DATA_ALIGNMENT;
}
return TRUE;
@ -796,7 +791,8 @@ tsmux_stream_default_get_es_descrs (TsMuxStream * stream,
g_return_if_fail (stream != NULL);
g_return_if_fail (pmt_stream != NULL);
if (stream->is_audio && stream->language[0] != '\0') {
if (stream->gst_stream_type == GST_STREAM_TYPE_AUDIO
&& stream->language[0] != '\0') {
descriptor = gst_mpegts_descriptor_from_iso_639_language (stream->language);
g_ptr_array_add (pmt_stream->descriptors, descriptor);
descriptor = NULL;
@ -928,7 +924,7 @@ tsmux_stream_default_get_es_descrs (TsMuxStream * stream,
case TSMUX_ST_PES_METADATA:
if (stream->is_id3_metadata) {
if (stream->internal_stream_type == TSMUX_ST_PS_ID3) {
// metadata_descriptor
GstMpegtsMetadataDescriptor metadata_descriptor;
@ -972,7 +968,7 @@ tsmux_stream_default_get_es_descrs (TsMuxStream * stream,
g_ptr_array_add (pmt_stream->descriptors, descriptor);
break;
}
if (stream->is_opus) {
if (stream->internal_stream_type == TSMUX_ST_PS_OPUS) {
descriptor = gst_mpegts_descriptor_from_registration ("Opus", NULL, 0);
g_ptr_array_add (pmt_stream->descriptors, descriptor);
@ -983,7 +979,7 @@ tsmux_stream_default_get_es_descrs (TsMuxStream * stream,
g_ptr_array_add (pmt_stream->descriptors, descriptor);
}
if (stream->is_meta) {
if (stream->internal_stream_type == TSMUX_ST_PS_KLV) {
descriptor = gst_mpegts_descriptor_from_registration ("KLVA", NULL, 0);
GST_DEBUG ("adding KLVA registration descriptor");
g_ptr_array_add (pmt_stream->descriptors, descriptor);

View file

@ -147,7 +147,12 @@ enum TsMuxStreamState {
struct TsMuxStream {
TsMuxStreamState state;
TsMuxPacketInfo pi;
guint stream_type;
/* Stream type to be used in PES/PSI */
TsMuxStreamType stream_type;
/* internal stream identifier (used for private section/pes) */
TsMuxStreamType internal_stream_type;
/* Nature of the stream (audio, video, ..) */
GstStreamType gst_stream_type;
/* stream_id (13818-1) */
guint8 id;
@ -159,8 +164,6 @@ struct TsMuxStream {
/* requested index in the PMT */
gint pmt_index;
gboolean is_video_stream;
/* data available for writing out
* and total sum of sizes */
GList *buffers;
@ -210,11 +213,7 @@ struct TsMuxStream {
gboolean is_dvb_sub;
gchar language[4];
gboolean is_meta;
gboolean is_audio;
/* Opus */
gboolean is_opus;
guint8 opus_channel_config[1 + 2 + 1 + 1 + 255];
gsize opus_channel_config_len;
@ -228,8 +227,6 @@ struct TsMuxStream {
guint16 profile_and_level;
gboolean interlace_mode;
guint8 color_spec;
gboolean is_id3_metadata;
};
/* stream management */