Skip to content

Commit 32b74a8

Browse files
i-n-g-oneilcsmith-net
authored andcommitted
add getTemplate, add getter for PadTemplate, add PadTemplateTest (#105)
1 parent fbe01e8 commit 32b74a8

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed

src/org/freedesktop/gstreamer/Pad.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,4 +678,15 @@ public FlowReturn pullRange(long offset, int size, Buffer[] buffer) {
678678
public FlowReturn push(final Buffer buffer) {
679679
return GSTPAD_API.gst_pad_push(this, buffer);
680680
}
681+
682+
/**
683+
* Gets the template for pad.
684+
*
685+
* @return the GstPadTemplate from which this pad was instantiated,
686+
* or NULL if this pad has no template. Unref after usage.
687+
*/
688+
public PadTemplate getTemplate() {
689+
return GSTPAD_API.gst_pad_get_pad_template(this);
690+
}
691+
681692
}

src/org/freedesktop/gstreamer/PadTemplate.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
package org.freedesktop.gstreamer;
2323

24+
import org.freedesktop.gstreamer.lowlevel.GstPadTemplateAPI;
2425
import static org.freedesktop.gstreamer.lowlevel.GstPadTemplateAPI.GSTPADTEMPLATE_API;
2526

2627
/**
@@ -79,4 +80,39 @@ public PadTemplate(String nameTemplate, PadDirection direction, PadPresence pres
7980
public Caps getCaps() {
8081
return GSTPADTEMPLATE_API.gst_pad_template_get_caps(this);
8182
}
83+
84+
/**
85+
* Gets the name of this template
86+
*
87+
* @return the name of this template
88+
*/
89+
public String getTemplateName() {
90+
return get("name-template").toString();
91+
}
92+
93+
/**
94+
* Gets the direction of this template
95+
*
96+
* @return {@link PadDirection}
97+
*/
98+
public PadDirection getDirection() {
99+
Object d = get("direction");
100+
if (d instanceof Number) {
101+
return PadDirection.values()[((Number) d).intValue()];
102+
}
103+
return null;
104+
}
105+
106+
/**
107+
* Gets presence of this template
108+
*
109+
* @return {@link PadPresence}
110+
*/
111+
public PadPresence getPresence() {
112+
Object p = get("presence");
113+
if (p instanceof Number) {
114+
return PadPresence.values()[((Number) p).intValue()];
115+
}
116+
return null;
117+
}
82118
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* This file is part of gstreamer-java.
3+
*
4+
* gstreamer-java is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Lesser General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* gstreamer-java is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public License
15+
* along with gstreamer-java. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package org.freedesktop.gstreamer;
19+
20+
import org.junit.After;
21+
import org.junit.AfterClass;
22+
import static org.junit.Assert.assertEquals;
23+
import org.junit.Before;
24+
import org.junit.BeforeClass;
25+
import org.junit.Test;
26+
27+
/**
28+
*
29+
* @author inx
30+
*/
31+
public class PadTemplateTest {
32+
33+
@BeforeClass
34+
public static void setUpClass() throws Exception {
35+
Gst.init("test", new String[] {});
36+
}
37+
38+
@AfterClass
39+
public static void tearDownClass() throws Exception {
40+
Gst.deinit();
41+
}
42+
43+
@Before
44+
public void setUp() throws Exception {
45+
}
46+
47+
@After
48+
public void tearDown() throws Exception {
49+
}
50+
51+
@Test
52+
public void padTemplate()
53+
throws Exception
54+
{
55+
Element src = ElementFactory.make("fakesrc", "src");
56+
Element sink = ElementFactory.make("fakesink", "sink");
57+
Pad srcPad = src.getStaticPad("src");
58+
Pad sinkPad = sink.getStaticPad("sink");
59+
PadTemplate template;
60+
61+
template = srcPad.getTemplate();
62+
assertEquals("wrong name!", template.getTemplateName(), "src");
63+
assertEquals("wrong direction!", template.getDirection(), PadDirection.SRC);
64+
assertEquals("wrong presence!", template.getPresence(), PadPresence.ALWAYS);
65+
66+
template = sinkPad.getTemplate();
67+
assertEquals("wrong name!", template.getTemplateName(), "sink");
68+
assertEquals("wrong direction!", template.getDirection(), PadDirection.SINK);
69+
assertEquals("wrong presence!", template.getPresence(), PadPresence.ALWAYS);
70+
}
71+
}

0 commit comments

Comments
 (0)