QtGStreamer  0.10.2
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
query.cpp
00001 /*
00002     Copyright (C) 2010  Collabora Multimedia.
00003       @author Mauricio Piacentini <mauricio.piacentini@collabora.co.uk>
00004 
00005     This library is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU Lesser General Public License as published
00007     by the Free Software Foundation; either version 2.1 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU Lesser General Public License for more details.
00014 
00015     You should have received a copy of the GNU Lesser General Public License
00016     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017 */
00018 #include "query.h"
00019 #include "element.h"
00020 #include "../QGlib/error.h"
00021 #include "../QGlib/string_p.h"
00022 #include <QtCore/QUrl>
00023 #include <QtCore/QDebug>
00024 #include <gst/gst.h>
00025 
00026 namespace QGst {
00027 
00028 QString Query::typeName() const
00029 {
00030     return QString::fromUtf8(GST_QUERY_TYPE_NAME(object<GstQuery>()));
00031 }
00032 
00033 QueryType Query::type() const
00034 {
00035     return static_cast<QueryType>(GST_QUERY_TYPE(object<GstQuery>()));
00036 }
00037 
00038 StructurePtr Query::internalStructure()
00039 {
00040     GstStructure *structure = gst_query_get_structure(object<GstQuery>());
00041     return SharedStructure::fromMiniObject(structure, MiniObjectPtr(this));
00042 }
00043 
00044 //********************************************************
00045 
00046 PositionQueryPtr PositionQuery::create(Format format)
00047 {
00048     return PositionQueryPtr::wrap(gst_query_new_position(static_cast<GstFormat>(format)), false);
00049 }
00050 
00051 Format PositionQuery::format() const
00052 {
00053     GstFormat f;
00054     gst_query_parse_position(object<GstQuery>(), &f, NULL);
00055     return static_cast<Format>(f);
00056 }
00057 
00058 qint64 PositionQuery::position() const
00059 {
00060     gint64 p;
00061     gst_query_parse_position(object<GstQuery>(), NULL, &p);
00062     return p;
00063 }
00064 
00065 void PositionQuery::setValues(Format format, qint64 position)
00066 {
00067     gst_query_set_position(object<GstQuery>(), static_cast<GstFormat>(format), position);
00068 }
00069 
00070 //********************************************************
00071 
00072 DurationQueryPtr DurationQuery::create(Format format)
00073 {
00074     return DurationQueryPtr::wrap(gst_query_new_duration(static_cast<GstFormat>(format)), false);
00075 }
00076 
00077 Format DurationQuery::format() const
00078 {
00079     GstFormat f;
00080     gst_query_parse_duration(object<GstQuery>(), &f, NULL);
00081     return static_cast<Format>(f);
00082 }
00083 
00084 qint64 DurationQuery::duration() const
00085 {
00086     gint64 d;
00087     gst_query_parse_duration(object<GstQuery>(), NULL, &d);
00088     return d;
00089 }
00090 
00091 void DurationQuery::setValues(Format format, qint64 duration)
00092 {
00093     gst_query_set_duration(object<GstQuery>(), static_cast<GstFormat>(format), duration);
00094 }
00095 
00096 //********************************************************
00097 
00098 LatencyQueryPtr LatencyQuery::create()
00099 {
00100     return LatencyQueryPtr::wrap(gst_query_new_latency(), false);
00101 }
00102 
00103 bool LatencyQuery::hasLive() const
00104 {
00105     gboolean l;
00106     gst_query_parse_latency(object<GstQuery>(), &l, NULL, NULL);
00107     return l;
00108 }
00109 
00110 ClockTime LatencyQuery::minimumLatency() const
00111 {
00112     GstClockTime c;
00113     gst_query_parse_latency(object<GstQuery>(), NULL, &c, NULL);
00114     return c;
00115 }
00116 
00117 ClockTime LatencyQuery::maximumLatency() const
00118 {
00119     GstClockTime c;
00120     gst_query_parse_latency(object<GstQuery>(), NULL, NULL, &c);
00121     return c;
00122 }
00123 
00124 void LatencyQuery::setValues(bool live, ClockTime minimumLatency, ClockTime maximumLatency)
00125 {
00126     gst_query_set_latency(object<GstQuery>(), live, minimumLatency, maximumLatency);
00127 }
00128 
00129 //********************************************************
00130 
00131 SeekingQueryPtr SeekingQuery::create(Format format)
00132 {
00133     return SeekingQueryPtr::wrap(gst_query_new_seeking(static_cast<GstFormat>(format)), false);
00134 }
00135 
00136 Format SeekingQuery::format() const
00137 {
00138     GstFormat f;
00139     gst_query_parse_seeking(object<GstQuery>(), &f, NULL, NULL, NULL);
00140     return static_cast<Format>(f);
00141 }
00142 
00143 bool SeekingQuery::seekable() const
00144 {
00145     gboolean s;
00146     gst_query_parse_seeking(object<GstQuery>(), NULL, &s, NULL, NULL);
00147     return s;
00148 }
00149 
00150 qint64 SeekingQuery::segmentStart() const
00151 {
00152     gint64 s;
00153     gst_query_parse_seeking(object<GstQuery>(), NULL, NULL, &s, NULL);
00154     return s;
00155 }
00156 
00157 qint64 SeekingQuery::segmentEnd() const
00158 {
00159     gint64 s;
00160     gst_query_parse_seeking(object<GstQuery>(), NULL, NULL, NULL, &s);
00161     return s;
00162 }
00163 
00164 void SeekingQuery::setValues(Format format, bool seekable, qint64 segmentStart, qint64 segmentEnd)
00165 {
00166     gst_query_set_seeking(object<GstQuery>(), static_cast<GstFormat>(format), seekable,
00167                           segmentStart, segmentEnd);
00168 }
00169 
00170 //********************************************************
00171 
00172 SegmentQueryPtr SegmentQuery::create(Format format)
00173 {
00174     return SegmentQueryPtr::wrap(gst_query_new_segment(static_cast<GstFormat>(format)), false);
00175 }
00176 
00177 double SegmentQuery::rate() const
00178 {
00179     gdouble r;
00180     gst_query_parse_segment(object<GstQuery>(), &r, NULL, NULL, NULL);
00181     return r;
00182 }
00183 
00184 Format SegmentQuery::format() const
00185 {
00186     GstFormat f;
00187     gst_query_parse_segment(object<GstQuery>(), NULL, &f, NULL, NULL);
00188     return static_cast<Format>(f);
00189 }
00190 
00191 qint64 SegmentQuery::startValue() const
00192 {
00193     gint64 s;
00194     gst_query_parse_segment(object<GstQuery>(), NULL, NULL, &s, NULL);
00195     return s;
00196 }
00197 
00198 qint64 SegmentQuery::stopValue() const
00199 {
00200     gint64 s;
00201     gst_query_parse_segment(object<GstQuery>(), NULL, NULL, NULL, &s);
00202     return s;
00203 }
00204 
00205 void SegmentQuery::setValues(Format format, double rate, qint64 startValue, qint64 stopValue)
00206 {
00207     gst_query_set_segment(object<GstQuery>(), rate, static_cast<GstFormat>(format), startValue,
00208                           stopValue);
00209 }
00210 
00211 //********************************************************
00212 
00213 ConvertQueryPtr ConvertQuery::create(Format sourceFormat, qint64 value, Format destinationFormat)
00214 {
00215     return ConvertQueryPtr::wrap(gst_query_new_convert(static_cast<GstFormat>(sourceFormat), value,
00216                                    static_cast<GstFormat>(destinationFormat)), false);
00217 }
00218 
00219 Format ConvertQuery::sourceFormat() const
00220 {
00221     GstFormat f;
00222     gst_query_parse_convert(object<GstQuery>(), &f, NULL, NULL, NULL);
00223     return static_cast<Format>(f);
00224 }
00225 
00226 qint64 ConvertQuery::sourceValue() const
00227 {
00228     gint64 v;
00229     gst_query_parse_convert(object<GstQuery>(), NULL, &v, NULL, NULL);
00230     return v;
00231 }
00232 
00233 Format ConvertQuery::destinationFormat() const
00234 {
00235     GstFormat f;
00236     gst_query_parse_convert(object<GstQuery>(), NULL, NULL, &f, NULL);
00237     return static_cast<Format>(f);
00238 }
00239 
00240 qint64 ConvertQuery::destinationValue() const
00241 {
00242     gint64 v;
00243     gst_query_parse_convert(object<GstQuery>(), NULL, NULL, NULL, &v);
00244     return v;
00245 }
00246 
00247 void ConvertQuery::setValues(Format sourceFormat, qint64 sourceValue, Format destinationFormat,
00248                               qint64 destinationValue)
00249 {
00250     gst_query_set_convert(object<GstQuery>(), static_cast<GstFormat>(sourceFormat), sourceValue,
00251                           static_cast<GstFormat>(destinationFormat), destinationValue);
00252 }
00253 
00254 //********************************************************
00255 
00256 FormatsQueryPtr FormatsQuery::create()
00257 {
00258     return FormatsQueryPtr::wrap(gst_query_new_formats(), false);
00259 }
00260 
00261 QList<Format> FormatsQuery::formats() const
00262 {
00263     guint cnt;
00264     QList<Format> formats;
00265     gst_query_parse_formats_length(object<GstQuery>(), &cnt);
00266     GstFormat f;
00267     for (uint i=0; i<cnt; i++) {
00268         gst_query_parse_formats_nth(object<GstQuery>(), i, &f);
00269         formats << static_cast<Format>(f);
00270     }
00271     return formats;
00272 }
00273 
00274 void FormatsQuery::setFormats(const QList<Format> & formats)
00275 {
00276     int cnt = formats.count();
00277     if (cnt==0) return;
00278     GstFormat *f = new GstFormat[cnt];
00279     for (int i=0; i<cnt; i++) {
00280         f[i] = static_cast<GstFormat>(formats.at(i));
00281     }
00282     gst_query_set_formatsv(object<GstQuery>(), cnt, f);
00283     delete [] f;
00284 }
00285 
00286 //********************************************************
00287 
00288 BufferingQueryPtr BufferingQuery::create(Format format)
00289 {
00290     return BufferingQueryPtr::wrap(gst_query_new_buffering(static_cast<GstFormat>(format)), false);
00291 }
00292 
00293 bool BufferingQuery::isBusy() const
00294 {
00295     gboolean b;
00296     gst_query_parse_buffering_percent(object<GstQuery>(), &b, NULL);
00297     return b;
00298 }
00299 
00300 int BufferingQuery::percent() const
00301 {
00302     gint p;
00303     gst_query_parse_buffering_percent(object<GstQuery>(), NULL, &p);
00304     return p;
00305 }
00306 
00307 void BufferingQuery::setBufferingPercent(bool busy, int percent)
00308 {
00309     gst_query_set_buffering_percent(object<GstQuery>(), busy, percent);
00310 }
00311 
00312 BufferingMode BufferingQuery::mode() const
00313 {
00314     GstBufferingMode m;
00315     gst_query_parse_buffering_stats(object<GstQuery>(), &m, NULL, NULL, NULL);
00316     return static_cast<BufferingMode>(m);
00317 }
00318 
00319 int BufferingQuery::averageIn() const
00320 {
00321     gint a;
00322     gst_query_parse_buffering_stats(object<GstQuery>(), NULL, &a, NULL, NULL);
00323     return a;
00324 }
00325 
00326 int BufferingQuery::averageOut() const
00327 {
00328     gint a;
00329     gst_query_parse_buffering_stats(object<GstQuery>(), NULL, NULL, &a, NULL);
00330     return a;
00331 
00332 }
00333 
00334 qint64 BufferingQuery::bufferingLeft() const
00335 {
00336     gint64 l;
00337     gst_query_parse_buffering_stats(object<GstQuery>(), NULL, NULL, NULL, &l);
00338     return l;
00339 }
00340 ;
00341 void BufferingQuery::setBufferingStats(BufferingMode mode, int averageIn,
00342                                        int averageOut, qint64 bufferingLeft)
00343 {
00344     gst_query_set_buffering_stats(object<GstQuery>(), static_cast<GstBufferingMode>(mode),
00345                                   averageIn, averageOut, bufferingLeft);
00346 }
00347 
00348 Format BufferingQuery::rangeFormat() const
00349 {
00350     GstFormat f;
00351     gst_query_parse_buffering_range(object<GstQuery>(), &f, NULL, NULL, NULL);
00352     return static_cast<Format>(f);
00353 }
00354 
00355 qint64 BufferingQuery::rangeStart() const
00356 {
00357     gint64 r;
00358     gst_query_parse_buffering_range(object<GstQuery>(), NULL, &r, NULL, NULL);
00359     return r;
00360 }
00361 
00362 qint64 BufferingQuery::rangeStop() const
00363 {
00364     gint64 r;
00365     gst_query_parse_buffering_range(object<GstQuery>(), NULL, NULL, &r, NULL);
00366     return r;
00367 }
00368 
00369 qint64 BufferingQuery::estimatedTotal() const
00370 {
00371     gint64 r;
00372     gst_query_parse_buffering_range(object<GstQuery>(), NULL, NULL, NULL, &r);
00373     return r;
00374 }
00375 
00376 void BufferingQuery::setBufferingRange(Format rangeFormat, qint64 rangeStart,
00377                                        qint64 rangeStop, qint64 estimatedTotal)
00378 {
00379     gst_query_set_buffering_range(object<GstQuery>(), static_cast<GstFormat>(rangeFormat),
00380                                   rangeStart, rangeStop, estimatedTotal);
00381 }
00382 
00383 //********************************************************
00384 
00385 UriQueryPtr UriQuery::create()
00386 {
00387     return UriQueryPtr::wrap(gst_query_new_uri(), false);
00388 }
00389 
00390 QUrl UriQuery::uri() const
00391 {
00392     gchar *uri;
00393     gst_query_parse_uri(object<GstQuery>(), &uri);
00394     return QUrl::fromPercentEncoding(uri);
00395 }
00396 
00397 void UriQuery::setUri(const QUrl & uri)
00398 {
00399     gst_query_set_uri(object<GstQuery>(), uri.toEncoded());
00400 }
00401 
00402 } //namespace QGst