9 get_position_info (GstElement * cdparanoia)
11 GstFormat track_format;
12 const GstFormat *formats;
15 track_format = gst_format_get_by_nick ("track");
16 g_assert (track_format != 0);
18 pad = gst_element_get_pad (cdparanoia, "src");
19 formats = gst_pad_get_formats (pad);
22 const GstFormatDefinition *definition;
27 definition = gst_format_get_details (*formats);
30 res = gst_pad_query (pad, GST_QUERY_POSITION, &format, &position);
32 if (format == GST_FORMAT_TIME) {
33 position /= GST_SECOND;
34 g_print ("%s: %" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT,
35 definition->nick, position / 60, position % 60);
37 g_print ("%s: %" G_GINT64_FORMAT, definition->nick, position);
49 get_track_info (GstElement * cdparanoia)
51 GstFormat track_format;
52 gint64 total_tracks = 0, total_time = 0;
54 const GstFormat *formats;
56 gint64 time_count = 0;
58 track_format = gst_format_get_by_nick ("track");
59 g_assert (track_format != 0);
61 pad = gst_element_get_pad (cdparanoia, "src");
62 formats = gst_pad_get_formats (pad);
64 /* we loop over all supported formats and report the total
67 const GstFormatDefinition *definition;
72 definition = gst_format_get_details (*formats);
75 res = gst_pad_query (pad, GST_QUERY_TOTAL, &format, &total);
77 if (format == GST_FORMAT_TIME) {
79 g_print ("%s total: %" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT "\n",
80 definition->nick, total / 60, total % 60);
82 g_print ("%s total: %" G_GINT64_FORMAT "\n", definition->nick, total);
84 if (format == track_format)
86 else if (format == GST_FORMAT_TIME)
89 g_print ("failed to get %s total\n", definition->nick);
94 /* then we loop over all the tracks to get more info.
95 * since pad_convert always works from 0, the time from track 1 needs
96 * to be substracted from track 2 */
97 for (i = 0; i <= total_tracks; i++) {
101 if (i < total_tracks) {
104 format = GST_FORMAT_TIME;
105 res = gst_pad_convert (pad, track_format, i, &format, &time);
113 /* for the first track (i==0) we wait until we have the
114 * time of the next track */
116 gint64 length = time - time_count;
118 g_print ("track %d: %" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT
119 " -> %" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT ", length: %"
120 G_GINT64_FORMAT ":%02" G_GINT64_FORMAT "\n",
122 time_count / 60, time_count % 60,
123 time / 60, time % 60, length / 60, length % 60);
126 g_print ("could not get time for track %d\n", i);
134 main (int argc, char **argv)
136 GstElement *pipeline;
137 GstElement *cdparanoia;
138 GstElement *audiosink;
140 GstFormat track_format;
145 gst_init (&argc, &argv);
147 pipeline = gst_pipeline_new ("pipeline");
149 cdparanoia = gst_element_factory_make ("cdparanoia", "cdparanoia");
150 g_assert (cdparanoia);
151 g_object_set (G_OBJECT (cdparanoia), "paranoia_mode", 0, NULL);
153 audiosink = gst_element_factory_make (DEFAULT_AUDIOSINK, DEFAULT_AUDIOSINK);
154 g_assert (audiosink);
156 gst_bin_add (GST_BIN (pipeline), cdparanoia);
157 gst_bin_add (GST_BIN (pipeline), audiosink);
159 gst_element_link_pads (cdparanoia, "src", audiosink, "sink");
161 g_signal_connect (G_OBJECT (pipeline), "deep_notify",
162 G_CALLBACK (gst_object_default_deep_notify), NULL);
164 gst_element_set_state (pipeline, GST_STATE_PAUSED);
166 /* now we go into probe mode */
167 get_track_info (cdparanoia);
169 track_format = gst_format_get_by_nick ("track");
170 g_assert (track_format != 0);
172 pad = gst_element_get_pad (cdparanoia, "src");
175 g_print ("playing from track 3\n");
177 event = gst_event_new_seek (track_format |
178 GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH, 3);
180 res = gst_pad_send_event (pad, event);
182 g_warning ("seek failed");
184 gst_element_set_state (pipeline, GST_STATE_PLAYING);
187 while (count++ < 500) {
188 get_position_info (cdparanoia);
189 g_usleep (G_USEC_PER_SEC / 2);
191 gst_element_set_state (pipeline, GST_STATE_PAUSED);
193 g_print ("\nplaying from second 25 to second 29\n");
194 /* seek to some seconds */
195 event = gst_event_new_segment_seek (GST_FORMAT_TIME |
196 GST_SEEK_METHOD_SET |
197 GST_SEEK_FLAG_FLUSH, 25 * GST_SECOND, 29 * GST_SECOND);
198 res = gst_pad_send_event (pad, event);
200 g_warning ("seek failed");
202 gst_element_set_state (pipeline, GST_STATE_PLAYING);
205 while (count++ < 500) {
206 get_position_info (cdparanoia);
207 g_usleep (G_USEC_PER_SEC / 2);
211 /* shutdown everything again */
212 gst_element_set_state (pipeline, GST_STATE_NULL);