+2005-10-20 Tim-Philipp Müller <tim at centricular dot net>
+
+ * ext/vorbis/vorbisenc.c: (gst_vorbisenc_get_query_types),
+ (gst_vorbisenc_src_query):
+ Implement position and duration queries.
+
+ * gst/playback/test3.c: (update_scale), (main):
+ Fix for async state changes and print nicer output.
+
2005-10-20 Wim Taymans <wim@fluendo.com>
* gst/playback/test5.c: (new_pad), (no_more_pads), (start_finding),
{
static const GstQueryType gst_vorbisenc_src_query_types[] = {
GST_QUERY_POSITION,
+ GST_QUERY_DURATION,
+ GST_QUERY_CONVERT,
0
};
{
gboolean res = TRUE;
GstVorbisEnc *vorbisenc;
+ GstPad *peerpad;
- vorbisenc = GST_VORBISENC (GST_PAD_PARENT (pad));
+ vorbisenc = GST_VORBISENC (gst_pad_get_parent (pad));
+ peerpad = gst_pad_get_peer (GST_PAD (vorbisenc->sinkpad));
switch (GST_QUERY_TYPE (query)) {
case GST_QUERY_POSITION:
{
-#if 0
- switch (*format) {
- case GST_FORMAT_BYTES:
- case GST_FORMAT_TIME:
- {
- gint64 peer_value;
- const GstFormat *peer_formats;
+ GstFormat fmt, req_fmt;
+ gint64 pos, val;
- res = FALSE;
+ gst_query_parse_position (query, &req_fmt, NULL);
+ if ((res = gst_pad_query_position (peerpad, &req_fmt, &val))) {
+ gst_query_set_position (query, req_fmt, val);
+ break;
+ }
- peer_formats =
- gst_pad_get_formats (GST_PAD_PEER (vorbisenc->sinkpad));
+ fmt = GST_FORMAT_TIME;
+ if (!(res = gst_pad_query_position (peerpad, &fmt, &pos)))
+ break;
- while (peer_formats && *peer_formats && !res) {
+ if ((res = gst_pad_query_convert (peerpad, fmt, pos, &req_fmt, &val))) {
+ gst_query_set_position (query, req_fmt, val);
+ }
+ break;
+ }
+ case GST_QUERY_DURATION:
+ {
+ GstFormat fmt, req_fmt;
+ gint64 dur, val;
- GstFormat peer_format = *peer_formats;
+ gst_query_parse_duration (query, &req_fmt, NULL);
+ if ((res = gst_pad_query_duration (peerpad, &req_fmt, &val))) {
+ gst_query_set_duration (query, req_fmt, val);
+ break;
+ }
- /* do the probe */
- if (gst_pad_query (GST_PAD_PEER (vorbisenc->sinkpad),
- GST_QUERY_TOTAL, &peer_format, &peer_value)) {
- GstFormat conv_format;
+ fmt = GST_FORMAT_TIME;
+ if (!(res = gst_pad_query_duration (peerpad, &fmt, &dur)))
+ break;
- /* convert to TIME */
- conv_format = GST_FORMAT_TIME;
- res = gst_vorbisenc_convert_sink (vorbisenc->sinkpad,
- peer_format, peer_value, &conv_format, value);
- /* and to final format */
- res &= gst_vorbisenc_convert_src (pad,
- GST_FORMAT_TIME, *value, format, value);
- }
- peer_formats++;
- }
- break;
- }
- default:
- res = FALSE;
- break;
+ if ((res = gst_pad_query_convert (peerpad, fmt, dur, &req_fmt, &val))) {
+ gst_query_set_duration (query, req_fmt, val);
}
-#endif
- res = FALSE;
break;
}
case GST_QUERY_CONVERT:
}
error:
+ gst_object_unref (peerpad);
+ gst_object_unref (vorbisenc);
return res;
}
static gboolean
update_scale (GstElement * element)
{
- gint64 duration;
- gint64 position;
+ gint64 duration = -1;
+ gint64 position = -1;
GstFormat format = GST_FORMAT_TIME;
+ gchar dur_str[32], pos_str[32];
- gst_element_query_position (element, &format, &position);
- gst_element_query_duration (element, &format, &duration);
+ if (gst_element_query_position (element, &format, &position) &&
+ position != -1) {
+ g_snprintf (pos_str, 32, "%" GST_TIME_FORMAT, GST_TIME_ARGS (position));
+ } else {
+ g_snprintf (pos_str, 32, "-:--:--.---------");
+ }
+
+ if (gst_element_query_duration (element, &format, &duration) &&
+ duration != -1) {
+ g_snprintf (dur_str, 32, "%" GST_TIME_FORMAT, GST_TIME_ARGS (duration));
+ } else {
+ g_snprintf (dur_str, 32, "-:--:--.---------");
+ }
- g_print ("%" G_GINT64_FORMAT " %" G_GINT64_FORMAT "\n", duration, position);
+ g_print ("%s / %s\n", pos_str, dur_str);
return TRUE;
}
g_object_set (G_OBJECT (player), "uri", argv[1], NULL);
res = gst_element_set_state (player, GST_STATE_PLAYING);
- if (res != GST_STATE_CHANGE_SUCCESS) {
+ if (res == GST_STATE_CHANGE_FAILURE) {
g_print ("could not play\n");
return -1;
}