tsmux: Split off j2k descriptor code in separate function

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7172>
This commit is contained in:
Edward Hervey 2024-08-29 14:49:59 +02:00 committed by Tim-Philipp Müller
parent 6ce1910c5b
commit 838ad5c7e4

View file

@ -728,6 +728,79 @@ tsmux_stream_write_pes_header (TsMuxStream * stream, guint8 * data)
}
}
static GstMpegtsDescriptor *
j2k_descriptor (TsMuxStream * stream)
{
GstMpegtsDescriptor *descriptor;
/* J2K video descriptor
* descriptor_tag 8 uimsbf
* descriptor_length 8 uimsbf
* profile_and_level 16 uimsbf
* horizontal_size 32 uimsbf
* vertical_size 32 uimsbf
* max_bit_rate 32 uimsbf
* max_buffer_size 32 uimsbf
* DEN_frame_rate 16 uimsbf
* NUM_frame_rate 16 uimsbf
* color_specification 8 bslbf
* still_mode 1 bslbf
* interlace_video 1 bslbf
* reserved 6 bslbf
* private_data_byte 8 bslbf
*/
gint8 still_interlace_reserved = 0x00;
int wr_size = 0;
guint8 *add_info = NULL;
guint8 level = stream->profile_and_level & 0xF;
guint32 max_buffer_size = 0;
GstByteWriter writer;
gst_byte_writer_init_with_size (&writer, 32, FALSE);
switch (level) {
case 1:
case 2:
case 3:
max_buffer_size = 1250000;
break;
case 4:
max_buffer_size = 2500000;
break;
case 5:
max_buffer_size = 5000000;
break;
case 6:
max_buffer_size = 10000000;
break;
default:
break;
}
gst_byte_writer_put_uint16_be (&writer, stream->profile_and_level);
gst_byte_writer_put_uint32_be (&writer, stream->horizontal_size);
gst_byte_writer_put_uint32_be (&writer, stream->vertical_size);
gst_byte_writer_put_uint32_be (&writer, max_buffer_size);
gst_byte_writer_put_uint32_be (&writer, stream->max_bitrate);
gst_byte_writer_put_uint16_be (&writer, stream->den);
gst_byte_writer_put_uint16_be (&writer, stream->num);
gst_byte_writer_put_uint8 (&writer, stream->color_spec);
if (stream->interlace_mode)
still_interlace_reserved |= 0x40;
gst_byte_writer_put_uint8 (&writer, still_interlace_reserved);
gst_byte_writer_put_uint8 (&writer, 0x00); /* private data byte */
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_J2K_VIDEO, add_info,
wr_size);
g_free (add_info);
return descriptor;
}
/**
* tsmux_stream_add_data:
* @stream: a #TsMuxStream
@ -825,70 +898,7 @@ tsmux_stream_default_get_es_descrs (TsMuxStream * stream,
break;
case TSMUX_ST_VIDEO_JP2K:
{
/* J2K video descriptor
* descriptor_tag 8 uimsbf
* descriptor_length 8 uimsbf
* profile_and_level 16 uimsbf
* horizontal_size 32 uimsbf
* vertical_size 32 uimsbf
* max_bit_rate 32 uimsbf
* max_buffer_size 32 uimsbf
* DEN_frame_rate 16 uimsbf
* NUM_frame_rate 16 uimsbf
* color_specification 8 bslbf
* still_mode 1 bslbf
* interlace_video 1 bslbf
* reserved 6 bslbf
* private_data_byte 8 bslbf
*/
gint8 still_interlace_reserved = 0x00;
int wr_size = 0;
guint8 *add_info = NULL;
guint8 level = stream->profile_and_level & 0xF;
guint32 max_buffer_size = 0;
GstByteWriter writer;
gst_byte_writer_init_with_size (&writer, 32, FALSE);
switch (level) {
case 1:
case 2:
case 3:
max_buffer_size = 1250000;
break;
case 4:
max_buffer_size = 2500000;
break;
case 5:
max_buffer_size = 5000000;
break;
case 6:
max_buffer_size = 10000000;
break;
default:
break;
}
gst_byte_writer_put_uint16_be (&writer, stream->profile_and_level);
gst_byte_writer_put_uint32_be (&writer, stream->horizontal_size);
gst_byte_writer_put_uint32_be (&writer, stream->vertical_size);
gst_byte_writer_put_uint32_be (&writer, max_buffer_size);
gst_byte_writer_put_uint32_be (&writer, stream->max_bitrate);
gst_byte_writer_put_uint16_be (&writer, stream->den);
gst_byte_writer_put_uint16_be (&writer, stream->num);
gst_byte_writer_put_uint8 (&writer, stream->color_spec);
if (stream->interlace_mode)
still_interlace_reserved |= 0x40;
gst_byte_writer_put_uint8 (&writer, still_interlace_reserved);
gst_byte_writer_put_uint8 (&writer, 0x00); /* private data byte */
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_J2K_VIDEO, add_info,
wr_size);
descriptor = j2k_descriptor (stream);
g_ptr_array_add (pmt_stream->descriptors, descriptor);
}
break;