1/* gstreamermm - a C++ wrapper for gstreamer 2 * 3 * Copyright 2008 The gstreamermm Development Team 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2.1 of the License, or (at your option) any later version. 9 * 10 * This library 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 GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public 16 * License along with this library; if not, write to the Free 17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 */ 19 20#include <gst/gst.h> 21#include <gstreamermm/miniobject.h> 22#include <gstreamermm/structure.h> 23#include <gstreamermm/format.h> 24#include <gstreamermm/caps.h> 25#include <gstreamermm/pad.h> 26#include <gstreamermm/allocator.h> 27#include <glibmm/arrayhandle.h> 28 29_DEFS(gstreamermm,gst) 30 31namespace Glib 32{ 33 template<typename T> 34 Glib::RefPtr<T> wrap_query_derived(GstQuery* object, bool take_copy = false) 35 { 36 if(take_copy && object) 37 gst_query_ref(object); 38 39 // See the comment at the top of this file, if you want to know why the cast works. 40 return Glib::RefPtr<T>(reinterpret_cast<T*>(object)); 41 } 42} 43 44namespace Gst 45{ 46 47#define FLAG(name) GST_QUERY_TYPE_##name 48 49_WRAP_ENUM(BufferingMode, GstBufferingMode) 50_WRAP_ENUM(QueryType, GstQueryType) 51_WRAP_ENUM(QueryTypeFlags, GstQueryTypeFlags) 52_WRAP_ENUM(SchedulingFlags, GstSchedulingFlags) 53 54#undef FLAG 55 56namespace Enums 57{ 58 59/** Gets a printable name for the given query type. 60 * 61 * @param type The query type. 62 * @return The name of the query. 63 */ 64Glib::ustring get_name(QueryType type); 65_IGNORE(gst_query_type_get_name) 66 67/** Gets the Gst::QueryTypeFlags associated with @a type. 68 * 69 * @param type a Gst::QueryType. 70 * @return a Gst::QueryTypeFlags; 71 */ 72Gst::QueryTypeFlags get_flags(QueryType type); 73_IGNORE(gst_query_type_get_flags) 74 75/** Gets the unique quark for the given query type. 76 * 77 * @param type The query type. 78 * @return The quark associated with the query type. 79 */ 80Glib::QueryQuark get_quark(QueryType type); 81_IGNORE(gst_query_type_to_quark) 82 83} //namespace Enums 84 85/** A class used to perform queries on pads and elements. 86 * 87 * Queries can be performed on pads (gst_pad_query()) and elements 88 * (gst_element_query()). Please note that some queries might need a running 89 * pipeline to work. 90 * 91 * Queries can be created using the gst_query_new_*() functions. 92 * Query values can be set using gst_query_set_*(), and parsed using 93 * gst_query_parse_*() helpers. 94 * 95 * The following example shows how to query the duration of a pipeline: 96 * 97 * @code 98 * Glib::RefPtr<Gst::Query> query = Gst::QueryDuration::create(Gst::FORMAT_TIME); 99 * bool res = pipeline->query(query); 100 * if(res) 101 * { 102 * gint64 duration = Glib::RefPtr<Gst::QueryDuration>::cast_dynamic(query)->parse(); 103 * ... 104 * } 105 * @endcode 106 */ 107class Query : public MiniObject 108{ 109 _CLASS_OPAQUE_REFCOUNTED(Query, GstQuery, NONE, gst_query_ref, gst_query_unref) 110 _IGNORE(gst_query_ref, gst_query_unref) 111 112public: 113 /** Makes a writable query from the given query. 114 * @return A Gst::Query (possibly the same pointer) that is writable. 115 */ 116 Glib::RefPtr<Gst::Query> create_writable(); 117 118// A copy is taken so that the original is not freed by the wrapper. 119#m4 _CONVERSION(`const GstStructure*',`Gst::Structure',`Glib::wrap(const_cast<GstStructure*>($3), true)') 120 _WRAP_METHOD(Gst::Structure get_structure() const, gst_query_get_structure) 121 122 _WRAP_METHOD(static Glib::RefPtr<Gst::Query> create_buffering(Gst::Format format), gst_query_new_buffering) 123 124 _WRAP_METHOD(static Glib::RefPtr<Gst::Query> create_allocation(Glib::RefPtr<Gst::Caps> caps, bool need_pool), gst_query_new_allocation) 125 126 _WRAP_METHOD(static Glib::RefPtr<Gst::Query> create_uri(), gst_query_new_uri) 127 128 _WRAP_METHOD(static Glib::RefPtr<Gst::Query> create_scheduling(), gst_query_new_scheduling) 129 130 _WRAP_METHOD(static Glib::RefPtr<Gst::Query> create_drain(), gst_query_new_drain) 131 132 _WRAP_METHOD(static Glib::RefPtr<Gst::Query> create_custom(Gst::QueryType type, const Gst::Structure& structure), gst_query_new_custom) 133 134 _WRAP_METHOD(static Glib::RefPtr<Gst::Query> create_convert(Gst::Format format, gint64 value, Gst::Format dest_format), gst_query_new_convert) 135 136 _WRAP_METHOD(static Glib::RefPtr<Gst::Query> create_position(Gst::Format format), gst_query_new_position) 137 138 _WRAP_METHOD(static Glib::RefPtr<Gst::Query> create_duration(Gst::Format format), gst_query_new_duration) 139 140 _WRAP_METHOD(static Glib::RefPtr<Gst::Query> create_latency(), gst_query_new_latency) 141 142 _WRAP_METHOD(static Glib::RefPtr<Gst::Query> create_seeking(Gst::Format format), gst_query_new_seeking) 143 144 _WRAP_METHOD(static Glib::RefPtr<Gst::Query> create_formats(), gst_query_new_formats) 145 146 _WRAP_METHOD(static Glib::RefPtr<Gst::Query> create_segment(Gst::Format format), gst_query_new_segment) 147 148 _WRAP_METHOD(static Glib::RefPtr<Gst::Query> create_caps(Glib::RefPtr<Gst::Caps> filter), gst_query_new_caps) 149 150 _WRAP_METHOD(static Glib::RefPtr<Gst::Query> create_accept_caps(Glib::RefPtr<Gst::Caps> filter), gst_query_new_accept_caps) 151 152 /** Get the Gst::QueryType of the query. 153 */ 154 _MEMBER_GET(query_type, type, QueryType, GstQueryType) 155 156 _WRAP_METHOD(Glib::RefPtr<Gst::Query> copy(), gst_query_copy) 157 158 _IGNORE(gst_query_set_duration) 159 _IGNORE(gst_query_parse_duration) 160 _IGNORE(gst_query_set_convert) 161 _IGNORE(gst_query_parse_convert) 162 _IGNORE(gst_query_set_seeking) 163 _IGNORE(gst_query_parse_seeking) 164 _IGNORE(gst_query_set_buffering_percent) 165 _IGNORE(gst_query_parse_buffering_percent) 166 _IGNORE(gst_query_set_buffering_stats) 167 _IGNORE(gst_query_parse_buffering_stats) 168 _IGNORE(gst_query_set_buffering_range) 169 _IGNORE(gst_query_parse_buffering_range) 170 _IGNORE(gst_query_set_latency) 171 _IGNORE(gst_query_parse_latency) 172 _IGNORE(gst_query_set_position) 173 _IGNORE(gst_query_parse_position) 174 _IGNORE(gst_query_set_formatsv) 175 _IGNORE(gst_query_parse_segment) 176 _IGNORE(gst_query_set_segment) 177 _IGNORE(gst_query_parse_caps) 178 _IGNORE(gst_query_parse_scheduling) 179 _IGNORE(gst_query_set_scheduling) 180 _IGNORE(gst_query_add_scheduling_mode) 181 _IGNORE(gst_query_get_n_scheduling_modes) 182 _IGNORE(gst_query_parse_nth_scheduling_mode) 183 _IGNORE(gst_query_has_scheduling_mode) 184 _IGNORE(gst_query_has_scheduling_mode_with_flags) 185 _IGNORE(gst_query_parse_allocation) 186 _IGNORE(gst_query_get_n_allocation_pools) 187 _IGNORE(gst_query_remove_nth_allocation_pool) 188 _IGNORE(gst_query_add_allocation_param) 189 _IGNORE(gst_query_get_n_allocation_params) 190 _IGNORE(gst_query_parse_nth_allocation_param) 191 _IGNORE(gst_query_set_nth_allocation_param) 192 _IGNORE(gst_query_remove_nth_allocation_param) 193 _IGNORE(gst_query_add_allocation_meta) 194 _IGNORE(gst_query_get_n_allocation_metas) 195 _IGNORE(gst_query_parse_nth_allocation_meta) 196 _IGNORE(gst_query_remove_nth_allocation_meta) 197 _IGNORE(gst_query_find_allocation_meta) 198 _IGNORE(gst_query_parse_uri) 199 _IGNORE(gst_query_set_uri) 200 _IGNORE(gst_query_set_formatsv) 201 _IGNORE(gst_query_parse_n_formats) 202 _IGNORE(gst_query_parse_nth_format) 203 _IGNORE(gst_query_set_caps_result) 204 _IGNORE(gst_query_parse_caps_result) 205 _IGNORE(gst_query_get_n_buffering_ranges) 206 _IGNORE(gst_query_add_buffering_range) 207 _IGNORE(gst_query_parse_nth_buffering_range) 208 _IGNORE(gst_query_set_uri_redirection) 209 _IGNORE(gst_query_parse_uri_redirection) 210 _IGNORE(gst_query_parse_accept_caps) 211 _IGNORE(gst_query_parse_accept_caps_result) 212 _IGNORE(gst_query_set_accept_caps_result) 213 214protected: 215 // This method is used in the create() methods to convert a wrapped GstQuery 216 // to one of the more specific Gst::Query types. 217 template <class QueryType> 218 static inline Glib::RefPtr<QueryType> wrap(GstQuery* query, 219 bool take_copy = false); 220}; 221 222//TODO: Modify create methods of derived Query classes to return 223//Glib::RefPtr<...> to the derived class and not just Gst::Query. Must deal 224//with GstStructure immutability problem (bug #510301) first because casting 225//Glib::RefPtrs references the objects which causes problems when GStreamer API 226//tries to modify the GstStructures of the objects. 227 228/** A custom application query object. See create() for more details. 229 */ 230class QueryApplication : public Query 231{ 232public: 233 234 /** Constructs a new custom application query object. The Gst::Query may be 235 * used by applications in their own way. Please note that a custom 236 * Gst::QueryType must be used in order for the returned Gst::Query to 237 * actually be a Gst::QueryApplication type. 238 * @param type The query type. 239 * @param structure A structure for the query. 240 * @return The new Gst::QueryApplication. 241 */ 242 static Glib::RefPtr<Gst::QueryApplication> 243 create(QueryType type, const Gst::Structure& structure); 244}; 245 246/** A convert query object. See create() for more details. 247 */ 248class QueryConvert : public Query 249{ 250public: 251 252 /** Constructs a new convert query object. A convert query is used to ask 253 * for a conversion between one format and another. 254 * @param src_format The source Gst::Format for the new query. 255 * @param value The value to convert. 256 * @param dest_format The target Gst::Format. 257 * @return The new Gst::QueryConvert. 258 */ 259 static Glib::RefPtr<Gst::QueryConvert> 260 create(Format src_format, gint64 value, Format dest_format); 261 262 /** Answer a convert query by setting the requested values. 263 * @param src_format The source Gst::Format. 264 * @param src_value The source value. 265 * @param dest_format The destination Gst::Format. 266 * @param dest_value The destination value. 267 */ 268 void set(Format src_format, gint64 src_value, Format dest_format, gint64 dest_value); 269 270 /** Parse a convert query answer. Use the other parse() methods for parsing 271 * individual values. 272 * @param src_format The storage for the Gst::Format of the source value. 273 * @param src_value The storage for the source value. 274 * @param dest_format The storage for the Gst::Format of the destination. 275 * value. 276 * @param dest_value The storage for the destination value. 277 */ 278 void parse(Format& src_format, gint64& src_value, Format& dest_format, gint64& dest_value) const; 279 280 /** Parse the destination format and value of a convert query answer. 281 * @param dest_format The storage for the Gst::Format of the destination 282 * value. 283 * @param dest_value The storage for the destination value. 284 */ 285 void parse(Format& dest_format, gint64& dest_value) const; 286 287 /** Parse the source format of a convert query answer, returning the format. 288 * @return The Gst::Format of the source value. 289 */ 290 Format parse_src_format() const; 291 292 /** Parse the source value of a convert query answer returning, the value. 293 * @return The source value. 294 */ 295 gint64 parse_src_value() const; 296 297 /** Parse the destination format of a convert query answer, returning the 298 * format. 299 * @return The Gst::Format of the destination value. 300 */ 301 Format parse_dest_format() const; 302 303 /** Parse the destination value of a convert query answer, returning the 304 * value. 305 * @return The destination value. 306 */ 307 gint64 parse_dest_value() const; 308}; 309 310/** A stream position query object. See create() for more details. 311 */ 312class QueryPosition : public Query 313{ 314public: 315 316 /** Constructs a new query stream position query object. A position query is 317 * used to query the current position of playback in the streams, in some 318 * format. 319 * @param format The default Gst::Format for the new query. 320 * @return The new Gst::QueryPosition. 321 */ 322 static Glib::RefPtr<Gst::QueryPosition> create(Format format); 323 324 /** Answer a position query by setting the requested value in the given 325 * format. 326 * @param format The requested Gst::Format. 327 * @param position The position to set. 328 */ 329 void set(Format format, gint64 position); 330 331 /** Parse a position query, writing the format into format, and the position 332 * into @a position. Use the other parse() methods for parsing individual 333 * values. 334 * @param format The storage for the Gst::Format of the position values. 335 * @param position The storage for the current position. 336 */ 337 void parse(Format& format, gint64& position) const; 338 339 /** Parse the position of a position query, returning the position. 340 * @return The current position of the position query. 341 */ 342 gint64 parse() const; 343 344 /** Parse the format of a position query, returning the format. 345 * @return The the Gst::Format of the position values. 346 */ 347 Format parse_format() const; 348}; 349 350/** A stream duration query object. See create() for more details. 351 */ 352class QueryDuration : public Query 353{ 354public: 355 356 /** Constructs a new stream duration query object to query in the given 357 * format. A duration query will give the total length of the stream. 358 * @param format The Gst::Format for this duration query. 359 * @return The new Gst::QueryDuration. 360 */ 361 static Glib::RefPtr<Gst::QueryDuration> create(Format format); 362 363 /** Answer a duration query by setting the requested value in the given 364 * format. 365 * @param format The Gst::Format for the duration. 366 * @param duration The duration of the stream. 367 */ 368 void set(Format format, gint64 duration); 369 370 /** Parse a duration query answer. Write the format of the duration into 371 * @a format, and the value into @a duration. Use the other parse() methods 372 * for parsing individual values. 373 * @param format The storage for the Gst::Format of the duration value. 374 * @param duration The storage for the total duration. 375 */ 376 void parse(Format& format, gint64& duration) const; 377 378 /** Parse a duration query answer, returning the duration. 379 * @return The total duration. 380 */ 381 gint64 parse() const; 382 383 /** Parse a duration query answer, returning the format of the duration. 384 * @return The Gst::Format of the duration value. 385 */ 386 Format parse_format() const; 387}; 388 389/** A latency query object. See create() for more details. 390 */ 391class QueryLatency : public Query 392{ 393public: 394 395 /** Constructs a new latency query object. A latency query is usually 396 * performed by sinks to compensate for additional latency introduced by 397 * elements in the pipeline. 398 * @return The new Gst::QueryLatency. 399 */ 400 static Glib::RefPtr<Gst::QueryLatency> create(); 401 402 /** Answer a latency query by setting the requested values in the given 403 * format. 404 * @param live If there is a live element upstream. 405 * @param min_latency The minimal latency of the live element. 406 * @param max_latency The maximal latency of the live element. 407 */ 408 void set(bool live, ClockTime min_latency, ClockTime max_latency); 409 410 /** Parse a latency query answer. Use the other parse() methods for parsing 411 * individual values. 412 * @param live Storage for live. 413 * @param min_latency The storage for the min latency. 414 * @param max_latency The storage for the max latency. 415 */ 416 void parse(bool& live, ClockTime& min_latency, ClockTime& max_latency) const; 417 418 /** Parse a latency query answer, returning the live status. 419 * @return the live satus. 420 */ 421 bool parse_live() const; 422 423 /** Parse a latency query answer, returning the minimum latency. 424 * @return The minimum latency. 425 */ 426 ClockTime parse_min() const; 427 428 /** Parse a latency query answer, returning the maximum latency. 429 * @return The maximum latency. 430 */ 431 ClockTime parse_max() const; 432}; 433 434/** A seeking query object. See create() for more details. 435 */ 436class QuerySeeking : public Query 437{ 438public: 439 440 /** Constructs a new query object for querying seeking properties of the 441 * stream. 442 * @param format The default Gst::Format for the new query. 443 * @return The new Gst::QuerySeeking. 444 */ 445 static Glib::RefPtr<Gst::QuerySeeking> create(Format format); 446 447 /** Set the seeking query result fields in query. 448 * @param format The format to set for @a the segment_start and 449 * @a segment_end values. 450 * @param seekable The seekable flag to set. 451 * @param segment_start The segment_start to set. 452 * @param segment_end The segment_end to set. 453 */ 454 void set(Format format, bool seekable, gint64 segment_start, gint64 segment_end); 455 456 /** Parse a seeking query, writing the format into format, and other results 457 * into the passed parameters. Use the other parse() methods for parsing 458 * individual values. 459 * @param format The storage location for the foramt. 460 * @param seekable The storage location for the seekable flag. 461 * @param segment_start The storage location for the segment start value. 462 * @param segment_end The storage location for the segment end. 463 */ 464 void parse(Format& format, bool& seekable, gint64& segment_start, gint64& segment_end) const; 465 466 /** Parse a seeking query, returning the format. 467 * @return The format. 468 */ 469 Format parse_format() const; 470 471 /** Parse a seeking query, returning the seekable status. 472 * @return The seekable flag. 473 */ 474 bool parse_seekable() const; 475 476 /** Parse a seeking query, returning the segment start value. 477 * @return The segment start. 478 */ 479 gint64 parse_start() const; 480 481 /** Parse a seeking query, returning the segment end value. 482 * @return The segment end. 483 */ 484 gint64 parse_end() const; 485}; 486 487/** A formats query object. See create() for more details. 488 */ 489class QueryFormats : public Query 490{ 491public: 492 493 /** Constructs a new query object for querying formats of the stream. 494 * @return The new Gst::QueryFormats. 495 */ 496 static Glib::RefPtr<Gst::QueryFormats> create(); 497 498 /** Set the formats query result fields. All the formats in the array are 499 * used. 500 * @param formats An array containing Gst::Format values. 501 */ 502 void set(const Glib::ArrayHandle<Format>& formats); 503 504 /** Set the formats query result fields using only @a n_formats from @a 505 * formats. The number of formats passed in the formats array must be 506 * greater than or equal to @a n_formats. 507 * @param n_formats The number of formats to set. 508 * @param formats An array containing at least @a n_formats Gst::Format 509 * values. 510 */ 511 void set(int n_formats, const Glib::ArrayHandle<Format>& formats); 512 513 /** Parse and return the number of formats in the formats query. 514 * @return The number of formats in this query. 515 */ 516 guint parse_length() const; 517 518 /** Parse the format query and return the @a nth format from it. If the list 519 * contains less elements than @a nth, Gst::FORMAT_UNDEFINED will be 520 * returned. 521 * @param nth The index of the format to return. 522 * @return the @a nth format or Gst::FORMAT_UNDEFINED. 523 */ 524 Format parse(guint nth) const; 525}; 526 527/** A new segment query object. See create() for more details. 528 */ 529class QuerySegment : public Query 530{ 531public: 532 533 /** Constructs a new segment query object. A segment query is used to 534 * discover information about the currently configured segment for playback. 535 * @param format The Gst::Format for the new query. 536 * @return The new Gst::QuerySegment. 537 */ 538 static Glib::RefPtr<Gst::QuerySegment> create(Format format); 539 540 /** Answer a segment query by setting the requested values. The normal 541 * playback segment of a pipeline is 0 to duration at the default rate of 542 * 1.0. If a seek was performed on the pipeline to play a different segment, 543 * this query will return the range specified in the last seek. 544 * 545 * @a start_value and @a stop_value will respectively contain the configured 546 * playback range start and stop values expressed in @a format. The values 547 * are always between 0 and the duration of the media and @a start_value <= 548 * @a stop_value. @a rate will contain the playback rate. For negative 549 * rates, playback will actually happen from @a stop_value to @a start_value. 550 * 551 * @param rate The rate of the segment. 552 * @param format The Gst::Format of the segment values (@a start_value and 553 * @a stop_value). 554 * @param start_value The start value. 555 * @param stop_value The stop value. 556 */ 557 void set(double rate, Format format, gint64 start_value, gint64 stop_value); 558 559 /** Parse a segment query answer. See set() for an explanation of the 560 * function arguments. Use the other parse() methods to parse individual 561 * values. 562 * 563 * @param rate The storage for the rate of the segment. 564 * @param format The storage for the Gst::Format of the values. 565 * @param start_value The storage for the start value. 566 * @param stop_value The storage for the stop value. 567 */ 568 void parse(double& rate, Format& format, gint64& start_value, gint64& stop_value) const; 569 570 /** Parse a segment query answer, returning the rate. See set() for an 571 * explanation of the function arguments. 572 * @return The rate of the segment. 573 */ 574 double parse_rate() const; 575 576 /** Parse a segment query answer, returning the format. See set() for an 577 * explanation of the function arguments. 578 * @return The Gst::Format of the start and stop values. 579 */ 580 Format parse_format() const; 581 582 /** Parse a segment query answer, returning the start value. See set() for 583 * an explanation of the function arguments. 584 * @return The start value. 585 */ 586 gint64 parse_start() const; 587 588 /** Parse a segment query answer, returning the stop value. See set() for 589 * an explanation of the function arguments. 590 * @return The stop value. 591 */ 592 gint64 parse_stop() const; 593}; 594 595/** A new buffering query object. See create() for more details. 596 */ 597class QueryBuffering : public Query 598{ 599public: 600 601 /** Constructs a new query object for querying the buffering status of a 602 * stream. 603 * @param format The default Gst::Format for the new query. 604 * @return The new Gst::QueryBuffering. 605 */ 606 static Glib::RefPtr<Gst::QueryBuffering> create(Format format); 607 608 /** Set the percentage of buffered data. This is a value between 0 and 100. 609 * The @a busy indicator is true when the buffering is in progress. 610 * @param busy If buffering is busy. 611 * @param percent A buffering percent. 612 */ 613 void set(bool busy, int percent); 614 615 /** Get the busy flag and percentage of the buffered data. The percent is a 616 * value between 0 and 100. The busy indicator is true when the buffering 617 * is in progress. Use the other parse() methods to parse individual 618 * values. 619 * @param busy The location to store the buffering busy flag. 620 * @param percent The location to store the buffering percent. 621 */ 622 void parse(bool& busy, int& percent) const; 623 624 /** Get the busy flag of the buffered data. The busy indicator is true when 625 * the buffering is in progress. 626 * @return The buffering busy flag. 627 */ 628 bool parse_busy() const; 629 630 /** Get the percentage of the buffered data. The percent is a value between 631 * 0 and 100. 632 * @return The buffering percent. 633 */ 634 int parse_percent() const; 635 636 /** Configures the buffering stats values in query. 637 * @param mode A buffering mode. 638 * @param avg_in The average input rate. 639 * @param avg_out The average output rate. 640 * @param buffering_left Amount of buffering time left. 641 */ 642 void set(BufferingMode mode, int avg_in, int avg_out, gint64 buffering_left); 643 644 /** Extracts the buffering stats values from the query. Use the other 645 * parse() methods to parse individual values. 646 * @param mode The location to store the buffering mode. 647 * @param avg_in The location to store the average input rate. 648 * @param avg_out The location to store the average output rate. 649 * @param buffering_left The location to store the amount of buffering time 650 * left. 651 */ 652 void parse(BufferingMode& mode, int& avg_in, int& avg_out, gint64 buffering_left) const; 653 654 /** Extracts the buffering mode from the query. 655 * @return The the buffering mode. 656 */ 657 BufferingMode parse_mode() const; 658 659 /** Extracts the average input rate from the query. 660 * @return The average input rate. 661 */ 662 int parse_input_rate() const; 663 664 /** Extracts the average output rate from the query. 665 * @return The average output rate. 666 */ 667 int parse_output_rate() const; 668 669 /** Extracts the buffering time left from the query. 670 * @return The the amount of buffering time left. 671 */ 672 gint64 parse_time_left() const; 673 674 /** Set the available query result fields in query. 675 * @param format The format to set for the start and stop values. 676 * @param start The start to set. 677 * @param stop The stop to set. 678 * @param estimated_total Estimated total amount of download time. 679 */ 680 void set(Format format, gint64 start, gint64 stop, gint64 estimated_total); 681 682 /** Parse the query, writing the format into format, and other 683 * results into the passed parameters. Use the other parse() methods to 684 * parse individual values. 685 * @param format The location to store the format. 686 * @param start The location to store the start. 687 * @param stop The location to store the stop. 688 * @param estimated_total The location to store the estimated total amount 689 * of download time. 690 */ 691 void parse(Format& format, gint64& start, gint64& stop, gint64& estimated_total) const; 692 693 /** Parse the query, returning the format. 694 * @return The format. 695 */ 696 Format parse_format() const; 697 698 /** Parse the query, returning the start range value. 699 * @return The start value. 700 */ 701 gint64 parse_start() const; 702 703 /** Parse the query, returning the stop range value. 704 * @return The stop value. 705 */ 706 gint64 parse_stop() const; 707 708 /** Parse the query, returning the estimated total amount of download time. 709 * @return The estimated total amount of download time. 710 */ 711 gint64 parse_total_time() const; 712 713 /** Retrieve the number of values currently stored in the 714 * buffered-ranges array of the query's structure. 715 * @return the range array size as a guint. 716 */ 717 guint get_n_buffering_ranges() const; 718 719 /** Set the buffering-ranges array field in @a query. The current last 720 * start position of the array should be inferior to @a start. 721 * @param start start position of the range. 722 * @param stop stop position of the range. 723 * @return a bool indicating if the range was added or not. 724 */ 725 bool add_buffering_range(gint64 start, gint64 stop); 726 727 /** Parse an available query and get the start and stop values stored 728 * at the @a index of the buffered ranges array. 729 * @param index position in the buffered-ranges array to read. 730 * @param start the start position to set, or NULL. 731 * @param stop the stop position to set, or NULL. 732 * @return a bool indicating if the parsing succeeded. 733 */ 734 bool parse_nth_buffering_range(guint index, gint64& start, gint64& stop) const; 735}; 736 737/** A new caps query object. See create() for more details. 738 */ 739class QueryCaps : public Query 740{ 741public: 742 743 /** Constructs a new query object for querying the caps. 744 * 745 * The CAPS query should return the allowable caps for a pad in the context 746 * of the element's state, its link to other elements, and the devices or files 747 * it has opened. These caps must be a subset of the pad template caps. In the 748 * NULL state with no links, the CAPS query should ideally return the same caps 749 * as the pad template. In rare circumstances, an object property can affect 750 * the caps returned by the CAPS query, but this is discouraged. 751 * For most filters, the caps returned by CAPS query is directly affected by the 752 * allowed caps on other pads. For demuxers and decoders, the caps returned by 753 * the srcpad's getcaps function is directly related to the stream data. Again, 754 * the CAPS query should return the most specific caps it reasonably can, since this 755 * helps with autoplugging. 756 * 757 * The @a filter is used to restrict the result caps, only the caps matching 758 * @a filter should be returned from the CAPS query. Specifying a filter might 759 * greatly reduce the amount of processing an element needs to do. 760 * @param filter a filter. 761 * @return The new Gst::QureyCaps. 762 */ 763 static Glib::RefPtr<Gst::QueryCaps> 764 create(const Glib::RefPtr<Gst::Caps>& filter); 765 766 /** Get the filter from the caps @a query. The caps remains valid as long as 767 * @a query remains valid. 768 * @return caps filter. 769 */ 770 Glib::RefPtr<Gst::Caps> parse() const; 771 772 /** Get the caps result from @a query. The caps remains valid as long as 773 * @a query remains valid. 774 * @return a pointer to the caps. 775 */ 776 Glib::RefPtr<Gst::Caps> parse_caps_result() const; 777 778 /** Set the @a caps result in @a query. 779 * @param caps a pointer to the caps. 780 */ 781 void set_caps_result(const Glib::RefPtr<Gst::Caps>& caps); 782}; 783 784/** A new scheduling query object. See create() for more details. 785 */ 786class QueryScheduling : public Query 787{ 788public: 789 790 /** Constructs a new query object for querying the scheduling properties. 791 * @return A new Gst::QueryScheduling. 792 */ 793 static Glib::RefPtr<Gst::QueryScheduling> 794 create(); 795 796 /** Set the scheduling properties. 797 * @param flags Gst::SchedulingFlags. 798 * @param minsize the suggested minimum size of pull requests. 799 * @param maxsize the suggested maximum size of pull requests. 800 * @param align the suggested alignment of pull requests. 801 */ 802 void parse(Gst::SchedulingFlags& flags, gint& minsize, gint& maxsize, gint& align) const; 803 804 /** Set the scheduling properties. 805 * @param flags Gst::SchedulingFlags. 806 * @param minsize the suggested minimum size of pull requests. 807 * @param maxsize the suggested maximum size of pull requests. 808 * @param align the suggested alignment of pull requests. 809 */ 810 void set(Gst::SchedulingFlags flags, gint minsize, gint maxsize, gint align); 811 812 /** Add @a mode as aone of the supported scheduling modes to @a query. 813 * 814 * @param mode A Gst::PadMode. 815 */ 816 void add_scheduling_mode(Gst::PadMode mode); 817 818 /** Retrieve the number of values currently stored in the 819 * scheduling mode array of the query's structure. 820 * @return the scheduling mode array size as a guint. 821 */ 822 guint get_n_scheduling_modes() const; 823 824 /** Parse an available query and get the scheduling mode 825 * at @a index of the scheduling modes array. 826 * @param index position in the scheduling modes array to read 827 * @return a Gst::PadMode of the scheduling mode at @a index. 828 */ 829 Gst::PadMode parse_nth_scheduling_mode(guint index) const; 830 831 /** Check if @a query has scheduling mode set. 832 * @param mode the scheduling mode. 833 * @return true when @a mode is in the list of scheduling modes. 834 */ 835 bool has_scheduling_mode(Gst::PadMode mode) const; 836 837 /** Check if @a query has scheduling mode set and @a flags is set in 838 * query scheduling flags. 839 * @param mode the scheduling mode. 840 * @param flags Gst::SchedulingFlags. 841 */ 842 bool has_scheduling_mode_with_flags(Gst::PadMode mode, Gst::SchedulingFlags flags) const; 843}; 844 845/** A new scheduling query object. See create() for more details. 846 */ 847class QueryAllocation : public Query 848{ 849public: 850 /** Constructs a new query object for querying the allocation properties. 851 * @param caps the negotiated caps. 852 * @param need_pool return a pool. 853 * @return a new Gst::Query. 854 */ 855 static Glib::RefPtr<Gst::QueryAllocation> 856 create(const Glib::RefPtr<Gst::Caps>& caps, bool need_pool); 857 858 /** Parse an allocation query, writing the requested caps in @a caps and 859 * whether a pool is needed in @a need_pool, if the respective parameters 860 * are non-NULL. 861 * @param caps the Gst::Caps. 862 * @param need_pool whether a Gst::BufferPool is needed. 863 */ 864 void parse(Glib::RefPtr<Gst::Caps>& caps, bool& need_pool) const; 865 866 /** Retrieve the number of values currently stored in the 867 * pool array of the query's structure. 868 * @return the pool array size as a guint. 869 */ 870 guint get_n_allocation_pools() const; 871 872 /** Remove the allocation pool at @a index of the allocation pool array. 873 * @param index position in the allocation pool array to remove. 874 */ 875 void remove_nth_allocation_pool(guint index); 876 877 /** Add @a allocator and its @a params as a supported memory allocator. 878 * @param allocator the memory allocator. 879 * @param params a Gst::AllocationParams. 880 */ 881 void add_allocation_param(const Glib::RefPtr<Gst::Allocator>& allocator, const Gst::AllocationParams& params); 882 883 /** Retrieve the number of values currently stored in the 884 * allocator params array of the query's structure. 885 * 886 * If no memory allocator is specified, the downstream element can handle 887 * the default memory allocator. The first memory allocator in the query 888 * should be generic and allow mapping to system memory, all following 889 * allocators should be ordered by preference with the preferred one first. 890 * @return the allocator array size as guint. 891 */ 892 guint get_n_allocation_params() const; 893 894 /** Parse an available query and get the alloctor and its params 895 * at @a index of the allocator array. 896 * @param index position in the allocator array to read. 897 * @param allocator variable to hold the result. 898 * @param params parameters for the allocator. 899 */ 900 void parse_nth_allocation_param(guint index, Glib::RefPtr<Gst::Allocator>& allocator, Gst::AllocationParams& params) const; 901 902 /** Parse an available query and get the alloctor and its params 903 * at @a index of the allocator array. 904 * @param index position in the allocator array to set. 905 * @param allocator new allocator to set. 906 * @param params parameters for the allocator. 907 */ 908 void set_nth_allocation_param(guint index, const Glib::RefPtr<Gst::Allocator>& allocator, const Gst::AllocationParams& params); 909 910 /** Remove the allocation param at @a index of the allocation param array. 911 * @param index position in the allocation param array to remove 912 */ 913 void remove_nth_allocation_param(guint index); 914 915 /** Add @a api with @a params as one of the supported metadata API to @a query. 916 * @param api the metadata API. 917 * @param params API specific parameters. 918 */ 919 void add_allocation_meta(GType api, const Gst::Structure& params); 920 921 /** Retrieve the number of values currently stored in the 922 * meta API array of the query's structure. 923 * @return the metadata API array size as a guint. 924 */ 925 guint get_n_allocation_metas() const; 926 927 /** Parse an available query and get the metadata API 928 * at @a index of the metadata API array. 929 * @param index position in the metadata API array to read. 930 * @param params API specific flags. 931 */ 932 GType parse_nth_allocation_meta(guint index, Gst::Structure& params) const; 933 934 /** Remove the metadata API at @a index of the metadata API array. 935 * @param index positon in the metadata API array to remove. 936 */ 937 void remove_nth_allocation_meta(guint index); 938 939 /** Check if @a query has metadata @a api set. When this function returns TRUE, 940 * @a index will contain the index where the requested API and the flags can be 941 * found. 942 * @param api the metadata API. 943 * @param index the index 944 * @return true when @a api is in the list of metadata. 945 */ 946 bool find_allocation_meta(GType api, guint& index) const; 947}; 948 949/** A new uri query object. See create() for more details. 950 */ 951class QueryUri : public Query 952{ 953public: 954 /** Constructs a new query URI query object. Use gst_query_unref() 955 * when done with it. An URI query is used to query the current URI 956 * that is used by the source or sink. 957 * @return a new Gst::Query. 958 */ 959 static Glib::RefPtr<Gst::QueryUri> create(); 960 961 /** Parse an URI query, writing the URI into @a uri as a newly 962 * allocated string, if the respective parameters are non-NULL. 963 * Free the string with g_free() after usage. 964 * @return the storage for the current URI. 965 */ 966 Glib::ustring parse() const; 967 968 /** Answer a URI query by setting the requested URI. 969 * @param uri the URI to set. 970 */ 971 void set(const Glib::ustring& uri); 972 973 /** Answer a URI query by setting the requested URI redirection. 974 * @param uri the URI to set. 975 */ 976 void set_uri_redirection(const Glib::ustring& uri); 977 978 /** Parse an URI query, return URI, if the respective parameters. 979 * @return the storage for the redirect URI (may be empty). 980 */ 981 Glib::ustring parse_uri_redirection() const; 982}; 983 984/** A new accept caps query object. See create() for more details. 985 */ 986class QueryAcceptCaps : public Query 987{ 988public: 989 /** Constructs a new query object for querying if @a caps are accepted. 990 * @return a new Gst::Query. 991 */ 992 static Glib::RefPtr<Gst::QueryAcceptCaps> create(const Glib::RefPtr<Gst::Caps>& caps); 993 994 /** Get the caps from @a query. The caps remains valid as long as @a query remains 995 * valid. 996 * @return a caps. 997 */ 998 Glib::RefPtr<Gst::Caps> parse_accept_caps() const; 999 1000 /** Parse the result from @a query and store in @a result. 1001 * @return location for the result. 1002 */ 1003 bool parse_accept_caps_result() const; 1004 1005 /** Set @a result as the result for the @a query. 1006 * @param result the result to set. 1007 */ 1008 void set_accept_caps_result(bool result); 1009}; 1010 1011} //namespace Gst 1012