| 1 |
/* gstreamermm - a C++ wrapper for gstreamer |
| 2 |
* |
| 3 |
* Copyright 2008-2016 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 |
#include <gst/gstvalue.h> |
| 22 |
#include <glibmm/value_custom.h> |
| 23 |
|
| 24 |
_DEFS(gstreamermm,gst) |
| 25 |
|
| 26 |
namespace Gst |
| 27 |
{ |
| 28 |
|
| 29 |
/** @defgroup GstHelperClasses gstreamermm Helper Classes |
| 30 |
* Classes used to represent GStreamer internal GValue types such as |
| 31 |
* GST_TYPE_FRACTION, etc. |
| 32 |
*/ |
| 33 |
|
| 34 |
/** A class that represents a 4 byte identifier (used in codecs). |
| 35 |
* Gst::Fourcc is used to store a four byte identifier in Gst::Structure of |
| 36 |
* Gst::Caps as a value representing a property (see GStreamer Application |
| 37 |
* Development Manual section 8.2.2 and GstValue docs). When the value is set, |
| 38 |
* it is transformed to a GStreamer GType so retrieving the value is a bit |
| 39 |
* different. The class can be used in setting and getting a Gst::Structure |
| 40 |
* field like so: |
| 41 |
* |
| 42 |
* @code |
| 43 |
* Glib::Value<Gst::Fourcc> value; |
| 44 |
* value.init(Glib::Value<Gst::Fourcc>::value_type()); |
| 45 |
* value.set(Gst::Fourcc('M', 'J', 'P', 'G')); |
| 46 |
* |
| 47 |
* Gst::Structure structure("my-structure"); |
| 48 |
* structure.set_field("id", value); |
| 49 |
* ... |
| 50 |
* Glib::ValueBase gst_value; |
| 51 |
* structure.get_field("id", gst_value); |
| 52 |
* Gst::Fourcc fourcc(gst_value); |
| 53 |
* char first_char = fourcc.first; |
| 54 |
* ... |
| 55 |
* @endcode |
| 56 |
* |
| 57 |
* Last reviewed on 2016-08-27 (1.8.0) |
| 58 |
* |
| 59 |
* @ingroup GstHelperClasses |
| 60 |
*/ |
| 61 |
class Fourcc |
| 62 |
{ |
| 63 |
public: |
| 64 |
/** Construct an undefined Gst::Fourcc. |
| 65 |
*/ |
| 66 |
Fourcc(); |
| 67 |
|
| 68 |
/** Construct a Gst::Fourcc from another. |
| 69 |
*/ |
| 70 |
Fourcc(const Fourcc& src); |
| 71 |
|
| 72 |
/** Construct a Gst::Fourcc from 4 characters. |
| 73 |
*/ |
| 74 |
Fourcc(char first, char second, char third, char fourth); |
| 75 |
|
| 76 |
/** Construct a Gst::Fourcc from an input string. Caller is responsible for |
| 77 |
* ensuring the input string consists of at least four characters. |
| 78 |
*/ |
| 79 |
explicit Fourcc(const Glib::ustring& s); |
| 80 |
|
| 81 |
/** Construct a Gst::Fourcc from a 32 bit unsigned integer. |
| 82 |
*/ |
| 83 |
explicit Fourcc(guint32 fourcc); |
| 84 |
|
| 85 |
Fourcc& operator=(const Fourcc& src); |
| 86 |
|
| 87 |
|
| 88 |
public: |
| 89 |
|
| 90 |
public: |
| 91 |
char first; |
| 92 |
char second; |
| 93 |
char third; |
| 94 |
char fourth; |
| 95 |
|
| 96 |
private: |
| 97 |
void set_ccs(guint32 fourcc); |
| 98 |
}; |
| 99 |
|
| 100 |
|
| 101 |
/** A class that represents a fraction. |
| 102 |
* Gst::Fraction is used to store a fraction in Gst::Structures of Gst::Caps as |
| 103 |
* a value representing a property (see GStreamer Application Development |
| 104 |
* Manual section 8.2.2 and GstValue docs). When the value is set, it is |
| 105 |
* transformed to a GStreamer GType so retrieving the value is a bit different. |
| 106 |
* The class can be used in setting and getting a Gst::Structure field like so: |
| 107 |
* |
| 108 |
* @code |
| 109 |
* Glib::Value<Gst::Fraction> value; |
| 110 |
* value.init(Glib::Value<Gst::Fraction>::value_type()); |
| 111 |
* value.set(Gst::Fraction(25,1)); |
| 112 |
* |
| 113 |
* Gst::Structure structure("my-structure"); |
| 114 |
* structure.set_field("framerate", value); |
| 115 |
* ... |
| 116 |
* Glib::ValueBase gst_value; |
| 117 |
* structure.get_field("framerate", gst_value); |
| 118 |
* Gst::Fraction fract(gst_value); |
| 119 |
* int numerator = fract.num; |
| 120 |
* ... |
| 121 |
* @endcode |
| 122 |
* |
| 123 |
* Last reviewed on 2016-08-27 (1.8.0) |
| 124 |
* |
| 125 |
* @ingroup GstHelperClasses |
| 126 |
*/ |
| 127 |
class Fraction |
| 128 |
{ |
| 129 |
public: |
| 130 |
/** Constructs a zero Gst::Fraction (0/1). |
| 131 |
*/ |
| 132 |
Fraction(); |
| 133 |
|
| 134 |
/** Constructs a Gst::Fraction from another. |
| 135 |
*/ |
| 136 |
Fraction(const Fraction& src); |
| 137 |
|
| 138 |
/** Constructs a Gst::Fraction (num/denom). |
| 139 |
*/ |
| 140 |
Fraction(int num, int denom); |
| 141 |
|
| 142 |
/** Constructs a Gst::Fraction from a GST_TYPE_FRACTION. |
| 143 |
*/ |
| 144 |
explicit Fraction(const Glib::ValueBase& gst_fraction_value); |
| 145 |
|
| 146 |
/** Constructs a Gst::Fraction from a GST_TYPE_FRACTION. |
| 147 |
*/ |
| 148 |
explicit Fraction(const GValue& gst_fraction_value); |
| 149 |
|
| 150 |
Fraction& operator=(const Fraction& src); |
| 151 |
|
| 152 |
|
| 153 |
public: |
| 154 |
int num; |
| 155 |
int denom; |
| 156 |
}; |
| 157 |
|
| 158 |
/** A class that represents a range (min - max). |
| 159 |
* Gst::Range is used to store a range in Gst::Structures of |
| 160 |
* Gst::Caps as a value representing a property (see GStreamer Application |
| 161 |
* Development Manual section 8.2.2 and GstValue docs). When the value is set, |
| 162 |
* it is transformed to a GStreamer GType so retrieving the value is a bit |
| 163 |
* different. The class can be used in setting and getting a Gst::Structure |
| 164 |
* field like so: |
| 165 |
* |
| 166 |
* @code |
| 167 |
* Glib::Value<Gst::Range<int>> value; |
| 168 |
* value.init(Glib::Value<Gst::Range<int>>::value_type()); |
| 169 |
* value.set(Gst::Range<int>(8000, 50000)); |
| 170 |
* |
| 171 |
* Gst::Structure structure("my-structure"); |
| 172 |
* structure.set_field("rate", value); |
| 173 |
* ... |
| 174 |
* Glib::ValueBase gst_value; |
| 175 |
* structure.get_field("rate", gst_value); |
| 176 |
* Gst::Range<int> range(gst_value); |
| 177 |
* int max = range.max; |
| 178 |
* ... |
| 179 |
* @endcode |
| 180 |
* |
| 181 |
* Gst::Range should be used with following types: int, double, Gst::Fraction. |
| 182 |
* |
| 183 |
* Last reviewed on 2016-08-27 (1.8.0) |
| 184 |
* |
| 185 |
* @ingroup GstHelperClasses |
| 186 |
*/ |
| 187 |
template<typename T> |
| 188 |
class Range |
| 189 |
{ |
| 190 |
public: |
| 191 |
/** Constructs a zero Gst::Range. |
| 192 |
*/ |
| 193 |
Range() : min(T()), max(T()) {} |
| 194 |
|
| 195 |
/** Constructs a Gst::Range (min - max). |
| 196 |
*/ |
| 197 |
Range(T min, T max) : min(min), max(max) {} |
| 198 |
|
| 199 |
/** Constructs an Gst::Range from another range. |
| 200 |
*/ |
| 201 |
Range(const Range& src) : min(src.min), max(src.max) {} |
| 202 |
|
| 203 |
/** Constructs an Gst::Range from a Glib::ValueBase. |
| 204 |
*/ |
| 205 |
explicit Range(const Glib::Value<Range<T>>& range_value) |
| 206 |
{ |
| 207 |
min = range_value.get().min; |
| 208 |
max = range_value.get().max; |
| 209 |
} |
| 210 |
|
| 211 |
/** Constructs an Gst::Range from a GValue. |
| 212 |
*/ |
| 213 |
explicit Range(const GValue& range_value) |
| 214 |
{ |
| 215 |
init_range(range_value); |
| 216 |
} |
| 217 |
|
| 218 |
Range& operator=(const Range& src) |
| 219 |
{ |
| 220 |
min = src.min; |
| 221 |
max = src.max; |
| 222 |
return *this; |
| 223 |
} |
| 224 |
|
| 225 |
public: |
| 226 |
T min; |
| 227 |
T max; |
| 228 |
|
| 229 |
private: |
| 230 |
void init_range(const GValue& range_value); |
| 231 |
}; |
| 232 |
|
| 233 |
} //namespace Gst |
| 234 |
|
| 235 |
#ifndef DOXYGEN_SHOULD_SKIP_THIS |
| 236 |
namespace Glib |
| 237 |
{ |
| 238 |
|
| 239 |
template<> |
| 240 |
class Value<Gst::Fourcc> : public Value<unsigned int> |
| 241 |
{ |
| 242 |
public: |
| 243 |
typedef Gst::Fourcc CppType; |
| 244 |
typedef guint32 CType; |
| 245 |
|
| 246 |
static GType value_type() G_GNUC_CONST; |
| 247 |
|
| 248 |
void set(const Gst::Fourcc& data); |
| 249 |
Gst::Fourcc get() const; |
| 250 |
}; |
| 251 |
|
| 252 |
template<> |
| 253 |
class Value<Gst::Range<int>> : public ValueBase_Boxed |
| 254 |
{ |
| 255 |
public: |
| 256 |
typedef Gst::Range<int> CppType; |
| 257 |
|
| 258 |
static GType value_type() G_GNUC_CONST; |
| 259 |
|
| 260 |
void set(const Gst::Range<int>& data); |
| 261 |
Gst::Range<int> get() const; |
| 262 |
}; |
| 263 |
|
| 264 |
template<> |
| 265 |
class Value<Gst::Range<double>> : public ValueBase_Boxed |
| 266 |
{ |
| 267 |
public: |
| 268 |
typedef Gst::Range<double> CppType; |
| 269 |
|
| 270 |
static GType value_type() G_GNUC_CONST; |
| 271 |
|
| 272 |
void set(const Gst::Range<double>& data); |
| 273 |
Gst::Range<double> get() const; |
| 274 |
}; |
| 275 |
|
| 276 |
template<> |
| 277 |
class Value<Gst::Fraction> : public ValueBase_Boxed |
| 278 |
{ |
| 279 |
public: |
| 280 |
typedef Gst::Fraction CppType; |
| 281 |
|
| 282 |
static GType value_type() G_GNUC_CONST; |
| 283 |
|
| 284 |
void set(const Gst::Fraction& data); |
| 285 |
Gst::Fraction get() const; |
| 286 |
}; |
| 287 |
|
| 288 |
template<> |
| 289 |
class Value<Gst::Range<Gst::Fraction>> : public ValueBase_Boxed |
| 290 |
{ |
| 291 |
public: |
| 292 |
typedef Gst::Range<Gst::Fraction> CppType; |
| 293 |
|
| 294 |
static GType value_type() G_GNUC_CONST; |
| 295 |
|
| 296 |
void set(const Gst::Range<Gst::Fraction>& data); |
| 297 |
Gst::Range<Gst::Fraction> get() const; |
| 298 |
}; |
| 299 |
|
| 300 |
} // namespace Glib |
| 301 |
#endif /* DOXYGEN_SHOULD_SKIP_THIS */ |