mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-07 07:58:51 +00:00
basetsmux: Clean up gst_base_ts_mux_create_stream
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/981>
This commit is contained in:
parent
273e2a1db6
commit
a8ebf72627
1 changed files with 68 additions and 64 deletions
|
@ -372,10 +372,8 @@ release_buffer_cb (guint8 * data, void *user_data)
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
gst_base_ts_mux_create_stream (GstBaseTsMux * mux, GstBaseTsMuxPad * ts_pad)
|
gst_base_ts_mux_create_stream (GstBaseTsMux * mux, GstBaseTsMuxPad * ts_pad)
|
||||||
{
|
{
|
||||||
GstFlowReturn ret = GST_FLOW_ERROR;
|
|
||||||
GstCaps *caps;
|
GstCaps *caps;
|
||||||
GstStructure *s;
|
GstStructure *s;
|
||||||
GstPad *pad;
|
|
||||||
guint st = TSMUX_ST_RESERVED;
|
guint st = TSMUX_ST_RESERVED;
|
||||||
const gchar *mt;
|
const gchar *mt;
|
||||||
const GValue *value = NULL;
|
const GValue *value = NULL;
|
||||||
|
@ -385,16 +383,18 @@ gst_base_ts_mux_create_stream (GstBaseTsMux * mux, GstBaseTsMuxPad * ts_pad)
|
||||||
guint8 main_level = 0;
|
guint8 main_level = 0;
|
||||||
guint32 max_rate = 0;
|
guint32 max_rate = 0;
|
||||||
guint8 color_spec = 0;
|
guint8 color_spec = 0;
|
||||||
j2k_private_data *private_data = NULL;
|
|
||||||
const gchar *stream_format = NULL;
|
const gchar *stream_format = NULL;
|
||||||
|
const char *interlace_mode = NULL;
|
||||||
|
|
||||||
pad = GST_PAD (ts_pad);
|
caps = gst_pad_get_current_caps (GST_PAD (ts_pad));
|
||||||
caps = gst_pad_get_current_caps (pad);
|
if (caps == NULL) {
|
||||||
if (caps == NULL)
|
GST_DEBUG_OBJECT (ts_pad, "Sink pad caps were not set before pushing");
|
||||||
goto not_negotiated;
|
return GST_FLOW_NOT_NEGOTIATED;
|
||||||
|
}
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (pad, "Creating stream with PID 0x%04x for caps %"
|
GST_DEBUG_OBJECT (ts_pad,
|
||||||
GST_PTR_FORMAT, ts_pad->pid, caps);
|
"Creating stream with PID 0x%04x for caps %" GST_PTR_FORMAT,
|
||||||
|
ts_pad->pid, caps);
|
||||||
|
|
||||||
s = gst_caps_get_structure (caps, 0);
|
s = gst_caps_get_structure (caps, 0);
|
||||||
|
|
||||||
|
@ -421,7 +421,7 @@ gst_base_ts_mux_create_stream (GstBaseTsMux * mux, GstBaseTsMuxPad * ts_pad)
|
||||||
gint mpegversion;
|
gint mpegversion;
|
||||||
|
|
||||||
if (!gst_structure_get_int (s, "mpegversion", &mpegversion)) {
|
if (!gst_structure_get_int (s, "mpegversion", &mpegversion)) {
|
||||||
GST_ERROR_OBJECT (pad, "caps missing mpegversion");
|
GST_ERROR_OBJECT (ts_pad, "caps missing mpegversion");
|
||||||
goto not_negotiated;
|
goto not_negotiated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -460,7 +460,7 @@ gst_base_ts_mux_create_stream (GstBaseTsMux * mux, GstBaseTsMuxPad * ts_pad)
|
||||||
/* Check the stream format. We need codec_data with RAW streams and mpegversion=4 */
|
/* Check the stream format. We need codec_data with RAW streams and mpegversion=4 */
|
||||||
if (g_strcmp0 (stream_format, "raw") == 0) {
|
if (g_strcmp0 (stream_format, "raw") == 0) {
|
||||||
if (codec_data) {
|
if (codec_data) {
|
||||||
GST_DEBUG_OBJECT (pad,
|
GST_DEBUG_OBJECT (ts_pad,
|
||||||
"we have additional codec data (%" G_GSIZE_FORMAT " bytes)",
|
"we have additional codec data (%" G_GSIZE_FORMAT " bytes)",
|
||||||
gst_buffer_get_size (codec_data));
|
gst_buffer_get_size (codec_data));
|
||||||
ts_pad->codec_data = gst_buffer_ref (codec_data);
|
ts_pad->codec_data = gst_buffer_ref (codec_data);
|
||||||
|
@ -474,14 +474,14 @@ gst_base_ts_mux_create_stream (GstBaseTsMux * mux, GstBaseTsMuxPad * ts_pad)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
GST_WARNING_OBJECT (pad, "unsupported mpegversion %d", mpegversion);
|
GST_WARNING_OBJECT (ts_pad, "unsupported mpegversion %d", mpegversion);
|
||||||
goto not_negotiated;
|
goto not_negotiated;
|
||||||
}
|
}
|
||||||
} else if (strcmp (mt, "video/mpeg") == 0) {
|
} else if (strcmp (mt, "video/mpeg") == 0) {
|
||||||
gint mpegversion;
|
gint mpegversion;
|
||||||
|
|
||||||
if (!gst_structure_get_int (s, "mpegversion", &mpegversion)) {
|
if (!gst_structure_get_int (s, "mpegversion", &mpegversion)) {
|
||||||
GST_ERROR_OBJECT (pad, "caps missing mpegversion");
|
GST_ERROR_OBJECT (ts_pad, "caps missing mpegversion");
|
||||||
goto not_negotiated;
|
goto not_negotiated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -496,7 +496,7 @@ gst_base_ts_mux_create_stream (GstBaseTsMux * mux, GstBaseTsMuxPad * ts_pad)
|
||||||
st = TSMUX_ST_VIDEO_MPEG4;
|
st = TSMUX_ST_VIDEO_MPEG4;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
GST_WARNING_OBJECT (pad, "unsupported mpegversion %d", mpegversion);
|
GST_WARNING_OBJECT (ts_pad, "unsupported mpegversion %d", mpegversion);
|
||||||
goto not_negotiated;
|
goto not_negotiated;
|
||||||
}
|
}
|
||||||
} else if (strcmp (mt, "subpicture/x-dvb") == 0) {
|
} else if (strcmp (mt, "subpicture/x-dvb") == 0) {
|
||||||
|
@ -511,7 +511,7 @@ gst_base_ts_mux_create_stream (GstBaseTsMux * mux, GstBaseTsMuxPad * ts_pad)
|
||||||
|
|
||||||
if (!gst_codec_utils_opus_parse_caps (caps, NULL, &channels,
|
if (!gst_codec_utils_opus_parse_caps (caps, NULL, &channels,
|
||||||
&mapping_family, &stream_count, &coupled_count, channel_mapping)) {
|
&mapping_family, &stream_count, &coupled_count, channel_mapping)) {
|
||||||
GST_ERROR_OBJECT (pad, "Incomplete Opus caps");
|
GST_ERROR_OBJECT (ts_pad, "Incomplete Opus caps");
|
||||||
goto not_negotiated;
|
goto not_negotiated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -558,7 +558,7 @@ gst_base_ts_mux_create_stream (GstBaseTsMux * mux, GstBaseTsMuxPad * ts_pad)
|
||||||
channels) == 0) {
|
channels) == 0) {
|
||||||
opus_channel_config_code = channels | 0x80;
|
opus_channel_config_code = channels | 0x80;
|
||||||
} else {
|
} else {
|
||||||
GST_FIXME_OBJECT (pad, "Opus channel mapping not handled");
|
GST_FIXME_OBJECT (ts_pad, "Opus channel mapping not handled");
|
||||||
goto not_negotiated;
|
goto not_negotiated;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -580,21 +580,22 @@ gst_base_ts_mux_create_stream (GstBaseTsMux * mux, GstBaseTsMuxPad * ts_pad)
|
||||||
const GValue *vMainlevel = gst_structure_get_value (s, "main-level");
|
const GValue *vMainlevel = gst_structure_get_value (s, "main-level");
|
||||||
const GValue *vFramerate = gst_structure_get_value (s, "framerate");
|
const GValue *vFramerate = gst_structure_get_value (s, "framerate");
|
||||||
const GValue *vColorimetry = gst_structure_get_value (s, "colorimetry");
|
const GValue *vColorimetry = gst_structure_get_value (s, "colorimetry");
|
||||||
private_data = g_new0 (j2k_private_data, 1);
|
j2k_private_data *private_data;
|
||||||
|
|
||||||
/* for now, we relax the condition that profile must exist and equal
|
/* for now, we relax the condition that profile must exist and equal
|
||||||
* GST_JPEG2000_PARSE_PROFILE_BC_SINGLE */
|
* GST_JPEG2000_PARSE_PROFILE_BC_SINGLE */
|
||||||
if (vProfile) {
|
if (vProfile) {
|
||||||
profile = g_value_get_int (vProfile);
|
profile = g_value_get_int (vProfile);
|
||||||
if (profile != GST_JPEG2000_PARSE_PROFILE_BC_SINGLE) {
|
if (profile != GST_JPEG2000_PARSE_PROFILE_BC_SINGLE) {
|
||||||
GST_LOG_OBJECT (pad, "Invalid JPEG 2000 profile %d", profile);
|
GST_LOG_OBJECT (ts_pad, "Invalid JPEG 2000 profile %d", profile);
|
||||||
/*goto not_negotiated; */
|
/* goto not_negotiated; */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* for now, we will relax the condition that the main level must be present */
|
/* for now, we will relax the condition that the main level must be present */
|
||||||
if (vMainlevel) {
|
if (vMainlevel) {
|
||||||
main_level = g_value_get_uint (vMainlevel);
|
main_level = g_value_get_uint (vMainlevel);
|
||||||
if (main_level > 11) {
|
if (main_level > 11) {
|
||||||
GST_ERROR_OBJECT (pad, "Invalid main level %d", main_level);
|
GST_ERROR_OBJECT (ts_pad, "Invalid main level %d", main_level);
|
||||||
goto not_negotiated;
|
goto not_negotiated;
|
||||||
}
|
}
|
||||||
if (main_level >= 6) {
|
if (main_level >= 6) {
|
||||||
|
@ -618,10 +619,12 @@ gst_base_ts_mux_create_stream (GstBaseTsMux * mux, GstBaseTsMuxPad * ts_pad)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/*GST_ERROR_OBJECT (pad, "Missing main level");
|
/* GST_ERROR_OBJECT (ts_pad, "Missing main level");
|
||||||
goto not_negotiated; */
|
* goto not_negotiated; */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We always mux video in J2K-over-MPEG-TS non-interlaced mode */
|
/* We always mux video in J2K-over-MPEG-TS non-interlaced mode */
|
||||||
|
private_data = g_new0 (j2k_private_data, 1);
|
||||||
private_data->interlace = FALSE;
|
private_data->interlace = FALSE;
|
||||||
private_data->den = 0;
|
private_data->den = 0;
|
||||||
private_data->num = 0;
|
private_data->num = 0;
|
||||||
|
@ -651,7 +654,8 @@ gst_base_ts_mux_create_stream (GstBaseTsMux * mux, GstBaseTsMuxPad * ts_pad)
|
||||||
}
|
}
|
||||||
private_data->color_spec = color_spec;
|
private_data->color_spec = color_spec;
|
||||||
} else {
|
} else {
|
||||||
GST_ERROR_OBJECT (pad, "Colorimetry not present in caps");
|
GST_ERROR_OBJECT (ts_pad, "Colorimetry not present in caps");
|
||||||
|
g_free (private_data);
|
||||||
goto not_negotiated;
|
goto not_negotiated;
|
||||||
}
|
}
|
||||||
st = TSMUX_ST_VIDEO_JP2K;
|
st = TSMUX_ST_VIDEO_JP2K;
|
||||||
|
@ -666,56 +670,56 @@ gst_base_ts_mux_create_stream (GstBaseTsMux * mux, GstBaseTsMuxPad * ts_pad)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (st == TSMUX_ST_RESERVED) {
|
||||||
if (st != TSMUX_ST_RESERVED) {
|
GST_ERROR_OBJECT (ts_pad, "Failed to determine stream type");
|
||||||
ts_pad->stream = tsmux_create_stream (mux->tsmux, st, ts_pad->pid,
|
goto error;
|
||||||
ts_pad->language);
|
|
||||||
} else {
|
|
||||||
GST_DEBUG_OBJECT (pad, "Failed to determine stream type");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ts_pad->stream != NULL) {
|
ts_pad->stream =
|
||||||
const char *interlace_mode = gst_structure_get_string (s, "interlace-mode");
|
tsmux_create_stream (mux->tsmux, st, ts_pad->pid, ts_pad->language);
|
||||||
gst_structure_get_int (s, "rate", &ts_pad->stream->audio_sampling);
|
if (ts_pad->stream == NULL)
|
||||||
gst_structure_get_int (s, "channels", &ts_pad->stream->audio_channels);
|
goto error;
|
||||||
gst_structure_get_int (s, "bitrate", &ts_pad->stream->audio_bitrate);
|
|
||||||
|
|
||||||
/* frame rate */
|
interlace_mode = gst_structure_get_string (s, "interlace-mode");
|
||||||
gst_structure_get_fraction (s, "framerate", &ts_pad->stream->num,
|
gst_structure_get_int (s, "rate", &ts_pad->stream->audio_sampling);
|
||||||
&ts_pad->stream->den);
|
gst_structure_get_int (s, "channels", &ts_pad->stream->audio_channels);
|
||||||
|
gst_structure_get_int (s, "bitrate", &ts_pad->stream->audio_bitrate);
|
||||||
|
|
||||||
/* Interlace mode */
|
/* frame rate */
|
||||||
ts_pad->stream->interlace_mode = FALSE;
|
gst_structure_get_fraction (s, "framerate", &ts_pad->stream->num,
|
||||||
if (interlace_mode) {
|
&ts_pad->stream->den);
|
||||||
ts_pad->stream->interlace_mode =
|
|
||||||
g_str_equal (interlace_mode, "interleaved");
|
|
||||||
}
|
|
||||||
/* Width and Height */
|
|
||||||
gst_structure_get_int (s, "width", &ts_pad->stream->horizontal_size);
|
|
||||||
gst_structure_get_int (s, "height", &ts_pad->stream->vertical_size);
|
|
||||||
|
|
||||||
ts_pad->stream->color_spec = color_spec;
|
/* Interlace mode */
|
||||||
ts_pad->stream->max_bitrate = max_rate;
|
ts_pad->stream->interlace_mode = FALSE;
|
||||||
ts_pad->stream->profile_and_level = profile | main_level;
|
if (interlace_mode) {
|
||||||
|
ts_pad->stream->interlace_mode =
|
||||||
ts_pad->stream->opus_channel_config_code = opus_channel_config_code;
|
g_str_equal (interlace_mode, "interleaved");
|
||||||
|
|
||||||
tsmux_stream_set_buffer_release_func (ts_pad->stream, release_buffer_cb);
|
|
||||||
tsmux_program_add_stream (ts_pad->prog, ts_pad->stream);
|
|
||||||
|
|
||||||
ret = GST_FLOW_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Width and Height */
|
||||||
|
gst_structure_get_int (s, "width", &ts_pad->stream->horizontal_size);
|
||||||
|
gst_structure_get_int (s, "height", &ts_pad->stream->vertical_size);
|
||||||
|
|
||||||
|
ts_pad->stream->color_spec = color_spec;
|
||||||
|
ts_pad->stream->max_bitrate = max_rate;
|
||||||
|
ts_pad->stream->profile_and_level = profile | main_level;
|
||||||
|
|
||||||
|
ts_pad->stream->opus_channel_config_code = opus_channel_config_code;
|
||||||
|
|
||||||
|
tsmux_stream_set_buffer_release_func (ts_pad->stream, release_buffer_cb);
|
||||||
|
tsmux_program_add_stream (ts_pad->prog, ts_pad->stream);
|
||||||
|
|
||||||
gst_caps_unref (caps);
|
gst_caps_unref (caps);
|
||||||
return ret;
|
return GST_FLOW_OK;
|
||||||
|
|
||||||
/* ERRORS */
|
/* ERRORS */
|
||||||
not_negotiated:
|
not_negotiated:
|
||||||
{
|
gst_caps_unref (caps);
|
||||||
g_free (private_data);
|
return GST_FLOW_NOT_NEGOTIATED;
|
||||||
GST_DEBUG_OBJECT (pad, "Sink pad caps were not set before pushing");
|
|
||||||
if (caps)
|
error:
|
||||||
gst_caps_unref (caps);
|
gst_caps_unref (caps);
|
||||||
return GST_FLOW_NOT_NEGOTIATED;
|
return GST_FLOW_ERROR;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
|
Loading…
Reference in a new issue