Debian Codegraph @

gstreamer/src/bufferlist.ccg

raw
1 /* gstreamermm - a C++ wrapper for gstreamer
2 *
3 * Copyright 2008-2015 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 <gstreamermm/buffer.h>
21 _PINCLUDE(gstreamermm/private/miniobject_p.h)
22
23 extern "C"
24 {
25
26 static gboolean BufferList_Foreach_gstreamermm_callback(GstBuffer** buffer, guint idx, void* data)
27 {
28 Gst::BufferList::SlotForeach* the_slot =
29 static_cast<Gst::BufferList::SlotForeach*>(data);
30
31 try
32 {
33 // First wrap the original buffer.
34 Glib::RefPtr<Gst::Buffer> temp = Glib::wrap(*buffer, true);
35
36 // Call the slot which can modify the buffer (ie. set it to a new one or
37 // clear it altogether).
38 bool result =
39 static_cast<bool>((*the_slot)(temp, idx));
40
41 // Set the reference to the buffer according to how the temp buffer has
42 // been altered.
43 if(!temp)
44 {
45 // Clear the reference to the original buffer also.
46 *buffer = nullptr;
47 }
48 else if(*buffer != temp->gobj())
49 {
50 // The temp buffer has been set to a new one so make the reference point
51 // to it and take an extra reference for when the temp wrapper is
52 // destroyed (I think that's right).
53 *buffer = temp->gobj();
54 temp->reference();
55 }
56
57 return result;
58 }
59 catch(...)
60 {
61 Glib::exception_handlers_invoke();
62 }
63
64 return true; // continue
65 }
66
67 } // extern "C"
68
69
70 namespace Gst
71 {
72 void BufferList::insert(gint idx, const Glib::RefPtr<Gst::Buffer>& buffer)
73 {
74 buffer->reference();
75 gst_buffer_list_insert(gobj(), idx, buffer->gobj());
76 }
77
78 void BufferList::foreach(const SlotForeach& slot)
79 {
80 gst_buffer_list_foreach(gobj(), &BufferList_Foreach_gstreamermm_callback,
81 const_cast<SlotForeach*>(&slot));
82 }
83
84 } //namespace Gst