/* gstreamermm - a C++ wrapper for gstreamer
 *
 * Copyright 2008-2015 The gstreamermm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * 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.
 */

_PINCLUDE(gstreamermm/private/miniobject_p.h)

namespace Gst
{
Glib::RefPtr<Gst::Buffer> Buffer::create(guint size)
{
  return Glib::wrap(gst_buffer_new_allocate(nullptr, size, nullptr));
}

Glib::RefPtr<Buffer> Buffer::create_writable()
{
  return Glib::RefPtr<Buffer>::cast_static(MiniObject::create_writable());
}

guint64 Buffer::offset_none()
{
  return GST_BUFFER_OFFSET_NONE;
}

Glib::RefPtr<Gst::Buffer> Buffer::append_region(Glib::RefPtr<Gst::Buffer>&& buf, gssize offset, gssize size)
{
  if (is_writable())
  {
    return Glib::wrap(gst_buffer_append_region(gobj(), buf.release()->gobj(), offset, size), true);
  }
  else
  {
    reference();
    return Glib::wrap(gst_buffer_append_region(gobj(), buf.release()->gobj(), offset, size), false);
  }
}

Glib::RefPtr<Gst::Buffer> Buffer::append(Glib::RefPtr<Gst::Buffer>&& buf)
{
  return append_region(std::move(buf), 0, -1);
}

} // namespace Gst
