Skip to content

Commit edd7ad2

Browse files
mutantbobneilcsmith-net
authored andcommitted
include new gstreamer message types; Pad.link() return result becomes an exception (#95)
* add a few new message types * Pad.link() no longer returns a result. Instead it throws an exception for abnormal results * add javadoc; PadLinkException now derives from GstException * fix testGetPackage() to not fail on a gentoo system * Update PadLinkException with private linkResult and package private constructor for now; remove link_() method from Pad; fix formatting.
1 parent a6e7f9d commit edd7ad2

File tree

5 files changed

+69
-14
lines changed

5 files changed

+69
-14
lines changed

src/org/freedesktop/gstreamer/MessageType.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,22 @@ public enum MessageType implements IntegerEnum {
208208
* (Since 1.4)
209209
*/
210210
DEVICE_REMOVED(EXTENDED.intValue() + 2),
211+
/**
212+
* Message indicating a {@link GObject} property has changed (Since 1.10)
213+
*/
214+
PROPERTY_NOTIFY(EXTENDED.intValue() + 3),
215+
/**
216+
* Message indicating a new {@link GstStreamCollection} is available (Since 1.10)
217+
*/
218+
STREAM_COLLECTION(EXTENDED.intValue()+4),
219+
/**
220+
* Message indicating the active selection of {@link GstStreams} has changed (Since 1.10)
221+
*/
222+
STREAMS_SELECTED(EXTENDED.intValue() + 5),
223+
/**
224+
* Message indicating to request the application to try to play the given URL(s). Useful if for example a HTTP 302/303 response is received with a non-HTTP URL inside. (Since 1.10)
225+
*/
226+
REDIRECT(EXTENDED.intValue() + 6),
211227
/**
212228
* mask for all of the above messages.
213229
*/

src/org/freedesktop/gstreamer/Pad.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,16 +203,19 @@ public boolean peerAcceptCaps(Caps caps) {
203203
}
204204

205205
/**
206-
* Links this pad and a sink pad.
206+
* Links this source pad and a sink pad.
207207
*
208208
* MT Safe.
209-
* @param pad the sink Pad to link.
210-
* @return A result code indicating if the connection worked or what went wrong.
209+
* @param sink the sink Pad to link.
210+
* @throws PadLinkException if pads cannot be linked.
211211
*/
212-
public PadLinkReturn link(Pad pad) {
213-
return GSTPAD_API.gst_pad_link(this, pad);
212+
public void link(Pad sink) throws PadLinkException {
213+
PadLinkReturn result = GSTPAD_API.gst_pad_link(this, sink);
214+
if (result != PadLinkReturn.OK) {
215+
throw new PadLinkException(result);
216+
}
214217
}
215-
218+
216219
/**
217220
*
218221
* Unlinks the source pad from the sink pad.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.freedesktop.gstreamer;
2+
3+
/**
4+
* The exception thrown when a pad link operation returns a non-OK result
5+
*/
6+
public class PadLinkException extends GstException {
7+
8+
private final PadLinkReturn linkResult;
9+
10+
PadLinkException(PadLinkReturn result) {
11+
this("failed to link pads (" + result + ")", result);
12+
}
13+
14+
PadLinkException(String message, PadLinkReturn result) {
15+
super(message);
16+
linkResult = result;
17+
}
18+
19+
/**
20+
* Get the PadLinkReturn result that caused this exception.
21+
* @return PadLinkReturn
22+
*/
23+
public PadLinkReturn getLinkResult() {
24+
return linkResult;
25+
}
26+
27+
}

test/org/freedesktop/gstreamer/BinTest.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
import static org.junit.Assert.assertFalse;
2424
import static org.junit.Assert.assertNotNull;
2525
import static org.junit.Assert.assertTrue;
26+
import static org.junit.Assert.fail;
2627

27-
import java.lang.ref.WeakReference;
2828
import java.util.Iterator;
2929
import java.util.List;
3030
import java.util.concurrent.atomic.AtomicInteger;
@@ -143,7 +143,9 @@ public void elementAdded(Bin bin, Element elem) {
143143
assertEquals("Callback not called", 2, removed.get());
144144
}
145145
@Test
146-
public void addLinked() {
146+
public void addLinked()
147+
throws PadLinkException
148+
{
147149
/* adding an element with linked pads to a bin unlinks the pads */
148150
Pipeline pipeline = new Pipeline((String) null);
149151
assertNotNull("Could not create pipeline", pipeline);
@@ -158,7 +160,7 @@ public void addLinked() {
158160
Pad sinkpad = sink.getStaticPad("sink");
159161
assertNotNull("Could not get sink pad", sinkpad);
160162

161-
assertEquals("Could not link src and sink pads", PadLinkReturn.OK, srcpad.link(sinkpad));
163+
srcpad.link(sinkpad);
162164

163165
/* pads are linked now */
164166
assertTrue("srcpad not linked", srcpad.isLinked());
@@ -172,14 +174,19 @@ public void addLinked() {
172174
assertFalse("sinkpad is still linked after being added to bin", sinkpad.isLinked());
173175

174176
/* cannot link pads in wrong hierarchy */
175-
assertEquals("Should not be able to link pads in different hierarchy",
176-
PadLinkReturn.WRONG_HIERARCHY, srcpad.link(sinkpad));
177+
try {
178+
srcpad.link(sinkpad);
179+
fail("Should not be able to link pads in different hierarchy");
180+
} catch (PadLinkException e) {
181+
assertEquals("Should not be able to link pads in different hierarchy",
182+
PadLinkReturn.WRONG_HIERARCHY, e.getLinkResult());
183+
}
177184

178185
/* adding other element to bin as well */
179186
pipeline.add(sink);
180187

181188
/* now we can link again */
182-
assertEquals("Could not link src and sink pads when in same bin", PadLinkReturn.OK, srcpad.link(sinkpad));
189+
srcpad.link(sinkpad);
183190

184191
/* check if pads really are linked */
185192
assertTrue("srcpad not linked", srcpad.isLinked());

test/org/freedesktop/gstreamer/PadTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,14 @@ public void getPad() throws Exception {
8181
assertTrue("Sink pad not garbage collected", GCTracker.waitGC(sinkRef));
8282
}
8383
@Test
84-
public void padLink() throws Exception {
84+
public void padLink()
85+
throws Exception
86+
{
8587
Element src = ElementFactory.make("fakesrc", "src");
8688
Element sink = ElementFactory.make("fakesink", "src");
8789
Pad srcPad = src.getStaticPad("src");
8890
Pad sinkPad = sink.getStaticPad("sink");
89-
assertEquals("Could not link pads", PadLinkReturn.OK, srcPad.link(sinkPad));
91+
srcPad.link(sinkPad);
9092
}
9193

9294
@Ignore("This seems to fail because gst1.0 doesn't actually send the event because pads " +

0 commit comments

Comments
 (0)