tsmux: Refactor AC3 descriptor to use GstByteWriter

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4681>
This commit is contained in:
Vivia Nikolaidou 2023-05-22 14:37:55 +03:00 committed by Edward Hervey
parent 637e263504
commit 866d5d87c4

View file

@ -856,11 +856,11 @@ tsmux_stream_default_get_es_descrs (TsMuxStream * stream,
break;
case TSMUX_ST_PS_AUDIO_AC3:
{
guint8 add_info[10];
guint8 *pos;
int wr_size = 0;
guint8 *add_info = NULL;
guint8 data;
guint bitrate;
gboolean has_language;
guint total_length = 7;
guint bitrates[20][2] = {
{32000, 0x00}
,
@ -902,8 +902,8 @@ tsmux_stream_default_get_es_descrs (TsMuxStream * stream,
};
gint i;
guint bitrate_code = 0x12;
pos = add_info;
GstByteWriter writer;
gst_byte_writer_init_with_size (&writer, 7, FALSE);
/* audio_stream_descriptor () | ATSC A/52-2001 Annex A
*
@ -933,18 +933,19 @@ tsmux_stream_default_get_es_descrs (TsMuxStream * stream,
/* 3 bits sample_rate_code, 5 bits hardcoded bsid (default ver 8) */
switch (stream->audio_sampling) {
case 48000:
*pos++ = 0x08;
data = 0x08;
break;
case 44100:
*pos++ = 0x28;
data = 0x28;
break;
case 32000:
*pos++ = 0x48;
data = 0x48;
break;
default:
*pos++ = 0xE8;
data = 0xE8;
break; /* 48, 44.1 or 32 Khz */
}
gst_byte_writer_put_uint8 (&writer, data);
/* 1 bit bit_rate_limit, 5 bits bit_rate_code, 2 bits suround_mode */
bitrate = MAX (stream->audio_bitrate, stream->max_bitrate);
@ -954,58 +955,65 @@ tsmux_stream_default_get_es_descrs (TsMuxStream * stream,
}
bitrate_code = bitrates[i][1];
}
*pos = bitrate_code << 2;
*pos++ |= 0x80; /* This is a maximum bitrate */
data = bitrate_code << 2;
data |= 0x80; /* This is a maximum bitrate */
gst_byte_writer_put_uint8 (&writer, data);
/* 3 bits bsmod, 4 bits num_channels, 1 bit full_svc */
switch (stream->audio_channels) {
case 1:
*pos = 0x01 << 1;
data = 0x01 << 1;
break; /* 1/0 */
case 2:
*pos = 0x02 << 1;
data = 0x02 << 1;
break; /* 2/0 */
case 3:
*pos = 0x0A << 1;
data = 0x0A << 1;
break; /* <= 3 */
case 4:
*pos = 0x0B << 1;
data = 0x0B << 1;
break; /* <= 4 */
case 5:
*pos = 0x0C << 1;
data = 0x0C << 1;
break; /* <= 5 */
case 6:
default:
*pos = 0x0D << 1;
data = 0x0D << 1;
break; /* <= 6 */
}
*pos++ |= 0x01; /* full_svc is hardcoded to 1 for now */
data |= 0x01; /* full_svc is hardcoded to 1 for now */
gst_byte_writer_put_uint8 (&writer, data);
/* deprecated langcod */
*pos++ = 0xff;
data = 0xff;
gst_byte_writer_put_uint8 (&writer, data);
/* 3 bits mainid, 2 bits priority, 3 bits reserved */
*pos++ = 0x0f;
data = 0x0f;
gst_byte_writer_put_uint8 (&writer, data);
/* 7 bits textlen, 1 bit text_code */
*pos++ = 0x00;
data = 0x00;
gst_byte_writer_put_uint8 (&writer, data);
/* no text provided, jumping directly to language */
has_language = (stream->language[0] != '\0');
if (has_language) {
*pos++ = 0xbf;
*pos++ = stream->language[0];
*pos++ = stream->language[1];
*pos++ = stream->language[2];
total_length = 10;
data = 0xbf;
gst_byte_writer_put_uint8 (&writer, data);
gst_byte_writer_put_data (&writer, (guint8 *) stream->language, 3);
} else {
*pos++ = 0x3f;
data = 0x3f;
gst_byte_writer_put_uint8 (&writer, data);
}
descriptor = gst_mpegts_descriptor_from_registration ("AC-3", NULL, 0);
g_ptr_array_add (pmt_stream->descriptors, descriptor);
wr_size = gst_byte_writer_get_size (&writer);
add_info = gst_byte_writer_reset_and_get_data (&writer);
descriptor =
gst_mpegts_descriptor_from_custom (GST_MTS_DESC_AC3_AUDIO_STREAM,
add_info, total_length);
add_info, wr_size);
g_ptr_array_add (pmt_stream->descriptors, descriptor);
break;
}