Skip to content

Commit 9f72f68

Browse files
Fix ColorBalance interface and move GList creation code out of public API for GstInterface.
1 parent 98c9c59 commit 9f72f68

File tree

4 files changed

+91
-108
lines changed

4 files changed

+91
-108
lines changed

src/org/freedesktop/gstreamer/interfaces/ColorBalance.java

Lines changed: 86 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
* You should have received a copy of the GNU Lesser General Public License
1717
* version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
1818
*/
19-
2019
package org.freedesktop.gstreamer.interfaces;
2120

2221
import java.util.List;
@@ -25,95 +24,101 @@
2524
import org.freedesktop.gstreamer.lowlevel.GstAPI.GstCallback;
2625

2726
import com.sun.jna.Pointer;
27+
import java.util.ArrayList;
28+
import org.freedesktop.gstreamer.glib.GObject;
29+
import org.freedesktop.gstreamer.lowlevel.GlibAPI;
2830

2931
import static org.freedesktop.gstreamer.lowlevel.GstColorBalanceAPI.GSTCOLORBALANCE_API;
3032

3133
public class ColorBalance extends GstInterface {
32-
/**
33-
* Wraps the {@link Element} in a <tt>ColorBalance</tt> interface
34-
*
35-
* @param element
36-
* the element to use as a <tt>ColorBalance</tt>
37-
* @return a <tt>ColorBalance</tt> for the element
38-
*/
39-
public static final ColorBalance wrap(Element element) {
40-
return new ColorBalance(element);
41-
}
4234

43-
/**
44-
* Creates a new ColorBalance instance
45-
*
46-
* @param element
47-
* the element that implements the ColorBalance interface
48-
*/
49-
private ColorBalance(Element element) {
50-
super(element, GSTCOLORBALANCE_API.gst_color_balance_get_type());
51-
}
35+
/**
36+
* Wraps the {@link Element} in a <tt>ColorBalance</tt> interface
37+
*
38+
* @param element the element to use as a <tt>ColorBalance</tt>
39+
* @return a <tt>ColorBalance</tt> for the element
40+
*/
41+
public static final ColorBalance wrap(Element element) {
42+
return new ColorBalance(element);
43+
}
44+
45+
/**
46+
* Creates a new ColorBalance instance
47+
*
48+
* @param element the element that implements the ColorBalance interface
49+
*/
50+
private ColorBalance(Element element) {
51+
super(element, GSTCOLORBALANCE_API.gst_color_balance_get_type());
52+
}
5253

53-
/**
54-
* Retrieves a list of ColorBalanceChannels from the ColorBalance
55-
*
56-
* @return a list of color balance channels available on this device
57-
*/
58-
public List<ColorBalanceChannel> getChannelList() {
59-
return objectList(GSTCOLORBALANCE_API.gst_color_balance_list_channels(this),
60-
new ListElementCreator<ColorBalanceChannel>() {
61-
public ColorBalanceChannel create(Pointer pointer) {
62-
return channelFor(pointer, true);
63-
}
64-
});
65-
}
54+
/**
55+
* Retrieves a list of ColorBalanceChannels from the ColorBalance
56+
*
57+
* @return a list of color balance channels available on this device
58+
*/
59+
public List<ColorBalanceChannel> getChannelList() {
60+
61+
GlibAPI.GList glist = GSTCOLORBALANCE_API.gst_color_balance_list_channels(this);
62+
List<ColorBalanceChannel> list = new ArrayList<>();
63+
GlibAPI.GList next = glist;
64+
while (next != null) {
65+
if (next.data != null) {
66+
list.add(channelFor(next.data, true));
67+
}
68+
next = next.next();
69+
}
70+
return list;
71+
}
72+
73+
/**
74+
* Retrieves a ColorBalanceChannel for the given Pointer
75+
*
76+
* @param pointer
77+
* @param needRef
78+
* @return a ColorBalanceChannel instance
79+
*/
80+
private final ColorBalanceChannel channelFor(Pointer pointer,
81+
boolean needRef) {
82+
return new ColorBalanceChannel(this, pointer, needRef, true);
83+
}
6684

67-
/**
68-
* Retrieves a ColorBalanceChannel for the given Pointer
69-
*
70-
* @param pointer
71-
* @param needRef
72-
* @return a ColorBalanceChannel instance
73-
*/
74-
private final ColorBalanceChannel channelFor(Pointer pointer,
75-
boolean needRef) {
76-
return new ColorBalanceChannel(this, pointer, needRef, true);
77-
}
85+
/**
86+
* Signal emitted when color balance value changed
87+
*
88+
* @see #connect(VALUE_CHANGED)
89+
* @see #disconnect(VALUE_CHANGED)
90+
*/
91+
public static interface VALUE_CHANGED {
7892

79-
/**
80-
* Signal emitted when color balance value changed
81-
*
82-
* @see #connect(VALUE_CHANGED)
83-
* @see #disconnect(VALUE_CHANGED)
84-
*/
85-
public static interface VALUE_CHANGED {
86-
/**
87-
* Called when the color balance channel value changes
88-
*/
89-
public void colorBalanceValueChanged(ColorBalance colorBalance,
90-
ColorBalanceChannel channel, int value);
91-
}
93+
/**
94+
* Called when the color balance channel value changes
95+
*/
96+
public void colorBalanceValueChanged(ColorBalance colorBalance,
97+
ColorBalanceChannel channel, int value);
98+
}
9299

93-
/**
94-
* Add a listener for norm-changed messages.
95-
*
96-
* @param listener
97-
* the listener to be called when the norm changes
98-
*/
99-
public void connect(final VALUE_CHANGED listener) {
100-
element.connect(VALUE_CHANGED.class, listener, new GstCallback() {
101-
@SuppressWarnings("unused")
102-
public boolean callback(Pointer colorBalance, ColorBalanceChannel channel, int value) {
103-
listener.colorBalanceValueChanged(ColorBalance.this, channel, value);
104-
return true;
105-
}
106-
});
107-
}
100+
/**
101+
* Add a listener for norm-changed messages.
102+
*
103+
* @param listener the listener to be called when the norm changes
104+
*/
105+
public void connect(final VALUE_CHANGED listener) {
106+
element.connect(VALUE_CHANGED.class, listener, new GstCallback() {
107+
@SuppressWarnings("unused")
108+
public boolean callback(Pointer colorBalance, ColorBalanceChannel channel, int value) {
109+
listener.colorBalanceValueChanged(ColorBalance.this, channel, value);
110+
return true;
111+
}
112+
});
113+
}
108114

109-
/**
110-
* Disconnect the listener for norm-changed messages.
111-
*
112-
* @param listener
113-
* the listener that was registered to receive the message.
114-
*/
115-
public void disconnect(VALUE_CHANGED listener) {
116-
element.disconnect(VALUE_CHANGED.class, listener);
117-
}
115+
/**
116+
* Disconnect the listener for norm-changed messages.
117+
*
118+
* @param listener the listener that was registered to receive the message.
119+
*/
120+
public void disconnect(VALUE_CHANGED listener) {
121+
element.disconnect(VALUE_CHANGED.class, listener);
122+
}
118123

119124
}

src/org/freedesktop/gstreamer/interfaces/ColorBalanceChannel.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
* Copyright (c) 2019 Neil C Smith
23
* Copyright (c) 2009 Levente Farkas
34
* Copyright (c) 2009 Tamas Korodi <[email protected]>
45
*

src/org/freedesktop/gstreamer/interfaces/GstInterface.java

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
* Copyright (c) 2019 Neil C Smith
23
* Copyright (c) 2009 Levente Farkas
34
* Copyright (c) 2008 Wayne Meissner
45
*
@@ -21,12 +22,8 @@
2122

2223
import org.freedesktop.gstreamer.lowlevel.GType;
2324
import org.freedesktop.gstreamer.lowlevel.NativeValue;
24-
import java.util.ArrayList;
25-
import java.util.List;
2625

2726
import org.freedesktop.gstreamer.Element;
28-
import org.freedesktop.gstreamer.glib.GObject;
29-
import org.freedesktop.gstreamer.lowlevel.GlibAPI.GList;
3027

3128
import com.sun.jna.Pointer;
3229

@@ -46,26 +43,5 @@ protected Object nativeValue() {
4643
public Element getElement() {
4744
return element;
4845
}
49-
50-
protected interface ListElementCreator<E> {
51-
E create(Pointer pointer);
52-
}
53-
54-
/**
55-
* Build a {@link java.util.List} of {@link Object} from the native GList.
56-
* @param glist The native list to get the objects from.
57-
* @param creator The proxy class to wrap the list elements in.
58-
* @return The converted list.
59-
*/
60-
protected <T extends GObject> List<T> objectList(GList glist, ListElementCreator<T> creator) {
61-
List<T> list = new ArrayList<T>();
62-
GList next = glist;
63-
while (next != null) {
64-
if (next.data != null) {
65-
list.add(creator.create(next.data));
66-
}
67-
next = next.next();
68-
}
69-
return list;
70-
}
46+
7147
}

src/org/freedesktop/gstreamer/lowlevel/GstColorBalanceAPI.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
* Copyright (c) 2019 Neil C Smith
23
* Copyright (c) 2009 Levente Farkas
34
* Copyright (c) 2009 Tamas Korodi <[email protected]>
45
*
@@ -29,7 +30,7 @@
2930
import java.util.List;
3031

3132
public interface GstColorBalanceAPI extends Library {
32-
GstColorBalanceAPI GSTCOLORBALANCE_API = GstNative.load("gstinterfaces", GstColorBalanceAPI.class);
33+
GstColorBalanceAPI GSTCOLORBALANCE_API = GstNative.load("gstvideo", GstColorBalanceAPI.class);
3334

3435
GType gst_color_balance_channel_get_type();
3536
GType gst_color_balance_get_type();

0 commit comments

Comments
 (0)