-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPipelineTest.java
More file actions
109 lines (89 loc) · 3.31 KB
/
PipelineTest.java
File metadata and controls
109 lines (89 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package gir2java.tests;
import generated.Gst;
import generated.glib20.glib.GMainLoop;
import generated.gobject20.gobject.GObject;
import generated.gstreamer10.gst.GstCaps;
import generated.gstreamer10.gst.GstElement;
import generated.gstreamer10.gst.GstElementFactory;
import generated.gstreamer10.gst.GstMiniObject;
import generated.gstreamer10.gst.GstPipeline;
import generated.gstreamer10.gst.GstState;
import org.bridj.Pointer;
public class PipelineTest {
public static class Shutdown implements Runnable {
private GMainLoop mainLoop;
private long timeoutMillis;
public Shutdown(GMainLoop mainLoop, long timeoutMillis) {
this.mainLoop = mainLoop;
this.timeoutMillis = timeoutMillis;
}
@Override
public void run() {
try {
Thread.sleep(timeoutMillis);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mainLoop.quit();
}
}
public static void main(String[] args) {
Gst.init(null, null);
Pointer<GMainLoop> mainLoopPointer = GMainLoop._new(null, false).as(GMainLoop.class);
Pointer<GstElement> source = (Pointer<GstElement>)GstElementFactory.make(
Pointer.pointerToCString("videotestsrc"),
Pointer.pointerToCString("source")
);
Pointer<GstElement> capsfilter = (Pointer<GstElement>)GstElementFactory.make(
Pointer.pointerToCString("capsfilter"),
Pointer.pointerToCString("capsf")
);
Pointer<GstElement> textoverlay = (Pointer<GstElement>)GstElementFactory.make(
Pointer.pointerToCString("textoverlay"),
Pointer.pointerToCString("text")
);
Pointer<GstElement> sink = (Pointer<GstElement>)GstElementFactory.make(
Pointer.pointerToCString("autovideosink"),
Pointer.pointerToCString("sink")
);
if (source == null || textoverlay == null || sink == null) {
System.err.println("An element could not be created, exiting.");
return;
}
Pointer<GstCaps> caps =
GstCaps.from_string(Pointer.pointerToCString("video/x-raw,width=352,height=288,framerate=30/1"));
GObject.set(
capsfilter,
Pointer.pointerToCString("caps"),
caps,
null);
//The set above takes a reference to the caps, we don't need ours anymore.
/*
* XXX: We need this cast to GstMiniObject* here because the gir file does not declare it as a superclass.
* The unref() method would normally be inherited.
*/
caps.as(GstMiniObject.class).get().unref();
GObject.set(
textoverlay,
Pointer.pointerToCString("text"),
Pointer.pointerToCString("Assembling pipelines works!"),
Pointer.pointerToCString("font-desc"),
Pointer.pointerToCString("25"),
null);
GstPipeline pipeline =
GstPipeline.gstpipeline__new(Pointer.pointerToCString("the_pipeline")).as(GstPipeline.class).get();
pipeline.add_many(source, capsfilter, textoverlay, sink, null);
source.get().link_many(capsfilter, textoverlay, sink, null);
pipeline.set_state(GstState.GST_STATE_PLAYING);
GMainLoop mainLoop = mainLoopPointer.get();
System.out.println("Everything seems OK so far, starting main loop");
//TODO: use a proper bus watch to wait for EOS
new Thread(new Shutdown(mainLoop, 5000), "Shutdown thread").start();
mainLoop.run();
//The fun stuff happens, then:
System.out.println("Main loop finished");
pipeline.set_state(GstState.GST_STATE_NULL);
pipeline.gstobject_unref();
}
}