[gstreamermm] Gst::VideoInfo: wrap VideoInfo as _CLASS_GENERIC



commit 3b4b048c8d360d605df171e27415d3a1e5d64e40
Author: Marcin Kolny <marcin kolny flytronic pl>
Date:   Tue Jul 7 11:20:16 2015 +0200

    Gst::VideoInfo: wrap VideoInfo as _CLASS_GENERIC
    
    GstVideoInfo object usually is static allocated, and boxedtype can store
    only dynamic allocated structures.
    
        * gstreamer/src/videoinfo.{ccg|hg}: add custom constructors,
          destructor, operator= in VideoInfo class.

 gstreamer/src/videoinfo.ccg |   40 +++++++++++++++++++++++++++++++++++++++-
 gstreamer/src/videoinfo.hg  |   25 +++++++++++++++++++++++--
 2 files changed, 62 insertions(+), 3 deletions(-)
---
diff --git a/gstreamer/src/videoinfo.ccg b/gstreamer/src/videoinfo.ccg
index c3ce6f6..bad9a73 100644
--- a/gstreamer/src/videoinfo.ccg
+++ b/gstreamer/src/videoinfo.ccg
@@ -15,4 +15,42 @@
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free
  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
\ No newline at end of file
+ */
+
+namespace Gst
+{
+VideoInfo::VideoInfo()
+: take_ownership(true)
+{
+  gobject_ = gst_video_info_new();
+}
+
+VideoInfo::VideoInfo(const VideoInfo& other)
+{
+  gobject_ = gst_video_info_copy(other.gobject_);
+  take_ownership = true;
+}
+
+VideoInfo& VideoInfo::operator=(const VideoInfo& other)
+{
+  if (take_ownership)
+    gst_video_info_free(gobject_);
+
+  take_ownership = true;
+  gobject_ = gst_video_info_copy(other.gobject_);
+
+  return *this;
+}
+
+VideoInfo::VideoInfo(GstVideoInfo* castitem, bool take_ownership)
+: gobject_(castitem),
+  take_ownership(take_ownership)
+{
+}
+
+VideoInfo::~VideoInfo()
+{
+  if (take_ownership)
+    gst_video_info_free(gobject_);
+}
+}
diff --git a/gstreamer/src/videoinfo.hg b/gstreamer/src/videoinfo.hg
index dc86f01..670d9b8 100644
--- a/gstreamer/src/videoinfo.hg
+++ b/gstreamer/src/videoinfo.hg
@@ -36,9 +36,26 @@ namespace Gst
 
 class VideoInfo
 {
-  _CLASS_BOXEDTYPE(VideoInfo, GstVideoInfo, gst_video_info_new, gst_video_info_copy, gst_video_info_free)
-
+  _CLASS_GENERIC(VideoInfo, GstVideoInfo)
+  _IGNORE(gst_video_info_free)
+  _IGNORE(gst_video_info_copy)
 public:
+  VideoInfo();
+  VideoInfo(const VideoInfo& other);
+  VideoInfo& operator=(const VideoInfo& other);
+
+  /** This constructor allows to wrap both dynamic and static allocated
+    * GstVideoInfo object. If castitem is either static allocated or
+    * dynamic allocated, but will be freed somewhere else, @take_ownership
+    * should be set to false. If @take_ownership is set to true, castitem
+    * is freed in VideoInfo destructor.
+    */
+  VideoInfo(GstVideoInfo* castitem, bool take_ownership);
+  ~VideoInfo();
+
+  GstVideoInfo* gobj() { return gobject_; }
+  const GstVideoInfo* gobj() const { return gobject_; }
+
   _WRAP_METHOD(void init(), gst_video_info_init)
   _WRAP_METHOD(void set_format(Gst::VideoFormat format, guint width, guint height), 
gst_video_info_set_format)
   _WRAP_METHOD(bool from_caps(const Glib::RefPtr<const Gst::Caps>& caps), gst_video_info_from_caps)
@@ -86,6 +103,10 @@ public:
   
   _MEMBER_GET(multiview_flags, ABI.abi.multiview_flags, Gst::VideoMultiviewFlags, GstVideoMultiviewFlags)
   _MEMBER_SET(multiview_flags, ABI.abi.multiview_flags, Gst::VideoMultiviewFlags, GstVideoMultiviewFlags)
+
+private:
+  GstVideoInfo* gobject_;
+  bool take_ownership;
 };
 
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]