mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-04 05:22:30 +00:00
discoverer: extract some common code
Extract code to make a GstDiscovererInfo. Extracts code that sets StreamInfo.
This commit is contained in:
parent
dd4fe544bc
commit
20cdbc83f3
1 changed files with 42 additions and 76 deletions
|
@ -762,6 +762,35 @@ gst_discoverer_merge_and_replace_tags (GstTagList ** taglist,
|
||||||
gst_tag_list_unref (new_tags);
|
gst_tag_list_unref (new_tags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
collect_common_information (GstDiscovererStreamInfo * info,
|
||||||
|
const GstStructure * st)
|
||||||
|
{
|
||||||
|
if (gst_structure_id_has_field (st, _TOC_QUARK)) {
|
||||||
|
gst_structure_id_get (st, _TOC_QUARK, GST_TYPE_TOC, &info->toc, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gst_structure_id_has_field (st, _STREAM_ID_QUARK)) {
|
||||||
|
gst_structure_id_get (st, _STREAM_ID_QUARK, G_TYPE_STRING, &info->stream_id,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static GstDiscovererStreamInfo *
|
||||||
|
make_info (GstDiscovererStreamInfo * parent, GType type, GstCaps * caps)
|
||||||
|
{
|
||||||
|
GstDiscovererStreamInfo *info;
|
||||||
|
|
||||||
|
if (parent)
|
||||||
|
info = gst_discoverer_stream_info_ref (parent);
|
||||||
|
else {
|
||||||
|
info = g_object_new (type, NULL);
|
||||||
|
if (caps)
|
||||||
|
info->caps = gst_caps_ref (caps);
|
||||||
|
}
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
/* Parses a set of caps and tags in st and populates a GstDiscovererStreamInfo
|
/* Parses a set of caps and tags in st and populates a GstDiscovererStreamInfo
|
||||||
* structure (parent, if !NULL, otherwise it allocates one)
|
* structure (parent, if !NULL, otherwise it allocates one)
|
||||||
*/
|
*/
|
||||||
|
@ -772,19 +801,13 @@ collect_information (GstDiscoverer * dc, const GstStructure * st,
|
||||||
GstCaps *caps;
|
GstCaps *caps;
|
||||||
GstStructure *caps_st;
|
GstStructure *caps_st;
|
||||||
GstTagList *tags_st;
|
GstTagList *tags_st;
|
||||||
GstToc *toc_st;
|
|
||||||
const gchar *name;
|
const gchar *name;
|
||||||
gchar *stream_id;
|
|
||||||
int tmp;
|
int tmp;
|
||||||
guint utmp;
|
guint utmp;
|
||||||
|
|
||||||
if (!st || !gst_structure_id_has_field (st, _CAPS_QUARK)) {
|
if (!st || !gst_structure_id_has_field (st, _CAPS_QUARK)) {
|
||||||
GST_WARNING ("Couldn't find caps !");
|
GST_WARNING ("Couldn't find caps !");
|
||||||
if (parent)
|
return make_info (parent, GST_TYPE_DISCOVERER_STREAM_INFO, NULL);
|
||||||
return gst_discoverer_stream_info_ref (parent);
|
|
||||||
else
|
|
||||||
return (GstDiscovererStreamInfo *)
|
|
||||||
g_object_new (GST_TYPE_DISCOVERER_STREAM_INFO, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_structure_id_get (st, _CAPS_QUARK, GST_TYPE_CAPS, &caps, NULL);
|
gst_structure_id_get (st, _CAPS_QUARK, GST_TYPE_CAPS, &caps, NULL);
|
||||||
|
@ -795,13 +818,8 @@ collect_information (GstDiscoverer * dc, const GstStructure * st,
|
||||||
GstDiscovererAudioInfo *info;
|
GstDiscovererAudioInfo *info;
|
||||||
const gchar *format_str;
|
const gchar *format_str;
|
||||||
|
|
||||||
if (parent)
|
info = (GstDiscovererAudioInfo *) make_info (parent,
|
||||||
info = (GstDiscovererAudioInfo *) gst_discoverer_stream_info_ref (parent);
|
GST_TYPE_DISCOVERER_AUDIO_INFO, caps);
|
||||||
else {
|
|
||||||
info = (GstDiscovererAudioInfo *)
|
|
||||||
g_object_new (GST_TYPE_DISCOVERER_AUDIO_INFO, NULL);
|
|
||||||
info->parent.caps = gst_caps_ref (caps);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gst_structure_get_int (caps_st, "rate", &tmp))
|
if (gst_structure_get_int (caps_st, "rate", &tmp))
|
||||||
info->sample_rate = (guint) tmp;
|
info->sample_rate = (guint) tmp;
|
||||||
|
@ -834,16 +852,7 @@ collect_information (GstDiscoverer * dc, const GstStructure * st,
|
||||||
gst_discoverer_merge_and_replace_tags (&info->parent.tags, tags_st);
|
gst_discoverer_merge_and_replace_tags (&info->parent.tags, tags_st);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gst_structure_id_has_field (st, _TOC_QUARK)) {
|
collect_common_information (&info->parent, st);
|
||||||
gst_structure_id_get (st, _TOC_QUARK, GST_TYPE_TOC, &toc_st, NULL);
|
|
||||||
info->parent.toc = toc_st;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gst_structure_id_has_field (st, _STREAM_ID_QUARK)) {
|
|
||||||
gst_structure_id_get (st, _STREAM_ID_QUARK, G_TYPE_STRING, &stream_id,
|
|
||||||
NULL);
|
|
||||||
info->parent.stream_id = stream_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!info->language && ((GstDiscovererStreamInfo *) info)->tags) {
|
if (!info->language && ((GstDiscovererStreamInfo *) info)->tags) {
|
||||||
gchar *language;
|
gchar *language;
|
||||||
|
@ -861,13 +870,8 @@ collect_information (GstDiscoverer * dc, const GstStructure * st,
|
||||||
GstDiscovererVideoInfo *info;
|
GstDiscovererVideoInfo *info;
|
||||||
GstVideoInfo vinfo;
|
GstVideoInfo vinfo;
|
||||||
|
|
||||||
if (parent)
|
info = (GstDiscovererVideoInfo *) make_info (parent,
|
||||||
info = (GstDiscovererVideoInfo *) gst_discoverer_stream_info_ref (parent);
|
GST_TYPE_DISCOVERER_VIDEO_INFO, caps);
|
||||||
else {
|
|
||||||
info = (GstDiscovererVideoInfo *)
|
|
||||||
g_object_new (GST_TYPE_DISCOVERER_VIDEO_INFO, NULL);
|
|
||||||
info->parent.caps = gst_caps_ref (caps);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gst_video_info_from_caps (&vinfo, caps)) {
|
if (gst_video_info_from_caps (&vinfo, caps)) {
|
||||||
info->width = (guint) vinfo.width;
|
info->width = (guint) vinfo.width;
|
||||||
|
@ -895,20 +899,10 @@ collect_information (GstDiscoverer * dc, const GstStructure * st,
|
||||||
info->max_bitrate = utmp;
|
info->max_bitrate = utmp;
|
||||||
|
|
||||||
/* FIXME: Is it worth it to remove the tags we've parsed? */
|
/* FIXME: Is it worth it to remove the tags we've parsed? */
|
||||||
gst_discoverer_merge_and_replace_tags (&info->parent.tags,
|
gst_discoverer_merge_and_replace_tags (&info->parent.tags, tags_st);
|
||||||
(GstTagList *) tags_st);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gst_structure_id_has_field (st, _TOC_QUARK)) {
|
collect_common_information (&info->parent, st);
|
||||||
gst_structure_id_get (st, _TOC_QUARK, GST_TYPE_TOC, &toc_st, NULL);
|
|
||||||
info->parent.toc = toc_st;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gst_structure_id_has_field (st, _STREAM_ID_QUARK)) {
|
|
||||||
gst_structure_id_get (st, _STREAM_ID_QUARK, G_TYPE_STRING, &stream_id,
|
|
||||||
NULL);
|
|
||||||
info->parent.stream_id = stream_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
gst_caps_unref (caps);
|
gst_caps_unref (caps);
|
||||||
return (GstDiscovererStreamInfo *) info;
|
return (GstDiscovererStreamInfo *) info;
|
||||||
|
@ -916,14 +910,8 @@ collect_information (GstDiscoverer * dc, const GstStructure * st,
|
||||||
} else if (is_subtitle_caps (caps)) {
|
} else if (is_subtitle_caps (caps)) {
|
||||||
GstDiscovererSubtitleInfo *info;
|
GstDiscovererSubtitleInfo *info;
|
||||||
|
|
||||||
if (parent)
|
info = (GstDiscovererSubtitleInfo *) make_info (parent,
|
||||||
info =
|
GST_TYPE_DISCOVERER_SUBTITLE_INFO, caps);
|
||||||
(GstDiscovererSubtitleInfo *) gst_discoverer_stream_info_ref (parent);
|
|
||||||
else {
|
|
||||||
info = (GstDiscovererSubtitleInfo *)
|
|
||||||
g_object_new (GST_TYPE_DISCOVERER_SUBTITLE_INFO, NULL);
|
|
||||||
info->parent.caps = gst_caps_ref (caps);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gst_structure_id_has_field (st, _TAGS_QUARK)) {
|
if (gst_structure_id_has_field (st, _TAGS_QUARK)) {
|
||||||
const gchar *language;
|
const gchar *language;
|
||||||
|
@ -938,16 +926,7 @@ collect_information (GstDiscoverer * dc, const GstStructure * st,
|
||||||
gst_discoverer_merge_and_replace_tags (&info->parent.tags, tags_st);
|
gst_discoverer_merge_and_replace_tags (&info->parent.tags, tags_st);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gst_structure_id_has_field (st, _TOC_QUARK)) {
|
collect_common_information (&info->parent, st);
|
||||||
gst_structure_id_get (st, _TOC_QUARK, GST_TYPE_TOC, &toc_st, NULL);
|
|
||||||
info->parent.toc = toc_st;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gst_structure_id_has_field (st, _STREAM_ID_QUARK)) {
|
|
||||||
gst_structure_id_get (st, _STREAM_ID_QUARK, G_TYPE_STRING, &stream_id,
|
|
||||||
NULL);
|
|
||||||
info->parent.stream_id = stream_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!info->language && ((GstDiscovererStreamInfo *) info)->tags) {
|
if (!info->language && ((GstDiscovererStreamInfo *) info)->tags) {
|
||||||
gchar *language;
|
gchar *language;
|
||||||
|
@ -964,27 +943,14 @@ collect_information (GstDiscoverer * dc, const GstStructure * st,
|
||||||
/* None of the above - populate what information we can */
|
/* None of the above - populate what information we can */
|
||||||
GstDiscovererStreamInfo *info;
|
GstDiscovererStreamInfo *info;
|
||||||
|
|
||||||
if (parent)
|
info = make_info (parent, GST_TYPE_DISCOVERER_STREAM_INFO, caps);
|
||||||
info = gst_discoverer_stream_info_ref (parent);
|
|
||||||
else {
|
|
||||||
info = (GstDiscovererStreamInfo *)
|
|
||||||
g_object_new (GST_TYPE_DISCOVERER_STREAM_INFO, NULL);
|
|
||||||
info->caps = gst_caps_ref (caps);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gst_structure_id_get (st, _TAGS_QUARK, GST_TYPE_TAG_LIST, &tags_st,
|
if (gst_structure_id_get (st, _TAGS_QUARK, GST_TYPE_TAG_LIST, &tags_st,
|
||||||
NULL)) {
|
NULL)) {
|
||||||
gst_discoverer_merge_and_replace_tags (&info->tags, tags_st);
|
gst_discoverer_merge_and_replace_tags (&info->tags, tags_st);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gst_structure_id_get (st, _TOC_QUARK, GST_TYPE_TOC, &toc_st, NULL)) {
|
collect_common_information (info, st);
|
||||||
info->toc = toc_st;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gst_structure_id_get (st, _STREAM_ID_QUARK, G_TYPE_STRING, &stream_id,
|
|
||||||
NULL)) {
|
|
||||||
info->stream_id = stream_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
gst_caps_unref (caps);
|
gst_caps_unref (caps);
|
||||||
return info;
|
return info;
|
||||||
|
|
Loading…
Reference in a new issue