Debian Codegraph @

gstreamer/src/taglist.ccg

raw
1 /* gstreamermm - a C++ wrapper for gstreamer
2 *
3 * Copyright 2008 The gstreamermm Development Team
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include <gst/gst.h>
21
22 namespace
23 {
24
25 extern "C"
26 {
27
28 static void TagList_foreach_gstreamermm_callback(const GstTagList*, const char *tag, void* data)
29 {
30 Gst::TagList::SlotForeach& slot_foreach = *static_cast<Gst::TagList::SlotForeach*>(data);
31
32 try
33 {
34 slot_foreach(Glib::convert_const_gchar_ptr_to_ustring(tag));
35 }
36 catch (...)
37 {
38 Glib::exception_handlers_invoke();
39 }
40 }
41
42 } // extern "C"
43
44 } // anonymous namespace
45
46 namespace Gst
47 {
48
49 // Make sure the order here is the same order as in Gst::Tag.
50 static const char* const _tag_strings[] =
51 {
52 GST_TAG_TITLE,
53 GST_TAG_TITLE_SORTNAME,
54 GST_TAG_ARTIST,
55 GST_TAG_ARTIST_SORTNAME,
56 GST_TAG_ALBUM,
57 GST_TAG_ALBUM_SORTNAME,
58 GST_TAG_DATE,
59 GST_TAG_GENRE,
60 GST_TAG_COMMENT,
61 GST_TAG_EXTENDED_COMMENT,
62 GST_TAG_TRACK_NUMBER,
63 GST_TAG_TRACK_COUNT,
64 GST_TAG_ALBUM_VOLUME_NUMBER,
65 GST_TAG_ALBUM_VOLUME_COUNT,
66 GST_TAG_LOCATION,
67 GST_TAG_DESCRIPTION,
68 GST_TAG_VERSION,
69 GST_TAG_ISRC,
70 GST_TAG_ORGANIZATION,
71 GST_TAG_COPYRIGHT,
72 GST_TAG_COPYRIGHT_URI,
73 GST_TAG_COMPOSER,
74 GST_TAG_CONTACT,
75 GST_TAG_LICENSE,
76 GST_TAG_LICENSE_URI,
77 GST_TAG_PERFORMER,
78 GST_TAG_DURATION,
79 GST_TAG_CODEC,
80 GST_TAG_VIDEO_CODEC,
81 GST_TAG_AUDIO_CODEC,
82 GST_TAG_BITRATE,
83 GST_TAG_NOMINAL_BITRATE,
84 GST_TAG_MINIMUM_BITRATE,
85 GST_TAG_MAXIMUM_BITRATE,
86 GST_TAG_SERIAL,
87 GST_TAG_ENCODER,
88 GST_TAG_ENCODER_VERSION,
89 GST_TAG_TRACK_GAIN,
90 GST_TAG_TRACK_PEAK,
91 GST_TAG_ALBUM_GAIN,
92 GST_TAG_ALBUM_PEAK,
93 GST_TAG_REFERENCE_LEVEL,
94 GST_TAG_LANGUAGE_CODE,
95 GST_TAG_IMAGE,
96 GST_TAG_PREVIEW_IMAGE,
97 GST_TAG_ATTACHMENT,
98 GST_TAG_BEATS_PER_MINUTE,
99 GST_TAG_KEYWORDS,
100 GST_TAG_GEO_LOCATION_NAME,
101 GST_TAG_GEO_LOCATION_LATITUDE,
102 GST_TAG_GEO_LOCATION_LONGITUDE,
103 GST_TAG_GEO_LOCATION_ELEVATION
104 };
105
106 const char* gstreamermm_get_stock_tag(Tag tag)
107 {
108 return _tag_strings[tag];
109 }
110
111 TagList::operator bool() const
112 {
113 return gobject_ != nullptr;
114 }
115
116 std::ostream& operator<<(std::ostream& stream, Tag tag)
117 {
118 stream << _tag_strings[tag];
119 return stream;
120 }
121
122 void TagList::add_value(Tag tag, const Glib::ValueBase& value, TagMergeMode mode)
123 {
124 add_value(_tag_strings[tag], value, mode);
125 }
126
127 void TagList::add_value(const Glib::ustring& tag, const Glib::ValueBase& value, TagMergeMode mode)
128 {
129 gst_tag_list_add_value(gobj(), static_cast<GstTagMergeMode>(mode),
130 tag.c_str(), value.gobj());
131 }
132
133 void TagList::add(Tag tag, const char* data, TagMergeMode mode)
134 {
135 add(_tag_strings[tag], data, mode);
136 }
137
138 void TagList::add(const Glib::ustring& tag, const char* data, TagMergeMode mode)
139 {
140 gst_tag_list_add(gobj(), static_cast<GstTagMergeMode>(mode), tag.c_str(), data,
141 static_cast<void*>(0));
142 }
143
144 void TagList::add(Tag tag, const Glib::Date& date, TagMergeMode mode)
145 {
146 add(_tag_strings[tag], date, mode);
147 }
148
149 void TagList::add(const Glib::ustring& tag, const Glib::Date& date, TagMergeMode mode)
150 {
151 gst_tag_list_add(gobj(), static_cast<GstTagMergeMode>(mode), tag.c_str(), date.gobj(), nullptr);
152 }
153
154 void TagList::foreach(const SlotForeach& slot)
155 {
156 gst_tag_list_foreach(gobj(), &TagList_foreach_gstreamermm_callback,
157 const_cast<SlotForeach*>(&slot));
158 }
159
160 bool TagList::get_value(Tag tag, Glib::ValueBase& dest) const
161 {
162 return get_value(_tag_strings[tag], dest);
163 }
164
165 bool TagList::get_value(const Glib::ustring& tag, Glib::ValueBase& dest) const
166 {
167 GValue gst_value = G_VALUE_INIT;
168 if(gst_tag_list_copy_value(&gst_value, const_cast<GstTagList*>(gobj()), tag.c_str()))
169 {
170 g_value_copy(&gst_value, dest.gobj());
171 g_value_unset(&gst_value);
172 return true;
173 }
174 return false;
175 }
176
177 bool TagList::get_value(Tag tag, guint index, Glib::ValueBase& value) const
178 {
179 return get_value(_tag_strings[tag], index, value);
180 }
181
182 bool TagList::get_value(const Glib::ustring& tag, guint index, Glib::ValueBase& value) const
183 {
184 const GValue* gst_value =
185 gst_tag_list_get_value_index(const_cast<GstTagList*>(gobj()),
186 tag.c_str(), index);
187
188 if(gst_value)
189 {
190 g_value_copy(gst_value, value.gobj());
191 return true;
192 }
193
194 return false;
195 }
196
197 } // namespace Gst