Skip to content

Commit 0ccb139

Browse files
Update and document org.freedesktop.gstreamer.query package.
1 parent 69664cb commit 0ccb139

File tree

14 files changed

+377
-258
lines changed

14 files changed

+377
-258
lines changed

src/org/freedesktop/gstreamer/lowlevel/GTypeMapper.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
public class GTypeMapper extends com.sun.jna.DefaultTypeMapper {
5252

5353
public GTypeMapper() {
54-
addTypeConverter(QueryType.class, querytypeConverter);
54+
// addTypeConverter(QueryType.class, querytypeConverter);
5555
addToNativeConverter(URI.class, uriConverter);
5656
addTypeConverter(ClockTime.class, clocktimeConverter);
5757
}
@@ -234,20 +234,20 @@ public Class<?> nativeType() {
234234
return Native.POINTER_SIZE == 8 ? Long.class : Integer.class;
235235
}
236236
};
237-
private TypeConverter querytypeConverter = new TypeConverter() {
238-
239-
public Object toNative(Object arg, ToNativeContext context) {
240-
return ((QueryType)arg).intValue();
241-
}
242-
243-
public Object fromNative(Object arg0, FromNativeContext arg1) {
244-
return QueryType.valueOf(((Number) arg0).intValue());
245-
}
246-
247-
public Class<?> nativeType() {
248-
return Integer.class;
249-
}
250-
};
237+
// private TypeConverter querytypeConverter = new TypeConverter() {
238+
//
239+
// public Object toNative(Object arg, ToNativeContext context) {
240+
// return ((QueryType)arg).intValue();
241+
// }
242+
//
243+
// public Object fromNative(Object arg0, FromNativeContext arg1) {
244+
// return QueryType.valueOf(((Number) arg0).intValue());
245+
// }
246+
//
247+
// public Class<?> nativeType() {
248+
// return Integer.class;
249+
// }
250+
// };
251251
private static ToNativeConverter uriConverter = new ToNativeConverter() {
252252

253253
public Object toNative(Object arg0, ToNativeContext arg1) {

src/org/freedesktop/gstreamer/lowlevel/GstQueryAPI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public static final class QueryStruct extends com.sun.jna.Structure {
109109
public volatile GstMiniObjectAPI.MiniObjectStruct mini_object;
110110

111111
/*< public > *//* with COW */
112-
public volatile int type;
112+
public volatile QueryType type;
113113

114114
public QueryStruct(Pointer ptr) {
115115
useMemory(ptr);

src/org/freedesktop/gstreamer/lowlevel/SubtypeMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static class MapHolder {
156156
}};
157157
public static Class<? extends NativeObject> subtypeFor(Pointer ptr) {
158158
GstQueryAPI.QueryStruct struct = new GstQueryAPI.QueryStruct(ptr);
159-
QueryType type = QueryType.valueOf((Integer) struct.readField("type"));
159+
QueryType type = (QueryType) struct.readField("type");
160160
Class<? extends Query> queryClass = typeMap.get(type);
161161
return queryClass != null ? queryClass : Query.class;
162162
}

src/org/freedesktop/gstreamer/query/AllocationQuery.java

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
* Copyright (c) 2019 Neil C Smith
23
* Copyright (c) 2016 Christophe Lafolet
34
*
45
* This file is part of gstreamer-java.
@@ -26,40 +27,76 @@
2627
import com.sun.jna.Pointer;
2728
import org.freedesktop.gstreamer.lowlevel.NativeObject;
2829

30+
/**
31+
* An allocation query for querying allocation properties.
32+
* <p>
33+
* See upstream documentation at
34+
* <a href="https://gstreamer.freedesktop.org/data/doc/gstreamer/stable/gstreamer/html/GstQuery.html#gst-query-new-allocation"
35+
* >https://gstreamer.freedesktop.org/data/doc/gstreamer/stable/gstreamer/html/GstQuery.html#gst-query-new-allocation</a>
36+
* <p>
37+
*
38+
*/
2939
public class AllocationQuery extends Query {
40+
3041
/**
3142
* This constructor is for internal use only.
43+
*
3244
* @param init initialization data.
3345
*/
34-
public AllocationQuery(Initializer init) {
35-
// special case : no ref shall be added
36-
// the allocationQuery is an in/out parameter during query notification
37-
// so, we shall keep query writable for add methods
38-
super(initializer(init.ptr, false, true));
46+
AllocationQuery(Initializer init) {
47+
// special case : no ref shall be added
48+
// the allocationQuery is an in/out parameter during query notification
49+
// so, we shall keep query writable for add methods
50+
super(initializer(init.ptr, false, true));
3951
}
4052

53+
/**
54+
* Create a new allocation query.
55+
*
56+
* @param caps the negotiated {@link Caps}
57+
* @param need_pool return a pool.
58+
*/
4159
public AllocationQuery(Caps caps, boolean need_pool) {
4260
this(initializer(GstQueryAPI.GSTQUERY_API.ptr_gst_query_new_allocation(caps, need_pool)));
4361
}
4462

63+
/**
64+
* Whether a {@link BufferPool} is needed.
65+
*
66+
* @return true if BufferPool needed
67+
*/
4568
public boolean isPoolNeeded() {
46-
boolean[] need_pool = {false};
47-
GstQueryAPI.GSTQUERY_API.gst_query_parse_allocation(this, null, need_pool);
48-
return need_pool[0];
69+
boolean[] need_pool = {false};
70+
GstQueryAPI.GSTQUERY_API.gst_query_parse_allocation(this, null, need_pool);
71+
return need_pool[0];
4972
}
5073

74+
/**
75+
* Get the requested {@link Caps}
76+
*
77+
* @return requested Caps
78+
*/
5179
public Caps getCaps() {
52-
Pointer[] ptr = new Pointer[1];
53-
GstQueryAPI.GSTQUERY_API.gst_query_parse_allocation(this, ptr, null);
80+
Pointer[] ptr = new Pointer[1];
81+
GstQueryAPI.GSTQUERY_API.gst_query_parse_allocation(this, ptr, null);
5482
// return new Caps(new Initializer(ptr[0], false, true));
5583
return NativeObject.objectFor(ptr[0], Caps.class, false, true);
5684
}
5785

58-
public void addAllocationMeta(GType api, Structure params) {
59-
GstQueryAPI.GSTQUERY_API.gst_query_add_allocation_meta(this, api, params);
86+
// @TODO how best not to expose GType?
87+
void addAllocationMeta(GType api, Structure params) {
88+
GstQueryAPI.GSTQUERY_API.gst_query_add_allocation_meta(this, api, params);
6089
}
6190

62-
public void addBufferPool(BufferPool pool, int size, int min_buffers, int max_buffers) {
63-
GstQueryAPI.GSTQUERY_API.gst_query_add_allocation_pool(this, pool, size, min_buffers, max_buffers);
91+
/**
92+
* Set the pool parameters of the query.
93+
*
94+
* @param pool the {@link BufferPool}
95+
* @param size the buffer size
96+
* @param min_buffers the min buffers
97+
* @param max_buffers the max buffers
98+
*/
99+
public void addAllocationPool(BufferPool pool, int size, int min_buffers, int max_buffers) {
100+
GstQueryAPI.GSTQUERY_API.gst_query_add_allocation_pool(this, pool, size, min_buffers, max_buffers);
64101
}
65102
}

src/org/freedesktop/gstreamer/query/ConvertQuery.java

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
* Copyright (C) 2019 Neil C Smith
23
* Copyright (C) 2008 Wayne Meissner
34
* Copyright (C) 1999,2000 Erik Walthinsen <[email protected]>
45
* 2000 Wim Taymans <[email protected]>
@@ -18,41 +19,86 @@
1819
* You should have received a copy of the GNU Lesser General Public License
1920
* version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
2021
*/
21-
2222
package org.freedesktop.gstreamer.query;
2323

2424
import org.freedesktop.gstreamer.Format;
2525
import org.freedesktop.gstreamer.lowlevel.GstQueryAPI;
2626

2727
/**
28-
* Convert values between formats
28+
* A convert query used to ask for a conversion between one format and another.
29+
* <p>
30+
* See upstream documentation at
31+
* <a href="https://gstreamer.freedesktop.org/data/doc/gstreamer/stable/gstreamer/html/GstQuery.html#gst-query-new-convert"
32+
* >https://gstreamer.freedesktop.org/data/doc/gstreamer/stable/gstreamer/html/GstQuery.html#gst-query-new-convert</a>
33+
* <p>
2934
*/
3035
public class ConvertQuery extends Query {
3136

32-
public ConvertQuery(Initializer init) {
37+
ConvertQuery(Initializer init) {
3338
super(init);
3439
}
40+
41+
/**
42+
* Construct a new convert query object.
43+
*
44+
* @param srcFormat the source {@link Format} for the new query
45+
* @param value the value to convert
46+
* @param destFormat the target {@link Format}
47+
*/
3548
public ConvertQuery(Format srcFormat, long value, Format destFormat) {
3649
this(initializer(GstQueryAPI.GSTQUERY_API.ptr_gst_query_new_convert(srcFormat, value, destFormat)));
3750
}
51+
52+
/**
53+
* Answer a convert query by setting the requested values.
54+
*
55+
* @param srcFormat the source {@link Format}
56+
* @param srcValue the source value
57+
* @param dstFormat the destination {@link Format}
58+
* @param dstValue the destination value
59+
*/
3860
public void setConvert(Format srcFormat, long srcValue, Format dstFormat, long dstValue) {
3961
GstQueryAPI.GSTQUERY_API.gst_query_set_convert(this, srcFormat, srcValue, dstFormat, dstValue);
4062
}
63+
64+
/**
65+
* Get the source {@link Format} of this query.
66+
*
67+
* @return source Format
68+
*/
4169
public Format getSourceFormat() {
4270
Format[] fmt = new Format[1];
4371
GstQueryAPI.GSTQUERY_API.gst_query_parse_convert(this, fmt, null, null, null);
4472
return fmt[0];
4573
}
74+
75+
/**
76+
* Get the destination {@link Format} of this query.
77+
*
78+
* @return destination Format
79+
*/
4680
public Format getDestinationFormat() {
4781
Format[] fmt = new Format[1];
4882
GstQueryAPI.GSTQUERY_API.gst_query_parse_convert(this, null, null, fmt, null);
4983
return fmt[0];
5084
}
85+
86+
/**
87+
* Get the source value of this query.
88+
*
89+
* @return source value
90+
*/
5191
public long getSourceValue() {
5292
long[] value = new long[1];
5393
GstQueryAPI.GSTQUERY_API.gst_query_parse_convert(this, null, value, null, null);
5494
return value[0];
5595
}
96+
97+
/**
98+
* Get the destination value of this query.
99+
*
100+
* @return destination value
101+
*/
56102
public long getDestinationValue() {
57103
long[] value = new long[1];
58104
GstQueryAPI.GSTQUERY_API.gst_query_parse_convert(this, null, null, null, value);

src/org/freedesktop/gstreamer/query/DurationQuery.java

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
* Copyright (C) 2019 Neil C Smith
23
* Copyright (C) 2008 Wayne Meissner
34
* Copyright (C) 1999,2000 Erik Walthinsen <[email protected]>
45
* 2000 Wim Taymans <[email protected]>
@@ -18,40 +19,50 @@
1819
* You should have received a copy of the GNU Lesser General Public License
1920
* version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
2021
*/
21-
2222
package org.freedesktop.gstreamer.query;
2323

2424
import org.freedesktop.gstreamer.Format;
2525
import org.freedesktop.gstreamer.lowlevel.GstQueryAPI;
2626

2727
/**
28-
* Used to query the total duration of a stream.
28+
* A duration query used to get the total length of a stream.
29+
* <p>
30+
* See upstream documentation at
31+
* <a href="https://gstreamer.freedesktop.org/data/doc/gstreamer/stable/gstreamer/html/GstQuery.html#gst-query-new-duration"
32+
* >https://gstreamer.freedesktop.org/data/doc/gstreamer/stable/gstreamer/html/GstQuery.html#gst-query-new-duration</a>
33+
* <p>
34+
* @see Format
2935
*/
3036
public class DurationQuery extends Query {
3137

32-
public DurationQuery(Initializer init) {
38+
DurationQuery(Initializer init) {
3339
super(init);
3440
}
41+
3542
/**
36-
* Constructs a new stream duration query object to query in the given format.
37-
* A duration query will give the total length of the stream.
38-
*
43+
* Constructs a new stream duration query object to query in the given
44+
* format. A duration query will give the total length of the stream.
45+
*
3946
* @param format the {@link Format} for this duration query.
4047
*/
4148
public DurationQuery(Format format) {
4249
super(initializer(GstQueryAPI.GSTQUERY_API.ptr_gst_query_new_duration(format)));
4350
}
51+
4452
/**
45-
* Answers a duration query by setting the requested value in the given format.
53+
* Answers a duration query by setting the requested value in the given
54+
* format.
55+
*
4656
* @param format the {@link Format} for the duration
4757
* @param duration the duration of the stream
4858
*/
4959
public void setDuration(Format format, long duration) {
5060
GstQueryAPI.GSTQUERY_API.gst_query_set_duration(this, format, duration);
5161
}
62+
5263
/**
5364
* Gets the format of this duration query.
54-
*
65+
*
5566
* @return The {@link Format} of the duration value.
5667
*/
5768
public Format getFormat() {
@@ -61,19 +72,20 @@ public Format getFormat() {
6172
}
6273

6374
/**
64-
* Gets the duration answer for this duration query.
65-
*
75+
* Gets the duration answer for this query, in the format available from
76+
* {@link #getFormat() }
77+
*
6678
* @return The total duration.
6779
*/
6880
public long getDuration() {
6981
long[] duration = new long[1];
7082
GstQueryAPI.GSTQUERY_API.gst_query_parse_duration(this, null, duration);
7183
return duration[0];
7284
}
73-
85+
7486
/**
7587
* Gets the duration as a user-readable string.
76-
*
88+
*
7789
* @return A string representing the duration.
7890
*/
7991
@Override

0 commit comments

Comments
 (0)