|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2019 Neil C Smith |
| 2 | + * Copyright (c) 2020 Neil C Smith |
3 | 3 | * Copyright (c) 2007 Wayne Meissner
|
4 | 4 | *
|
5 | 5 | * This file is part of gstreamer-java.
|
|
27 | 27 | import static org.junit.Assert.assertTrue;
|
28 | 28 |
|
29 | 29 | import java.lang.ref.WeakReference;
|
| 30 | +import java.util.concurrent.atomic.AtomicBoolean; |
30 | 31 | import java.util.concurrent.atomic.AtomicReference;
|
31 | 32 | import org.freedesktop.gstreamer.event.FlushStopEvent;
|
32 | 33 |
|
|
35 | 36 | import org.junit.AfterClass;
|
36 | 37 | import org.junit.Before;
|
37 | 38 | import org.junit.BeforeClass;
|
38 |
| -import org.junit.Ignore; |
39 | 39 | import org.junit.Test;
|
40 | 40 |
|
41 | 41 | /**
|
@@ -127,6 +127,40 @@ public PadProbeReturn eventReceived(Pad pad, Event event) {
|
127 | 127 | assertNotSame("event_prober.probeEvent() should not have been called", ev2, e.get());
|
128 | 128 | }
|
129 | 129 |
|
| 130 | + @Test |
| 131 | + public void addEventProbe_Remove() { |
| 132 | + Element elem = ElementFactory.make("identity", "src"); |
| 133 | + Event ev = new TagEvent(new TagList()); |
| 134 | + |
| 135 | + Pad sink = elem.getStaticPad("sink"); |
| 136 | + |
| 137 | + final AtomicReference<Event> e = new AtomicReference<Event>(); |
| 138 | + |
| 139 | + Pad.EVENT_PROBE event_probe = new Pad.EVENT_PROBE() { |
| 140 | + |
| 141 | + public PadProbeReturn eventReceived(Pad pad, Event event) { |
| 142 | + e.set(event); |
| 143 | + return PadProbeReturn.REMOVE; |
| 144 | + } |
| 145 | + }; |
| 146 | + |
| 147 | + sink.setActive(true); |
| 148 | + sink.sendEvent(new FlushStopEvent()); |
| 149 | + |
| 150 | + sink.addEventProbe(event_probe); |
| 151 | + sink.sendEvent(ev); |
| 152 | + assertEquals("event_prober.probeEvent() was not called", ev, e.get()); |
| 153 | + |
| 154 | + Event ev2 = new TagEvent(new TagList()); |
| 155 | + sink.sendEvent(ev2); |
| 156 | + assertNotSame("event_prober.probeEvent() should not have been called", ev2, e.get()); |
| 157 | + |
| 158 | + WeakReference<Pad.EVENT_PROBE> probeRef = new WeakReference<>(event_probe); |
| 159 | + event_probe = null; |
| 160 | + assertTrue("Removed probe not collected", GCTracker.waitGC(probeRef)); |
| 161 | + |
| 162 | + } |
| 163 | + |
130 | 164 | @Test
|
131 | 165 | public void addProbe_Event() {
|
132 | 166 | Element elem = ElementFactory.make("identity", "src");
|
@@ -156,6 +190,42 @@ public void addProbe_Event() {
|
156 | 190 | sink.sendEvent(ev2);
|
157 | 191 | assertNotSame("Probe (Event) should not have been called", ev2, e.get());
|
158 | 192 | }
|
| 193 | + |
| 194 | + @Test |
| 195 | + public void addProbe_EventRemove() { |
| 196 | + Element elem = ElementFactory.make("identity", "src"); |
| 197 | + Event ev = new TagEvent(new TagList()); |
| 198 | + |
| 199 | + Pad sink = elem.getStaticPad("sink"); |
| 200 | + |
| 201 | + final AtomicReference<Event> e = new AtomicReference<>(); |
| 202 | + |
| 203 | + Pad.PROBE probe = (Pad pad, PadProbeInfo info) -> { |
| 204 | + assertTrue("Info type does not include event downstream", |
| 205 | + info.getType().contains(PadProbeType.EVENT_DOWNSTREAM)); |
| 206 | + e.set(info.getEvent()); |
| 207 | + return PadProbeReturn.REMOVE; |
| 208 | + }; |
| 209 | + |
| 210 | + sink.setActive(true); |
| 211 | + sink.sendEvent(new FlushStopEvent()); |
| 212 | + |
| 213 | + sink.addProbe(PadProbeType.EVENT_BOTH, probe); |
| 214 | + sink.sendEvent(ev); |
| 215 | + assertEquals("Probe (Event) was not called", ev, e.get()); |
| 216 | + |
| 217 | + Event ev2 = new TagEvent(new TagList()); |
| 218 | + sink.sendEvent(ev2); |
| 219 | + assertNotSame("Probe (Event) should not have been called", ev2, e.get()); |
| 220 | + |
| 221 | + WeakReference<Pad.PROBE> probeRef = new WeakReference<>(probe); |
| 222 | + probe = null; |
| 223 | + assertTrue("Removed probe not collected", GCTracker.waitGC(probeRef)); |
| 224 | + |
| 225 | + Event ev3 = new TagEvent(new TagList()); |
| 226 | + sink.sendEvent(ev3); |
| 227 | + assertNotSame("Probe (Event) should not have been called", ev3, e.get()); |
| 228 | + } |
159 | 229 |
|
160 | 230 | @Test
|
161 | 231 | public void addDataProbe() {
|
@@ -229,4 +299,29 @@ public void addProbe_Data() {
|
229 | 299 | assertNotSame("Probe (Data) should not have been called", buf2, b.get());
|
230 | 300 | }
|
231 | 301 |
|
| 302 | + @Test |
| 303 | + public void addProbe_Idle() { |
| 304 | + |
| 305 | + Element elem = ElementFactory.make("identity", "src"); |
| 306 | + final AtomicBoolean called = new AtomicBoolean(); |
| 307 | + |
| 308 | + Pad src = elem.getStaticPad("src"); |
| 309 | + |
| 310 | + Pad.PROBE probe = (Pad pad, PadProbeInfo info) -> { |
| 311 | + called.set(true); |
| 312 | + return PadProbeReturn.REMOVE; |
| 313 | + }; |
| 314 | + |
| 315 | + src.addProbe(PadProbeType.IDLE, probe); |
| 316 | + |
| 317 | + assertTrue("Idle probe not called", called.get()); |
| 318 | + |
| 319 | + WeakReference<Pad.PROBE> probeRef = new WeakReference<>(probe); |
| 320 | + |
| 321 | + probe = null; |
| 322 | + |
| 323 | + assertTrue("Idle probe not collected", GCTracker.waitGC(probeRef)); |
| 324 | + |
| 325 | + } |
| 326 | + |
232 | 327 | }
|
0 commit comments