Skip to content

Commit d1a2b58

Browse files
Merge pull request #52 from lafoletc/AllocationQuery
Add AllocationQuery
2 parents 2f09960 + c01e3d5 commit d1a2b58

File tree

10 files changed

+319
-118
lines changed

10 files changed

+319
-118
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2016 Christophe Lafolet
3+
*
4+
* This file is part of gstreamer-java.
5+
*
6+
* This code is free software: you can redistribute it and/or modify it under
7+
* the terms of the GNU Lesser General Public License version 3 only, as
8+
* published by the Free Software Foundation.
9+
*
10+
* This code is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13+
* version 3 for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
package org.freedesktop.gstreamer;
19+
20+
import org.freedesktop.gstreamer.lowlevel.GstBufferPoolAPI;
21+
22+
import com.sun.jna.Pointer;
23+
24+
public class BufferPool extends GstObject {
25+
26+
public static final String GTYPE_NAME = "GstBufferPool";
27+
28+
/**
29+
* This constructor is for internal use only.
30+
* @param init initialization data.
31+
*/
32+
public BufferPool(final Initializer init) {
33+
super(init);
34+
}
35+
36+
/**
37+
* Creates a new instance of BufferPool
38+
*/
39+
public BufferPool() {
40+
this(initializer(GstBufferPoolAPI.GSTBUFFERPOOL_API.ptr_gst_buffer_pool_new()));
41+
}
42+
43+
public void setParams(Caps caps, int size, int min_buffers, int max_buffers) {
44+
Structure config = GstBufferPoolAPI.GSTBUFFERPOOL_API.gst_buffer_pool_get_config(this);
45+
GstBufferPoolAPI.GSTBUFFERPOOL_API.gst_buffer_pool_config_set_params(config, caps, size, min_buffers, max_buffers);
46+
}
47+
48+
public Caps getCaps() {
49+
Structure config = GstBufferPoolAPI.GSTBUFFERPOOL_API.gst_buffer_pool_get_config(this);
50+
Pointer[] ptr = new Pointer[1];
51+
GstBufferPoolAPI.GSTBUFFERPOOL_API.gst_buffer_pool_config_get_params(config, ptr, null, null, null);
52+
return new Caps(new Initializer(ptr[0], false, true));
53+
}
54+
55+
}

src/org/freedesktop/gstreamer/Gst.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,11 +448,13 @@ private static synchronized void loadAllClasses() {
448448
GDate.class,
449449
GValue.class,
450450
GValueArray.class,
451+
TagList.class,
451452
TimedValue.class,
452453
ValueArray.class,
453454
ValueList.class,
454455
// ----------- Base -------------
455456
Buffer.class,
457+
BufferPool.class,
456458
Bus.class,
457459
Caps.class,
458460
Clock.class,
@@ -480,8 +482,6 @@ private static synchronized void loadAllClasses() {
480482
DecodeBin.class,
481483
Pipeline.class,
482484
PlayBin.class,
483-
URIDecodeBin.class,
484-
//
485-
TagList.class
485+
URIDecodeBin.class
486486
};
487487
}

src/org/freedesktop/gstreamer/elements/BaseSink.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@
2828
import org.freedesktop.gstreamer.MiniObject;
2929
import org.freedesktop.gstreamer.Pad;
3030
import org.freedesktop.gstreamer.lowlevel.BaseSinkAPI;
31+
import org.freedesktop.gstreamer.lowlevel.BaseSinkAPI.GstBaseSinkClass;
32+
import org.freedesktop.gstreamer.lowlevel.BaseSinkAPI.GstBaseSinkStruct;
33+
import org.freedesktop.gstreamer.lowlevel.BaseSinkAPI.ProposeAllocation;
3134
import org.freedesktop.gstreamer.lowlevel.GstAPI;
35+
import org.freedesktop.gstreamer.query.AllocationQuery;
3236

3337
import com.sun.jna.Pointer;
3438

@@ -202,5 +206,33 @@ public void connect(final PREROLL_HANDOFF listener) {
202206
*/
203207
public void disconnect(PREROLL_HANDOFF listener) {
204208
disconnect(PREROLL_HANDOFF.class, listener);
205-
}
209+
}
210+
211+
/**
212+
* Signal emitted when this {@link BaseSink} received a {@link ProposeAllocation} query.
213+
*
214+
* @see #setProposeAllocationHandler(ProposeAllocationHandler)
215+
*/
216+
public static interface ProposeAllocationHandler {
217+
public boolean proposeAllocation(BaseSink sink, AllocationQuery query);
218+
}
219+
220+
/**
221+
* Set a handler for the {@link ProposeAllocation} query on this sink
222+
*
223+
* @param handler The handler to be called when a {@link ProposeAllocation} is received.
224+
*/
225+
public void setProposeAllocationHandler(final ProposeAllocationHandler handler) {
226+
GstBaseSinkStruct struct = new GstBaseSinkStruct(handle());
227+
struct.readField("element");
228+
GstBaseSinkClass basesinkClass = new GstBaseSinkClass(struct.element.object.object.g_type_instance.g_class.getPointer());
229+
basesinkClass.propose_allocation = new ProposeAllocation() {
230+
@Override
231+
public boolean callback(BaseSink sink, AllocationQuery query) {
232+
return handler.proposeAllocation(sink, query);
233+
}
234+
};
235+
basesinkClass.writeField("propose_allocation");
236+
}
237+
206238
}

0 commit comments

Comments
 (0)