tsdemux: refactor pad creation

Avoid repeating the same pad creation code everywhere
This commit is contained in:
Thiago Santos 2015-06-04 13:36:32 -03:00
parent 2b207c0b65
commit b4c9aa1c30

View file

@ -1045,6 +1045,8 @@ create_pad_for_stream (MpegTSBase * base, MpegTSBaseStream * bstream,
const GstMpegtsDescriptor *desc = NULL;
GstPad *pad = NULL;
gboolean sparse = FALSE;
gboolean is_audio = FALSE, is_video = FALSE, is_subpicture = FALSE,
is_private = FALSE;
gst_ts_demux_create_tags (stream);
@ -1065,49 +1067,43 @@ create_pad_for_stream (MpegTSBase * base, MpegTSBaseStream * bstream,
GST_MTS_DESC_AC3_AUDIO_STREAM);
if (ac3_desc && DESC_AC_AUDIO_STREAM_bsid (ac3_desc->data) != 16) {
GST_LOG ("ac3 audio");
template = gst_static_pad_template_get (&audio_template);
name = g_strdup_printf ("audio_%04x", bstream->pid);
is_audio = TRUE;
caps = gst_caps_new_empty_simple ("audio/x-ac3");
} else {
template = gst_static_pad_template_get (&audio_template);
name = g_strdup_printf ("audio_%04x", bstream->pid);
is_audio = TRUE;
caps = gst_caps_new_empty_simple ("audio/x-eac3");
}
break;
}
case ST_BD_AUDIO_EAC3:
case ST_BD_AUDIO_AC3_PLUS:
template = gst_static_pad_template_get (&audio_template);
name = g_strdup_printf ("audio_%04x", bstream->pid);
is_audio = TRUE;
caps = gst_caps_new_empty_simple ("audio/x-eac3");
break;
case ST_BD_AUDIO_AC3_TRUE_HD:
template = gst_static_pad_template_get (&audio_template);
name = g_strdup_printf ("audio_%04x", bstream->pid);
is_audio = TRUE;
caps = gst_caps_new_empty_simple ("audio/x-true-hd");
stream->target_pes_substream = 0x72;
break;
case ST_BD_AUDIO_LPCM:
template = gst_static_pad_template_get (&audio_template);
name = g_strdup_printf ("audio_%04x", bstream->pid);
is_audio = TRUE;
caps = gst_caps_new_empty_simple ("audio/x-private-ts-lpcm");
break;
case ST_BD_PGS_SUBPICTURE:
template = gst_static_pad_template_get (&subpicture_template);
name = g_strdup_printf ("subpicture_%04x", bstream->pid);
is_subpicture = TRUE;
caps = gst_caps_new_empty_simple ("subpicture/x-pgs");
sparse = TRUE;
break;
case ST_BD_AUDIO_DTS_HD:
case ST_BD_AUDIO_DTS_HD_MASTER_AUDIO:
template = gst_static_pad_template_get (&audio_template);
name = g_strdup_printf ("audio_%04x", bstream->pid);
is_audio = TRUE;
caps = gst_caps_new_empty_simple ("audio/x-dts");
stream->target_pes_substream = 0x71;
break;
}
}
if (template && name && caps)
if (caps)
goto done;
/* Handle non-BluRay stream types */
@ -1122,8 +1118,7 @@ create_pad_for_stream (MpegTSBase * base, MpegTSBaseStream * bstream,
* * profile_and_level
*/
GST_LOG ("mpeg video");
template = gst_static_pad_template_get (&video_template);
name = g_strdup_printf ("video_%04x", bstream->pid);
is_video = TRUE;
caps = gst_caps_new_simple ("video/mpeg",
"mpegversion", G_TYPE_INT,
bstream->stream_type == GST_MPEGTS_STREAM_TYPE_VIDEO_MPEG1 ? 1 : 2,
@ -1133,8 +1128,7 @@ create_pad_for_stream (MpegTSBase * base, MpegTSBaseStream * bstream,
case GST_MPEGTS_STREAM_TYPE_AUDIO_MPEG1:
case GST_MPEGTS_STREAM_TYPE_AUDIO_MPEG2:
GST_LOG ("mpeg audio");
template = gst_static_pad_template_get (&audio_template);
name = g_strdup_printf ("audio_%04x", bstream->pid);
is_audio = TRUE;
caps =
gst_caps_new_simple ("audio/mpeg", "mpegversion", G_TYPE_INT, 1,
NULL);
@ -1150,8 +1144,7 @@ create_pad_for_stream (MpegTSBase * base, MpegTSBaseStream * bstream,
desc = mpegts_get_descriptor_from_stream (bstream, GST_MTS_DESC_DVB_AC3);
if (desc) {
GST_LOG ("ac3 audio");
template = gst_static_pad_template_get (&audio_template);
name = g_strdup_printf ("audio_%04x", bstream->pid);
is_audio = TRUE;
caps = gst_caps_new_empty_simple ("audio/x-ac3");
break;
}
@ -1161,8 +1154,7 @@ create_pad_for_stream (MpegTSBase * base, MpegTSBaseStream * bstream,
GST_MTS_DESC_DVB_ENHANCED_AC3);
if (desc) {
GST_LOG ("ac3 audio");
template = gst_static_pad_template_get (&audio_template);
name = g_strdup_printf ("audio_%04x", bstream->pid);
is_audio = TRUE;
caps = gst_caps_new_empty_simple ("audio/x-eac3");
break;
}
@ -1171,8 +1163,7 @@ create_pad_for_stream (MpegTSBase * base, MpegTSBaseStream * bstream,
GST_MTS_DESC_DVB_TELETEXT);
if (desc) {
GST_LOG ("teletext");
template = gst_static_pad_template_get (&private_template);
name = g_strdup_printf ("private_%04x", bstream->pid);
is_private = TRUE;
caps = gst_caps_new_empty_simple ("application/x-teletext");
sparse = TRUE;
break;
@ -1182,8 +1173,7 @@ create_pad_for_stream (MpegTSBase * base, MpegTSBaseStream * bstream,
GST_MTS_DESC_DVB_SUBTITLING);
if (desc) {
GST_LOG ("subtitling");
template = gst_static_pad_template_get (&private_template);
name = g_strdup_printf ("private_%04x", bstream->pid);
is_private = TRUE;
caps = gst_caps_new_empty_simple ("subpicture/x-dvb");
sparse = TRUE;
break;
@ -1194,18 +1184,15 @@ create_pad_for_stream (MpegTSBase * base, MpegTSBaseStream * bstream,
case DRF_ID_DTS2:
case DRF_ID_DTS3:
/* SMPTE registered DTS */
template = gst_static_pad_template_get (&private_template);
name = g_strdup_printf ("private_%04x", bstream->pid);
is_private = TRUE;
caps = gst_caps_new_empty_simple ("audio/x-dts");
break;
case DRF_ID_S302M:
template = gst_static_pad_template_get (&audio_template);
name = g_strdup_printf ("audio_%04x", bstream->pid);
is_audio = TRUE;
caps = gst_caps_new_empty_simple ("audio/x-smpte-302m");
break;
case DRF_ID_HEVC:
template = gst_static_pad_template_get (&video_template);
name = g_strdup_printf ("video_%04x", bstream->pid);
is_video = TRUE;
caps = gst_caps_new_simple ("video/x-h265",
"stream-format", G_TYPE_STRING, "byte-stream",
"alignment", G_TYPE_STRING, "nal", NULL);
@ -1216,8 +1203,7 @@ create_pad_for_stream (MpegTSBase * base, MpegTSBaseStream * bstream,
/* hack for itv hd (sid 10510, video pid 3401 */
if (program->program_number == 10510 && bstream->pid == 3401) {
template = gst_static_pad_template_get (&video_template);
name = g_strdup_printf ("video_%04x", bstream->pid);
is_video = TRUE;
caps = gst_caps_new_simple ("video/x-h264",
"stream-format", G_TYPE_STRING, "byte-stream",
"alignment", G_TYPE_STRING, "nal", NULL);
@ -1238,36 +1224,31 @@ create_pad_for_stream (MpegTSBase * base, MpegTSBaseStream * bstream,
/* caps = gst_caps_new_simple ("hdv/aux-a", NULL); */
break;
case GST_MPEGTS_STREAM_TYPE_AUDIO_AAC_ADTS:
template = gst_static_pad_template_get (&audio_template);
name = g_strdup_printf ("audio_%04x", bstream->pid);
is_audio = TRUE;
caps = gst_caps_new_simple ("audio/mpeg",
"mpegversion", G_TYPE_INT, 2,
"stream-format", G_TYPE_STRING, "adts", NULL);
break;
case GST_MPEGTS_STREAM_TYPE_AUDIO_AAC_LATM:
template = gst_static_pad_template_get (&audio_template);
name = g_strdup_printf ("audio_%04x", bstream->pid);
is_audio = TRUE;
caps = gst_caps_new_simple ("audio/mpeg",
"mpegversion", G_TYPE_INT, 4,
"stream-format", G_TYPE_STRING, "loas", NULL);
break;
case GST_MPEGTS_STREAM_TYPE_VIDEO_MPEG4:
template = gst_static_pad_template_get (&video_template);
name = g_strdup_printf ("video_%04x", bstream->pid);
is_video = TRUE;
caps = gst_caps_new_simple ("video/mpeg",
"mpegversion", G_TYPE_INT, 4,
"systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
break;
case GST_MPEGTS_STREAM_TYPE_VIDEO_H264:
template = gst_static_pad_template_get (&video_template);
name = g_strdup_printf ("video_%04x", bstream->pid);
is_video = TRUE;
caps = gst_caps_new_simple ("video/x-h264",
"stream-format", G_TYPE_STRING, "byte-stream",
"alignment", G_TYPE_STRING, "nal", NULL);
break;
case GST_MPEGTS_STREAM_TYPE_VIDEO_HEVC:
template = gst_static_pad_template_get (&video_template);
name = g_strdup_printf ("video_%04x", bstream->pid);
is_video = TRUE;
caps = gst_caps_new_simple ("video/x-h265",
"stream-format", G_TYPE_STRING, "byte-stream",
"alignment", G_TYPE_STRING, "nal", NULL);
@ -1276,8 +1257,7 @@ create_pad_for_stream (MpegTSBase * base, MpegTSBaseStream * bstream,
if (bstream->registration_id == 0x64726163) {
GST_LOG ("dirac");
/* dirac in hex */
template = gst_static_pad_template_get (&video_template);
name = g_strdup_printf ("video_%04x", bstream->pid);
is_video = TRUE;
caps = gst_caps_new_empty_simple ("video/x-dirac");
}
break;
@ -1295,8 +1275,7 @@ create_pad_for_stream (MpegTSBase * base, MpegTSBaseStream * bstream,
"for VC1. Assuming plain VC1.");
}
template = gst_static_pad_template_get (&video_template);
name = g_strdup_printf ("video_%04x", bstream->pid);
is_video = TRUE;
caps = gst_caps_new_simple ("video/x-wmv",
"wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WVC1", NULL);
@ -1308,8 +1287,7 @@ create_pad_for_stream (MpegTSBase * base, MpegTSBaseStream * bstream,
mpegts_get_descriptor_from_stream (bstream,
GST_MTS_DESC_DVB_ENHANCED_AC3);
if (desc) {
template = gst_static_pad_template_get (&audio_template);
name = g_strdup_printf ("audio_%04x", bstream->pid);
is_audio = TRUE;
caps = gst_caps_new_empty_simple ("audio/x-eac3");
break;
}
@ -1321,8 +1299,7 @@ create_pad_for_stream (MpegTSBase * base, MpegTSBaseStream * bstream,
if (bstream->registration_id == DRF_ID_AC3 ||
program->registration_id == DRF_ID_GA94 ||
mpegts_get_descriptor_from_stream (bstream, GST_MTS_DESC_DVB_AC3)) {
template = gst_static_pad_template_get (&audio_template);
name = g_strdup_printf ("audio_%04x", bstream->pid);
is_audio = TRUE;
caps = gst_caps_new_empty_simple ("audio/x-ac3");
break;
}
@ -1330,31 +1307,26 @@ create_pad_for_stream (MpegTSBase * base, MpegTSBaseStream * bstream,
GST_WARNING ("AC3 stream type found but no guaranteed "
"way found to differentiate between AC3 and EAC3. "
"Assuming plain AC3.");
template = gst_static_pad_template_get (&audio_template);
name = g_strdup_printf ("audio_%04x", bstream->pid);
is_audio = TRUE;
caps = gst_caps_new_empty_simple ("audio/x-ac3");
break;
case ST_PS_AUDIO_DTS:
template = gst_static_pad_template_get (&audio_template);
name = g_strdup_printf ("audio_%04x", bstream->pid);
is_audio = TRUE;
caps = gst_caps_new_empty_simple ("audio/x-dts");
break;
case ST_PS_AUDIO_LPCM:
template = gst_static_pad_template_get (&audio_template);
name = g_strdup_printf ("audio_%04x", bstream->pid);
is_audio = TRUE;
caps = gst_caps_new_empty_simple ("audio/x-lpcm");
break;
case ST_PS_DVD_SUBPICTURE:
template = gst_static_pad_template_get (&subpicture_template);
name = g_strdup_printf ("subpicture_%04x", bstream->pid);
is_subpicture = TRUE;
caps = gst_caps_new_empty_simple ("subpicture/x-dvd");
sparse = TRUE;
break;
case 0x42:
/* hack for Chinese AVS video stream which use 0x42 as stream_id
* NOTE: this is unofficial and within the ISO reserved range. */
template = gst_static_pad_template_get (&video_template);
name = g_strdup_printf ("video_%04x", bstream->pid);
is_video = TRUE;
caps = gst_caps_new_empty_simple ("video/x-cavs");
break;
default:
@ -1364,6 +1336,24 @@ create_pad_for_stream (MpegTSBase * base, MpegTSBaseStream * bstream,
}
done:
if (caps) {
if (is_audio) {
template = gst_static_pad_template_get (&audio_template);
name = g_strdup_printf ("audio_%04x", bstream->pid);
} else if (is_video) {
template = gst_static_pad_template_get (&video_template);
name = g_strdup_printf ("video_%04x", bstream->pid);
} else if (is_private) {
template = gst_static_pad_template_get (&private_template);
name = g_strdup_printf ("private_%04x", bstream->pid);
} else if (is_subpicture) {
template = gst_static_pad_template_get (&subpicture_template);
name = g_strdup_printf ("subpicture_%04x", bstream->pid);
} else
g_assert_not_reached ();
}
if (template && name && caps) {
GstEvent *event;
gchar *stream_id;