QtGStreamer 1.2.0
Loading...
Searching...
No Matches
query.cpp
1/*
2 Copyright (C) 2010 Collabora Multimedia.
3 @author Mauricio Piacentini <mauricio.piacentini@collabora.co.uk>
4
5 This library is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published
7 by the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18#include "query.h"
19#include "element.h"
20#include "../QGlib/error.h"
21#include "../QGlib/string_p.h"
22#include <QtCore/QUrl>
23#include <QtCore/QDebug>
24#include <gst/gst.h>
25
26namespace QGst {
27
28QString Query::typeName() const
29{
30 return QString::fromUtf8(GST_QUERY_TYPE_NAME(object<GstQuery>()));
31}
32
33QueryType Query::type() const
34{
35 return static_cast<QueryType>(GST_QUERY_TYPE(object<GstQuery>()));
36}
37
38StructureConstPtr Query::internalStructure()
39{
40 const GstStructure *structure = gst_query_get_structure(object<GstQuery>());
41 return SharedStructure::fromMiniObject(const_cast<GstStructure *>(structure), MiniObjectPtr(this));
42}
43
44//********************************************************
45
46PositionQueryPtr PositionQuery::create(Format format)
47{
48 return PositionQueryPtr::wrap(gst_query_new_position(static_cast<GstFormat>(format)), false);
49}
50
51Format PositionQuery::format() const
52{
53 GstFormat f;
54 gst_query_parse_position(object<GstQuery>(), &f, NULL);
55 return static_cast<Format>(f);
56}
57
58qint64 PositionQuery::position() const
59{
60 gint64 p;
61 gst_query_parse_position(object<GstQuery>(), NULL, &p);
62 return p;
63}
64
65void PositionQuery::setValues(Format format, qint64 position)
66{
67 gst_query_set_position(object<GstQuery>(), static_cast<GstFormat>(format), position);
68}
69
70//********************************************************
71
72DurationQueryPtr DurationQuery::create(Format format)
73{
74 return DurationQueryPtr::wrap(gst_query_new_duration(static_cast<GstFormat>(format)), false);
75}
76
77Format DurationQuery::format() const
78{
79 GstFormat f;
80 gst_query_parse_duration(object<GstQuery>(), &f, NULL);
81 return static_cast<Format>(f);
82}
83
84qint64 DurationQuery::duration() const
85{
86 gint64 d;
87 gst_query_parse_duration(object<GstQuery>(), NULL, &d);
88 return d;
89}
90
91void DurationQuery::setValues(Format format, qint64 duration)
92{
93 gst_query_set_duration(object<GstQuery>(), static_cast<GstFormat>(format), duration);
94}
95
96//********************************************************
97
98LatencyQueryPtr LatencyQuery::create()
99{
100 return LatencyQueryPtr::wrap(gst_query_new_latency(), false);
101}
102
103bool LatencyQuery::hasLive() const
104{
105 gboolean l;
106 gst_query_parse_latency(object<GstQuery>(), &l, NULL, NULL);
107 return l;
108}
109
110ClockTime LatencyQuery::minimumLatency() const
111{
112 GstClockTime c;
113 gst_query_parse_latency(object<GstQuery>(), NULL, &c, NULL);
114 return c;
115}
116
117ClockTime LatencyQuery::maximumLatency() const
118{
119 GstClockTime c;
120 gst_query_parse_latency(object<GstQuery>(), NULL, NULL, &c);
121 return c;
122}
123
124void LatencyQuery::setValues(bool live, ClockTime minimumLatency, ClockTime maximumLatency)
125{
126 gst_query_set_latency(object<GstQuery>(), live, minimumLatency, maximumLatency);
127}
128
129//********************************************************
130
131SeekingQueryPtr SeekingQuery::create(Format format)
132{
133 return SeekingQueryPtr::wrap(gst_query_new_seeking(static_cast<GstFormat>(format)), false);
134}
135
136Format SeekingQuery::format() const
137{
138 GstFormat f;
139 gst_query_parse_seeking(object<GstQuery>(), &f, NULL, NULL, NULL);
140 return static_cast<Format>(f);
141}
142
143bool SeekingQuery::seekable() const
144{
145 gboolean s;
146 gst_query_parse_seeking(object<GstQuery>(), NULL, &s, NULL, NULL);
147 return s;
148}
149
150qint64 SeekingQuery::segmentStart() const
151{
152 gint64 s;
153 gst_query_parse_seeking(object<GstQuery>(), NULL, NULL, &s, NULL);
154 return s;
155}
156
157qint64 SeekingQuery::segmentEnd() const
158{
159 gint64 s;
160 gst_query_parse_seeking(object<GstQuery>(), NULL, NULL, NULL, &s);
161 return s;
162}
163
164void SeekingQuery::setValues(Format format, bool seekable, qint64 segmentStart, qint64 segmentEnd)
165{
166 gst_query_set_seeking(object<GstQuery>(), static_cast<GstFormat>(format), seekable,
167 segmentStart, segmentEnd);
168}
169
170//********************************************************
171
172SegmentQueryPtr SegmentQuery::create(Format format)
173{
174 return SegmentQueryPtr::wrap(gst_query_new_segment(static_cast<GstFormat>(format)), false);
175}
176
177double SegmentQuery::rate() const
178{
179 gdouble r;
180 gst_query_parse_segment(object<GstQuery>(), &r, NULL, NULL, NULL);
181 return r;
182}
183
184Format SegmentQuery::format() const
185{
186 GstFormat f;
187 gst_query_parse_segment(object<GstQuery>(), NULL, &f, NULL, NULL);
188 return static_cast<Format>(f);
189}
190
191qint64 SegmentQuery::startValue() const
192{
193 gint64 s;
194 gst_query_parse_segment(object<GstQuery>(), NULL, NULL, &s, NULL);
195 return s;
196}
197
198qint64 SegmentQuery::stopValue() const
199{
200 gint64 s;
201 gst_query_parse_segment(object<GstQuery>(), NULL, NULL, NULL, &s);
202 return s;
203}
204
205void SegmentQuery::setValues(Format format, double rate, qint64 startValue, qint64 stopValue)
206{
207 gst_query_set_segment(object<GstQuery>(), rate, static_cast<GstFormat>(format), startValue,
208 stopValue);
209}
210
211//********************************************************
212
213ConvertQueryPtr ConvertQuery::create(Format sourceFormat, qint64 value, Format destinationFormat)
214{
215 return ConvertQueryPtr::wrap(gst_query_new_convert(static_cast<GstFormat>(sourceFormat), value,
216 static_cast<GstFormat>(destinationFormat)), false);
217}
218
219Format ConvertQuery::sourceFormat() const
220{
221 GstFormat f;
222 gst_query_parse_convert(object<GstQuery>(), &f, NULL, NULL, NULL);
223 return static_cast<Format>(f);
224}
225
226qint64 ConvertQuery::sourceValue() const
227{
228 gint64 v;
229 gst_query_parse_convert(object<GstQuery>(), NULL, &v, NULL, NULL);
230 return v;
231}
232
233Format ConvertQuery::destinationFormat() const
234{
235 GstFormat f;
236 gst_query_parse_convert(object<GstQuery>(), NULL, NULL, &f, NULL);
237 return static_cast<Format>(f);
238}
239
240qint64 ConvertQuery::destinationValue() const
241{
242 gint64 v;
243 gst_query_parse_convert(object<GstQuery>(), NULL, NULL, NULL, &v);
244 return v;
245}
246
247void ConvertQuery::setValues(Format sourceFormat, qint64 sourceValue, Format destinationFormat,
248 qint64 destinationValue)
249{
250 gst_query_set_convert(object<GstQuery>(), static_cast<GstFormat>(sourceFormat), sourceValue,
251 static_cast<GstFormat>(destinationFormat), destinationValue);
252}
253
254//********************************************************
255
256FormatsQueryPtr FormatsQuery::create()
257{
258 return FormatsQueryPtr::wrap(gst_query_new_formats(), false);
259}
260
261QList<Format> FormatsQuery::formats() const
262{
263 guint cnt;
264 QList<Format> formats;
265 gst_query_parse_n_formats(object<GstQuery>(), &cnt);
266 GstFormat f;
267 for (uint i=0; i<cnt; i++) {
268 gst_query_parse_nth_format(object<GstQuery>(), i, &f);
269 formats << static_cast<Format>(f);
270 }
271 return formats;
272}
273
274void FormatsQuery::setFormats(const QList<Format> & formats)
275{
276 int cnt = formats.count();
277 if (cnt==0) return;
278 GstFormat *f = new GstFormat[cnt];
279 for (int i=0; i<cnt; i++) {
280 f[i] = static_cast<GstFormat>(formats.at(i));
281 }
282 gst_query_set_formatsv(object<GstQuery>(), cnt, f);
283 delete [] f;
284}
285
286//********************************************************
287
288BufferingQueryPtr BufferingQuery::create(Format format)
289{
290 return BufferingQueryPtr::wrap(gst_query_new_buffering(static_cast<GstFormat>(format)), false);
291}
292
293bool BufferingQuery::isBusy() const
294{
295 gboolean b;
296 gst_query_parse_buffering_percent(object<GstQuery>(), &b, NULL);
297 return b;
298}
299
300int BufferingQuery::percent() const
301{
302 gint p;
303 gst_query_parse_buffering_percent(object<GstQuery>(), NULL, &p);
304 return p;
305}
306
307void BufferingQuery::setBufferingPercent(bool busy, int percent)
308{
309 gst_query_set_buffering_percent(object<GstQuery>(), busy, percent);
310}
311
312BufferingMode BufferingQuery::mode() const
313{
314 GstBufferingMode m;
315 gst_query_parse_buffering_stats(object<GstQuery>(), &m, NULL, NULL, NULL);
316 return static_cast<BufferingMode>(m);
317}
318
319int BufferingQuery::averageIn() const
320{
321 gint a;
322 gst_query_parse_buffering_stats(object<GstQuery>(), NULL, &a, NULL, NULL);
323 return a;
324}
325
326int BufferingQuery::averageOut() const
327{
328 gint a;
329 gst_query_parse_buffering_stats(object<GstQuery>(), NULL, NULL, &a, NULL);
330 return a;
331
332}
333
334qint64 BufferingQuery::bufferingLeft() const
335{
336 gint64 l;
337 gst_query_parse_buffering_stats(object<GstQuery>(), NULL, NULL, NULL, &l);
338 return l;
339}
340;
341void BufferingQuery::setBufferingStats(BufferingMode mode, int averageIn,
342 int averageOut, qint64 bufferingLeft)
343{
344 gst_query_set_buffering_stats(object<GstQuery>(), static_cast<GstBufferingMode>(mode),
345 averageIn, averageOut, bufferingLeft);
346}
347
348Format BufferingQuery::rangeFormat() const
349{
350 GstFormat f;
351 gst_query_parse_buffering_range(object<GstQuery>(), &f, NULL, NULL, NULL);
352 return static_cast<Format>(f);
353}
354
355qint64 BufferingQuery::rangeStart() const
356{
357 gint64 r;
358 gst_query_parse_buffering_range(object<GstQuery>(), NULL, &r, NULL, NULL);
359 return r;
360}
361
362qint64 BufferingQuery::rangeStop() const
363{
364 gint64 r;
365 gst_query_parse_buffering_range(object<GstQuery>(), NULL, NULL, &r, NULL);
366 return r;
367}
368
369qint64 BufferingQuery::estimatedTotal() const
370{
371 gint64 r;
372 gst_query_parse_buffering_range(object<GstQuery>(), NULL, NULL, NULL, &r);
373 return r;
374}
375
376void BufferingQuery::setBufferingRange(Format rangeFormat, qint64 rangeStart,
377 qint64 rangeStop, qint64 estimatedTotal)
378{
379 gst_query_set_buffering_range(object<GstQuery>(), static_cast<GstFormat>(rangeFormat),
380 rangeStart, rangeStop, estimatedTotal);
381}
382
383//********************************************************
384
385UriQueryPtr UriQuery::create()
386{
387 return UriQueryPtr::wrap(gst_query_new_uri(), false);
388}
389
390QUrl UriQuery::uri() const
391{
392 gchar *uri;
393 gst_query_parse_uri(object<GstQuery>(), &uri);
394 return QUrl::fromPercentEncoding(uri);
395}
396
397void UriQuery::setUri(const QUrl & uri)
398{
399 gst_query_set_uri(object<GstQuery>(), uri.toEncoded());
400}
401
402} //namespace QGst
static RefPointer< T > wrap(typename T::CType *nativePtr, bool increaseRef=true)
Definition refpointer.h:328
Wrappers for GStreamer classes.