summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Sauer <ensonic@users.sf.net>2013-10-02 11:27:41 +0200
committerStefan Sauer <ensonic@users.sf.net>2013-10-02 22:26:39 +0200
commit20cdbc83f3cebc2eba1eaf79445a6bda13fdafac (patch)
treeab9b6de9aebc2e9b53856dd6ea9732e19a51ae1b
parentdd4fe544bcafcf0f00660811d6c5d2b68b69ca25 (diff)
discoverer: extract some common code
Extract code to make a GstDiscovererInfo. Extracts code that sets StreamInfo.
-rw-r--r--gst-libs/gst/pbutils/gstdiscoverer.c118
1 files changed, 42 insertions, 76 deletions
diff --git a/gst-libs/gst/pbutils/gstdiscoverer.c b/gst-libs/gst/pbutils/gstdiscoverer.c
index 5229b041f..73baa8eb1 100644
--- a/gst-libs/gst/pbutils/gstdiscoverer.c
+++ b/gst-libs/gst/pbutils/gstdiscoverer.c
@@ -762,6 +762,35 @@ gst_discoverer_merge_and_replace_tags (GstTagList ** taglist,
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
* structure (parent, if !NULL, otherwise it allocates one)
*/
@@ -772,19 +801,13 @@ collect_information (GstDiscoverer * dc, const GstStructure * st,
GstCaps *caps;
GstStructure *caps_st;
GstTagList *tags_st;
- GstToc *toc_st;
const gchar *name;
- gchar *stream_id;
int tmp;
guint utmp;
if (!st || !gst_structure_id_has_field (st, _CAPS_QUARK)) {
GST_WARNING ("Couldn't find caps !");
- if (parent)
- return gst_discoverer_stream_info_ref (parent);
- else
- return (GstDiscovererStreamInfo *)
- g_object_new (GST_TYPE_DISCOVERER_STREAM_INFO, NULL);
+ return make_info (parent, GST_TYPE_DISCOVERER_STREAM_INFO, 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;
const gchar *format_str;
- if (parent)
- info = (GstDiscovererAudioInfo *) gst_discoverer_stream_info_ref (parent);
- else {
- info = (GstDiscovererAudioInfo *)
- g_object_new (GST_TYPE_DISCOVERER_AUDIO_INFO, NULL);
- info->parent.caps = gst_caps_ref (caps);
- }
+ info = (GstDiscovererAudioInfo *) make_info (parent,
+ GST_TYPE_DISCOVERER_AUDIO_INFO, caps);
if (gst_structure_get_int (caps_st, "rate", &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);
}
- if (gst_structure_id_has_field (st, _TOC_QUARK)) {
- 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;
- }
+ collect_common_information (&info->parent, st);
if (!info->language && ((GstDiscovererStreamInfo *) info)->tags) {
gchar *language;
@@ -861,13 +870,8 @@ collect_information (GstDiscoverer * dc, const GstStructure * st,
GstDiscovererVideoInfo *info;
GstVideoInfo vinfo;
- if (parent)
- info = (GstDiscovererVideoInfo *) gst_discoverer_stream_info_ref (parent);
- else {
- info = (GstDiscovererVideoInfo *)
- g_object_new (GST_TYPE_DISCOVERER_VIDEO_INFO, NULL);
- info->parent.caps = gst_caps_ref (caps);
- }
+ info = (GstDiscovererVideoInfo *) make_info (parent,
+ GST_TYPE_DISCOVERER_VIDEO_INFO, caps);
if (gst_video_info_from_caps (&vinfo, caps)) {
info->width = (guint) vinfo.width;
@@ -895,20 +899,10 @@ collect_information (GstDiscoverer * dc, const GstStructure * st,
info->max_bitrate = utmp;
/* FIXME: Is it worth it to remove the tags we've parsed? */
- gst_discoverer_merge_and_replace_tags (&info->parent.tags,
- (GstTagList *) tags_st);
- }
-
- if (gst_structure_id_has_field (st, _TOC_QUARK)) {
- gst_structure_id_get (st, _TOC_QUARK, GST_TYPE_TOC, &toc_st, NULL);
- info->parent.toc = toc_st;
+ gst_discoverer_merge_and_replace_tags (&info->parent.tags, tags_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;
- }
+ collect_common_information (&info->parent, st);
gst_caps_unref (caps);
return (GstDiscovererStreamInfo *) info;
@@ -916,14 +910,8 @@ collect_information (GstDiscoverer * dc, const GstStructure * st,
} else if (is_subtitle_caps (caps)) {
GstDiscovererSubtitleInfo *info;
- if (parent)
- info =
- (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);
- }
+ info = (GstDiscovererSubtitleInfo *) make_info (parent,
+ GST_TYPE_DISCOVERER_SUBTITLE_INFO, caps);
if (gst_structure_id_has_field (st, _TAGS_QUARK)) {
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);
}
- if (gst_structure_id_has_field (st, _TOC_QUARK)) {
- 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;
- }
+ collect_common_information (&info->parent, st);
if (!info->language && ((GstDiscovererStreamInfo *) info)->tags) {
gchar *language;
@@ -964,27 +943,14 @@ collect_information (GstDiscoverer * dc, const GstStructure * st,
/* None of the above - populate what information we can */
GstDiscovererStreamInfo *info;
- if (parent)
- 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);
- }
+ info = make_info (parent, GST_TYPE_DISCOVERER_STREAM_INFO, caps);
if (gst_structure_id_get (st, _TAGS_QUARK, GST_TYPE_TAG_LIST, &tags_st,
NULL)) {
gst_discoverer_merge_and_replace_tags (&info->tags, tags_st);
}
- if (gst_structure_id_get (st, _TOC_QUARK, GST_TYPE_TOC, &toc_st, NULL)) {
- info->toc = toc_st;
- }
-
- if (gst_structure_id_get (st, _STREAM_ID_QUARK, G_TYPE_STRING, &stream_id,
- NULL)) {
- info->stream_id = stream_id;
- }
+ collect_common_information (info, st);
gst_caps_unref (caps);
return info;