From 75b39d2e829774c932d25f1806ed9b7865e28c8b Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Sun, 9 Jun 2019 23:47:15 +0200 Subject: [PATCH 1/4] Structure: Add Accessor for GstValueList Fields --- src/org/freedesktop/gstreamer/Structure.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/org/freedesktop/gstreamer/Structure.java b/src/org/freedesktop/gstreamer/Structure.java index 478b6ee9..ae98897c 100644 --- a/src/org/freedesktop/gstreamer/Structure.java +++ b/src/org/freedesktop/gstreamer/Structure.java @@ -210,7 +210,22 @@ public double[] getDoubles(String fieldName, double[] array) { } } } - + + public List getValueList(String fieldName) { + GValue val = GSTSTRUCTURE_API.gst_structure_get_value(this, fieldName); + if(!val.g_type.equals(GSTVALUE_API.gst_value_list_get_type())) { + return null; + } + + int size = GSTVALUE_API.gst_value_list_get_size(val); + ArrayList values = new ArrayList<>(size); + for (int i = 0; i Date: Mon, 10 Jun 2019 12:49:36 +0200 Subject: [PATCH 2/4] StructureTest: Add Tests for accessing ValueLists --- test/org/freedesktop/gstreamer/StructureTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/org/freedesktop/gstreamer/StructureTest.java b/test/org/freedesktop/gstreamer/StructureTest.java index 3cf5d816..74914608 100644 --- a/test/org/freedesktop/gstreamer/StructureTest.java +++ b/test/org/freedesktop/gstreamer/StructureTest.java @@ -1,5 +1,6 @@ package org.freedesktop.gstreamer; +import java.util.Arrays; import java.util.List; import static org.junit.Assert.*; @@ -151,4 +152,18 @@ public void testFraction() { assertEquals(17, structure.getFraction("fraction").getNumerator()); assertEquals(10, structure.getFraction("fraction").getDenominator()); } + + @Test + public void testValueListInteger() { + Caps caps = Caps.fromString("audio/x-raw,rate={44100,48000}"); + List rates = caps.getStructure(0).getValueList("rate"); + assertEquals(Arrays.asList(44100, 48000), rates); + } + + @Test + public void testValueListStrings() { + Caps caps = Caps.fromString("video/x-raw,format={RGB, BGR, RGBx, BGRx}"); + List formats = caps.getStructure(0).getValueList("format"); + assertEquals(Arrays.asList("RGB", "BGR", "RGBx","BGRx"), formats); + } } From b06686b4ed4d887c6fd286ddd1e8bc45264dec89 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Mon, 10 Jun 2019 13:48:52 +0200 Subject: [PATCH 3/4] Structure: Move Code to access ValueList into getValues() --- src/org/freedesktop/gstreamer/Structure.java | 51 +++++++++++-------- .../freedesktop/gstreamer/StructureTest.java | 39 ++++++++------ 2 files changed, 52 insertions(+), 38 deletions(-) diff --git a/src/org/freedesktop/gstreamer/Structure.java b/src/org/freedesktop/gstreamer/Structure.java index ae98897c..0daa13f3 100644 --- a/src/org/freedesktop/gstreamer/Structure.java +++ b/src/org/freedesktop/gstreamer/Structure.java @@ -21,17 +21,18 @@ import com.sun.jna.Pointer; import com.sun.jna.ptr.PointerByReference; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.freedesktop.gstreamer.lowlevel.GType; -import org.freedesktop.gstreamer.lowlevel.GValueAPI; import org.freedesktop.gstreamer.glib.NativeObject; import org.freedesktop.gstreamer.glib.Natives; import org.freedesktop.gstreamer.lowlevel.GPointer; +import org.freedesktop.gstreamer.lowlevel.GType; +import org.freedesktop.gstreamer.lowlevel.GValueAPI; import org.freedesktop.gstreamer.lowlevel.GValueAPI.GValue; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import static org.freedesktop.gstreamer.lowlevel.GValueAPI.GVALUE_API; import static org.freedesktop.gstreamer.lowlevel.GstStructureAPI.GSTSTRUCTURE_API; import static org.freedesktop.gstreamer.lowlevel.GstValueAPI.GSTVALUE_API; @@ -211,21 +212,6 @@ public double[] getDoubles(String fieldName, double[] array) { } } - public List getValueList(String fieldName) { - GValue val = GSTSTRUCTURE_API.gst_structure_get_value(this, fieldName); - if(!val.g_type.equals(GSTVALUE_API.gst_value_list_get_type())) { - return null; - } - - int size = GSTVALUE_API.gst_value_list_get_size(val); - ArrayList values = new ArrayList<>(size); - for (int i = 0; i List getValues(Class type, String fieldName) { - Object val = getValue(fieldName); + GValue gValue = GSTSTRUCTURE_API.gst_structure_get_value(this, fieldName); + if (gValue == null) { + throw new InvalidFieldException(type.getSimpleName(), fieldName); + } + + GType gType = gValue.getType(); + if (gType.equals(GSTVALUE_API.gst_value_list_get_type())) { + int size = GSTVALUE_API.gst_value_list_get_size(gValue); + ArrayList values = new ArrayList<>(size); + for (int i = 0; i rates = caps.getStructure(0).getValueList("rate"); - assertEquals(Arrays.asList(44100, 48000), rates); - } + @Test + public void testValueListInteger() { + Caps caps = Caps.fromString("audio/x-raw,rate={44100,48000}"); + List rates = caps.getStructure(0).getValues(Integer.class, "rate"); + assertEquals(Arrays.asList(44100, 48000), rates); + } - @Test - public void testValueListStrings() { - Caps caps = Caps.fromString("video/x-raw,format={RGB, BGR, RGBx, BGRx}"); - List formats = caps.getStructure(0).getValueList("format"); - assertEquals(Arrays.asList("RGB", "BGR", "RGBx","BGRx"), formats); - } + @Test + public void testValueListStrings() { + Caps caps = Caps.fromString("video/x-raw,format={RGB, BGR, RGBx, BGRx}"); + List formats = caps.getStructure(0).getValues(String.class, "format"); + assertEquals(Arrays.asList("RGB", "BGR", "RGBx","BGRx"), formats); + } + + @Test(expected = Structure.InvalidFieldException.class) + public void testValueListChecksType() { + Caps caps = Caps.fromString("video/x-raw,format={RGB, BGR, RGBx, BGRx}"); + caps.getStructure(0).getValues(Integer.class, "format"); + } } From 9f2c065d681bbb043f025928d1821690f8cc5ff4 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Mon, 10 Jun 2019 17:03:03 +0200 Subject: [PATCH 4/4] Structure: Update Javadoc --- src/org/freedesktop/gstreamer/Structure.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/org/freedesktop/gstreamer/Structure.java b/src/org/freedesktop/gstreamer/Structure.java index 0daa13f3..03128af5 100644 --- a/src/org/freedesktop/gstreamer/Structure.java +++ b/src/org/freedesktop/gstreamer/Structure.java @@ -436,8 +436,8 @@ public Object getValue(String fieldName) { * Throws {@link InvalidFieldException} if the field does not exist, or the * field values cannot be converted to type T. *

- * This method only currently supports lists of values inside a GValueArray - * - other native list types will be supported in future. + * This method currently supports lists of values inside a GValueArray or + * GstValueList. * * @param * @param type type of values