QtGStreamer  1.2.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
buffer.cpp
1 /*
2  Copyright (C) 2010 Collabora Multimedia.
3  @author Mauricio Piacentini <mauricio.piacentini@collabora.co.uk>
4 
5  This library is free software; you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published
7  by the Free Software Foundation; either version 2.1 of the License, or
8  (at your option) any later version.
9 
10  This program 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
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "buffer.h"
19 #include "caps.h"
20 #include <QtCore/QDebug>
21 #include <gst/gst.h>
22 
23 namespace QGst {
24 class MapInfo;
25 
26 BufferPtr Buffer::create(uint size)
27 {
28  return BufferPtr::wrap(gst_buffer_new_allocate(NULL, size, NULL), false);
29 }
30 
31 quint32 Buffer::size() const
32 {
33  return gst_buffer_get_size(object<GstBuffer>());
34 }
35 
36 ClockTime Buffer::decodingTimeStamp() const
37 {
38  return GST_BUFFER_DTS(object<GstBuffer>());
39 }
40 
41 ClockTime Buffer::presentationTimeStamp() const
42 {
43  return GST_BUFFER_PTS(object<GstBuffer>());
44 }
45 
46 ClockTime Buffer::duration() const
47 {
48  return GST_BUFFER_DURATION(object<GstBuffer>());
49 }
50 
51 quint64 Buffer::offset() const
52 {
53  return GST_BUFFER_OFFSET(object<GstBuffer>());
54 }
55 
56 quint64 Buffer::offsetEnd() const
57 {
58  return GST_BUFFER_OFFSET_END(object<GstBuffer>());
59 }
60 
61 BufferFlags Buffer::flags() const
62 {
63  return BufferFlags(GST_BUFFER_FLAGS(object<GstBuffer>()));
64 }
65 
66 void Buffer::setFlags(const BufferFlags flags)
67 {
68  GST_BUFFER_FLAGS(object<GstBuffer>()) = flags;
69 }
70 
71 BufferPtr Buffer::copy() const
72 {
73  return BufferPtr::wrap(gst_buffer_copy(object<GstBuffer>()), false);
74 }
75 
76 void Buffer::setSize(uint size)
77 {
78  gst_buffer_set_size(object<GstBuffer>(), size);
79 }
80 
81 uint Buffer::extract(uint offset, void *dest, uint size)
82 {
83  return gst_buffer_extract(object<GstBuffer>(), offset, dest, size);
84 }
85 
86 uint Buffer::memoryCount() const
87 {
88  return gst_buffer_n_memory (object<GstBuffer>());
89 }
90 
91 MemoryPtr Buffer::getMemory(uint index) const
92 {
93  return MemoryPtr::wrap(gst_buffer_get_memory(object<GstBuffer>(), index), false);
94 }
95 
96 bool Buffer::map(MapInfo &info, MapFlags flags)
97 {
98  if (!gst_buffer_map(object<GstBuffer>(), static_cast<GstMapInfo *>(info.m_object),
99  static_cast<GstMapFlags>(static_cast<int>(flags)))) {
100  return false;
101  }
102  return true;
103 }
104 
105 void Buffer::unmap(MapInfo &info)
106 {
107  gst_buffer_unmap(object<GstBuffer>(), static_cast<GstMapInfo *>(info.m_object));
108 }
109 
110 } //namespace QGst
static RefPointer< T > wrap(typename T::CType *nativePtr, bool increaseRef=true)
Definition: refpointer.h:326