/** * @brief Handle queries. * * GstBaseSink method implementation. */ static gboolean gst_tensor_sink2_query (GstBaseSink * sink, GstQuery * query) { GstTensorSink2 *self; GstQueryType type; GstFormat format; self = GST_TENSOR_SINK2 (sink); type = GST_QUERY_TYPE (query); GST_DEBUG_OBJECT (self, "Received %s query: %" GST_PTR_FORMAT, GST_QUERY_TYPE_NAME (query), query); switch (type) { case GST_QUERY_SEEKING: /** tensor sink does not support seeking */ gst_query_parse_seeking (query, &format, NULL, NULL, NULL); gst_query_set_seeking (query, format, FALSE, 0, -1); return TRUE; default: break; } return GST_BASE_SINK_CLASS (parent_class)->query (sink, query); }
static gboolean play_do_seek (GstElement * pipeline, gint64 pos, gdouble rate, GstPlayTrickMode mode) { GstSeekFlags seek_flags; GstQuery *query; GstEvent *seek; gboolean seekable = FALSE; query = gst_query_new_seeking (GST_FORMAT_TIME); if (!gst_element_query (pipeline, query)) { gst_query_unref (query); return FALSE; } gst_query_parse_seeking (query, NULL, &seekable, NULL, NULL); gst_query_unref (query); if (!seekable) return FALSE; seek_flags = GST_SEEK_FLAG_FLUSH; switch (mode) { case GST_PLAY_TRICK_MODE_DEFAULT: seek_flags |= GST_SEEK_FLAG_TRICKMODE; break; case GST_PLAY_TRICK_MODE_DEFAULT_NO_AUDIO: seek_flags |= GST_SEEK_FLAG_TRICKMODE | GST_SEEK_FLAG_TRICKMODE_NO_AUDIO; break; case GST_PLAY_TRICK_MODE_KEY_UNITS: seek_flags |= GST_SEEK_FLAG_TRICKMODE_KEY_UNITS; break; case GST_PLAY_TRICK_MODE_KEY_UNITS_NO_AUDIO: seek_flags |= GST_SEEK_FLAG_TRICKMODE_KEY_UNITS | GST_SEEK_FLAG_TRICKMODE_NO_AUDIO; break; case GST_PLAY_TRICK_MODE_NONE: default: break; } if (rate >= 0) seek = gst_event_new_seek (rate, GST_FORMAT_TIME, seek_flags | GST_SEEK_FLAG_ACCURATE, /* start */ GST_SEEK_TYPE_SET, pos, /* stop */ GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE); else seek = gst_event_new_seek (rate, GST_FORMAT_TIME, seek_flags | GST_SEEK_FLAG_ACCURATE, /* start */ GST_SEEK_TYPE_SET, 0, /* stop */ GST_SEEK_TYPE_SET, pos); if (!gst_element_send_event (pipeline, seek)) return FALSE; cur_rate = rate; trick_mode = mode; return TRUE; }
static gboolean _src_query (GstAggregator * self, GstQuery * query) { gboolean res = TRUE; switch (GST_QUERY_TYPE (query)) { case GST_QUERY_SEEKING: { GstFormat format; /* don't pass it along as some (file)sink might claim it does * whereas with a collectpads in between that will not likely work */ gst_query_parse_seeking (query, &format, NULL, NULL, NULL); gst_query_set_seeking (query, format, FALSE, 0, -1); res = TRUE; goto discard; } default: break; } return gst_pad_query_default (self->srcpad, GST_OBJECT (self), query); discard: return res; }
P_INVOKE gboolean bp_can_seek (BansheePlayer *player) { GstQuery *query; gboolean can_seek = TRUE; g_return_val_if_fail (IS_BANSHEE_PLAYER (player), FALSE); if (player->playbin == NULL) { return FALSE; } query = gst_query_new_seeking (GST_FORMAT_TIME); if (!gst_element_query (player->playbin, query)) { // This will probably fail, 100% of the time, because it's apparently // very unimplemented in GStreamer... when it's fixed // we will return FALSE here, and show the warning // g_warning ("Could not query pipeline for seek ability"); return bp_get_duration (player) > 0; } gst_query_parse_seeking (query, NULL, &can_seek, NULL, NULL); gst_query_unref (query); return can_seek && bp_get_duration (player) > 0; }
static void handle_message (CustomData *data, GstMessage *msg) { GError *err; gchar *debug_info; switch (GST_MESSAGE_TYPE (msg)) { case GST_MESSAGE_ERROR: gst_message_parse_error (msg, &err, &debug_info); g_printerr ("Error received from element %s: %s\n", GST_OBJECT_NAME (msg->src), err->message); g_printerr ("Debugging information: %s\n", debug_info ? debug_info : "none"); g_clear_error (&err); g_free (debug_info); data->terminate = TRUE; break; case GST_MESSAGE_EOS: g_print ("End-Of-Stream reached.\n"); data->terminate = TRUE; break; case GST_MESSAGE_DURATION: /* The duration has changed, mark the current one as invalid */ data->duration = GST_CLOCK_TIME_NONE; break; case GST_MESSAGE_STATE_CHANGED: { GstState old_state, new_state, pending_state; gst_message_parse_state_changed (msg, &old_state, &new_state, &pending_state); if (GST_MESSAGE_SRC (msg) == GST_OBJECT (data->playbin2)) { g_print ("Pipeline state changed from %s to %s:\n", gst_element_state_get_name (old_state), gst_element_state_get_name (new_state)); /* Remember whether we are in the PLAYING state or not */ data->playing = (new_state == GST_STATE_PLAYING); if (data->playing) { /* We just moved to PLAYING. Check if seeking is possible */ GstQuery *query; gint64 start, end; query = gst_query_new_seeking (GST_FORMAT_TIME); if (gst_element_query (data->playbin2, query)) { gst_query_parse_seeking (query, NULL, &data->seek_enabled, &start, &end); if (data->seek_enabled) { g_print ("Seeking is ENABLED from %" GST_TIME_FORMAT " to %" GST_TIME_FORMAT "\n", GST_TIME_ARGS (start), GST_TIME_ARGS (end)); } else { g_print ("Seeking is DISABLED for this stream.\n"); } } else { g_printerr ("Seeking query failed."); } gst_query_unref (query); } } } break; default: /* We should not reach here */ g_printerr ("Unexpected message received.\n"); break; } gst_message_unref (msg); }
static gboolean gst_hls_demux_src_query (GstPad * pad, GstQuery * query) { GstHLSDemux *hlsdemux; gboolean ret = FALSE; if (query == NULL) return FALSE; hlsdemux = GST_HLS_DEMUX (gst_pad_get_element_private (pad)); switch (query->type) { case GST_QUERY_DURATION:{ GstClockTime duration; GstFormat fmt; gst_query_parse_duration (query, &fmt, NULL); if (fmt == GST_FORMAT_TIME) { duration = gst_m3u8_client_get_duration (hlsdemux->client); if (GST_CLOCK_TIME_IS_VALID (duration) && duration > 0) { gst_query_set_duration (query, GST_FORMAT_TIME, duration); ret = TRUE; } } break; } case GST_QUERY_URI: if (hlsdemux->client) { /* FIXME: Do we answer with the variant playlist, with the current * playlist or the the uri of the least downlowaded fragment? */ gst_query_set_uri (query, hlsdemux->client->current->uri); ret = TRUE; } break; case GST_QUERY_SEEKING:{ GstFormat fmt; gint stop = -1; gst_query_parse_seeking (query, &fmt, NULL, NULL, NULL); if (fmt == GST_FORMAT_TIME) { GstClockTime duration; duration = gst_m3u8_client_get_duration (hlsdemux->client); if (GST_CLOCK_TIME_IS_VALID (duration) && duration > 0) stop = duration; } gst_query_set_seeking (query, fmt, FALSE, 0, stop); ret = TRUE; break; } default: /* Don't fordward queries upstream because of the special nature of this * "demuxer", which relies on the upstream element only to be fed with the * first playlist */ break; } return ret; }
/* generate queries to adaptive demux */ static gboolean testQueryCheckDataReceived (GstAdaptiveDemuxTestEngine * engine, GstAdaptiveDemuxTestOutputStream * stream, GstBuffer * buffer, gpointer user_data) { GList *pads; GstPad *pad; GstQuery *query; gboolean ret; gint64 duration; gboolean seekable; gint64 segment_start; gint64 segment_end; gchar *uri; gchar *redirect_uri; gboolean redirect_permanent; pads = GST_ELEMENT_PADS (stream->appsink); /* AppSink should have only 1 pad */ fail_unless (pads != NULL); fail_unless (g_list_length (pads) == 1); pad = GST_PAD (pads->data); query = gst_query_new_duration (GST_FORMAT_TIME); ret = gst_pad_peer_query (pad, query); fail_unless (ret == TRUE); gst_query_parse_duration (query, NULL, &duration); fail_unless (duration == 135743 * GST_MSECOND); gst_query_unref (query); query = gst_query_new_seeking (GST_FORMAT_TIME); ret = gst_pad_peer_query (pad, query); fail_unless (ret == TRUE); gst_query_parse_seeking (query, NULL, &seekable, &segment_start, &segment_end); fail_unless (seekable == TRUE); fail_unless (segment_start == 0); fail_unless (segment_end == duration); gst_query_unref (query); query = gst_query_new_uri (); ret = gst_pad_peer_query (pad, query); fail_unless (ret == TRUE); gst_query_parse_uri (query, &uri); gst_query_parse_uri_redirection (query, &redirect_uri); gst_query_parse_uri_redirection_permanent (query, &redirect_permanent); fail_unless (strcmp (uri, "http://unit.test/test.mpd") == 0); /* adaptive demux does not reply with redirect information */ fail_unless (redirect_uri == NULL); fail_unless (redirect_permanent == FALSE); g_free (uri); g_free (redirect_uri); gst_query_unref (query); return gst_adaptive_demux_test_check_received_data (engine, stream, buffer, user_data); }
static gboolean gst_fd_sink_query (GstBaseSink * bsink, GstQuery * query) { gboolean res = FALSE; GstFdSink *fdsink; fdsink = GST_FD_SINK (bsink); switch (GST_QUERY_TYPE (query)) { case GST_QUERY_POSITION: { GstFormat format; gst_query_parse_position (query, &format, NULL); switch (format) { case GST_FORMAT_DEFAULT: case GST_FORMAT_BYTES: gst_query_set_position (query, GST_FORMAT_BYTES, fdsink->current_pos); res = TRUE; break; default: break; } break; } case GST_QUERY_FORMATS: gst_query_set_formats (query, 2, GST_FORMAT_DEFAULT, GST_FORMAT_BYTES); res = TRUE; break; case GST_QUERY_URI: gst_query_set_uri (query, fdsink->uri); res = TRUE; break; case GST_QUERY_SEEKING:{ GstFormat format; gst_query_parse_seeking (query, &format, NULL, NULL, NULL); if (format == GST_FORMAT_BYTES || format == GST_FORMAT_DEFAULT) { gst_query_set_seeking (query, GST_FORMAT_BYTES, fdsink->seekable, 0, -1); } else { gst_query_set_seeking (query, format, FALSE, 0, -1); } res = TRUE; break; } default: res = GST_BASE_SINK_CLASS (parent_class)->query (bsink, query); break; } return res; }
void test_nonseeking() { GstElement *src; GstQuery *seeking_query; gint pipe_fd[2]; gchar data[4096]; gboolean seekable; xmlfile = "fdsrc_test_nonseeking"; std_log(LOG_FILENAME_LINE, "Test Started test_nonseeking"); fail_if (pipe (pipe_fd) < 0); src = setup_fdsrc (); g_object_set (G_OBJECT (src), "num-buffers", 3, NULL); g_object_set (G_OBJECT (src), "fd", pipe_fd[0], NULL); fail_unless (gst_element_set_state (src, GST_STATE_PAUSED) == GST_STATE_CHANGE_SUCCESS, "could not set to paused"); memset (data, 0, 4096); fail_if (write (pipe_fd[1], data, 256) < 0); /* Test that fdsrc is non-seekable with a pipe */ fail_unless ((seeking_query = gst_query_new_seeking (GST_FORMAT_BYTES)) != NULL); fail_unless (gst_element_query (src, seeking_query) == TRUE); gst_query_parse_seeking (seeking_query, NULL, &seekable, NULL, NULL); fail_unless (seekable == FALSE); gst_query_unref (seeking_query); fail_unless (gst_element_set_state (src, GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null"); /* cleanup */ cleanup_fdsrc (src); close (pipe_fd[0]); close (pipe_fd[1]); std_log(LOG_FILENAME_LINE, "Test Successful"); create_xml(0); }
static void pragha_backend_evaluate_if_can_seek(PraghaBackend *backend) { GstQuery *query; PraghaBackendPrivate *priv = backend->priv; query = gst_query_new_seeking (GST_FORMAT_TIME); if (gst_element_query (priv->pipeline, query)) gst_query_parse_seeking (query, NULL, &priv->can_seek, NULL, NULL); gst_query_unref (query); }
void test_seeking() { GstElement *src; gint in_fd; GstQuery *seeking_query; gboolean seekable; xmlfile = "fdsrc_test_seeking"; std_log(LOG_FILENAME_LINE, "Test Started test_seeking"); #ifndef TESTFILE #error TESTFILE not defined #endif in_fd = errno ; fail_if ((in_fd = open ("c:\\data\\gstreamer\\warning.wav", O_RDONLY)) < 0); src = setup_fdsrc (); g_object_set (G_OBJECT (src), "fd", in_fd, NULL); fail_unless (gst_element_set_state (src, GST_STATE_PAUSED) == GST_STATE_CHANGE_SUCCESS, "could not set to paused"); /* Test that fdsrc is seekable with a file fd */ fail_unless ((seeking_query = gst_query_new_seeking (GST_FORMAT_BYTES)) != NULL); fail_unless (gst_element_query (src, seeking_query) == TRUE); gst_query_parse_seeking (seeking_query, NULL, &seekable, NULL, NULL); fail_unless (seekable == TRUE); gst_query_unref (seeking_query); fail_unless (gst_element_set_state (src, GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null"); /* cleanup */ cleanup_fdsrc (src); close (in_fd); std_log(LOG_FILENAME_LINE, "Test Successful"); create_xml(0); }
static VALUE seeking_parse(VALUE self) { GstFormat format; gboolean seekable; gint64 segment_start, segment_end; gst_query_parse_seeking(RVAL2GST_QUERY(self), &format, &seekable, &segment_start, &segment_end); return rb_ary_new3(4, GST_FORMAT2RVAL(format), CBOOL2RVAL(seekable), LL2NUM(segment_start), LL2NUM(segment_end)); }
bool SourceObject::IsSeekable () const { std::shared_ptr<GstQuery> query (gst_query_new_seeking (GST_FORMAT_TIME), gst_query_unref); if (!gst_element_query (GST_ELEMENT (Dec_), query.get ())) return false; gboolean seekable = false; GstFormat format; gint64 start = 0, stop = 0; gst_query_parse_seeking (query.get (), &format, &seekable, &start, &stop); return seekable; }
static gboolean event_forward_func (GstPad * pad, EventData * evdata) { gboolean ret = TRUE; GstPad *peer = gst_pad_get_peer (pad); GstAggregatorPadPrivate *padpriv = GST_AGGREGATOR_PAD (pad)->priv; if (peer) { ret = gst_pad_send_event (peer, gst_event_ref (evdata->event)); GST_DEBUG_OBJECT (pad, "return of event push is %d", ret); gst_object_unref (peer); } if (ret == FALSE) { if (GST_EVENT_TYPE (evdata->event) == GST_EVENT_SEEK) GST_ERROR_OBJECT (pad, "Event %" GST_PTR_FORMAT " failed", evdata->event); if (GST_EVENT_TYPE (evdata->event) == GST_EVENT_SEEK) { GstQuery *seeking = gst_query_new_seeking (GST_FORMAT_TIME); if (gst_pad_query (peer, seeking)) { gboolean seekable; gst_query_parse_seeking (seeking, NULL, &seekable, NULL, NULL); if (seekable == FALSE) { GST_INFO_OBJECT (pad, "Source not seekable, We failed but it does not matter!"); ret = TRUE; } } else { GST_ERROR_OBJECT (pad, "Query seeking FAILED"); } } if (evdata->flush) { padpriv->pending_flush_start = FALSE; padpriv->pending_flush_stop = FALSE; } } else { evdata->one_actually_seeked = TRUE; } evdata->result &= ret; /* Always send to all pads */ return FALSE; }
static void relative_seek (GstPlay * play, gdouble percent) { GstQuery *query; gboolean seekable = FALSE; gint64 dur = -1, pos = -1, step; g_return_if_fail (percent >= -1.0 && percent <= 1.0); if (!gst_element_query_position (play->playbin, GST_FORMAT_TIME, &pos)) goto seek_failed; query = gst_query_new_seeking (GST_FORMAT_TIME); if (!gst_element_query (play->playbin, query)) { gst_query_unref (query); goto seek_failed; } gst_query_parse_seeking (query, NULL, &seekable, NULL, &dur); gst_query_unref (query); if (!seekable || dur <= 0) goto seek_failed; step = dur * percent; if (ABS (step) < GST_SECOND) step = (percent < 0) ? -GST_SECOND : GST_SECOND; pos = pos + step; if (pos > dur) { if (!play_next (play)) { g_print ("\n%s\n", _("Reached end of play list.")); g_main_loop_quit (play->loop); } } else { if (pos < 0) pos = 0; play_do_seek (play, pos, play->rate, play->trick_mode); } return; seek_failed: { g_print ("\nCould not seek.\n"); } }
static gboolean gst_mve_demux_handle_src_query (GstPad * pad, GstQuery * query) { gboolean res = FALSE; switch (GST_QUERY_TYPE (query)) { case GST_QUERY_POSITION:{ GstFormat format; gst_query_parse_position (query, &format, NULL); /* we only support TIME */ if (format == GST_FORMAT_TIME) { GstMveDemuxStream *s = gst_pad_get_element_private (pad); if (s != NULL) { GST_OBJECT_LOCK (s); gst_query_set_position (query, GST_FORMAT_TIME, s->last_ts); GST_OBJECT_UNLOCK (s); res = TRUE; } } break; } case GST_QUERY_SEEKING:{ GstFormat format; gst_query_parse_seeking (query, &format, NULL, NULL, NULL); if (format == GST_FORMAT_TIME) { gst_query_set_seeking (query, GST_FORMAT_TIME, FALSE, 0, -1); res = TRUE; } break; } case GST_QUERY_DURATION:{ /* FIXME: really should implement/estimate this somehow */ res = FALSE; break; } default: res = gst_pad_query_default (pad, query); break; } return res; }
static void relative_seek (GstPlay * play, gdouble percent) { GstQuery *query; gboolean seekable = FALSE; gint64 dur = -1, pos = -1; g_return_if_fail (percent >= -1.0 && percent <= 1.0); if (!gst_element_query_position (play->playbin, GST_FORMAT_TIME, &pos)) goto seek_failed; query = gst_query_new_seeking (GST_FORMAT_TIME); if (!gst_element_query (play->playbin, query)) { gst_query_unref (query); goto seek_failed; } gst_query_parse_seeking (query, NULL, &seekable, NULL, &dur); gst_query_unref (query); if (!seekable || dur <= 0) goto seek_failed; pos = pos + dur * percent; if (pos > dur) { if (!play_next (play)) { g_print ("\nReached end of play list.\n"); g_main_loop_quit (play->loop); } } else { if (pos < 0) pos = 0; if (!gst_element_seek_simple (play->playbin, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT, pos)) goto seek_failed; } return; seek_failed: { g_print ("\nCould not seek.\n"); } }
static gboolean gst_gio_base_sink_query (GstBaseSink * bsink, GstQuery * query) { GstGioBaseSink *sink = GST_GIO_BASE_SINK (bsink); GstFormat format; switch (GST_QUERY_TYPE (query)) { case GST_QUERY_POSITION: gst_query_parse_position (query, &format, NULL); switch (format) { case GST_FORMAT_BYTES: case GST_FORMAT_DEFAULT: gst_query_set_position (query, format, sink->position); return TRUE; default: return FALSE; } case GST_QUERY_FORMATS: gst_query_set_formats (query, 2, GST_FORMAT_DEFAULT, GST_FORMAT_BYTES); return TRUE; case GST_QUERY_URI: if (GST_IS_URI_HANDLER (sink)) { gchar *uri; uri = gst_uri_handler_get_uri (GST_URI_HANDLER (sink)); gst_query_set_uri (query, uri); g_free (uri); return TRUE; } return FALSE; case GST_QUERY_SEEKING: gst_query_parse_seeking (query, &format, NULL, NULL, NULL); if (format == GST_FORMAT_BYTES || format == GST_FORMAT_DEFAULT) { gst_query_set_seeking (query, format, GST_GIO_STREAM_IS_SEEKABLE (sink->stream), 0, -1); } else { gst_query_set_seeking (query, format, FALSE, 0, -1); } return TRUE; default: return GST_BASE_SINK_CLASS (parent_class)->query (bsink, query); } }
bool GstVideoPlayerBackend::isSeekable() const { if (!m_pipeline) return false; GstQuery *query = gst_query_new_seeking(GST_FORMAT_TIME); gboolean re = gst_element_query(m_pipeline, query); if (re) { gboolean seekable; gst_query_parse_seeking(query, 0, &seekable, 0, 0); re = seekable; } else qDebug() << "gstreamer: Failed to query seeking properties of the stream"; gst_query_unref(query); return re; }
static gboolean gst_real_audio_demux_src_query (GstPad * pad, GstQuery * query) { GstRealAudioDemux *demux; gboolean ret = FALSE; demux = GST_REAL_AUDIO_DEMUX (gst_pad_get_parent (pad)); switch (GST_QUERY_TYPE (query)) { case GST_QUERY_DURATION:{ GstFormat format; gst_query_parse_duration (query, &format, NULL); if (format == GST_FORMAT_TIME && demux->duration > 0) { gst_query_set_duration (query, GST_FORMAT_TIME, demux->duration); ret = TRUE; } else if (format == GST_FORMAT_BYTES && demux->upstream_size > 0) { gst_query_set_duration (query, GST_FORMAT_BYTES, demux->upstream_size - demux->data_offset); ret = TRUE; } break; } case GST_QUERY_SEEKING:{ GstFormat format; gboolean seekable; gst_query_parse_seeking (query, &format, NULL, NULL, NULL); seekable = (format == GST_FORMAT_TIME && demux->seekable); gst_query_set_seeking (query, format, seekable, 0, (format == GST_FORMAT_TIME) ? demux->duration : -1); ret = TRUE; break; } default: ret = gst_pad_query_default (pad, query); break; } gst_object_unref (demux); return ret; }
static gboolean gst_fake_sink_query (GstBaseSink * bsink, GstQuery * query) { gboolean ret; switch (GST_QUERY_TYPE (query)) { case GST_QUERY_SEEKING:{ GstFormat fmt; /* we don't supporting seeking */ gst_query_parse_seeking (query, &fmt, NULL, NULL, NULL); gst_query_set_seeking (query, fmt, FALSE, 0, -1); ret = TRUE; break; } default: ret = GST_BASE_SINK_CLASS (parent_class)->query (bsink, query); break; } return ret; }
static gboolean impl_seekable (RBPlayer *player) { RBPlayerGst *mp = RB_PLAYER_GST (player); gboolean can_seek = TRUE; GstQuery *query; if (mp->priv->playbin == NULL) return FALSE; query = gst_query_new_seeking (GST_FORMAT_TIME); if (gst_element_query (mp->priv->playbin, query)) { gst_query_parse_seeking (query, NULL, &can_seek, NULL, NULL); } else { gst_query_unref (query); query = gst_query_new_duration (GST_FORMAT_TIME); can_seek = gst_element_query (mp->priv->playbin, query); } gst_query_unref (query); return can_seek; }
/** * @brief query vmethod implementation */ static gboolean gst_tensor_reposink_query (GstBaseSink * sink, GstQuery * query) { GstTensorRepoSink *self; GstQueryType type; GstFormat format; self = GST_TENSOR_REPOSINK (sink); type = GST_QUERY_TYPE (query); GST_DEBUG_OBJECT (self, "received query %s", GST_QUERY_TYPE_NAME (query)); switch (type) { case GST_QUERY_SEEKING: gst_query_parse_seeking (query, &format, NULL, NULL, NULL); gst_query_set_seeking (query, format, FALSE, 0, -1); return TRUE; default: break; } return GST_BASE_SINK_CLASS (parent_class)->query (sink, query); }
static gboolean gst_raw_parse_src_query (GstPad * pad, GstObject * parent, GstQuery * query) { GstRawParse *rp = GST_RAW_PARSE (parent); gboolean ret = FALSE; GST_DEBUG ("src_query %s", gst_query_type_get_name (GST_QUERY_TYPE (query))); switch (GST_QUERY_TYPE (query)) { case GST_QUERY_POSITION: { GstFormat format; gint64 time, value; GST_LOG ("query position"); gst_query_parse_position (query, &format, NULL); time = rp->segment.position; ret = gst_raw_parse_convert (rp, GST_FORMAT_TIME, time, format, &value); gst_query_set_position (query, format, value); break; } case GST_QUERY_DURATION:{ gint64 duration; GstFormat format; GstQuery *bquery; GST_LOG ("query duration"); ret = gst_pad_peer_query (rp->sinkpad, query); if (ret) goto done; gst_query_parse_duration (query, &format, NULL); /* We only handle TIME and DEFAULT format */ if (format != GST_FORMAT_TIME && format != GST_FORMAT_DEFAULT) goto error; bquery = gst_query_new_duration (GST_FORMAT_BYTES); ret = gst_pad_peer_query (rp->sinkpad, bquery); if (!ret) { gst_query_unref (bquery); goto error; } gst_query_parse_duration (bquery, NULL, &duration); gst_query_unref (bquery); ret = gst_raw_parse_convert (rp, GST_FORMAT_BYTES, duration, format, &duration); if (ret) gst_query_set_duration (query, format, duration); break; } case GST_QUERY_CONVERT: { GstFormat src_fmt, dest_fmt; gint64 src_val, dest_val; GST_LOG ("query convert"); gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val); ret = gst_raw_parse_convert (rp, src_fmt, src_val, dest_fmt, &dest_val); if (!ret) goto error; gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val); break; } case GST_QUERY_SEEKING:{ GstFormat fmt; ret = TRUE; gst_query_parse_seeking (query, &fmt, NULL, NULL, NULL); if (fmt != GST_FORMAT_TIME && fmt != GST_FORMAT_DEFAULT && fmt != GST_FORMAT_BYTES) { gst_query_set_seeking (query, fmt, FALSE, -1, -1); } else if (rp->mode == GST_PAD_MODE_PUSH) { GstQuery *peerquery = gst_query_new_seeking (GST_FORMAT_BYTES); gboolean seekable; seekable = gst_pad_peer_query (rp->sinkpad, peerquery); if (seekable) gst_query_parse_seeking (peerquery, NULL, &seekable, NULL, NULL); gst_query_unref (peerquery); gst_query_set_seeking (query, fmt, seekable, seekable ? 0 : -1, -1); } else { gst_query_set_seeking (query, fmt, TRUE, 0, -1); } break; } default: /* else forward upstream */ ret = gst_pad_query_default (rp->sinkpad, parent, query); break; } done: return ret; /* ERRORS */ error: { GST_DEBUG_OBJECT (rp, "query failed"); goto done; } }
/* handle queries for location and length in requested format */ static gboolean gst_aiff_parse_pad_query (GstPad * pad, GstQuery * query) { gboolean res = TRUE; GstAiffParse *aiff = GST_AIFF_PARSE (gst_pad_get_parent (pad)); /* only if we know */ if (aiff->state != AIFF_PARSE_DATA) { gst_object_unref (aiff); return FALSE; } switch (GST_QUERY_TYPE (query)) { case GST_QUERY_DURATION: { gint64 duration = 0; GstFormat format; gst_query_parse_duration (query, &format, NULL); switch (format) { case GST_FORMAT_TIME:{ if ((res = gst_aiff_parse_calculate_duration (aiff))) { duration = aiff->duration; } break; } default: format = GST_FORMAT_BYTES; duration = aiff->datasize; break; } gst_query_set_duration (query, format, duration); break; } case GST_QUERY_CONVERT: { gint64 srcvalue, dstvalue; GstFormat srcformat, dstformat; gst_query_parse_convert (query, &srcformat, &srcvalue, &dstformat, &dstvalue); res = gst_aiff_parse_pad_convert (pad, srcformat, srcvalue, &dstformat, &dstvalue); if (res) gst_query_set_convert (query, srcformat, srcvalue, dstformat, dstvalue); break; } case GST_QUERY_SEEKING:{ GstFormat fmt; gst_query_parse_seeking (query, &fmt, NULL, NULL, NULL); if (fmt == GST_FORMAT_TIME) { gboolean seekable = TRUE; if (!gst_aiff_parse_calculate_duration (aiff)) { seekable = FALSE; } gst_query_set_seeking (query, GST_FORMAT_TIME, seekable, 0, aiff->duration); res = TRUE; } break; } default: res = gst_pad_query_default (pad, query); break; } gst_object_unref (aiff); return res; }
static gboolean gst_musepackdec_src_query (GstPad * pad, GstObject * parent, GstQuery * query) { GstMusepackDec *musepackdec = GST_MUSEPACK_DEC (parent); GstFormat format; gboolean res = FALSE; gint samplerate; samplerate = g_atomic_int_get (&musepackdec->rate); if (samplerate == 0) goto done; switch (GST_QUERY_TYPE (query)) { case GST_QUERY_POSITION:{ gint64 cur, cur_off; gst_query_parse_position (query, &format, NULL); GST_OBJECT_LOCK (musepackdec); cur_off = musepackdec->segment.position; GST_OBJECT_UNLOCK (musepackdec); if (format == GST_FORMAT_TIME) { cur = gst_util_uint64_scale_int (cur_off, GST_SECOND, samplerate); gst_query_set_position (query, GST_FORMAT_TIME, cur); res = TRUE; } else if (format == GST_FORMAT_DEFAULT) { gst_query_set_position (query, GST_FORMAT_DEFAULT, cur_off); res = TRUE; } break; } case GST_QUERY_DURATION:{ gint64 len, len_off; gst_query_parse_duration (query, &format, NULL); GST_OBJECT_LOCK (musepackdec); len_off = musepackdec->segment.duration; GST_OBJECT_UNLOCK (musepackdec); if (format == GST_FORMAT_TIME) { len = gst_util_uint64_scale_int (len_off, GST_SECOND, samplerate); gst_query_set_duration (query, GST_FORMAT_TIME, len); res = TRUE; } else if (format == GST_FORMAT_DEFAULT) { gst_query_set_duration (query, GST_FORMAT_DEFAULT, len_off); res = TRUE; } break; } case GST_QUERY_SEEKING:{ GstFormat fmt; gint64 len, len_off; res = TRUE; gst_query_parse_seeking (query, &fmt, NULL, NULL, NULL); GST_OBJECT_LOCK (musepackdec); len_off = musepackdec->segment.duration; GST_OBJECT_UNLOCK (musepackdec); if (fmt == GST_FORMAT_TIME) { len = gst_util_uint64_scale_int (len_off, GST_SECOND, samplerate); gst_query_set_seeking (query, fmt, TRUE, 0, len); } else if (fmt == GST_FORMAT_DEFAULT) { gst_query_set_seeking (query, fmt, TRUE, 0, len_off); } else { gst_query_set_seeking (query, fmt, FALSE, -1, -1); } break; } default: res = gst_pad_query_default (pad, parent, query); break; } done: return res; }
void MediaImpl::_checkMessages() { if (_bus != NULL) { // Get message. GstMessage *msg = gst_bus_timed_pop_filtered( _bus, 0, (GstMessageType) (GST_MESSAGE_STATE_CHANGED | GST_MESSAGE_ERROR | GST_MESSAGE_EOS | GST_MESSAGE_ASYNC_DONE)); if (msg != NULL) { GError *err; gchar *debug_info; switch (GST_MESSAGE_TYPE (msg)) { // Error //////////////////////////////////////////////// case GST_MESSAGE_ERROR: gst_message_parse_error(msg, &err, &debug_info); g_printerr("Error received from element %s: %s\n", GST_OBJECT_NAME (msg->src), err->message); g_printerr("Debugging information: %s\n", debug_info ? debug_info : "none"); g_clear_error(&err); g_free(debug_info); if (!_isSharedMemorySource) { _terminate = true; } else { _attached = false; gst_element_set_state (_pipeline, GST_STATE_PAUSED); gst_element_set_state (_pipeline, GST_STATE_NULL); gst_element_set_state (_pipeline, GST_STATE_READY); } // _finish(); break; // End-of-stream //////////////////////////////////////// case GST_MESSAGE_EOS: // Automatically loop back. g_print("End-Of-Stream reached.\n"); resetMovie(); // _terminate = true; // _finish(); break; // Pipeline has prerolled/ready to play /////////////// case GST_MESSAGE_ASYNC_DONE: if (!_isMovieReady()) { // Check if seeking is allowed. gint64 start, end; GstQuery *query = gst_query_new_seeking (GST_FORMAT_TIME); if (gst_element_query (_pipeline, query)) { gst_query_parse_seeking (query, NULL, (gboolean*)&_seekEnabled, &start, &end); if (_seekEnabled) { g_print ("Seeking is ENABLED from %" GST_TIME_FORMAT " to %" GST_TIME_FORMAT "\n", GST_TIME_ARGS (start), GST_TIME_ARGS (end)); } else { g_print ("Seeking is DISABLED for this stream.\n"); } } else { g_printerr ("Seeking query failed."); } gst_query_unref (query); // Movie is ready! _setMovieReady(true); } break; case GST_MESSAGE_STATE_CHANGED: // We are only interested in state-changed messages from the pipeline. if (GST_MESSAGE_SRC (msg) == GST_OBJECT (_pipeline)) { GstState oldState, newState, pendingState; gst_message_parse_state_changed(msg, &oldState, &newState, &pendingState); g_print("Pipeline state for movie %s changed from %s to %s:\n", _uri.toUtf8().constData(), gst_element_state_get_name(oldState), gst_element_state_get_name(newState)); } break; default: // We should not reach here. g_printerr("Unexpected message received.\n"); break; } gst_message_unref(msg); } } }
static void test_queries (InsanityTest * test) { GstQuery *query = gst_query_new_seeking (GST_FORMAT_TIME); if (gst_element_query (glob_pipeline, query)) { GstFormat fmt; gboolean seekable, known_seekable; gst_query_parse_seeking (query, &fmt, &seekable, NULL, NULL); if (glob_media_desc_parser == NULL) { insanity_test_validate_checklist_item (test, "seekable-detection", TRUE, "No media-descriptor file, result not verified against it"); glob_seekable = seekable; } else { known_seekable = media_descriptor_parser_get_seekable (glob_media_desc_parser); insanity_test_validate_checklist_item (test, "seekable-detection", known_seekable == seekable, NULL); glob_seekable = known_seekable; } } else { if (glob_media_desc_parser != NULL) glob_seekable = media_descriptor_parser_get_seekable (glob_media_desc_parser); LOG (test, "%s Does not handle seeking queries (seekable-detection \"SKIP\")", gst_element_factory_get_metadata (gst_element_get_factory (glob_demuxer), GST_ELEMENT_METADATA_LONGNAME)); } gst_query_unref (query); query = gst_query_new_duration (GST_FORMAT_TIME); if (gst_element_query (glob_pipeline, query)) { GstFormat fmt; gchar *validate_msg = NULL; gint64 duration; if (glob_media_desc_parser == NULL) { gst_query_parse_duration (query, &fmt, &duration); validate_msg = g_strdup_printf ("Found duration %" GST_TIME_FORMAT " No media-descriptor file, result not verified against it", GST_TIME_ARGS (duration)); insanity_test_validate_checklist_item (test, "duration-detection", TRUE, validate_msg); g_free (validate_msg); glob_duration = duration; } else { glob_duration = media_descriptor_parser_get_duration (glob_media_desc_parser); gst_query_parse_duration (query, &fmt, &duration); if (glob_duration != duration) { validate_msg = g_strdup_printf ("Found time %" GST_TIME_FORMAT "-> %" GST_TIME_FORMAT, GST_TIME_ARGS (duration), GST_TIME_ARGS (glob_duration)); insanity_test_validate_checklist_item (test, "duration-detection", glob_duration == duration, validate_msg); g_free (validate_msg); } else { insanity_test_validate_checklist_item (test, "duration-detection", TRUE, NULL); } } } else { if (glob_media_desc_parser != NULL) glob_duration = media_descriptor_parser_get_seekable (glob_media_desc_parser); LOG (test, "%s Does not handle duration queries " "(duration-detection \"SKIP\")", gst_element_factory_get_metadata (gst_element_get_factory (glob_demuxer), GST_ELEMENT_METADATA_LONGNAME)); } if (GST_CLOCK_TIME_IS_VALID (glob_duration) && glob_playback_duration > glob_duration) { LOG (test, "playback_duration > media duration, setting it" "to media_duration != 2"); glob_playback_duration = glob_duration / 2; } gst_query_unref (query); next_test (test); }
static gboolean gst_au_parse_src_query (GstPad * pad, GstQuery * query) { GstAuParse *auparse; gboolean ret = FALSE; auparse = GST_AU_PARSE (gst_pad_get_parent (pad)); switch (GST_QUERY_TYPE (query)) { case GST_QUERY_DURATION:{ GstFormat bformat = GST_FORMAT_BYTES; GstFormat format; gint64 len, val; gst_query_parse_duration (query, &format, NULL); if (!gst_pad_query_peer_duration (auparse->sinkpad, &bformat, &len)) { GST_DEBUG_OBJECT (auparse, "failed to query upstream length"); break; } GST_OBJECT_LOCK (auparse); len -= auparse->offset; GST_OBJECT_UNLOCK (auparse); ret = gst_au_parse_src_convert (auparse, bformat, len, format, &val); if (ret) { gst_query_set_duration (query, format, val); } break; } case GST_QUERY_POSITION:{ GstFormat bformat = GST_FORMAT_BYTES; GstFormat format; gint64 pos, val; gst_query_parse_position (query, &format, NULL); if (!gst_pad_query_peer_position (auparse->sinkpad, &bformat, &pos)) { GST_DEBUG_OBJECT (auparse, "failed to query upstream position"); break; } GST_OBJECT_LOCK (auparse); pos -= auparse->offset; GST_OBJECT_UNLOCK (auparse); ret = gst_au_parse_src_convert (auparse, GST_FORMAT_BYTES, pos, format, &val); if (ret) { gst_query_set_position (query, format, val); } break; } case GST_QUERY_SEEKING:{ GstFormat format; gst_query_parse_seeking (query, &format, NULL, NULL, NULL); /* FIXME: query duration in 'format' gst_query_set_seeking (query, format, TRUE, 0, duration); */ gst_query_set_seeking (query, format, TRUE, 0, GST_CLOCK_TIME_NONE); ret = TRUE; break; } default: ret = gst_pad_query_default (pad, query); break; } gst_object_unref (auparse); return ret; }
static gboolean hls_test_bus_message (InsanityGstPipelineTest * ptest, GstMessage * msg) { switch (GST_MESSAGE_TYPE (msg)) { case GST_MESSAGE_BUFFERING: { gint per; gst_message_parse_buffering (msg, &per); /* First buffering happend properly, this is requiered to be able to * start seeking */ if (G_UNLIKELY (glob_buffered == FALSE)) { if (per == 100) { insanity_test_validate_checklist_item (INSANITY_TEST (ptest), "done-buffering", TRUE, NULL); glob_buffered = TRUE; if (glob_buffering_timeout != 0) { g_source_remove (glob_buffering_timeout); glob_buffering_timeout = 0; } } else { glob_buffering_timeout = g_timeout_add (250, (GSourceFunc) buffering_timeout, INSANITY_TEST (ptest)); } } break; } case GST_MESSAGE_STATE_CHANGED: if (GST_MESSAGE_SRC (msg) == GST_OBJECT (glob_pipeline)) { const char *validate_checklist_item = glob_validate_on_playing; GstState oldstate, newstate, pending; gst_message_parse_state_changed (msg, &oldstate, &newstate, &pending); if (newstate == GST_STATE_PAUSED && oldstate == GST_STATE_READY) { GstIterator *it; GValue v = { 0, }; gboolean queried; InsanityTest *test = INSANITY_TEST (ptest); GstQuery *query = gst_query_new_latency (); const gchar *step_message = "Could not query seeking\n"; if ((queried = gst_element_query (glob_pipeline, query))) { gst_query_parse_latency (query, &glob_is_live, NULL, NULL); step_message = NULL; } else insanity_test_printf (test, "Could not query\n"); insanity_gst_pipeline_test_set_live (ptest, glob_is_live); insanity_test_validate_checklist_item (test, "queried-live", queried, step_message); gst_query_unref (query); step_message = "Could not query seekable\n"; query = gst_query_new_seeking (GST_FORMAT_TIME); if ((queried = gst_element_query (glob_pipeline, query))) { gst_query_parse_seeking (query, NULL, &glob_is_seekable, NULL, NULL); step_message = NULL; } else insanity_test_printf (test, "Could not query\n"); insanity_test_validate_checklist_item (test, "queried-seekable", queried, step_message); gst_query_unref (query); /* Iterate over the bins to find a hlsdemux */ it = gst_bin_iterate_recurse (GST_BIN (glob_pipeline)); if (gst_iterator_find_custom (it, (GCompareFunc) find_hlsdemux, &v, NULL)) { glob_hlsdemux = g_value_dup_object (&v); } g_value_unset (&v); gst_iterator_free (it); if (glob_hlsdemux != NULL) { insanity_test_validate_checklist_item (test, "protocol-is-hls", TRUE, "HLS protocol in use"); gst_object_unref (glob_hlsdemux); } else { insanity_test_validate_checklist_item (test, "protocol-is-hls", FALSE, "HLS protocol in use"); insanity_test_done (test); } /* Watch pipeline only if seekable */ if (glob_is_seekable) watch_pipeline (ptest); } else if (newstate == GST_STATE_PLAYING && pending == GST_STATE_VOID_PENDING && validate_checklist_item) { glob_validate_on_playing = NULL; insanity_test_validate_checklist_item (INSANITY_TEST (ptest), validate_checklist_item, TRUE, NULL); /* let it run a couple seconds */ glob_wait_time = hls_test_get_wait_time (INSANITY_TEST (ptest)); glob_timer_id = g_timeout_add (250, (GSourceFunc) & wait_and_end_step, INSANITY_TEST (ptest)); } } break; case GST_MESSAGE_EOS: return FALSE; default: break; } return TRUE; }