mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-03-30 12:49:40 +00:00
ext/vorbis/vorbisenc.c: Implement position and duration queries.
Original commit message from CVS: * 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.
This commit is contained in:
parent
42f0462534
commit
a04b000bf4
3 changed files with 68 additions and 45 deletions
|
@ -1,3 +1,12 @@
|
|||
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),
|
||||
|
|
|
@ -405,6 +405,8 @@ gst_vorbisenc_get_query_types (GstPad * pad)
|
|||
{
|
||||
static const GstQueryType gst_vorbisenc_src_query_types[] = {
|
||||
GST_QUERY_POSITION,
|
||||
GST_QUERY_DURATION,
|
||||
GST_QUERY_CONVERT,
|
||||
0
|
||||
};
|
||||
|
||||
|
@ -416,52 +418,50 @@ gst_vorbisenc_src_query (GstPad * pad, GstQuery * query)
|
|||
{
|
||||
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;
|
||||
|
||||
peer_formats =
|
||||
gst_pad_get_formats (GST_PAD_PEER (vorbisenc->sinkpad));
|
||||
|
||||
while (peer_formats && *peer_formats && !res) {
|
||||
|
||||
GstFormat peer_format = *peer_formats;
|
||||
|
||||
/* do the probe */
|
||||
if (gst_pad_query (GST_PAD_PEER (vorbisenc->sinkpad),
|
||||
GST_QUERY_TOTAL, &peer_format, &peer_value)) {
|
||||
GstFormat conv_format;
|
||||
|
||||
/* 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;
|
||||
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;
|
||||
}
|
||||
|
||||
fmt = GST_FORMAT_TIME;
|
||||
if (!(res = gst_pad_query_position (peerpad, &fmt, &pos)))
|
||||
break;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
fmt = GST_FORMAT_TIME;
|
||||
if (!(res = gst_pad_query_duration (peerpad, &fmt, &dur)))
|
||||
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:
|
||||
|
@ -483,6 +483,8 @@ gst_vorbisenc_src_query (GstPad * pad, GstQuery * query)
|
|||
}
|
||||
|
||||
error:
|
||||
gst_object_unref (peerpad);
|
||||
gst_object_unref (vorbisenc);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,14 +23,26 @@
|
|||
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, "-:--:--.---------");
|
||||
}
|
||||
|
||||
g_print ("%" G_GINT64_FORMAT " %" G_GINT64_FORMAT "\n", duration, position);
|
||||
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 ("%s / %s\n", pos_str, dur_str);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -49,7 +61,7 @@ main (gint argc, gchar * argv[])
|
|||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue