|
22 | 22 |
|
23 | 23 | package org.freedesktop.gstreamer; |
24 | 24 |
|
25 | | -import com.sun.jna.Pointer; |
| 25 | +import static org.freedesktop.gstreamer.lowlevel.GstBufferAPI.GSTBUFFER_API; |
| 26 | + |
26 | 27 | import java.nio.ByteBuffer; |
27 | 28 |
|
28 | 29 | import org.freedesktop.gstreamer.lowlevel.GstBufferAPI; |
| 30 | +import org.freedesktop.gstreamer.lowlevel.GstBufferAPI.BufferStruct; |
29 | 31 | import org.freedesktop.gstreamer.lowlevel.GstBufferAPI.MapInfoStruct; |
30 | 32 |
|
31 | | -import static org.freedesktop.gstreamer.lowlevel.GstBufferAPI.GSTBUFFER_API; |
| 33 | +import com.sun.jna.Pointer; |
32 | 34 |
|
33 | 35 | /** |
34 | 36 | * Data-passing buffer type, supporting sub-buffers. |
@@ -91,10 +93,13 @@ public class Buffer extends MiniObject { |
91 | 93 | public static final String GTYPE_NAME = "GstBuffer"; |
92 | 94 |
|
93 | 95 | private final MapInfoStruct mapInfo; |
| 96 | + private final BufferStruct struct; |
| 97 | + |
94 | 98 |
|
95 | 99 | public Buffer(Initializer init) { |
96 | 100 | super(init); |
97 | 101 | mapInfo = new MapInfoStruct(); |
| 102 | + struct = new BufferStruct(handle()); |
98 | 103 | } |
99 | 104 |
|
100 | 105 | /** |
@@ -141,17 +146,36 @@ private static Pointer allocBuffer(int size) { |
141 | 146 | * @return A {@link java.nio.ByteBuffer} that can access this Buffer's data. |
142 | 147 | */ |
143 | 148 | public ByteBuffer map(boolean writeable) { |
144 | | - boolean ok = GSTBUFFER_API.gst_buffer_map(this, mapInfo, |
| 149 | + final boolean ok = GSTBUFFER_API.gst_buffer_map(this, mapInfo, |
145 | 150 | writeable ? GstBufferAPI.GST_MAP_WRITE : GstBufferAPI.GST_MAP_READ); |
146 | | - if (ok) { |
| 151 | + if (ok && mapInfo.data != null) { |
147 | 152 | return mapInfo.data.getByteBuffer(0, mapInfo.size.intValue()); |
148 | | - } else { |
149 | | - return null; |
150 | 153 | } |
| 154 | + return null; |
151 | 155 | } |
152 | 156 |
|
153 | 157 | public void unmap() { |
154 | 158 | GSTBUFFER_API.gst_buffer_unmap(this, mapInfo); |
155 | 159 | } |
156 | 160 |
|
| 161 | + /** |
| 162 | + * Gets the timestamps of this buffer. |
| 163 | + * The buffer DTS refers to the timestamp when the buffer should be decoded and is usually monotonically increasing. |
| 164 | + * |
| 165 | + * @return a ClockTime representing the timestamp or {@link ClockTime#NONE} when the timestamp is not known or relevant. |
| 166 | + */ |
| 167 | + public ClockTime getDecodeTimestamp() { |
| 168 | + return (ClockTime)this.struct.readField("dts"); |
| 169 | + } |
| 170 | + |
| 171 | + /** |
| 172 | + * Gets the timestamps of this buffer. |
| 173 | + * The buffer PTS refers to the timestamp when the buffer content should be presented to the user and is not always monotonically increasing. |
| 174 | + * |
| 175 | + * @return a ClockTime representing the timestamp or {@link ClockTime#NONE} when the timestamp is not known or relevant. |
| 176 | + */ |
| 177 | + public ClockTime getPresentationTimestamp() { |
| 178 | + return (ClockTime)this.struct.readField("pts"); |
| 179 | + } |
| 180 | + |
157 | 181 | } |
0 commit comments