[gstreamermm] Gst::Sample: increase reference in get_caps()



commit 1b3fb04a9e3cfe49a8e0f475b0a4046c19c17be9
Author: Marcin Kolny <marcin kolny gmail com>
Date:   Fri Apr 15 21:11:02 2016 +0200

    Gst::Sample: increase reference in get_caps()
    
        * .gitignore: add generated test executable file to ignore list.
        * gstreamer/src/sample.{ccg|hg}: fix get_caps(), implement create().
        * tests/Makefile.am:
        * tests/test-sample.cc: add test for Gst::Sample class.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=765078

 .gitignore               |    1 +
 gstreamer/src/sample.ccg |   11 +++++++++++
 gstreamer/src/sample.hg  |    7 +++----
 tests/Makefile.am        |    2 ++
 tests/test-sample.cc     |   23 +++++++++++++++++++++++
 5 files changed, 40 insertions(+), 4 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index d35597a..b242e9e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -552,6 +552,7 @@ tests/test-miniobject
 tests/test-pad
 tests/test-pipeline
 tests/test-query
+tests/test-sample
 tests/test-structure
 tests/test-taglist
 tests/test-urihandler
diff --git a/gstreamer/src/sample.ccg b/gstreamer/src/sample.ccg
index 8ce3a26..20ee67c 100644
--- a/gstreamer/src/sample.ccg
+++ b/gstreamer/src/sample.ccg
@@ -23,3 +23,14 @@
  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
+namespace Gst {
+
+Glib::RefPtr<Gst::Sample> Sample::create(const Glib::RefPtr<Gst::Buffer>& buffer, const 
Glib::RefPtr<Gst::Caps>& caps, const Gst::Segment& segment, Gst::Structure&& info)
+{
+  GstSample *sample = gst_sample_new(buffer->gobj(), caps->gobj(), segment.gobj(), info.gobj());
+  Gst::Structure empty_structure;
+  info.swap(empty_structure);
+
+  return Glib::wrap(sample, false);
+}
+}
\ No newline at end of file
diff --git a/gstreamer/src/sample.hg b/gstreamer/src/sample.hg
index e98fed0..0b71128 100644
--- a/gstreamer/src/sample.hg
+++ b/gstreamer/src/sample.hg
@@ -45,13 +45,12 @@ class Sample : public MiniObject
   _CLASS_OPAQUE_REFCOUNTED(Sample, GstSample, NONE, gst_sample_ref, gst_sample_unref)
   _IGNORE(gst_sample_ref, gst_sample_unref)
 
-  static Glib::RefPtr<Gst::Buffer> create(Glib::RefPtr<Gst::Buffer> buffer, Glib::RefPtr<Gst::Caps> caps,
-          Glib::RefPtr<const Gst::Segment> segment, Glib::RefPtr<Gst::Structure> info);
-
 public:
+   static Glib::RefPtr<Gst::Sample> create(const Glib::RefPtr<Gst::Buffer>& buffer, const 
Glib::RefPtr<Gst::Caps>& caps, const Gst::Segment& segment, Gst::Structure&& info);
+
   _WRAP_METHOD(Glib::RefPtr<Gst::Buffer> get_buffer(), gst_sample_get_buffer, refreturn)
   _WRAP_METHOD(Glib::RefPtr<const Gst::Buffer> get_buffer() const, gst_sample_get_buffer, constversion)
-  _WRAP_METHOD(Glib::RefPtr<Gst::Caps> get_caps(), gst_sample_get_caps)
+  _WRAP_METHOD(Glib::RefPtr<Gst::Caps> get_caps(), gst_sample_get_caps, refreturn)
   _WRAP_METHOD(Glib::RefPtr<const Gst::Caps> get_caps() const, gst_sample_get_caps, constversion)
 
 };
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0202d5e..caba3b9 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -39,6 +39,7 @@ check_PROGRAMS =                                \
         test-pad                                \
         test-pipeline                           \
         test-query                              \
+       test-sample                             \
         test-structure                          \
         test-taglist                            \
         test-urihandler                         \
@@ -82,6 +83,7 @@ test_miniobject_SOURCES                         = $(TEST_GTEST_SOURCES) test-min
 test_pad_SOURCES                                = $(TEST_GTEST_SOURCES) test-pad.cc
 test_pipeline_SOURCES                           = $(TEST_GTEST_SOURCES) test-pipeline.cc
 test_query_SOURCES                              = $(TEST_GTEST_SOURCES) test-query.cc
+test_sample_SOURCES                             = $(TEST_GTEST_SOURCES) test-sample.cc
 test_structure_SOURCES                          = $(TEST_GTEST_SOURCES) test-structure.cc
 test_taglist_SOURCES                            = $(TEST_GTEST_SOURCES) test-taglist.cc
 test_urihandler_SOURCES                         = $(TEST_GTEST_SOURCES) test-urihandler.cc
diff --git a/tests/test-sample.cc b/tests/test-sample.cc
new file mode 100644
index 0000000..a23efc8
--- /dev/null
+++ b/tests/test-sample.cc
@@ -0,0 +1,23 @@
+#include <gtest/gtest.h>
+#include <gstreamermm.h>
+
+using namespace Gst;
+using Glib::RefPtr;
+
+TEST(SampleTest, CheckGetCapsMethod)
+{
+  auto caps = Caps::create_any();
+  ASSERT_EQ(1, caps->get_refcount());
+
+  auto sample = Sample::create(RefPtr<Buffer>(), caps, Segment(), Structure());
+  ASSERT_EQ(2, caps->get_refcount());
+
+  {
+    auto tmp_caps = sample->get_caps();
+    ASSERT_EQ(3, caps->get_refcount());
+    ASSERT_TRUE(tmp_caps->equals(caps));
+  }
+  
+  ASSERT_EQ(2, caps->get_refcount());
+
+}


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