[gstreamermm: 99/167] fixed peper0's tests, minor changes in test-buffer-mapinfo test



commit 8d2a33498381fc5f4c3c72da9126e423fc26dcba
Author: Marcin Kolny at Flytronic <marcin kolny flytronic pl>
Date:   Wed Jul 31 13:44:53 2013 +0200

    fixed peper0's tests, minor changes in test-buffer-mapinfo test

 .gitignore                    |    4 ++++
 gstreamer/src/buffer.ccg      |    4 ++--
 gstreamer/src/sample.ccg      |    7 +++++++
 gstreamer/src/sample.hg       |    2 +-
 tests/test-buffer-mapinfo.cc  |    5 +++--
 tests/test-plugin-appsink.cc  |   20 +++++++++++++++-----
 tests/test-plugin-appsrc.cc   |    4 +++-
 tests/test-plugin-register.cc |   28 ++++++++++++++++++----------
 8 files changed, 53 insertions(+), 21 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 57ec67a..415257f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -482,7 +482,11 @@ tests/test-message-wrap
 tests/test-miniobject-wrap
 tests/test-pad
 tests/test-pipeline-add-element
+tests/test-plugin-appsink
+tests/test-plugin-appsrc
 tests/test-plugin-gen
+tests/test-plugin-pushsrc
+tests/test-plugin-register
 tests/test-plugin-signals
 tests/test-property-caps
 tests/test-query-wrap
diff --git a/gstreamer/src/buffer.ccg b/gstreamer/src/buffer.ccg
index f55af0b..cce27e2 100644
--- a/gstreamer/src/buffer.ccg
+++ b/gstreamer/src/buffer.ccg
@@ -27,12 +27,12 @@ namespace Gst
 
 Glib::RefPtr<Gst::Buffer> Buffer::copy() const
 {
-  return Glib::wrap(gst_buffer_copy(gobj()));
+  return Glib::wrap(gst_buffer_copy(gobj()), true);
 }
 
 Glib::RefPtr<Gst::Buffer> Buffer::create_writable()
 {
-  return Glib::wrap(gst_buffer_make_writable(gobj()));
+  return Glib::wrap(gst_buffer_make_writable(gobj()), true);
 }
 
 Glib::RefPtr<Gst::Buffer> Buffer::create(guint size)
diff --git a/gstreamer/src/sample.ccg b/gstreamer/src/sample.ccg
index 4fb111f..d9a37a7 100644
--- a/gstreamer/src/sample.ccg
+++ b/gstreamer/src/sample.ccg
@@ -27,3 +27,10 @@
 
 _PINCLUDE(gstreamermm/private/miniobject_p.h)
 
+namespace Gst
+{
+Glib::RefPtr<Gst::Buffer> Sample::get_buffer()
+{
+    return Glib::wrap(gst_sample_get_buffer(gobj()), true);
+}
+}
diff --git a/gstreamer/src/sample.hg b/gstreamer/src/sample.hg
index 59190a8..6d6b2e7 100644
--- a/gstreamer/src/sample.hg
+++ b/gstreamer/src/sample.hg
@@ -49,7 +49,7 @@ class Sample : public MiniObject
           Glib::RefPtr<const Gst::Segment> segment, Glib::RefPtr<Gst::Structure> info);
 
 public:
-  _WRAP_METHOD(Glib::RefPtr<Gst::Buffer> get_buffer(), gst_sample_get_buffer)
+  Glib::RefPtr<Gst::Buffer> get_buffer();
   _WRAP_METHOD(Glib::RefPtr<Gst::Caps> get_caps(), gst_sample_get_caps)
 
 };
diff --git a/tests/test-buffer-mapinfo.cc b/tests/test-buffer-mapinfo.cc
index bb2a946..46037eb 100644
--- a/tests/test-buffer-mapinfo.cc
+++ b/tests/test-buffer-mapinfo.cc
@@ -18,11 +18,12 @@ int main(int argc, char* argv[])
     cout << "Creating buffer..." << endl;
     Glib::RefPtr<Gst::Buffer> buffer = Gst::Buffer::create(buffer_size);
     Glib::RefPtr<Gst::MapInfo> mapinfo(new Gst::MapInfo());
-    Gst::MapFlags flags;
 
-    buffer->map(mapinfo, flags);
+    buffer->map(mapinfo, Gst::MAP_READ);
 
     assert(mapinfo->get_size() == buffer_size);
 
+    buffer->unmap(mapinfo);
+
     cout << "Correct!" << endl;
 }
diff --git a/tests/test-plugin-appsink.cc b/tests/test-plugin-appsink.cc
index bc35cce..5ec9827 100644
--- a/tests/test-plugin-appsink.cc
+++ b/tests/test-plugin-appsink.cc
@@ -60,9 +60,13 @@ int main(int argc, char** argv)
 
   std::string data = "hello world";
   Glib::RefPtr<Gst::Buffer> buf = Gst::Buffer::create(data.length() + 1);
-  strcpy((char *)buf->get_data(), data.c_str());
-  appsrc->push_buffer(buf);
+  Glib::RefPtr<Gst::MapInfo> mapinfo(new Gst::MapInfo());
 
+  buf = buf->create_writable();
+  buf->map(mapinfo, Gst::MAP_WRITE);
+  strcpy((char *)mapinfo->get_data(), data.c_str());
+  appsrc->push_buffer(buf);
+  buf->unmap(mapinfo);
   {
     std::cout << "waiting for state change" << std::endl;
     Gst::State state;
@@ -71,21 +75,27 @@ int main(int argc, char** argv)
   }
 
   Glib::RefPtr<Gst::Buffer> buf_out;
-  buf_out = appsink->pull_buffer();
+  Glib::RefPtr<Gst::Sample> sample = appsink->pull_sample();
+  assert(sample);
+  buf_out = sample->get_buffer();
   assert(buf_out);
-  assert(buf_out->get_data());
-  assert(std::string((char *)buf_out->get_data()) == data);
+  buf_out->map(mapinfo, Gst::MAP_READ);
+  assert(mapinfo->get_data());
+  assert(std::string((char *)mapinfo->get_data()) == data);
 
+  buf_out->unmap(mapinfo);
   appsrc->end_of_stream();
 
   std::cout << "waiting for eos or error" << std::endl;
   Glib::RefPtr<Gst::Message> msg = pipeline->get_bus()->poll((Gst::MessageType)(Gst::MESSAGE_EOS | 
Gst::MESSAGE_ERROR) , 1*Gst::SECOND);
+
   assert(msg);
   assert(msg->get_message_type() == Gst::MESSAGE_EOS);
   std::cout << "shutting down" << std::endl;
 
   pipeline->set_state(Gst::STATE_NULL);
 
+  pipeline->set_state(Gst::STATE_NULL);
 
   return 0;
 }
diff --git a/tests/test-plugin-appsrc.cc b/tests/test-plugin-appsrc.cc
index 55621d7..901069d 100644
--- a/tests/test-plugin-appsrc.cc
+++ b/tests/test-plugin-appsrc.cc
@@ -55,7 +55,9 @@ int main(int argc, char** argv)
 
   std::string data = "hello world";
   Glib::RefPtr<Gst::Buffer> buf = Gst::Buffer::create(data.length() + 1);
-  strcpy((char *)buf->get_data(), data.c_str());
+  Glib::RefPtr<Gst::MapInfo> mapinfo(new Gst::MapInfo());
+  buf->map(mapinfo, Gst::MapFlags());
+  strcpy((char *)mapinfo->get_data(), data.c_str());
   appsrc->push_buffer(buf);
 
   {
diff --git a/tests/test-plugin-register.cc b/tests/test-plugin-register.cc
index 5da04fe..9557bba 100644
--- a/tests/test-plugin-register.cc
+++ b/tests/test-plugin-register.cc
@@ -31,6 +31,7 @@
 #include <gstreamermm/appsrc.h>
 #include <gstreamermm/appsink.h>
 #include <cstring>
+#include <cstdio>
 
 //this is a bit hacky, but for now necessary for Gst::Element_Class::class_init_function which is used by 
register_mm_type
 #include <gstreamermm/private/element_p.h>
@@ -59,10 +60,12 @@ public:
 
   Gst::FlowReturn chain(const Glib::RefPtr<Gst::Pad> &pad, Glib::RefPtr<Gst::Buffer> &buf)
   {
-    assert(buf->gobj()->mini_object.refcount==1);
     buf = buf->create_writable();
-    //run some C++ function
-    std::sort(buf->get_data(), buf->get_data() + buf->get_size());
+    assert(buf->gobj()->mini_object.refcount==1);
+    Glib::RefPtr<Gst::MapInfo> mapinfo(new Gst::MapInfo());
+    buf->map(mapinfo, Gst::MAP_WRITE);
+    std::sort(mapinfo->get_data(), mapinfo->get_data() + mapinfo->get_size());
+    buf->unmap(mapinfo);
     assert(buf->gobj()->mini_object.refcount==1);
     return srcpad->push(buf);
   }
@@ -119,17 +122,22 @@ int main(int argc, char** argv)
   data.push_back(2);
   data.push_back(4);
   Glib::RefPtr<Gst::Buffer> buf = Gst::Buffer::create(data.size());
-  std::copy(data.begin(), data.end(), buf->get_data());
-  source->push_buffer(buf);
+  Glib::RefPtr<Gst::MapInfo> mapinfo(new Gst::MapInfo());
+  buf->map(mapinfo, Gst::MAP_WRITE);
 
+  std::copy(data.begin(), data.end(), mapinfo->get_data());
+  source->push_buffer(buf);
+  buf->unmap(mapinfo);
   std::cout << "pulling buffer" << std::endl;
   Glib::RefPtr<Gst::Buffer> buf_out;
-  buf_out = sink->pull_buffer();
-  assert(buf_out);
-  assert(buf_out->get_data());
-  std::sort(data.begin(), data.end());
-  assert(std::equal(data.begin(), data.end(), buf_out->get_data()));
+  assert(sink != NULL);
+  Glib::RefPtr<Gst::Sample> samp = sink->pull_preroll();
 
+  buf_out = samp->get_buffer();
+  assert(mapinfo->get_data());
+  std::sort(data.begin(), data.end());
+  assert(std::equal(data.begin(), data.end(), mapinfo->get_data()));
+  buf_out->unmap(mapinfo);
   std::cout << "finishing stream" << std::endl;
   source->end_of_stream();
 


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